bootstrap.js 66.3 KB
Newer Older
Chris Rebert's avatar
Chris Rebert committed
2001

XhmikosR's avatar
XhmikosR committed
2002
2003
2004
2005
2006
  $(window).on('load.bs.scrollspy.data-api', function () {
    $('[data-spy="scroll"]').each(function () {
      var $spy = $(this)
      Plugin.call($spy, $spy.data())
    })
2007
  })
2008

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

2011
/* ========================================================================
Chris Rebert's avatar
Chris Rebert committed
2012
 * Bootstrap: tab.js v3.3.4
Mark Otto's avatar
Mark Otto committed
2013
 * http://getbootstrap.com/javascript/#tabs
2014
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2015
 * Copyright 2011-2015 Twitter, Inc.
2016
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2017
 * ======================================================================== */
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
  // TAB CLASS DEFINITION
  // ====================
2025

XhmikosR's avatar
XhmikosR committed
2026
2027
2028
  var Tab = function (element) {
    this.element = $(element)
  }
2029

Chris Rebert's avatar
Chris Rebert committed
2030
  Tab.VERSION = '3.3.4'
Mark Otto's avatar
grunt    
Mark Otto committed
2031

2032
2033
  Tab.TRANSITION_DURATION = 150

XhmikosR's avatar
XhmikosR committed
2034
2035
2036
2037
  Tab.prototype.show = function () {
    var $this    = this.element
    var $ul      = $this.closest('ul:not(.dropdown-menu)')
    var selector = $this.data('target')
2038

XhmikosR's avatar
XhmikosR committed
2039
2040
2041
2042
    if (!selector) {
      selector = $this.attr('href')
      selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
    }
2043

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

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2046
2047
2048
2049
2050
2051
    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
2052
    })
2053

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2054
2055
    $previous.trigger(hideEvent)
    $this.trigger(showEvent)
2056

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

XhmikosR's avatar
XhmikosR committed
2059
    var $target = $(selector)
2060

XhmikosR's avatar
XhmikosR committed
2061
2062
    this.activate($this.closest('li'), $ul)
    this.activate($target, $target.parent(), function () {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2063
2064
2065
2066
      $previous.trigger({
        type: 'hidden.bs.tab',
        relatedTarget: $this[0]
      })
XhmikosR's avatar
XhmikosR committed
2067
2068
      $this.trigger({
        type: 'shown.bs.tab',
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2069
        relatedTarget: $previous[0]
2070
      })
XhmikosR's avatar
XhmikosR committed
2071
2072
    })
  }
2073

XhmikosR's avatar
XhmikosR committed
2074
2075
2076
2077
  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
2078
      && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
2079

XhmikosR's avatar
XhmikosR committed
2080
2081
2082
2083
    function next() {
      $active
        .removeClass('active')
        .find('> .dropdown-menu > .active')
Mark Otto's avatar
grunt    
Mark Otto committed
2084
2085
2086
2087
          .removeClass('active')
        .end()
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', false)
2088

Mark Otto's avatar
grunt    
Mark Otto committed
2089
2090
2091
2092
      element
        .addClass('active')
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2093
2094
2095
2096
2097
2098

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

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2101
      if (element.parent('.dropdown-menu').length) {
Mark Otto's avatar
grunt    
Mark Otto committed
2102
2103
2104
2105
2106
2107
        element
          .closest('li.dropdown')
            .addClass('active')
          .end()
          .find('[data-toggle="tab"]')
            .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2108
      }
fat's avatar
fat committed
2109

XhmikosR's avatar
XhmikosR committed
2110
      callback && callback()
2111
    }
fat's avatar
fat committed
2112

Mark Otto's avatar
grunt    
Mark Otto committed
2113
    $active.length && transition ?
XhmikosR's avatar
XhmikosR committed
2114
2115
      $active
        .one('bsTransitionEnd', next)
2116
        .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
2117
      next()
2118

XhmikosR's avatar
XhmikosR committed
2119
2120
    $active.removeClass('in')
  }
2121
2122


XhmikosR's avatar
XhmikosR committed
2123
2124
  // TAB PLUGIN DEFINITION
  // =====================
fat's avatar
fat committed
2125

