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