bootstrap.js 65.7 KB
Newer Older
2001

2002

XhmikosR's avatar
XhmikosR committed
2003
2004
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2005

XhmikosR's avatar
XhmikosR committed
2006
2007
  // TAB CLASS DEFINITION
  // ====================
2008

XhmikosR's avatar
XhmikosR committed
2009
2010
2011
  var Tab = function (element) {
    this.element = $(element)
  }
2012

Mark Otto's avatar
Mark Otto committed
2013
  Tab.VERSION = '3.3.2'
Mark Otto's avatar
grunt    
Mark Otto committed
2014

2015
2016
  Tab.TRANSITION_DURATION = 150

XhmikosR's avatar
XhmikosR committed
2017
2018
2019
2020
  Tab.prototype.show = function () {
    var $this    = this.element
    var $ul      = $this.closest('ul:not(.dropdown-menu)')
    var selector = $this.data('target')
2021

XhmikosR's avatar
XhmikosR committed
2022
2023
2024
2025
    if (!selector) {
      selector = $this.attr('href')
      selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
    }
2026

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

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2029
2030
2031
2032
2033
2034
    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
2035
    })
2036

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2037
2038
    $previous.trigger(hideEvent)
    $this.trigger(showEvent)
2039

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

XhmikosR's avatar
XhmikosR committed
2042
    var $target = $(selector)
2043

XhmikosR's avatar
XhmikosR committed
2044
2045
    this.activate($this.closest('li'), $ul)
    this.activate($target, $target.parent(), function () {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2046
2047
2048
2049
      $previous.trigger({
        type: 'hidden.bs.tab',
        relatedTarget: $this[0]
      })
XhmikosR's avatar
XhmikosR committed
2050
2051
      $this.trigger({
        type: 'shown.bs.tab',
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2052
        relatedTarget: $previous[0]
2053
      })
XhmikosR's avatar
XhmikosR committed
2054
2055
    })
  }
2056

XhmikosR's avatar
XhmikosR committed
2057
2058
2059
2060
  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
2061
      && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
2062

XhmikosR's avatar
XhmikosR committed
2063
2064
2065
2066
    function next() {
      $active
        .removeClass('active')
        .find('> .dropdown-menu > .active')
Mark Otto's avatar
grunt    
Mark Otto committed
2067
2068
2069
2070
          .removeClass('active')
        .end()
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', false)
2071

Mark Otto's avatar
grunt    
Mark Otto committed
2072
2073
2074
2075
      element
        .addClass('active')
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2076
2077
2078
2079
2080
2081

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

Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2084
      if (element.parent('.dropdown-menu').length) {
Mark Otto's avatar
grunt    
Mark Otto committed
2085
2086
2087
2088
2089
2090
        element
          .closest('li.dropdown')
            .addClass('active')
          .end()
          .find('[data-toggle="tab"]')
            .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2091
      }
fat's avatar
fat committed
2092

XhmikosR's avatar
XhmikosR committed
2093
      callback && callback()
2094
    }
fat's avatar
fat committed
2095

Mark Otto's avatar
grunt    
Mark Otto committed
2096
    $active.length && transition ?
XhmikosR's avatar
XhmikosR committed
2097
2098
      $active
        .one('bsTransitionEnd', next)
2099
        .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
2100
      next()
2101

XhmikosR's avatar
XhmikosR committed
2102
2103
    $active.removeClass('in')
  }
2104
2105


XhmikosR's avatar
XhmikosR committed
2106
2107
  // TAB PLUGIN DEFINITION
  // =====================
fat's avatar
fat committed
2108

