bootstrap.js 65.2 KB
Newer Older
Mark Otto's avatar
grunt    
Mark Otto committed
2001

XhmikosR's avatar
XhmikosR committed
2002
2003
  // TAB CLASS DEFINITION
  // ====================
2004

XhmikosR's avatar
XhmikosR committed
2005
2006
2007
  var Tab = function (element) {
    this.element = $(element)
  }
2008

Mark Otto's avatar
Mark Otto committed
2009
  Tab.VERSION = '3.3.1'
Mark Otto's avatar
grunt    
Mark Otto committed
2010

2011
2012
  Tab.TRANSITION_DURATION = 150

XhmikosR's avatar
XhmikosR committed
2013
2014
2015
2016
  Tab.prototype.show = function () {
    var $this    = this.element
    var $ul      = $this.closest('ul:not(.dropdown-menu)')
    var selector = $this.data('target')
2017

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

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

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2025
2026
2027
2028
2029
2030
    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
2031
    })
2032

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2033
2034
    $previous.trigger(hideEvent)
    $this.trigger(showEvent)
2035

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

XhmikosR's avatar
XhmikosR committed
2038
    var $target = $(selector)
2039

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

XhmikosR's avatar
XhmikosR committed
2053
2054
2055
2056
  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
2057
      && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
2058

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

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

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

XhmikosR's avatar
XhmikosR committed
2080
      if (element.parent('.dropdown-menu')) {
Mark Otto's avatar
grunt    
Mark Otto committed
2081
2082
2083
2084
2085
2086
        element
          .closest('li.dropdown')
            .addClass('active')
          .end()
          .find('[data-toggle="tab"]')
            .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2087
      }
fat's avatar
fat committed
2088

XhmikosR's avatar
XhmikosR committed
2089
      callback && callback()
2090
    }
fat's avatar
fat committed
2091

Mark Otto's avatar
grunt    
Mark Otto committed
2092
    $active.length && transition ?
XhmikosR's avatar
XhmikosR committed
2093
2094
      $active
        .one('bsTransitionEnd', next)
2095
        .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
2096
      next()
2097

XhmikosR's avatar
XhmikosR committed
2098
2099
    $active.removeClass('in')
  }
2100
2101


XhmikosR's avatar
XhmikosR committed
2102
2103
  // TAB PLUGIN DEFINITION
  // =====================
fat's avatar
fat committed
2104

XhmikosR's avatar
XhmikosR committed
2105
2106
2107
2108
  function Plugin(option) {
    return this.each(function () {
      var $this = $(this)
      var data  = $this.data('bs.tab')
2109

XhmikosR's avatar
XhmikosR committed
2110
2111
2112
2113
      if (!data) $this.data('bs.tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }
Mark Otto's avatar
Mark Otto committed
2114

XhmikosR's avatar
XhmikosR committed
2115
  var old = $.fn.tab
2116

XhmikosR's avatar
XhmikosR committed
2117
2118
  $.fn.tab             = Plugin
  $.fn.tab.Constructor = Tab
2119

2120

XhmikosR's avatar
XhmikosR committed
2121
2122
  // TAB NO CONFLICT
  // ===============
2123

XhmikosR's avatar
XhmikosR committed
2124
2125
2126
2127
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2128
2129


XhmikosR's avatar
XhmikosR committed
2130
2131
2132
  // TAB DATA-API
  // ============

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2133
  var clickHandler = function (e) {
XhmikosR's avatar
XhmikosR committed
2134
2135
    e.preventDefault()
    Plugin.call($(this), 'show')
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2136
2137
2138
2139
2140
  }

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

XhmikosR's avatar
XhmikosR committed
2142
}(jQuery);
2143

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


XhmikosR's avatar
XhmikosR committed
2153
2154
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2155

XhmikosR's avatar
XhmikosR committed
2156
2157
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2158

XhmikosR's avatar
XhmikosR committed
2159
2160
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2161

XhmikosR's avatar
XhmikosR committed
2162
2163
2164
    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
2165

XhmikosR's avatar
XhmikosR committed
2166
2167
2168
2169
    this.$element     = $(element)
    this.affixed      =
    this.unpin        =
    this.pinnedOffset = null
fat's avatar
fat committed
2170

XhmikosR's avatar
XhmikosR committed
2171
2172
    this.checkPosition()
  }
fat's avatar
fat committed
2173

Mark Otto's avatar
Mark Otto committed
2174
  Affix.VERSION  = '3.3.1'
2175

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

XhmikosR's avatar
XhmikosR committed
2178
2179
2180
2181
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2182

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

    return false
  }

XhmikosR's avatar
XhmikosR committed
2205
2206
2207
2208
2209
2210
2211
  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)
  }
2212

XhmikosR's avatar
XhmikosR committed
2213
2214
2215
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2216

XhmikosR's avatar
XhmikosR committed
2217
2218
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2219

2220
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2221
2222
2223
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2224
    var scrollHeight = $('body').height()
2225

XhmikosR's avatar
XhmikosR committed
2226
2227
2228
    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)
2229

2230
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2231

2232
2233
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2234

2235
2236
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2237

2238
      this.$element.trigger(e)
2239

2240
      if (e.isDefaultPrevented()) return
2241

2242
2243
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2244

2245
2246
2247
2248
2249
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2250

XhmikosR's avatar
XhmikosR committed
2251
2252
    if (affix == 'bottom') {
      this.$element.offset({
2253
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2254
      })
2255
    }
XhmikosR's avatar
XhmikosR committed
2256
  }
Mark Otto's avatar
Mark Otto committed
2257

2258

XhmikosR's avatar
XhmikosR committed
2259
2260
  // AFFIX PLUGIN DEFINITION
  // =======================
2261

XhmikosR's avatar
XhmikosR committed
2262
2263
2264
2265
2266
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2267

XhmikosR's avatar
XhmikosR committed
2268
2269
2270
2271
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2272

XhmikosR's avatar
XhmikosR committed
2273
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2274

XhmikosR's avatar
XhmikosR committed
2275
2276
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2277
2278


XhmikosR's avatar
XhmikosR committed
2279
2280
  // AFFIX NO CONFLICT
  // =================
2281

XhmikosR's avatar
XhmikosR committed
2282
2283
2284
2285
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2286
2287


XhmikosR's avatar
XhmikosR committed
2288
2289
  // AFFIX DATA-API
  // ==============
2290

XhmikosR's avatar
XhmikosR committed
2291
2292
2293
2294
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2295

XhmikosR's avatar
XhmikosR committed
2296
      data.offset = data.offset || {}
2297

Heinrich Fenkart's avatar
Heinrich Fenkart committed
2298
2299
      if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
      if (data.offsetTop    != null) data.offset.top    = data.offsetTop
2300

XhmikosR's avatar
XhmikosR committed
2301
      Plugin.call($spy, data)
2302
    })
Mark Otto's avatar
Mark Otto committed
2303
2304
  })

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