1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/bootstrap-source/bootstrap-3.0.3/js/affix.js Fri Dec 20 22:49:16 2013 +0100
1.3 @@ -0,0 +1,126 @@
1.4 +/* ========================================================================
1.5 + * Bootstrap: affix.js v3.0.3
1.6 + * http://getbootstrap.com/javascript/#affix
1.7 + * ========================================================================
1.8 + * Copyright 2013 Twitter, Inc.
1.9 + *
1.10 + * Licensed under the Apache License, Version 2.0 (the "License");
1.11 + * you may not use this file except in compliance with the License.
1.12 + * You may obtain a copy of the License at
1.13 + *
1.14 + * http://www.apache.org/licenses/LICENSE-2.0
1.15 + *
1.16 + * Unless required by applicable law or agreed to in writing, software
1.17 + * distributed under the License is distributed on an "AS IS" BASIS,
1.18 + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1.19 + * See the License for the specific language governing permissions and
1.20 + * limitations under the License.
1.21 + * ======================================================================== */
1.22 +
1.23 +
1.24 ++function ($) { "use strict";
1.25 +
1.26 + // AFFIX CLASS DEFINITION
1.27 + // ======================
1.28 +
1.29 + var Affix = function (element, options) {
1.30 + this.options = $.extend({}, Affix.DEFAULTS, options)
1.31 + this.$window = $(window)
1.32 + .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
1.33 + .on('click.bs.affix.data-api', $.proxy(this.checkPositionWithEventLoop, this))
1.34 +
1.35 + this.$element = $(element)
1.36 + this.affixed =
1.37 + this.unpin = null
1.38 +
1.39 + this.checkPosition()
1.40 + }
1.41 +
1.42 + Affix.RESET = 'affix affix-top affix-bottom'
1.43 +
1.44 + Affix.DEFAULTS = {
1.45 + offset: 0
1.46 + }
1.47 +
1.48 + Affix.prototype.checkPositionWithEventLoop = function () {
1.49 + setTimeout($.proxy(this.checkPosition, this), 1)
1.50 + }
1.51 +
1.52 + Affix.prototype.checkPosition = function () {
1.53 + if (!this.$element.is(':visible')) return
1.54 +
1.55 + var scrollHeight = $(document).height()
1.56 + var scrollTop = this.$window.scrollTop()
1.57 + var position = this.$element.offset()
1.58 + var offset = this.options.offset
1.59 + var offsetTop = offset.top
1.60 + var offsetBottom = offset.bottom
1.61 +
1.62 + if (typeof offset != 'object') offsetBottom = offsetTop = offset
1.63 + if (typeof offsetTop == 'function') offsetTop = offset.top()
1.64 + if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
1.65 +
1.66 + var affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ? false :
1.67 + offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' :
1.68 + offsetTop != null && (scrollTop <= offsetTop) ? 'top' : false
1.69 +
1.70 + if (this.affixed === affix) return
1.71 + if (this.unpin) this.$element.css('top', '')
1.72 +
1.73 + this.affixed = affix
1.74 + this.unpin = affix == 'bottom' ? position.top - scrollTop : null
1.75 +
1.76 + this.$element.removeClass(Affix.RESET).addClass('affix' + (affix ? '-' + affix : ''))
1.77 +
1.78 + if (affix == 'bottom') {
1.79 + this.$element.offset({ top: document.body.offsetHeight - offsetBottom - this.$element.height() })
1.80 + }
1.81 + }
1.82 +
1.83 +
1.84 + // AFFIX PLUGIN DEFINITION
1.85 + // =======================
1.86 +
1.87 + var old = $.fn.affix
1.88 +
1.89 + $.fn.affix = function (option) {
1.90 + return this.each(function () {
1.91 + var $this = $(this)
1.92 + var data = $this.data('bs.affix')
1.93 + var options = typeof option == 'object' && option
1.94 +
1.95 + if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
1.96 + if (typeof option == 'string') data[option]()
1.97 + })
1.98 + }
1.99 +
1.100 + $.fn.affix.Constructor = Affix
1.101 +
1.102 +
1.103 + // AFFIX NO CONFLICT
1.104 + // =================
1.105 +
1.106 + $.fn.affix.noConflict = function () {
1.107 + $.fn.affix = old
1.108 + return this
1.109 + }
1.110 +
1.111 +
1.112 + // AFFIX DATA-API
1.113 + // ==============
1.114 +
1.115 + $(window).on('load', function () {
1.116 + $('[data-spy="affix"]').each(function () {
1.117 + var $spy = $(this)
1.118 + var data = $spy.data()
1.119 +
1.120 + data.offset = data.offset || {}
1.121 +
1.122 + if (data.offsetBottom) data.offset.bottom = data.offsetBottom
1.123 + if (data.offsetTop) data.offset.top = data.offsetTop
1.124 +
1.125 + $spy.affix(data)
1.126 + })
1.127 + })
1.128 +
1.129 +}(jQuery);