bootstrap.js 64 KB
Newer Older
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2001
    if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
2002

XhmikosR's avatar
XhmikosR committed
2003
    var $target = $(selector)
2004

XhmikosR's avatar
XhmikosR committed
2005
2006
    this.activate($this.closest('li'), $ul)
    this.activate($target, $target.parent(), function () {
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2007
2008
2009
2010
      $previous.trigger({
        type: 'hidden.bs.tab',
        relatedTarget: $this[0]
      })
XhmikosR's avatar
XhmikosR committed
2011
2012
      $this.trigger({
        type: 'shown.bs.tab',
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2013
        relatedTarget: $previous[0]
2014
      })
XhmikosR's avatar
XhmikosR committed
2015
2016
    })
  }
2017

XhmikosR's avatar
XhmikosR committed
2018
2019
2020
2021
  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
2022
      && (($active.length && $active.hasClass('fade')) || !!container.find('> .fade').length)
2023

XhmikosR's avatar
XhmikosR committed
2024
2025
2026
2027
    function next() {
      $active
        .removeClass('active')
        .find('> .dropdown-menu > .active')
Mark Otto's avatar
grunt    
Mark Otto committed
2028
2029
2030
2031
          .removeClass('active')
        .end()
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', false)
2032

Mark Otto's avatar
grunt    
Mark Otto committed
2033
2034
2035
2036
      element
        .addClass('active')
        .find('[data-toggle="tab"]')
          .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2037
2038
2039
2040
2041
2042

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

XhmikosR's avatar
XhmikosR committed
2045
      if (element.parent('.dropdown-menu')) {
Mark Otto's avatar
grunt    
Mark Otto committed
2046
2047
2048
2049
2050
2051
        element
          .closest('li.dropdown')
            .addClass('active')
          .end()
          .find('[data-toggle="tab"]')
            .attr('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
2052
      }
fat's avatar
fat committed
2053

XhmikosR's avatar
XhmikosR committed
2054
      callback && callback()
2055
    }
fat's avatar
fat committed
2056

Mark Otto's avatar
grunt    
Mark Otto committed
2057
    $active.length && transition ?
XhmikosR's avatar
XhmikosR committed
2058
2059
      $active
        .one('bsTransitionEnd', next)
2060
        .emulateTransitionEnd(Tab.TRANSITION_DURATION) :
XhmikosR's avatar
XhmikosR committed
2061
      next()
2062

XhmikosR's avatar
XhmikosR committed
2063
2064
    $active.removeClass('in')
  }
2065
2066


XhmikosR's avatar
XhmikosR committed
2067
2068
  // TAB PLUGIN DEFINITION
  // =====================
fat's avatar
fat committed
2069

XhmikosR's avatar
XhmikosR committed
2070
2071
2072
2073
  function Plugin(option) {
    return this.each(function () {
      var $this = $(this)
      var data  = $this.data('bs.tab')
2074

XhmikosR's avatar
XhmikosR committed
2075
2076
2077
2078
      if (!data) $this.data('bs.tab', (data = new Tab(this)))
      if (typeof option == 'string') data[option]()
    })
  }
Mark Otto's avatar
Mark Otto committed
2079

XhmikosR's avatar
XhmikosR committed
2080
  var old = $.fn.tab
2081

XhmikosR's avatar
XhmikosR committed
2082
2083
  $.fn.tab             = Plugin
  $.fn.tab.Constructor = Tab
2084

2085

XhmikosR's avatar
XhmikosR committed
2086
2087
  // TAB NO CONFLICT
  // ===============
2088

XhmikosR's avatar
XhmikosR committed
2089
2090
2091
2092
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
    return this
  }
2093
2094


XhmikosR's avatar
XhmikosR committed
2095
2096
2097
2098
2099
2100
  // TAB DATA-API
  // ============

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

XhmikosR's avatar
XhmikosR committed
2103
}(jQuery);
2104

2105
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2106
 * Bootstrap: affix.js v3.2.0
Mark Otto's avatar
Mark Otto committed
2107
 * http://getbootstrap.com/javascript/#affix
2108
 * ========================================================================
2109
 * Copyright 2011-2014 Twitter, Inc.
2110
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2111
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2112
2113


