js/bootstrap-affix.js
changeset 0 ba8ab09f730e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/js/bootstrap-affix.js	Fri Jul 04 16:42:41 2014 +0400
     1.3 @@ -0,0 +1,117 @@
     1.4 +/* ==========================================================
     1.5 + * bootstrap-affix.js v2.3.1
     1.6 + * http://twitter.github.com/bootstrap/javascript.html#affix
     1.7 + * ==========================================================
     1.8 + * Copyright 2012 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 ($) {
    1.25 +
    1.26 +  "use strict"; // jshint ;_;
    1.27 +
    1.28 +
    1.29 + /* AFFIX CLASS DEFINITION
    1.30 +  * ====================== */
    1.31 +
    1.32 +  var Affix = function (element, options) {
    1.33 +    this.options = $.extend({}, $.fn.affix.defaults, options)
    1.34 +    this.$window = $(window)
    1.35 +      .on('scroll.affix.data-api', $.proxy(this.checkPosition, this))
    1.36 +      .on('click.affix.data-api',  $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this))
    1.37 +    this.$element = $(element)
    1.38 +    this.checkPosition()
    1.39 +  }
    1.40 +
    1.41 +  Affix.prototype.checkPosition = function () {
    1.42 +    if (!this.$element.is(':visible')) return
    1.43 +
    1.44 +    var scrollHeight = $(document).height()
    1.45 +      , scrollTop = this.$window.scrollTop()
    1.46 +      , position = this.$element.offset()
    1.47 +      , offset = this.options.offset
    1.48 +      , offsetBottom = offset.bottom
    1.49 +      , offsetTop = offset.top
    1.50 +      , reset = 'affix affix-top affix-bottom'
    1.51 +      , affix
    1.52 +
    1.53 +    if (typeof offset != 'object') offsetBottom = offsetTop = offset
    1.54 +    if (typeof offsetTop == 'function') offsetTop = offset.top()
    1.55 +    if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
    1.56 +
    1.57 +    affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ?
    1.58 +      false    : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ?
    1.59 +      'bottom' : offsetTop != null && scrollTop <= offsetTop ?
    1.60 +      'top'    : false
    1.61 +
    1.62 +    if (this.affixed === affix) return
    1.63 +
    1.64 +    this.affixed = affix
    1.65 +    this.unpin = affix == 'bottom' ? position.top - scrollTop : null
    1.66 +
    1.67 +    this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''))
    1.68 +  }
    1.69 +
    1.70 +
    1.71 + /* AFFIX PLUGIN DEFINITION
    1.72 +  * ======================= */
    1.73 +
    1.74 +  var old = $.fn.affix
    1.75 +
    1.76 +  $.fn.affix = function (option) {
    1.77 +    return this.each(function () {
    1.78 +      var $this = $(this)
    1.79 +        , data = $this.data('affix')
    1.80 +        , options = typeof option == 'object' && option
    1.81 +      if (!data) $this.data('affix', (data = new Affix(this, options)))
    1.82 +      if (typeof option == 'string') data[option]()
    1.83 +    })
    1.84 +  }
    1.85 +
    1.86 +  $.fn.affix.Constructor = Affix
    1.87 +
    1.88 +  $.fn.affix.defaults = {
    1.89 +    offset: 0
    1.90 +  }
    1.91 +
    1.92 +
    1.93 + /* AFFIX NO CONFLICT
    1.94 +  * ================= */
    1.95 +
    1.96 +  $.fn.affix.noConflict = function () {
    1.97 +    $.fn.affix = old
    1.98 +    return this
    1.99 +  }
   1.100 +
   1.101 +
   1.102 + /* AFFIX DATA-API
   1.103 +  * ============== */
   1.104 +
   1.105 +  $(window).on('load', function () {
   1.106 +    $('[data-spy="affix"]').each(function () {
   1.107 +      var $spy = $(this)
   1.108 +        , data = $spy.data()
   1.109 +
   1.110 +      data.offset = data.offset || {}
   1.111 +
   1.112 +      data.offsetBottom && (data.offset.bottom = data.offsetBottom)
   1.113 +      data.offsetTop && (data.offset.top = data.offsetTop)
   1.114 +
   1.115 +      $spy.affix(data)
   1.116 +    })
   1.117 +  })
   1.118 +
   1.119 +
   1.120 +}(window.jQuery);
   1.121 \ No newline at end of file