bootstrap.js 62 KB
Newer Older
2001

XhmikosR's avatar
XhmikosR committed
2002
2003
  $.fn.tab             = Plugin
  $.fn.tab.Constructor = Tab
2004

2005

XhmikosR's avatar
XhmikosR committed
2006
2007
  // TAB NO CONFLICT
  // ===============
2008

XhmikosR's avatar
XhmikosR committed
2009
2010
2011
2012
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2013
2014


XhmikosR's avatar
XhmikosR committed
2015
2016
2017
2018
2019
2020
  // TAB DATA-API
  // ============

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

XhmikosR's avatar
XhmikosR committed
2023
}(jQuery);
2024

2025
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2026
 * Bootstrap: affix.js v3.2.0
Mark Otto's avatar
Mark Otto committed
2027
 * http://getbootstrap.com/javascript/#affix
2028
 * ========================================================================
2029
 * Copyright 2011-2014 Twitter, Inc.
2030
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2031
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2032
2033


XhmikosR's avatar
XhmikosR committed
2034
2035
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2036

XhmikosR's avatar
XhmikosR committed
2037
2038
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2039

XhmikosR's avatar
XhmikosR committed
2040
2041
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2042

XhmikosR's avatar
XhmikosR committed
2043
2044
2045
    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
2046

XhmikosR's avatar
XhmikosR committed
2047
2048
2049
2050
    this.$element     = $(element)
    this.affixed      =
    this.unpin        =
    this.pinnedOffset = null
fat's avatar
fat committed
2051

XhmikosR's avatar
XhmikosR committed
2052
2053
    this.checkPosition()
  }
fat's avatar
fat committed
2054

Mark Otto's avatar
Mark Otto committed
2055
  Affix.VERSION  = '3.2.0'
2056

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

XhmikosR's avatar
XhmikosR committed
2059
2060
2061
2062
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2063

2064
2065
2066
2067
2068
2069
2070
2071
2072
2073
2074
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
  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
2086
2087
2088
2089
2090
2091
2092
  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)
  }
2093

XhmikosR's avatar
XhmikosR committed
2094
2095
2096
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2097

XhmikosR's avatar
XhmikosR committed
2098
2099
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2100

2101
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2102
2103
2104
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2105
    var scrollHeight = $('body').height()
2106

XhmikosR's avatar
XhmikosR committed
2107
2108
2109
    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)
2110

2111
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2112

2113
2114
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2115

2116
2117
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2118

2119
      this.$element.trigger(e)
2120

2121
      if (e.isDefaultPrevented()) return
2122

2123
2124
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2125

2126
2127
2128
2129
2130
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2131

XhmikosR's avatar
XhmikosR committed
2132
2133
    if (affix == 'bottom') {
      this.$element.offset({
2134
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2135
      })
2136
    }
XhmikosR's avatar
XhmikosR committed
2137
  }
Mark Otto's avatar
Mark Otto committed
2138

2139

XhmikosR's avatar
XhmikosR committed
2140
2141
  // AFFIX PLUGIN DEFINITION
  // =======================
2142

XhmikosR's avatar
XhmikosR committed
2143
2144
2145
2146
2147
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2148

XhmikosR's avatar
XhmikosR committed
2149
2150
2151
2152
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2153

XhmikosR's avatar
XhmikosR committed
2154
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2155

XhmikosR's avatar
XhmikosR committed
2156
2157
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2158
2159


XhmikosR's avatar
XhmikosR committed
2160
2161
  // AFFIX NO CONFLICT
  // =================
2162

XhmikosR's avatar
XhmikosR committed
2163
2164
2165
2166
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2167
2168


XhmikosR's avatar
XhmikosR committed
2169
2170
  // AFFIX DATA-API
  // ==============
2171

XhmikosR's avatar
XhmikosR committed
2172
2173
2174
2175
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2176

XhmikosR's avatar
XhmikosR committed
2177
      data.offset = data.offset || {}
2178

Heinrich Fenkart's avatar
Heinrich Fenkart committed
2179
2180
      if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
      if (data.offsetTop    != null) data.offset.top    = data.offsetTop
2181

XhmikosR's avatar
XhmikosR committed
2182
      Plugin.call($spy, data)
2183
    })
Mark Otto's avatar
Mark Otto committed
2184
2185
  })

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