Skip to content

Commit

Permalink
some progress on affix plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
fat committed Jul 23, 2012
1 parent fa1e1e3 commit dcf7569
Show file tree
Hide file tree
Showing 39 changed files with 503 additions and 221 deletions.
4 changes: 4 additions & 0 deletions docs/assets/css/bootstrap.css
Original file line number Diff line number Diff line change
Expand Up @@ -5501,3 +5501,7 @@ a.badge:hover {
.invisible {
visibility: hidden;
}

.affix {
position: fixed;
}
17 changes: 17 additions & 0 deletions docs/assets/css/docs.css
Original file line number Diff line number Diff line change
Expand Up @@ -891,6 +891,7 @@ form.bs-docs-example {
margin-right: 10px;
background-color: #fff;
border: 1px solid #e5e5e5;
margin-left: 0;
-webkit-border-radius: 6px;
-moz-border-radius: 6px;
border-radius: 6px;
Expand Down Expand Up @@ -930,11 +931,27 @@ form.bs-docs-example {
opacity: .75;
}

.bs-docs-sidenav.affix {
top: 40px;
}

@media (max-width: 979px) {

.bs-docs-sidenav.affix {
top: 0px;
}

.bs-docs-sidenav {
margin-top: 30px;
margin-right: 0;
}

}

@media (max-width: 767px) {

.bs-docs-sidenav.affix {
position: relative;
}

}
26 changes: 0 additions & 26 deletions docs/assets/js/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -43,32 +43,6 @@
})
}

// fix sub nav on scroll
var $win = $(window)
, $nav = $('.subhead .navbar-subnav')
, navTop = $('.subhead .navbar-subnav').length && $('.subhead .navbar-subnav').offset().top - 40
, isFixed = 0

processScroll()

// hack sad times - holdover until rewrite for 2.1
$nav.on('click', function () {
if (!isFixed) setTimeout(function () { $win.scrollTop($win.scrollTop() - 47) }, 10)
})

$win.on('scroll', processScroll)

function processScroll() {
var i, scrollTop = $win.scrollTop()
if (scrollTop >= navTop && !isFixed) {
isFixed = 1
$nav.addClass('navbar-subnav-fixed')
} else if (scrollTop <= navTop && isFixed) {
isFixed = 0
$nav.removeClass('navbar-subnav-fixed')
}
}

// tooltip demo
$('.tooltip-demo').tooltip({
selector: "a[rel=tooltip]"
Expand Down
104 changes: 104 additions & 0 deletions docs/assets/js/bootstrap-affix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
/* ==========================================================
* bootstrap-affix.js v2.1.0
* http://twitter.github.com/bootstrap/javascript.html#affix
* ==========================================================
* Copyright 2012 Twitter, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
* ========================================================== */


!function ($) {

"use strict"; // jshint ;_;


/* AFFIX CLASS DEFINITION
* ====================== */

var Affix = function (element, options) {
this.options = $.extend({}, $.fn.affix.defaults, options)
this.$window = $(window)
.on('scroll.affix.data-api', $.proxy(this.checkPosition, this))
.on('resize.affix.data-api', $.proxy(this.refresh, this))
this.$element = $(element)
this.refresh()
}

Affix.prototype.refresh = function () {
this.position = this.$element.offset()
}

Affix.prototype.checkPosition = function () {
if (!this.$element.is(':visible')) return

var scrollLeft = this.$window.scrollLeft()
, scrollTop = this.$window.scrollTop()
, position = this.position
, offset = this.options.offset
, affix

if (typeof offset != 'object') offset = { x: offset, y: offset }


affix = (offset.x == null || (position.left - scrollLeft <= offset.x))
&& (offset.y == null || (position.top - scrollTop <= offset.y))

if (affix == this.affixed) return

this.affixed = affix

this.$element[affix ? 'addClass' : 'removeClass']('affix')
}


/* AFFIX PLUGIN DEFINITION
* ======================= */

$.fn.affix = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('affix')
, options = typeof option == 'object' && option
if (!data) $this.data('affix', (data = new Affix(this, options)))
if (typeof option == 'string') data[option]()
})
}

$.fn.affix.Constructor = Affix

$.fn.affix.defaults = {
offset: 0
}



/* AFFIX DATA-API
* ============== */

$(function () {
$('[data-spy="affix"]').each(function () {
var $spy = $(this)
, data = $spy.data()

data.offset = data.offset || {}

data.offsetX && (data.offset.x = data.offsetX)
data.offsetY && (data.offset.y = data.offsetY)

$spy.affix(data)
})
})


}(window.jQuery);
4 changes: 2 additions & 2 deletions docs/assets/js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,9 @@
/* MODAL CLASS DEFINITION
* ====================== */

var Modal = function (content, options) {
var Modal = function (element, options) {
this.options = options
this.$element = $(content)
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
}
Expand Down
4 changes: 2 additions & 2 deletions docs/assets/js/bootstrap-popover.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* POPOVER PUBLIC CLASS DEFINITION
* =============================== */

var Popover = function ( element, options ) {
var Popover = function (element, options) {
this.init('popover', element, options)
}

Expand Down Expand Up @@ -72,7 +72,7 @@
}

, destroy: function () {
this.$element.off().removeData('popover')
this.hide().$element.off('.' + this.type).removeData(this.type)
}

})
Expand Down
12 changes: 6 additions & 6 deletions docs/assets/js/bootstrap-scrollspy.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,15 @@
"use strict"; // jshint ;_;