XhmikosR's avatar
XhmikosR committed
2114
2115
+function ($) {
  'use strict';
Mark Otto's avatar
grunt    
Mark Otto committed
2116

XhmikosR's avatar
XhmikosR committed
2117
2118
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2119

XhmikosR's avatar
XhmikosR committed
2120
2121
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Mark Otto's avatar
Mark Otto committed
2122

XhmikosR's avatar
XhmikosR committed
2123
2124
2125
    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
2126

XhmikosR's avatar
XhmikosR committed
2127
2128
2129
2130
    this.$element     = $(element)
    this.affixed      =
    this.unpin        =
    this.pinnedOffset = null
fat's avatar
fat committed
2131

XhmikosR's avatar
XhmikosR committed
2132
2133
    this.checkPosition()
  }
fat's avatar
fat committed
2134

Mark Otto's avatar
Mark Otto committed
2135
  Affix.VERSION  = '3.2.0'
2136

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

XhmikosR's avatar
XhmikosR committed
2139
2140
2141
2142
  Affix.DEFAULTS = {
    offset: 0,
    target: window
  }
2143

2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
  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
2166
2167
2168
2169
2170
2171
2172
  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)
  }
2173

XhmikosR's avatar
XhmikosR committed
2174
2175
2176
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }
fat's avatar
fat committed
2177

XhmikosR's avatar
XhmikosR committed
2178
2179
  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return
2180

2181
    var height       = this.$element.height()
XhmikosR's avatar
XhmikosR committed
2182
2183
2184
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom
2185
    var scrollHeight = $('body').height()
2186

XhmikosR's avatar
XhmikosR committed
2187
2188
2189
    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)
2190

2191
    var affix = this.getState(scrollHeight, height, offsetTop, offsetBottom)
2192

2193
2194
    if (this.affixed != affix) {
      if (this.unpin != null) this.$element.css('top', '')
2195

2196
2197
      var affixType = 'affix' + (affix ? '-' + affix : '')
      var e         = $.Event(affixType + '.bs.affix')
2198

2199
      this.$element.trigger(e)
2200

2201
      if (e.isDefaultPrevented()) return
2202

2203
2204
      this.affixed = affix
      this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2205

2206
2207
2208
2209
2210
      this.$element
        .removeClass(Affix.RESET)
        .addClass(affixType)
        .trigger(affixType.replace('affix', 'affixed') + '.bs.affix')
    }
2211

XhmikosR's avatar
XhmikosR committed
2212
2213
    if (affix == 'bottom') {
      this.$element.offset({
2214
        top: scrollHeight - height - offsetBottom
XhmikosR's avatar
XhmikosR committed
2215
      })
2216
    }
XhmikosR's avatar
XhmikosR committed
2217
  }
Mark Otto's avatar
Mark Otto committed
2218

2219

XhmikosR's avatar
XhmikosR committed
2220
2221
  // AFFIX PLUGIN DEFINITION
  // =======================
2222

XhmikosR's avatar
XhmikosR committed
2223
2224
2225
2226
2227
  function Plugin(option) {
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option
2228

XhmikosR's avatar
XhmikosR committed
2229
2230
2231
2232
      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }
2233

XhmikosR's avatar
XhmikosR committed
2234
  var old = $.fn.affix
Mark Otto's avatar
Mark Otto committed
2235

XhmikosR's avatar
XhmikosR committed
2236
2237
  $.fn.affix             = Plugin
  $.fn.affix.Constructor = Affix
2238
2239


XhmikosR's avatar
XhmikosR committed
2240
2241
  // AFFIX NO CONFLICT
  // =================
2242

XhmikosR's avatar
XhmikosR committed
2243
2244
2245
2246
  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }
2247
2248


XhmikosR's avatar
XhmikosR committed
2249
2250
  // AFFIX DATA-API
  // ==============
2251

XhmikosR's avatar
XhmikosR committed
2252
2253
2254
2255
  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()
2256

XhmikosR's avatar
XhmikosR committed
2257
      data.offset = data.offset || {}
2258

Heinrich Fenkart's avatar
Heinrich Fenkart committed
2259
2260
      if (data.offsetBottom != null) data.offset.bottom = data.offsetBottom
      if (data.offsetTop    != null) data.offset.top    = data.offsetTop
2261

XhmikosR's avatar
XhmikosR committed
2262
      Plugin.call($spy, data)
2263
    })
Mark Otto's avatar
Mark Otto committed
2264
2265
  })

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