bootstrap.js 60.5 KB
Newer Older
2001
2002
2003
2004
2005
2006
2007
2008
2009
      if (!prev.length) {
        prev = this.$menu.find('li').last()
      }

      prev.addClass('active')
    }

  , listen: function () {
      this.$element
fat's avatar
fat committed
2010
        .on('focus',    $.proxy(this.focus, this))
2011
2012
2013
2014
        .on('blur',     $.proxy(this.blur, this))
        .on('keypress', $.proxy(this.keypress, this))
        .on('keyup',    $.proxy(this.keyup, this))

Jacob Thornton's avatar
Jacob Thornton committed
2015
      if (this.eventSupported('keydown')) {
2016
        this.$element.on('keydown', $.proxy(this.keydown, this))
2017
2018
2019
2020
2021
      }

      this.$menu
        .on('click', $.proxy(this.click, this))
        .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
fat's avatar
fat committed
2022
        .on('mouseleave', 'li', $.proxy(this.mouseleave, this))
2023
2024
    }

Jacob Thornton's avatar
Jacob Thornton committed
2025
2026
2027
2028
2029
2030
2031
2032
2033
  , eventSupported: function(eventName) {
      var isSupported = eventName in this.$element
      if (!isSupported) {
        this.$element.setAttribute(eventName, 'return;')
        isSupported = typeof this.$element[eventName] === 'function'
      }
      return isSupported
    }

2034
  , move: function (e) {
2035
2036
      if (!this.shown) return

2037
2038
2039
2040
2041
2042
2043
2044
2045
2046
2047
2048
2049
2050
2051
2052
2053
2054
2055
2056
2057
2058
      switch(e.keyCode) {
        case 9: // tab
        case 13: // enter
        case 27: // escape
          e.preventDefault()
          break

        case 38: // up arrow
          e.preventDefault()
          this.prev()
          break

        case 40: // down arrow
          e.preventDefault()
          this.next()
          break
      }

      e.stopPropagation()
    }

  , keydown: function (e) {
fat's avatar
fat committed
2059
      this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27])
2060
2061
2062
2063
      this.move(e)
    }

  , keypress: function (e) {
2064
      if (this.suppressKeyPressRepeat) return
2065
2066
2067
      this.move(e)
    }

2068
2069
2070
2071
  , keyup: function (e) {
      switch(e.keyCode) {
        case 40: // down arrow
        case 38: // up arrow
2072
2073
2074
        case 16: // shift
        case 17: // ctrl
        case 18: // alt
2075
2076
2077
2078
2079
2080
2081
2082
2083
2084
2085
2086
2087
2088
2089
2090
2091
2092
2093
2094
2095
          break

        case 9: // tab
        case 13: // enter
          if (!this.shown) return
          this.select()
          break

        case 27: // escape
          if (!this.shown) return
          this.hide()
          break

        default:
          this.lookup()
      }

      e.stopPropagation()
      e.preventDefault()
  }

fat's avatar
fat committed
2096
2097
2098
2099
  , focus: function (e) {
      this.focused = true
    }

2100
  , blur: function (e) {
fat's avatar
fat committed
2101
2102
      this.focused = false
      if (!this.mousedover && this.shown) this.hide()
2103
2104
2105
2106
2107
2108
    }

  , click: function (e) {
      e.stopPropagation()
      e.preventDefault()
      this.select()
fat's avatar
rebuild    
fat committed
2109
      this.$element.focus()
2110
2111
2112
    }

  , mouseenter: function (e) {
fat's avatar
fat committed
2113
      this.mousedover = true
2114
2115
2116
2117
      this.$menu.find('.active').removeClass('active')
      $(e.currentTarget).addClass('active')
    }

fat's avatar
fat committed
2118
2119
2120
2121
2122
  , mouseleave: function (e) {
      this.mousedover = false
      if (!this.focused && this.shown) this.hide()
    }

2123
2124
2125
2126
2127
2128
  }


  /* TYPEAHEAD PLUGIN DEFINITION
   * =========================== */