/* SCROLLSPY CLASS DEFINITION
* ========================== */
/* SCROLLSPY CLASS DEFINITION
* ========================== */

function ScrollSpy( element, options) {
function ScrollSpy(element, options) {
var process = $.proxy(this.process, this)
, $element = $(element).is('body') ? $(window) : $(element)
, href
this.options = $.extend({}, $.fn.scrollspy.defaults, options)
this.$scrollElement = $element.on('scroll.scroll.data-api', process)
this.$scrollElement = $element.on('scroll.scroll-spy.data-api', process)
this.selector = (this.options.target
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|| '') + ' .nav li > a'
Expand Down Expand Up @@ -121,7 +121,7 @@
/* SCROLLSPY PLUGIN DEFINITION
* =========================== */

$.fn.scrollspy = function ( option ) {
$.fn.scrollspy = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('scrollspy')
Expand All @@ -141,7 +141,7 @@
/* SCROLLSPY DATA-API
* ================== */

$(function () {
$(window).on('load', function () {
$('[data-spy="scroll"]').each(function () {
var $spy = $(this)
$spy.scrollspy($spy.data())
Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/bootstrap-tab.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
/* TAB CLASS DEFINITION
* ==================== */

var Tab = function ( element ) {
var Tab = function (element) {
this.element = $(element)
}

Expand Down
8 changes: 5 additions & 3 deletions docs/assets/js/bootstrap-tooltip.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
}

this.options.selector ?
Expand Down Expand Up @@ -176,6 +176,8 @@
$.support.transition && this.$tip.hasClass('fade') ?
removeWithAnimation() :
$tip.remove()

return this
}

, fixTitle: function () {
Expand Down Expand Up @@ -236,7 +238,7 @@
}

, destroy: function () {
this.$element.off().removeData('tooltip')
this.hide().$element.off('.' + this.type).removeData(this.type)
}

}
Expand Down
30 changes: 16 additions & 14 deletions docs/assets/js/bootstrap.js
Original file line number Diff line number Diff line change
Expand Up @@ -751,9 +751,9 @@
/* MODAL CLASS DEFINITION
* ====================== */

var Modal = function (content, options) {
var Modal = function (element, options) {
this.options = options
this.$element = $(content)
this.$element = $(element)
.delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
}
Expand Down Expand Up @@ -1000,8 +1000,8 @@
if (this.options.trigger != 'manual') {
eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
}

this.options.selector ?
Expand Down Expand Up @@ -1129,6 +1129,8 @@
$.support.transition && this.$tip.hasClass('fade') ?
removeWithAnimation() :
$tip.remove()

return this
}

, fixTitle: function () {
Expand Down Expand Up @@ -1189,7 +1191,7 @@
}

, destroy: function () {
this.$element.off().removeData('tooltip')
this.hide().$element.off('.' + this.type).removeData(this.type)
}

}
Expand Down Expand Up @@ -1250,7 +1252,7 @@
/* POPOVER PUBLIC CLASS DEFINITION
* =============================== */

var Popover = function ( element, options ) {
var Popover = function (element, options) {
this.init('popover', element, options)
}

Expand Down Expand Up @@ -1296,7 +1298,7 @@
}

, destroy: function () {
this.$element.off().removeData('popover')
this.hide().$element.off('.' + this.type).removeData(this.type)
}

})
Expand Down Expand Up @@ -1348,15 +1350,15 @@
"use strict"; // jshint ;_;


/* SCROLLSPY CLASS DEFINITION
* ========================== */
/* SCROLLSPY CLASS DEFINITION
* ========================== */

function ScrollSpy( element, options) {
function ScrollSpy(element, options) {
var process = $.proxy(this.process, this)
, $element = $(element).is('body') ? $(window) : $(element)
, href
this.options = $.extend({}, $.fn.scrollspy.defaults, options)
this.$scrollElement = $element.on('scroll.scroll.data-api', process)
this.$scrollElement = $element.on('scroll.scroll-spy.data-api', process)
this.selector = (this.options.target
|| ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
|| '') + ' .nav li > a'
Expand Down Expand Up @@ -1446,7 +1448,7 @@
/* SCROLLSPY PLUGIN DEFINITION
* =========================== */

$.fn.scrollspy = function ( option ) {
$.fn.scrollspy = function (option) {
return this.each(function () {
var $this = $(this)
, data = $this.data('scrollspy')
Expand All @@ -1466,7 +1468,7 @@
/* SCROLLSPY DATA-API
* ================== */

$(function () {
$(window).on('load', function () {
$('[data-spy="scroll"]').each(function () {
var $spy = $(this)
$spy.scrollspy($spy.data())
Expand Down Expand Up @@ -1501,7 +1503,7 @@
/* TAB CLASS DEFINITION
* ==================== */

var Tab = function ( element ) {
var Tab = function (element) {
this.element = $(element)
}

Expand Down
2 changes: 1 addition & 1 deletion docs/assets/js/bootstrap.min.js

Large diffs are not rendered by default.

Loading

0 comments on commit dcf7569

Please sign in to comment.