XhmikosR's avatar
XhmikosR committed
2126
2127
2128
2129
  function Plugin(option) {
    return this.each(function () {
      var $this = $(this)
      var data  = $this.data('bs.tab')
2130

XhmikosR's avatar
XhmikosR committed
2131
2132
2133
2134
      if (!data) $this.data('bs.tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }
Mark Otto's avatar
Mark Otto committed
2135

XhmikosR's avatar
XhmikosR committed
2136
  var old = $.fn.tab
2137

XhmikosR's avatar
XhmikosR committed
2138
2139
  $.fn.tab             = Plugin
  $.fn.tab.Constructor = Tab
2140

2141

XhmikosR's avatar
XhmikosR committed
2142
2143
  // TAB NO CONFLICT
  // ===============
2144

XhmikosR's avatar
XhmikosR committed
2145
2146
2147
2148
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2149
2150


XhmikosR's avatar
XhmikosR committed
2151
2152
2153
  // TAB DATA-API
  // ============

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2154
  var clickHandler = function (e) {
XhmikosR's avatar
XhmikosR committed
2155
2156
    e.preventDefault()
    Plugin.call($(this), 'show')
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2157
2158
2159
2160
2161
  }

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

XhmikosR's avatar
XhmikosR committed
2163
}(jQuery);
2164

2165
/* ========================================================================
Chris Rebert's avatar
Chris Rebert committed
2166
 * Bootstrap: affix.js v3.3.4
Mark Otto's avatar
Mark Otto committed
2167
 * http://getbootstrap.com/javascript/#affix
2168
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2169
 * Copyright 2011-2015 Twitter, Inc.
2170
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2171
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2172
2173


XhmikosR's avatar
XhmikosR committed
2174
2175
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2176

XhmikosR's avatar
XhmikosR committed
2177
2178
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2179

XhmikosR's avatar
XhmikosR committed
2180
2181
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2182

XhmikosR's avatar
XhmikosR committed
2183
2184
2185
    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
2186

XhmikosR's avatar
XhmikosR committed
2187
    this.$element     = $(element)
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2188
2189
    this.affixed      = null
    this.unpin        = null
XhmikosR's avatar
XhmikosR committed
2190
    this.pinnedOffset = null
fat's avatar
fat committed
2191

XhmikosR's avatar
XhmikosR committed
2192
2193
    this.checkPosition()
  }
fat's avatar
fat committed
2194

Chris Rebert's avatar
Chris Rebert committed
2195
  Affix.VERSION  = '3.3.4'
2196

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

XhmikosR's avatar
XhmikosR committed
2199
2200
2201
2202
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2203

2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
  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
2220
    if (offsetTop != null && scrollTop <= offsetTop) return 'top'
2221
2222
2223
2224
2225
    if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'

    return false
  }

XhmikosR's avatar
XhmikosR committed
2226
2227
2228
2229
2230
2231
2232
  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)
  }
2233

XhmikosR's avatar
XhmikosR committed
2234
2235
2236
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2237

XhmikosR's avatar
XhmikosR committed
2238
2239
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2240

2241
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2242
2243
2244
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2245
    var scrollHeight = $(document.body).height()
2246

XhmikosR's avatar
XhmikosR committed
2247
2248
2249
    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)
2250

2251
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2252

2253
2254
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2255

2256
2257
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2258

2259
      this.$element.trigger(e)
2260

2261
      if (e.isDefaultPrevented()) return
2262

2263
2264
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2265

2266
2267
2268
2269
2270
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2271

XhmikosR's avatar
XhmikosR committed
2272
2273
    if (affix == 'bottom') {
      this.$element.offset({
2274
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2275
      })
2276
    }
XhmikosR's avatar
XhmikosR committed
2277
  }
Mark Otto's avatar
Mark Otto committed
2278

2279

XhmikosR's avatar
XhmikosR committed
2280
2281
  // AFFIX PLUGIN DEFINITION
  // =======================
2282

XhmikosR's avatar
XhmikosR committed
2283
2284
2285
2286
2287
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2288

XhmikosR's avatar
XhmikosR committed
2289
2290
2291
2292
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2293

XhmikosR's avatar
XhmikosR committed
2294
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2295

XhmikosR's avatar
XhmikosR committed
2296
2297
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2298
2299


XhmikosR's avatar
XhmikosR committed
2300
2301
  // AFFIX NO CONFLICT
  // =================
2302

XhmikosR's avatar
XhmikosR committed
2303
2304
2305
2306
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2307
2308


XhmikosR's avatar
XhmikosR committed
2309
2310
  // AFFIX DATA-API
  // ==============
2311

XhmikosR's avatar
XhmikosR committed
2312
2313
2314
2315
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2316

XhmikosR's avatar
XhmikosR committed
2317
      data.offset = data.offset || {}
2318

Heinrich Fenkart's avatar
Heinrich Fenkart committed
2319
2320
      if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
      if (data.offsetTop    != null) data.offset.top    = data.offsetTop
2321

XhmikosR's avatar
XhmikosR committed
2322
      Plugin.call($spy, data)
2323
    })
Mark Otto's avatar
Mark Otto committed
2324
2325
  })

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