2129
2130
  var old = $.fn.typeahead

2131
2132
2133
2134
2135
2136
2137
2138
2139
2140
2141
2142
2143
2144
2145
  $.fn.typeahead = function (option) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('typeahead')
        , options = typeof option == 'object' && option
      if (!data) $this.data('typeahead', (data = new Typeahead(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }

  $.fn.typeahead.defaults = {
    source: []
  , items: 8
  , menu: '<ul class="typeahead dropdown-menu"></ul>'
  , item: '<li><a href="#"></a></li>'
Jacob Thornton's avatar
Jacob Thornton committed
2146
  , minLength: 1
2147
2148
2149
2150
2151
  }

  $.fn.typeahead.Constructor = Typeahead


2152
2153
2154
2155
2156
2157
2158
2159
2160
2161
 /* TYPEAHEAD NO CONFLICT
  * =================== */

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


 /* TYPEAHEAD DATA-API
2162
2163
  * ================== */

2164
2165
2166
2167
  $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
    var $this = $(this)
    if ($this.data('typeahead')) return
    $this.typeahead($this.data())
2168
2169
  })

2170
}(window.jQuery);
Mark Otto's avatar
Mark Otto committed
2171
/* ==========================================================
Mark Otto's avatar
Mark Otto committed
2172
 * bootstrap-affix.js v3.0.0
Mark Otto's avatar
Mark Otto committed
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
2190
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
 * http://twitter.github.com/bootstrap/javascript.html#affix
 * ==========================================================
 * Copyright 2012 Twitter, Inc.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 * ========================================================== */


!function ($) {

  "use strict"; // jshint ;_;


 /* AFFIX CLASS DEFINITION
  * ====================== */

  var Affix = function (element, options) {
    this.options = $.extend({}, $.fn.affix.defaults, options)
2201
2202
2203
    this.$window = $(window)
      .on('scroll.affix.data-api', $.proxy(this.checkPosition, this))
      .on('click.affix.data-api',  $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this))
Mark Otto's avatar
Mark Otto committed
2204
2205
2206
2207
2208
2209
2210
2211
2212
2213
2214
2215
2216
2217
2218
2219
2220
2221
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
    this.$element = $(element)
    this.checkPosition()
  }

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

    var scrollHeight = $(document).height()
      , scrollTop = this.$window.scrollTop()
      , position = this.$element.offset()
      , offset = this.options.offset
      , offsetBottom = offset.bottom
      , offsetTop = offset.top
      , reset = 'affix affix-top affix-bottom'
      , affix

    if (typeof offset != 'object') offsetBottom = offsetTop = offset
    if (typeof offsetTop == 'function') offsetTop = offset.top()
    if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()

    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

    this.affixed = affix
    this.unpin = affix == 'bottom' ? position.top - scrollTop : null

    this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''))
  }


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

2241
2242
  var old = $.fn.affix

Mark Otto's avatar
Mark Otto committed
2243
2244
2245
2246
2247
2248
2249
2250
2251
2252
2253
2254
2255
2256
2257
2258
2259
  $.fn.affix = function (option) {
    return this.each(function () {
      var $this = $(this)
        , data = $this.data('affix')
        , options = typeof option == 'object' && option
      if (!data) $this.data('affix', (data = new Affix(this, options)))
      if (typeof option == 'string') data[option]()
    })
  }

  $.fn.affix.Constructor = Affix

  $.fn.affix.defaults = {
    offset: 0
  }


2260
2261
2262
2263
2264
2265
2266
2267
2268
 /* AFFIX NO CONFLICT
  * ================= */

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


Mark Otto's avatar
Mark Otto committed
2269
2270
2271
2272
2273
2274
2275
2276
2277
2278
2279
2280
2281
2282
2283
2284
2285
2286
 /* AFFIX DATA-API
  * ============== */

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

      data.offset = data.offset || {}

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

      $spy.affix(data)
    })
  })


2287
}(window.jQuery);
For faster browsing, not all history is shown. View entire blame