bootstrap.js 66 KB
Newer Older
2001

2002
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2003
 * Bootstrap: tab.js v3.3.2
Mark Otto's avatar
Mark Otto committed
2004
 * http://getbootstrap.com/javascript/#tabs
2005
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2006
 * Copyright 2011-2015 Twitter, Inc.
2007
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2008
 * ======================================================================== */
2009

2010

XhmikosR's avatar
XhmikosR committed
2011
2012
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2013

XhmikosR's avatar
XhmikosR committed
2014
2015
  // TAB CLASS DEFINITION
  // ====================
2016

XhmikosR's avatar
XhmikosR committed
2017
2018
2019
  var Tab = function (element) {
    this.element = $(element)
  }
2020

Mark Otto's avatar
Mark Otto committed
2021
  Tab.VERSION = '3.3.2'
Mark Otto's avatar
grunt    
Mark Otto committed
2022

2023
2024
  Tab.TRANSITION_DURATION = 150

XhmikosR's avatar
XhmikosR committed
2025
2026
2027
2028
  Tab.prototype.show = function () {
    var $this    = this.element
    var $ul      = $this.closest('ul:not(.dropdown-menu)')
    var selector = $this.data('target')
2029

XhmikosR's avatar
XhmikosR committed
2030
2031
2032
2033
    if (!selector) {
      selector = $this.attr('href')
      selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
    }
2034

XhmikosR's avatar
XhmikosR committed
2035
    if ($this.parent('li').hasClass('active')) return
2036

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2037
2038
2039
2040
2041
2042
    var $previous = $ul.find('.active:last a')
    var hideEvent = $.Event('hide.bs.tab', {
      relatedTarget: $this[0]
    })
    var showEvent = $.Event('show.bs.tab', {
      relatedTarget: $previous[0]
XhmikosR's avatar
XhmikosR committed
2043
    })
2044

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2045
2046
    $previous.trigger(hideEvent)
    $this.trigger(showEvent)
2047

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2048
    if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
2049

XhmikosR's avatar
XhmikosR committed
2050
    var $target = $(selector)
2051

XhmikosR's avatar
XhmikosR committed
2052
2053
    this.activate($this.closest('li'), $ul)
    this.activate($target, $target.parent(), function () {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2054
2055
2056
2057
      $previous.trigger({
        type: 'hidden.bs.tab',
        relatedTarget: $this[0]
      })
XhmikosR's avatar
XhmikosR committed
2058
2059
      $this.trigger({
        type: 'shown.bs.tab',
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2060
        relatedTarget: $previous[0]
2061
      })
XhmikosR's avatar
XhmikosR committed
2062
2063
    })
  }
2064

XhmikosR's avatar
XhmikosR committed
2065
2066
2067
2068
  Tab.prototype.activate = function (element, container, callback) {
    var $active    = container.find('> .active')
    var transition = callback
      && $.support.transition
Mark Otto's avatar
grunt    
Mark Otto committed
2069
      && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
2070

XhmikosR's avatar
XhmikosR committed
2071
2072
2073
2074
    function next() {
      $active
        .removeClass('active')
        .find('> .dropdown-menu > .active')
Mark Otto's avatar
grunt    
Mark Otto committed
2075
2076
2077
2078
          .removeClass('active')
        .end()
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', false)
2079

Mark Otto's avatar
grunt    
Mark Otto committed
2080
2081
2082
2083
      element
        .addClass('active')
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2084
2085
2086
2087
2088
2089

      if (transition) {
        element[0].offsetWidth // reflow for transition
        element.addClass('in')
      } else {
        element.removeClass('fade')
2090
      }
2091

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2092
      if (element.parent('.dropdown-menu').length) {
Mark Otto's avatar
grunt    
Mark Otto committed
2093
2094
2095
2096
2097
2098
        element
          .closest('li.dropdown')
            .addClass('active')
          .end()
          .find('[data-toggle="tab"]')
            .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2099
      }
fat's avatar
fat committed
2100

XhmikosR's avatar
XhmikosR committed
2101
      callback && callback()
2102
    }
fat's avatar
fat committed
2103

Mark Otto's avatar
grunt    
Mark Otto committed
2104
    $active.length && transition ?
XhmikosR's avatar
XhmikosR committed
2105
2106
      $active
        .one('bsTransitionEnd', next)
2107
        .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
2108
      next()
2109

XhmikosR's avatar
XhmikosR committed
2110
2111
    $active.removeClass('in')
  }
2112
2113


XhmikosR's avatar
XhmikosR committed
2114
2115
  // TAB PLUGIN DEFINITION
  // =====================
fat's avatar
fat committed
2116