XhmikosR's avatar
XhmikosR committed
2109
2110
2111
2112
  function Plugin(option) {
    return this.each(function () {
      var $this = $(this)
      var data  = $this.data('bs.tab')
2113

XhmikosR's avatar
XhmikosR committed
2114
2115
2116
2117
      if (!data) $this.data('bs.tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }
Mark Otto's avatar
Mark Otto committed
2118

XhmikosR's avatar
XhmikosR committed
2119
  var old = $.fn.tab
2120

XhmikosR's avatar
XhmikosR committed
2121
2122
  $.fn.tab             = Plugin
  $.fn.tab.Constructor = Tab
2123

2124

XhmikosR's avatar
XhmikosR committed
2125
2126
  // TAB NO CONFLICT
  // ===============
2127

XhmikosR's avatar
XhmikosR committed
2128
2129
2130
2131
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2132
2133


XhmikosR's avatar
XhmikosR committed
2134
2135
2136
  // TAB DATA-API
  // ============

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2137
  var clickHandler = function (e) {
XhmikosR's avatar
XhmikosR committed
2138
2139
    e.preventDefault()
    Plugin.call($(this), 'show')
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2140
2141
2142
2143
2144
  }

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

XhmikosR's avatar
XhmikosR committed
2146
}(jQuery);
2147

2148
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2149
 * Bootstrap: affix.js v3.3.2
Mark Otto's avatar
Mark Otto committed
2150
 * http://getbootstrap.com/javascript/#affix
2151
 * ========================================================================
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2152
 * Copyright 2011-2015 Twitter, Inc.
2153
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2154
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2155
2156


XhmikosR's avatar
XhmikosR committed
2157
2158
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2159

XhmikosR's avatar
XhmikosR committed
2160
2161
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2162

XhmikosR's avatar
XhmikosR committed
2163
2164
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2165

XhmikosR's avatar
XhmikosR committed
2166
2167
2168
    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
2169

XhmikosR's avatar
XhmikosR committed
2170
    this.$element     = $(element)
Bootstrap's Grunt bot's avatar
Bootstrap's Grunt bot committed
2171
2172
    this.affixed      = null
    this.unpin        = null
XhmikosR's avatar
XhmikosR committed
2173
    this.pinnedOffset = null
fat's avatar
fat committed
2174

XhmikosR's avatar
XhmikosR committed
2175
2176
    this.checkPosition()
  }
fat's avatar
fat committed
2177

Mark Otto's avatar
Mark Otto committed
2178
  Affix.VERSION  = '3.3.2'
2179

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

XhmikosR's avatar
XhmikosR committed
2182
2183
2184
2185
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2186

2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
2202
  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
2203
    if (offsetTop != null && scrollTop <= offsetTop) return 'top'
2204
2205
2206
2207
2208
    if (offsetBottom != null && (colliderTop + colliderHeight >= scrollHeight - offsetBottom)) return 'bottom'

    return false
  }

XhmikosR's avatar
XhmikosR committed
2209
2210
2211
2212
2213
2214
2215
  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)
  }
2216

XhmikosR's avatar
XhmikosR committed
2217
2218
2219
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2220

XhmikosR's avatar
XhmikosR committed
2221
2222
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2223

2224
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2225
2226
2227
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2228
    var scrollHeight = $('body').height()
2229

XhmikosR's avatar
XhmikosR committed
2230
2231
2232
    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)
2233

2234
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2235

2236
2237
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2238

2239
2240
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2241

2242
      this.$element.trigger(e)
2243

2244
      if (e.isDefaultPrevented()) return
2245

2246
2247
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2248

2249
2250
2251
2252
2253
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2254

XhmikosR's avatar
XhmikosR committed
2255
2256
    if (affix == 'bottom') {
      this.$element.offset({
2257
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2258
      })
2259
    }
XhmikosR's avatar
XhmikosR committed
2260
  }
Mark Otto's avatar
Mark Otto committed
2261

2262

XhmikosR's avatar
XhmikosR committed
2263
2264
  // AFFIX PLUGIN DEFINITION
  // =======================
2265

XhmikosR's avatar
XhmikosR committed
2266
2267
2268
2269
2270
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2271

XhmikosR's avatar
XhmikosR committed
2272
2273
2274
2275
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2276

XhmikosR's avatar
XhmikosR committed
2277
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2278

XhmikosR's avatar
XhmikosR committed
2279
2280
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2281
2282


XhmikosR's avatar
XhmikosR committed
2283
2284
  // AFFIX NO CONFLICT
  // =================
2285

XhmikosR's avatar
XhmikosR committed
2286
2287
2288
2289
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2290
2291


XhmikosR's avatar
XhmikosR committed
2292
2293
  // AFFIX DATA-API
  // ==============
2294

XhmikosR's avatar
XhmikosR committed
2295
2296
2297
2298
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2299

XhmikosR's avatar
XhmikosR committed
2300
      data.offset = data.offset || {}
2301

Heinrich Fenkart's avatar
Heinrich Fenkart committed
2302
2303
      if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
      if (data.offsetTop    != null) data.offset.top    = data.offsetTop
2304

XhmikosR's avatar
XhmikosR committed
2305
      Plugin.call($spy, data)
2306
    })
Mark Otto's avatar
Mark Otto committed
2307
2308
  })

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