info@54: /* ======================================================================== info@54: * Bootstrap: affix.js v3.0.3 info@54: * http://getbootstrap.com/javascript/#affix info@54: * ======================================================================== info@54: * Copyright 2013 Twitter, Inc. info@54: * info@54: * Licensed under the Apache License, Version 2.0 (the "License"); info@54: * you may not use this file except in compliance with the License. info@54: * You may obtain a copy of the License at info@54: * info@54: * http://www.apache.org/licenses/LICENSE-2.0 info@54: * info@54: * Unless required by applicable law or agreed to in writing, software info@54: * distributed under the License is distributed on an "AS IS" BASIS, info@54: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. info@54: * See the License for the specific language governing permissions and info@54: * limitations under the License. info@54: * ======================================================================== */ info@54: info@54: info@54: +function ($) { "use strict"; info@54: info@54: // AFFIX CLASS DEFINITION info@54: // ====================== info@54: info@54: var Affix = function (element, options) { info@54: this.options = $.extend({}, Affix.DEFAULTS, options) info@54: this.$window = $(window) info@54: .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this)) info@54: .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this)) info@54: info@54: this.$element = $(element) info@54: this.affixed = info@54: this.unpin = null info@54: info@54: this.checkPosition() info@54: } info@54: info@54: Affix.RESET = 'affix affix-top affix-bottom' info@54: info@54: Affix.DEFAULTS = { info@54: offset: 0 info@54: } info@54: info@54: Affix.prototype.checkPositionWithEventLoop = function () { info@54: setTimeout($.proxy(this.checkPosition, this), 1) info@54: } info@54: info@54: Affix.prototype.checkPosition = function () { info@54: if (!this.$element.is(':visible')) return info@54: info@54: var scrollHeight = $(document).height() info@54: var scrollTop = this.$window.scrollTop() info@54: var position = this.$element.offset() info@54: var offset = this.options.offset info@54: var offsetTop = offset.top info@54: var offsetBottom = offset.bottom info@54: info@54: if (typeof offset != 'object') offsetBottom = offsetTop = offset info@54: if (typeof offsetTop == 'function') offsetTop = offset.top() info@54: if (typeof offsetBottom == 'function') offsetBottom = offset.bottom() info@54: info@54: var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false : info@54: offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' : info@54: offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false info@54: info@54: if (this.affixed === affix) return info@54: if (this.unpin) this.$element.css('top', '') info@54: info@54: this.affixed = affix info@54: this.unpin = affix == 'bottom' ? position.top - scrollTop : null info@54: info@54: this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : '')) info@54: info@54: if (affix == 'bottom') { info@54: this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() }) info@54: } info@54: } info@54: info@54: info@54: // AFFIX PLUGIN DEFINITION info@54: // ======================= info@54: info@54: var old = $.fn.affix info@54: info@54: $.fn.affix = function (option) { info@54: return this.each(function () { info@54: var $this = $(this) info@54: var data = $this.data('bs.affix') info@54: var options = typeof option == 'object' && option info@54: info@54: if (!data) $this.data('bs.affix', (data = new Affix(this, options))) info@54: if (typeof option == 'string') data[option]() info@54: }) info@54: } info@54: info@54: $.fn.affix.Constructor = Affix info@54: info@54: info@54: // AFFIX NO CONFLICT info@54: // ================= info@54: info@54: $.fn.affix.noConflict = function () { info@54: $.fn.affix = old info@54: return this info@54: } info@54: info@54: info@54: // AFFIX DATA-API info@54: // ============== info@54: info@54: $(window).on('load', function () { info@54: $('[data-spy="affix"]').each(function () { info@54: var $spy = $(this) info@54: var data = $spy.data() info@54: info@54: data.offset = data.offset || {} info@54: info@54: if (data.offsetBottom) data.offset.bottom = data.offsetBottom info@54: if (data.offsetTop) data.offset.top = data.offsetTop info@54: info@54: $spy.affix(data) info@54: }) info@54: }) info@54: info@54: }(jQuery);