bootstrap.js 61.2 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
2001
2002
2003
2004
2005
2006
  // TAB DATA-API
  // ============

  $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
    e.preventDefault()
    Plugin.call($(this), 'show')
2007
2008
  })

XhmikosR's avatar
XhmikosR committed
2009
}(jQuery);
2010

2011
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2012
 * Bootstrap: affix.js v3.2.0
Mark Otto's avatar
Mark Otto committed
2013
 * http://getbootstrap.com/javascript/#affix
2014
 * ========================================================================
2015
 * Copyright 2011-2014 Twitter, Inc.
2016
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2017
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2018
2019


XhmikosR's avatar
XhmikosR committed
2020
2021
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2022

XhmikosR's avatar
XhmikosR committed
2023
2024
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2025

XhmikosR's avatar
XhmikosR committed
2026
2027
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2028

XhmikosR's avatar
XhmikosR committed
2029
2030
2031
    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))
Chris Rebert's avatar
Chris Rebert committed
2032

XhmikosR's avatar
XhmikosR committed
2033
2034
2035
2036
    this.$element     = $(element)
    this.affixed      =
    this.unpin        =
    this.pinnedOffset = null
fat's avatar
fat committed
2037

XhmikosR's avatar
XhmikosR committed
2038
2039
    this.checkPosition()
  }
fat's avatar
fat committed
2040

Mark Otto's avatar
Mark Otto committed
2041
  Affix.VERSION  = '3.2.0'
2042

XhmikosR's avatar
XhmikosR committed
2043
  Affix.RESET    = 'affix affix-top affix-bottom'
Mark Otto's avatar
grunt    
Mark Otto committed
2044

XhmikosR's avatar
XhmikosR committed
2045
2046
2047
2048
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2049

2050
2051
2052
2053
2054
2055
2056
2057
2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
  Affix.prototype.getState = function (scrollHeight, height, offsetTop, offsetBottom) {
    var scrollTop    = this.$target.scrollTop()
    var position     = this.$element.offset()
    var targetHeight = this.$target.height()

    if (offsetTop != null && this.affixed == 'top') return scrollTop < offsetTop ? 'top' : false

    if (this.affixed == 'bottom') {
      if (offsetTop != null) return (scrollTop + this.unpin <= position.top) ? false : 'bottom'
      return (scrollTop + targetHeight <= scrollHeight - offsetBottom) ? false : 'bottom'
    }

    var initializing   = this.affixed == null
    var colliderTop    = initializing ? scrollTop : position.top
    var colliderHeight = initializing ? targetHeight : height

    if (offsetTop != null && colliderTop <= offsetTop) return 'top'
    if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'

    return false
  }

XhmikosR's avatar
XhmikosR committed
2072
2073
2074
2075
2076
2077
2078
  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)
  }
2079

XhmikosR's avatar
XhmikosR committed
2080
2081
2082
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2083

XhmikosR's avatar
XhmikosR committed
2084
2085
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2086

2087
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2088
2089
2090
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2091
    var scrollHeight = $('body').height()
2092

XhmikosR's avatar
XhmikosR committed
2093
2094
2095
    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)
2096

2097
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2098

2099
2100
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2101

2102
2103
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2104

2105
      this.$element.trigger(e)
2106

2107
      if (e.isDefaultPrevented()) return
2108

2109
2110
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2111

2112
2113
2114
2115
2116
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2117

XhmikosR's avatar
XhmikosR committed
2118
2119
    if (affix == 'bottom') {
      this.$element.offset({
2120
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2121
      })
2122
    }
XhmikosR's avatar
XhmikosR committed
2123
  }
Mark Otto's avatar
Mark Otto committed
2124

2125

XhmikosR's avatar
XhmikosR committed
2126
2127
  // AFFIX PLUGIN DEFINITION
  // =======================
2128

XhmikosR's avatar
XhmikosR committed
2129
2130
2131
2132
2133
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2134

XhmikosR's avatar
XhmikosR committed
2135
2136
2137
2138
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2139

XhmikosR's avatar
XhmikosR committed
2140
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2141

XhmikosR's avatar
XhmikosR committed
2142
2143
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2144
2145


XhmikosR's avatar
XhmikosR committed
2146
2147
  // AFFIX NO CONFLICT
  // =================
2148

XhmikosR's avatar
XhmikosR committed
2149
2150
2151
2152
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2153
2154


XhmikosR's avatar
XhmikosR committed
2155
2156
  // AFFIX DATA-API
  // ==============
2157

XhmikosR's avatar
XhmikosR committed
2158
2159
2160
2161
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2162

XhmikosR's avatar
XhmikosR committed
2163
      data.offset = data.offset || {}
2164

XhmikosR's avatar
XhmikosR committed
2165
2166
      if (data.offsetBottom) data.offset.bottom = data.offsetBottom
      if (data.offsetTop)    data.offset.top    = data.offsetTop
2167

XhmikosR's avatar
XhmikosR committed
2168
      Plugin.call($spy, data)
2169
    })
Mark Otto's avatar
Mark Otto committed
2170
2171
  })

XhmikosR's avatar
XhmikosR committed
2172
}(jQuery);
For faster browsing, not all history is shown. View entire blame