2013-05-21 22:30:33 -04:00
|
|
|
/* ========================================================================
|
2014-01-30 11:30:37 -05:00
|
|
|
* Bootstrap: affix.js v3.1.0
|
2013-10-29 13:10:47 -04:00
|
|
|
* http://getbootstrap.com/javascript/#affix
|
2013-05-21 22:30:33 -04:00
|
|
|
* ========================================================================
|
2014-01-06 19:05:24 -05:00
|
|
|
* Copyright 2011-2014 Twitter, Inc.
|
2013-12-18 18:28:08 -05:00
|
|
|
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
|
2013-05-21 22:30:33 -04:00
|
|
|
* ======================================================================== */
|
2012-07-22 21:28:39 -04:00
|
|
|
|
|
|
|
|
2014-01-01 09:42:41 -05:00
|
|
|
+function ($) {
|
|
|
|
'use strict';
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
// AFFIX CLASS DEFINITION
|
|
|
|
// ======================
|
2012-07-22 21:28:39 -04:00
|
|
|
|
|
|
|
var Affix = function (element, options) {
|
2013-05-16 14:06:30 -04:00
|
|
|
this.options = $.extend({}, Affix.DEFAULTS, options)
|
2012-09-25 02:59:02 -04:00
|
|
|
this.$window = $(window)
|
2013-05-16 23:19:51 -04:00
|
|
|
.on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
|
|
|
|
.on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
|
2013-05-16 14:06:30 -04:00
|
|
|
|
2013-12-24 15:32:06 -05:00
|
|
|
this.$element = $(element)
|
|
|
|
this.affixed =
|
|
|
|
this.unpin =
|
|
|
|
this.pinnedOffset = null
|
2013-05-16 14:06:30 -04:00
|
|
|
|
2012-08-15 00:23:29 -04:00
|
|
|
this.checkPosition()
|
2012-07-22 21:28:39 -04:00
|
|
|
}
|
|
|
|
|
2013-07-26 02:30:13 -04:00
|
|
|
Affix.RESET = 'affix affix-top affix-bottom'
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
Affix.DEFAULTS = {
|
|
|
|
offset: 0
|
|
|
|
}
|
|
|
|
|
2013-12-24 15:32:06 -05:00
|
|
|
Affix.prototype.getPinnedOffset = function () {
|
|
|
|
if (this.pinnedOffset) return this.pinnedOffset
|
|
|
|
this.$element.removeClass(Affix.RESET).addClass('affix')
|
|
|
|
var scrollTop = this.$window.scrollTop()
|
|
|
|
var position = this.$element.offset()
|
|
|
|
return (this.pinnedOffset = position.top - scrollTop)
|
|
|
|
}
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
Affix.prototype.checkPositionWithEventLoop = function () {
|
|
|
|
setTimeout($.proxy(this.checkPosition, this), 1)
|
|
|
|
}
|
|
|
|
|
2012-07-22 21:28:39 -04:00
|
|
|
Affix.prototype.checkPosition = function () {
|
|
|
|
if (!this.$element.is(':visible')) return
|
|
|
|
|
2012-08-15 00:06:08 -04:00
|
|
|
var scrollHeight = $(document).height()
|
2013-05-16 14:06:30 -04:00
|
|
|
var scrollTop = this.$window.scrollTop()
|
|
|
|
var position = this.$element.offset()
|
|
|
|
var offset = this.options.offset
|
|
|
|
var offsetTop = offset.top
|
|
|
|
var offsetBottom = offset.bottom
|
|
|
|
|
2013-12-24 15:32:06 -05:00
|
|
|
if (this.affixed == 'top') position.top += scrollTop
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
if (typeof offset != 'object') offsetBottom = offsetTop = offset
|
2013-09-01 21:24:27 -04:00
|
|
|
if (typeof offsetTop == 'function') offsetTop = offset.top(this.$element)
|
|
|
|
if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element)
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false :
|
|
|
|
offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' :
|
|
|
|
offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2012-08-15 00:06:08 -04:00
|
|
|
if (this.affixed === affix) return
|
2013-07-26 02:30:13 -04:00
|
|
|
if (this.unpin) this.$element.css('top', '')
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2013-12-24 19:29:51 -05:00
|
|
|
var affixType = 'affix' + (affix ? '-' + affix : '')
|
|
|
|
var e = $.Event(affixType + '.bs.affix')
|
|
|
|
|
|
|
|
this.$element.trigger(e)
|
|
|
|
|
|
|
|
if (e.isDefaultPrevented()) return
|
|
|
|
|
2012-07-22 21:28:39 -04:00
|
|
|
this.affixed = affix
|
2013-12-24 15:32:06 -05:00
|
|
|
this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2013-12-24 19:29:51 -05:00
|
|
|
this.$element
|
|
|
|
.removeClass(Affix.RESET)
|
|
|
|
.addClass(affixType)
|
|
|
|
.trigger($.Event(affixType.replace('affix', 'affixed')))
|
2013-07-26 02:30:13 -04:00
|
|
|
|
|
|
|
if (affix == 'bottom') {
|
2013-12-05 10:28:31 -05:00
|
|
|
this.$element.offset({ top: scrollHeight - offsetBottom - this.$element.height() })
|
2013-07-26 02:30:13 -04:00
|
|
|
}
|
2012-07-22 21:28:39 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
// AFFIX PLUGIN DEFINITION
|
|
|
|
// =======================
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2012-12-07 17:06:01 -05:00
|
|
|
var old = $.fn.affix
|
|
|
|
|
2012-07-22 21:28:39 -04:00
|
|
|
$.fn.affix = function (option) {
|
|
|
|
return this.each(function () {
|
2013-05-16 14:06:30 -04:00
|
|
|
var $this = $(this)
|
2013-05-16 23:19:51 -04:00
|
|
|
var data = $this.data('bs.affix')
|
2013-05-16 14:06:30 -04:00
|
|
|
var options = typeof option == 'object' && option
|
|
|
|
|
2013-05-16 23:19:51 -04:00
|
|
|
if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
|
2012-07-22 21:28:39 -04:00
|
|
|
if (typeof option == 'string') data[option]()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
$.fn.affix.Constructor = Affix
|
|
|
|
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
// AFFIX NO CONFLICT
|
|
|
|
// =================
|
2012-12-07 17:06:01 -05:00
|
|
|
|
|
|
|
$.fn.affix.noConflict = function () {
|
|
|
|
$.fn.affix = old
|
|
|
|
return this
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
// AFFIX DATA-API
|
|
|
|
// ==============
|
2012-07-22 21:28:39 -04:00
|
|
|
|
2012-08-15 00:06:08 -04:00
|
|
|
$(window).on('load', function () {
|
2012-07-22 21:28:39 -04:00
|
|
|
$('[data-spy="affix"]').each(function () {
|
|
|
|
var $spy = $(this)
|
2013-05-16 14:06:30 -04:00
|
|
|
var data = $spy.data()
|
2012-07-23 21:17:43 -04:00
|
|
|
|
2012-07-22 21:28:39 -04:00
|
|
|
data.offset = data.offset || {}
|
|
|
|
|
2013-05-16 14:06:30 -04:00
|
|
|
if (data.offsetBottom) data.offset.bottom = data.offsetBottom
|
|
|
|
if (data.offsetTop) data.offset.top = data.offsetTop
|
2012-07-22 21:28:39 -04:00
|
|
|
|
|
|
|
$spy.affix(data)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2013-08-22 14:50:15 -04:00
|
|
|
}(jQuery);
|