XhmikosR's avatar
XhmikosR committed
2117
2118
2119
2120
  function Plugin(option) {
    return this.each(function () {
      var $this = $(this)
      var data  = $this.data('bs.tab')
2121

XhmikosR's avatar
XhmikosR committed
2122
2123
2124
2125
      if (!data) $this.data('bs.tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }
Mark Otto's avatar
Mark Otto committed
2126

XhmikosR's avatar
XhmikosR committed
2127
  var old = $.fn.tab
2128

XhmikosR's avatar
XhmikosR committed
2129
2130
  $.fn.tab             = Plugin
  $.fn.tab.Constructor = Tab
2131

2132

XhmikosR's avatar
XhmikosR committed
2133
2134
  // TAB NO CONFLICT
  // ===============
2135

XhmikosR's avatar
XhmikosR committed
2136
2137
2138
2139
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2140
2141


XhmikosR's avatar
XhmikosR committed
2142
2143
2144
  // TAB DATA-API
  // ============

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2145
  var clickHandler = function (e) {
XhmikosR's avatar
XhmikosR committed
2146
2147
    e.preventDefault()
    Plugin.call($(this), 'show')
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2148
2149
2150
2151
2152
  }

  $(document)
    .on('click.bs.tab.data-api', '[data-toggle="tab"]', clickHandler)
    .on('click.bs.tab.data-api', '[data-toggle="pill"]', clickHandler)
2153

XhmikosR's avatar
XhmikosR committed
2154
}(jQuery);
2155

2156
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2157
 * Bootstrap: affix.js v3.3.2
Mark Otto's avatar
Mark Otto committed
2158
 * http://getbootstrap.com/javascript/#affix
2159
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2160
 * Copyright 2011-2015 Twitter, Inc.
2161
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2162
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2163
2164


XhmikosR's avatar
XhmikosR committed
2165
2166
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2167

XhmikosR's avatar
XhmikosR committed
2168
2169
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2170

XhmikosR's avatar
XhmikosR committed
2171
2172
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2173

XhmikosR's avatar
XhmikosR committed
2174
2175
2176
    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
2177

XhmikosR's avatar
XhmikosR committed
2178
    this.$element     = $(element)
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2179
2180
    this.affixed      = null
    this.unpin        = null
XhmikosR's avatar
XhmikosR committed
2181
    this.pinnedOffset = null
fat's avatar
fat committed
2182

XhmikosR's avatar
XhmikosR committed
2183
2184
    this.checkPosition()
  }
fat's avatar
fat committed
2185

Mark Otto's avatar
Mark Otto committed
2186
  Affix.VERSION  = '3.3.2'
2187

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

XhmikosR's avatar
XhmikosR committed
2190
2191
2192
2193
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2194

2195
2196
2197
2198
2199
2200
2201
2202
2203
2204
2205
2206
2207
2208
2209
2210
  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

Chris Rebert's avatar
Chris Rebert committed
2211
    if (offsetTop != null && scrollTop <= offsetTop) return 'top'
2212
2213
2214
2215
2216
    if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'

    return false
  }

XhmikosR's avatar
XhmikosR committed
2217
2218
2219
2220
2221
2222
2223
  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)
  }
2224

XhmikosR's avatar
XhmikosR committed
2225
2226
2227
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2228

XhmikosR's avatar
XhmikosR committed
2229
2230
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2231

2232
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2233
2234
2235
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2236
    var scrollHeight = $('body').height()
2237

XhmikosR's avatar
XhmikosR committed
2238
2239
2240
    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)
2241

2242
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2243

2244
2245
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2246

2247
2248
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2249

2250
      this.$element.trigger(e)
2251

2252
      if (e.isDefaultPrevented()) return
2253

2254
2255
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2256

2257
2258
2259
2260
2261
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2262

XhmikosR's avatar
XhmikosR committed
2263
2264
    if (affix == 'bottom') {
      this.$element.offset({
2265
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2266
      })
2267
    }
XhmikosR's avatar
XhmikosR committed
2268
  }
Mark Otto's avatar
Mark Otto committed
2269

2270

XhmikosR's avatar
XhmikosR committed
2271
2272
  // AFFIX PLUGIN DEFINITION
  // =======================
2273

XhmikosR's avatar
XhmikosR committed
2274
2275
2276
2277
2278
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2279

XhmikosR's avatar
XhmikosR committed
2280
2281
2282
2283
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2284

XhmikosR's avatar
XhmikosR committed
2285
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2286

XhmikosR's avatar
XhmikosR committed
2287
2288
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2289
2290


XhmikosR's avatar
XhmikosR committed
2291
2292
  // AFFIX NO CONFLICT
  // =================
2293

XhmikosR's avatar
XhmikosR committed
2294
2295
2296
2297
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2298
2299


XhmikosR's avatar
XhmikosR committed
2300
2301
  // AFFIX DATA-API
  // ==============
2302

XhmikosR's avatar
XhmikosR committed
2303
2304
2305
2306
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2307

XhmikosR's avatar
XhmikosR committed
2308
      data.offset = data.offset || {}
2309

Heinrich Fenkart's avatar
Heinrich Fenkart committed
2310
2311
      if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
      if (data.offsetTop    != null) data.offset.top    = data.offsetTop
2312

XhmikosR's avatar
XhmikosR committed
2313
      Plugin.call($spy, data)
2314
    })
Mark Otto's avatar
Mark Otto committed
2315
2316
  })

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