bootstrap.js 61.4 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
2001
  // ===============
2002

XhmikosR's avatar
XhmikosR committed
2003
2004
2005
2006
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2007
2008


XhmikosR's avatar
XhmikosR committed
2009
2010
2011
2012
2013
2014
  // TAB DATA-API
  // ============

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

XhmikosR's avatar
XhmikosR committed
2017
}(jQuery);
2018

2019
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2020
 * Bootstrap: affix.js v3.2.0
Mark Otto's avatar
Mark Otto committed
2021
 * http://getbootstrap.com/javascript/#affix
2022
 * ========================================================================
2023
 * Copyright 2011-2014 Twitter, Inc.
2024
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2025
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2026
2027


XhmikosR's avatar
XhmikosR committed
2028
2029
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2030

XhmikosR's avatar
XhmikosR committed
2031
2032
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2033

XhmikosR's avatar
XhmikosR committed
2034
2035
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2036

XhmikosR's avatar
XhmikosR committed
2037
2038
2039
    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
2040

XhmikosR's avatar
XhmikosR committed
2041
2042
2043
2044
    this.$element     = $(element)
    this.affixed      =
    this.unpin        =
    this.pinnedOffset = null
fat's avatar
fat committed
2045

XhmikosR's avatar
XhmikosR committed
2046
2047
    this.checkPosition()
  }
fat's avatar
fat committed
2048

Mark Otto's avatar
Mark Otto committed
2049
  Affix.VERSION  = '3.2.0'
2050

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

XhmikosR's avatar
XhmikosR committed
2053
2054
2055
2056
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2057

2058
2059
2060
2061
2062
2063
2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
  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
2080
2081
2082
2083
2084
2085
2086
  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)
  }
2087

XhmikosR's avatar
XhmikosR committed
2088
2089
2090
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2091

XhmikosR's avatar
XhmikosR committed
2092
2093
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2094

2095
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2096
2097
2098
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2099
    var scrollHeight = $('body').height()
2100

XhmikosR's avatar
XhmikosR committed
2101
2102
2103
    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)
2104

2105
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2106

2107
2108
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2109

2110
2111
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2112

2113
      this.$element.trigger(e)
2114

2115
      if (e.isDefaultPrevented()) return
2116

2117
2118
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2119

2120
2121
2122
2123
2124
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2125

XhmikosR's avatar
XhmikosR committed
2126
2127
    if (affix == 'bottom') {
      this.$element.offset({
2128
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2129
      })
2130
    }
XhmikosR's avatar
XhmikosR committed
2131
  }
Mark Otto's avatar
Mark Otto committed
2132

2133

XhmikosR's avatar
XhmikosR committed
2134
2135
  // AFFIX PLUGIN DEFINITION
  // =======================
2136

XhmikosR's avatar
XhmikosR committed
2137
2138
2139
2140
2141
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2142

XhmikosR's avatar
XhmikosR committed
2143
2144
2145
2146
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2147

XhmikosR's avatar
XhmikosR committed
2148
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2149

XhmikosR's avatar
XhmikosR committed
2150
2151
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2152
2153


XhmikosR's avatar
XhmikosR committed
2154
2155
  // AFFIX NO CONFLICT
  // =================
2156

XhmikosR's avatar
XhmikosR committed
2157
2158
2159
2160
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2161
2162


XhmikosR's avatar
XhmikosR committed
2163
2164
  // AFFIX DATA-API
  // ==============
2165

XhmikosR's avatar
XhmikosR committed
2166
2167
2168
2169
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2170

XhmikosR's avatar
XhmikosR committed
2171
      data.offset = data.offset || {}
2172

XhmikosR's avatar
XhmikosR committed
2173
2174
      if (data.offsetBottom) data.offset.bottom = data.offsetBottom
      if (data.offsetTop)    data.offset.top    = data.offsetTop
2175

XhmikosR's avatar
XhmikosR committed
2176
      Plugin.call($spy, data)
2177
    })
Mark Otto's avatar
Mark Otto committed
2178
2179
  })

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