bootstrap.js 61.3 KB
Newer Older
2001
2002
  $.fn.tab.noConflict = function () {
    $.fn.tab = old
2003
2004
2005
    return this
  }

2006
2007
2008
2009
2010
2011

  // TAB DATA-API
  // ============

  $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
    e.preventDefault()
Mark Otto's avatar
Mark Otto committed
2012
    Plugin.call($(this), 'show')
2013
2014
  })

Mark Otto's avatar
grunt    
Mark Otto committed
2015
});
2016

2017
/* ========================================================================
Mark Otto's avatar
Mark Otto committed
2018
 * Bootstrap: affix.js v3.1.1
Mark Otto's avatar
Mark Otto committed
2019
 * http://getbootstrap.com/javascript/#affix
2020
 * ========================================================================
2021
 * Copyright 2011-2014 Twitter, Inc.
2022
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
2023
 * ======================================================================== */
Mark Otto's avatar
Mark Otto committed
2024
2025


Mark Otto's avatar
grunt    
Mark Otto committed
2026
2027
2028
2029
2030
(function (o_o) {
  typeof define  === 'function' && define.amd ? define(['jquery'], o_o) :
  typeof exports === 'object' ? o_o(require('jquery')) : o_o(this.jQuery)
})(function ($) {

2031
  'use strict';
Mark Otto's avatar
Mark Otto committed
2032

2033
2034
  // AFFIX CLASS DEFINITION
  // ======================
Mark Otto's avatar
Mark Otto committed
2035

2036
2037
  var Affix = function (element, options) {
    this.options = $.extend({}, Affix.DEFAULTS, options)
Chris Rebert's avatar
Chris Rebert committed
2038
2039

    this.$target = $(this.options.target)
2040
2041
      .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
      .on('click.bs.affix.data-api',  $.proxy(this.checkPositionWithEventLoop, this))
fat's avatar
fat committed
2042

fat's avatar
fat committed
2043
2044
2045
2046
    this.$element     = $(element)
    this.affixed      =
    this.unpin        =
    this.pinnedOffset = null
fat's avatar
fat committed
2047

2048
2049
2050
    this.checkPosition()
  }

Mark Otto's avatar
grunt    
Mark Otto committed
2051
2052
2053
  Affix.VERSION  = '3.1.1'

  Affix.RESET    = 'affix affix-top affix-bottom'
2054
2055

  Affix.DEFAULTS = {
Chris Rebert's avatar
Chris Rebert committed
2056
2057
    offset: 0,
    target: window
2058
2059
  }

fat's avatar
fat committed
2060
2061
2062
  Affix.prototype.getPinnedOffset = function () {
    if (this.pinnedOffset) return this.pinnedOffset
    this.$element.removeClass(Affix.RESET).addClass('affix')
Chris Rebert's avatar
Chris Rebert committed
2063
    var scrollTop = this.$target.scrollTop()
fat's avatar
fat committed
2064
2065
2066
2067
    var position  = this.$element.offset()
    return (this.pinnedOffset = position.top - scrollTop)
  }

2068
2069
2070
2071
2072
2073
2074
2075
  Affix.prototype.checkPositionWithEventLoop = function () {
    setTimeout($.proxy(this.checkPosition, this), 1)
  }

  Affix.prototype.checkPosition = function () {
    if (!this.$element.is(':visible')) return

    var scrollHeight = $(document).height()
Chris Rebert's avatar
Chris Rebert committed
2076
    var scrollTop    = this.$target.scrollTop()
2077
2078
2079
2080
2081
2082
    var position     = this.$element.offset()
    var offset       = this.options.offset
    var offsetTop    = offset.top
    var offsetBottom = offset.bottom

    if (typeof offset != 'object')         offsetBottom = offsetTop = offset
2083
2084
    if (typeof offsetTop == 'function')    offsetTop    = offset.top(this.$element)
    if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element)
2085
2086
2087
2088
2089
2090

    var affix = this.unpin   != null && (scrollTop + this.unpin <= position.top) ? false :
                offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' :
                offsetTop    != null && (scrollTop <= offsetTop) ? 'top' : false

    if (this.affixed === affix) return
fat's avatar
fat committed
2091
    if (this.unpin != null) this.$element.css('top', '')
2092

2093
2094
2095
2096
2097
2098
2099
    var affixType = 'affix' + (affix ? '-' + affix : '')
    var e         = $.Event(affixType + '.bs.affix')

    this.$element.trigger(e)

    if (e.isDefaultPrevented()) return

2100
    this.affixed = affix
fat's avatar
fat committed
2101
    this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
2102

2103
2104
2105
2106
    this.$element
      .removeClass(Affix.RESET)
      .addClass(affixType)
      .trigger($.Event(affixType.replace('affix', 'affixed')))
2107
2108

    if (affix == 'bottom') {
XhmikosR's avatar
XhmikosR committed
2109
2110
2111
      this.$element.offset({
        top: scrollHeight - this.$element.height() - offsetBottom
      })
2112
    }
Mark Otto's avatar
Mark Otto committed
2113
2114
  }

2115
2116
2117
2118

  // AFFIX PLUGIN DEFINITION
  // =======================

Mark Otto's avatar
Mark Otto committed
2119
  function Plugin(option) {
2120
2121
2122
2123
2124
2125
2126
2127
    return this.each(function () {
      var $this   = $(this)
      var data    = $this.data('bs.affix')
      var options = typeof option == 'object' && option

      if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
2128
2129
  }

Mark Otto's avatar
Mark Otto committed
2130
2131
2132
  var old = $.fn.affix

  $.fn.affix             = Plugin
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
2151
2152
2153
2154
2155
2156
2157
  $.fn.affix.Constructor = Affix


  // AFFIX NO CONFLICT
  // =================

  $.fn.affix.noConflict = function () {
    $.fn.affix = old
    return this
  }


  // AFFIX DATA-API
  // ==============

  $(window).on('load', function () {
    $('[data-spy="affix"]').each(function () {
      var $spy = $(this)
      var data = $spy.data()

      data.offset = data.offset || {}

      if (data.offsetBottom) data.offset.bottom = data.offsetBottom
      if (data.offsetTop)    data.offset.top    = data.offsetTop

Mark Otto's avatar
Mark Otto committed
2158
      Plugin.call($spy, data)
2159
    })
Mark Otto's avatar
Mark Otto committed
2160
2161
  })

Mark Otto's avatar
grunt    
Mark Otto committed
2162
});
For faster browsing, not all history is shown. View entire blame