You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

bootstrap.js 46 KiB

3 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722
  1. /* ===================================================
  2. * bootstrap-transition.js v2.0.0
  3. * http://twitter.github.com/bootstrap/javascript.html#transitions
  4. * ===================================================
  5. * Copyright 2012 Twitter, Inc.
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. * ========================================================== */
  19. !function( $ ) {
  20. $(function () {
  21. "use strict"
  22. /* CSS TRANSITION SUPPORT (https://gist.github.com/373874)
  23. * ======================================================= */
  24. $.support.transition = (function () {
  25. var thisBody = document.body || document.documentElement
  26. , thisStyle = thisBody.style
  27. , support = thisStyle.transition !== undefined || thisStyle.WebkitTransition !== undefined || thisStyle.MozTransition !== undefined || thisStyle.MsTransition !== undefined || thisStyle.OTransition !== undefined
  28. return support && {
  29. end: (function () {
  30. var transitionEnd = "TransitionEnd"
  31. if ( $.browser.webkit ) {
  32. transitionEnd = "webkitTransitionEnd"
  33. } else if ( $.browser.mozilla ) {
  34. transitionEnd = "transitionend"
  35. } else if ( $.browser.opera ) {
  36. transitionEnd = "oTransitionEnd"
  37. }
  38. return transitionEnd
  39. }())
  40. }
  41. })()
  42. })
  43. }( window.jQuery )
  44. /* ==========================================================
  45. * bootstrap-alert.js v2.0.0
  46. * http://twitter.github.com/bootstrap/javascript.html#alerts
  47. * ==========================================================
  48. * Copyright 2012 Twitter, Inc.
  49. *
  50. * Licensed under the Apache License, Version 2.0 (the "License");
  51. * you may not use this file except in compliance with the License.
  52. * You may obtain a copy of the License at
  53. *
  54. * http://www.apache.org/licenses/LICENSE-2.0
  55. *
  56. * Unless required by applicable law or agreed to in writing, software
  57. * distributed under the License is distributed on an "AS IS" BASIS,
  58. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  59. * See the License for the specific language governing permissions and
  60. * limitations under the License.
  61. * ========================================================== */
  62. !function( $ ){
  63. "use strict"
  64. /* ALERT CLASS DEFINITION
  65. * ====================== */
  66. var dismiss = '[data-dismiss="alert"]'
  67. , Alert = function ( el ) {
  68. $(el).on('click', dismiss, this.close)
  69. }
  70. Alert.prototype = {
  71. constructor: Alert
  72. , close: function ( e ) {
  73. var $this = $(this)
  74. , selector = $this.attr('data-target')
  75. , $parent
  76. if (!selector) {
  77. selector = $this.attr('href')
  78. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
  79. }
  80. $parent = $(selector)
  81. $parent.trigger('close')
  82. e && e.preventDefault()
  83. $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
  84. $parent.removeClass('in')
  85. function removeElement() {
  86. $parent.remove()
  87. $parent.trigger('closed')
  88. }
  89. $.support.transition && $parent.hasClass('fade') ?
  90. $parent.on($.support.transition.end, removeElement) :
  91. removeElement()
  92. }
  93. }
  94. /* ALERT PLUGIN DEFINITION
  95. * ======================= */
  96. $.fn.alert = function ( option ) {
  97. return this.each(function () {
  98. var $this = $(this)
  99. , data = $this.data('alert')
  100. if (!data) $this.data('alert', (data = new Alert(this)))
  101. if (typeof option == 'string') data[option].call($this)
  102. })
  103. }
  104. $.fn.alert.Constructor = Alert
  105. /* ALERT DATA-API
  106. * ============== */
  107. $(function () {
  108. $('body').on('click.alert.data-api', dismiss, Alert.prototype.close)
  109. })
  110. }( window.jQuery )
  111. /* ============================================================
  112. * bootstrap-button.js v2.0.0
  113. * http://twitter.github.com/bootstrap/javascript.html#buttons
  114. * ============================================================
  115. * Copyright 2012 Twitter, Inc.
  116. *
  117. * Licensed under the Apache License, Version 2.0 (the "License");
  118. * you may not use this file except in compliance with the License.
  119. * You may obtain a copy of the License at
  120. *
  121. * http://www.apache.org/licenses/LICENSE-2.0
  122. *
  123. * Unless required by applicable law or agreed to in writing, software
  124. * distributed under the License is distributed on an "AS IS" BASIS,
  125. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  126. * See the License for the specific language governing permissions and
  127. * limitations under the License.
  128. * ============================================================ */
  129. !function( $ ){
  130. "use strict"
  131. /* BUTTON PUBLIC CLASS DEFINITION
  132. * ============================== */
  133. var Button = function ( element, options ) {
  134. this.$element = $(element)
  135. this.options = $.extend({}, $.fn.button.defaults, options)
  136. }
  137. Button.prototype = {
  138. constructor: Button
  139. , setState: function ( state ) {
  140. var d = 'disabled'
  141. , $el = this.$element
  142. , data = $el.data()
  143. , val = $el.is('input') ? 'val' : 'html'
  144. state = state + 'Text'
  145. data.resetText || $el.data('resetText', $el[val]())
  146. $el[val](data[state] || this.options[state])
  147. // push to event loop to allow forms to submit
  148. setTimeout(function () {
  149. state == 'loadingText' ?
  150. $el.addClass(d).attr(d, d) :
  151. $el.removeClass(d).removeAttr(d)
  152. }, 0)
  153. }
  154. , toggle: function () {
  155. var $parent = this.$element.parent('[data-toggle="buttons-radio"]')
  156. $parent && $parent
  157. .find('.active')
  158. .removeClass('active')
  159. this.$element.toggleClass('active')
  160. }
  161. }
  162. /* BUTTON PLUGIN DEFINITION
  163. * ======================== */
  164. $.fn.button = function ( option ) {
  165. return this.each(function () {
  166. var $this = $(this)
  167. , data = $this.data('button')
  168. , options = typeof option == 'object' && option
  169. if (!data) $this.data('button', (data = new Button(this, options)))
  170. if (option == 'toggle') data.toggle()
  171. else if (option) data.setState(option)
  172. })
  173. }
  174. $.fn.button.defaults = {
  175. loadingText: 'loading...'
  176. }
  177. $.fn.button.Constructor = Button
  178. /* BUTTON DATA-API
  179. * =============== */
  180. $(function () {
  181. $('body').on('click.button.data-api', '[data-toggle^=button]', function ( e ) {
  182. $(e.target).button('toggle')
  183. })
  184. })
  185. }( window.jQuery )
  186. /* ==========================================================
  187. * bootstrap-carousel.js v2.0.0
  188. * http://twitter.github.com/bootstrap/javascript.html#carousel
  189. * ==========================================================
  190. * Copyright 2012 Twitter, Inc.
  191. *
  192. * Licensed under the Apache License, Version 2.0 (the "License");
  193. * you may not use this file except in compliance with the License.
  194. * You may obtain a copy of the License at
  195. *
  196. * http://www.apache.org/licenses/LICENSE-2.0
  197. *
  198. * Unless required by applicable law or agreed to in writing, software
  199. * distributed under the License is distributed on an "AS IS" BASIS,
  200. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  201. * See the License for the specific language governing permissions and
  202. * limitations under the License.
  203. * ========================================================== */
  204. !function( $ ){
  205. "use strict"
  206. /* CAROUSEL CLASS DEFINITION
  207. * ========================= */
  208. var Carousel = function (element, options) {
  209. this.$element = $(element)
  210. this.options = $.extend({}, $.fn.carousel.defaults, options)
  211. this.options.slide && this.slide(this.options.slide)
  212. }
  213. Carousel.prototype = {
  214. cycle: function () {
  215. this.interval = setInterval($.proxy(this.next, this), this.options.interval)
  216. return this
  217. }
  218. , to: function (pos) {
  219. var $active = this.$element.find('.active')
  220. , children = $active.parent().children()
  221. , activePos = children.index($active)
  222. , that = this
  223. if (pos > (children.length - 1) || pos < 0) return
  224. if (this.sliding) {
  225. return this.$element.one('slid', function () {
  226. that.to(pos)
  227. })
  228. }
  229. if (activePos == pos) {
  230. return this.pause().cycle()
  231. }
  232. return this.slide(pos > activePos ? 'next' : 'prev', $(children[pos]))
  233. }
  234. , pause: function () {
  235. clearInterval(this.interval)
  236. return this
  237. }
  238. , next: function () {
  239. if (this.sliding) return
  240. return this.slide('next')
  241. }
  242. , prev: function () {
  243. if (this.sliding) return
  244. return this.slide('prev')
  245. }
  246. , slide: function (type, next) {
  247. var $active = this.$element.find('.active')
  248. , $next = next || $active[type]()
  249. , isCycling = this.interval
  250. , direction = type == 'next' ? 'left' : 'right'
  251. , fallback = type == 'next' ? 'first' : 'last'
  252. , that = this
  253. this.sliding = true
  254. isCycling && this.pause()
  255. $next = $next.length ? $next : this.$element.find('.item')[fallback]()
  256. if (!$.support.transition && this.$element.hasClass('slide')) {
  257. this.$element.trigger('slide')
  258. $active.removeClass('active')
  259. $next.addClass('active')
  260. this.sliding = false
  261. this.$element.trigger('slid')
  262. } else {
  263. $next.addClass(type)
  264. $next[0].offsetWidth // force reflow
  265. $active.addClass(direction)
  266. $next.addClass(direction)
  267. this.$element.trigger('slide')
  268. this.$element.one($.support.transition.end, function () {
  269. $next.removeClass([type, direction].join(' ')).addClass('active')
  270. $active.removeClass(['active', direction].join(' '))
  271. that.sliding = false
  272. setTimeout(function () { that.$element.trigger('slid') }, 0)
  273. })
  274. }
  275. isCycling && this.cycle()
  276. return this
  277. }
  278. }
  279. /* CAROUSEL PLUGIN DEFINITION
  280. * ========================== */
  281. $.fn.carousel = function ( option ) {
  282. return this.each(function () {
  283. var $this = $(this)
  284. , data = $this.data('carousel')
  285. , options = typeof option == 'object' && option
  286. if (!data) $this.data('carousel', (data = new Carousel(this, options)))
  287. if (typeof option == 'number') data.to(option)
  288. else if (typeof option == 'string' || (option = options.slide)) data[option]()
  289. else data.cycle()
  290. })
  291. }
  292. $.fn.carousel.defaults = {
  293. interval: 5000
  294. }
  295. $.fn.carousel.Constructor = Carousel
  296. /* CAROUSEL DATA-API
  297. * ================= */
  298. $(function () {
  299. $('body').on('click.carousel.data-api', '[data-slide]', function ( e ) {
  300. var $this = $(this), href
  301. , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
  302. , options = !$target.data('modal') && $.extend({}, $target.data(), $this.data())
  303. $target.carousel(options)
  304. e.preventDefault()
  305. })
  306. })
  307. }( window.jQuery )
  308. /* =============================================================
  309. * bootstrap-collapse.js v2.0.0
  310. * http://twitter.github.com/bootstrap/javascript.html#collapse
  311. * =============================================================
  312. * Copyright 2012 Twitter, Inc.
  313. *
  314. * Licensed under the Apache License, Version 2.0 (the "License");
  315. * you may not use this file except in compliance with the License.
  316. * You may obtain a copy of the License at
  317. *
  318. * http://www.apache.org/licenses/LICENSE-2.0
  319. *
  320. * Unless required by applicable law or agreed to in writing, software
  321. * distributed under the License is distributed on an "AS IS" BASIS,
  322. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  323. * See the License for the specific language governing permissions and
  324. * limitations under the License.
  325. * ============================================================ */
  326. !function( $ ){
  327. "use strict"
  328. var Collapse = function ( element, options ) {
  329. this.$element = $(element)
  330. this.options = $.extend({}, $.fn.collapse.defaults, options)
  331. if (this.options["parent"]) {
  332. this.$parent = $(this.options["parent"])
  333. }
  334. this.options.toggle && this.toggle()
  335. }
  336. Collapse.prototype = {
  337. constructor: Collapse
  338. , dimension: function () {
  339. var hasWidth = this.$element.hasClass('width')
  340. return hasWidth ? 'width' : 'height'
  341. }
  342. , show: function () {
  343. var dimension = this.dimension()
  344. , scroll = $.camelCase(['scroll', dimension].join('-'))
  345. , actives = this.$parent && this.$parent.find('.in')
  346. , hasData
  347. if (actives && actives.length) {
  348. hasData = actives.data('collapse')
  349. actives.collapse('hide')
  350. hasData || actives.data('collapse', null)
  351. }
  352. this.$element[dimension](0)
  353. this.transition('addClass', 'show', 'shown')
  354. this.$element[dimension](this.$element[0][scroll])
  355. }
  356. , hide: function () {
  357. var dimension = this.dimension()
  358. this.reset(this.$element[dimension]())
  359. this.transition('removeClass', 'hide', 'hidden')
  360. this.$element[dimension](0)
  361. }
  362. , reset: function ( size ) {
  363. var dimension = this.dimension()
  364. this.$element
  365. .removeClass('collapse')
  366. [dimension](size || 'auto')
  367. [0].offsetWidth
  368. this.$element.addClass('collapse')
  369. }
  370. , transition: function ( method, startEvent, completeEvent ) {
  371. var that = this
  372. , complete = function () {
  373. if (startEvent == 'show') that.reset()
  374. that.$element.trigger(completeEvent)
  375. }
  376. this.$element
  377. .trigger(startEvent)
  378. [method]('in')
  379. $.support.transition && this.$element.hasClass('collapse') ?
  380. this.$element.one($.support.transition.end, complete) :
  381. complete()
  382. }
  383. , toggle: function () {
  384. this[this.$element.hasClass('in') ? 'hide' : 'show']()
  385. }
  386. }
  387. /* COLLAPSIBLE PLUGIN DEFINITION
  388. * ============================== */
  389. $.fn.collapse = function ( option ) {
  390. return this.each(function () {
  391. var $this = $(this)
  392. , data = $this.data('collapse')
  393. , options = typeof option == 'object' && option
  394. if (!data) $this.data('collapse', (data = new Collapse(this, options)))
  395. if (typeof option == 'string') data[option]()
  396. })
  397. }
  398. $.fn.collapse.defaults = {
  399. toggle: true
  400. }
  401. $.fn.collapse.Constructor = Collapse
  402. /* COLLAPSIBLE DATA-API
  403. * ==================== */
  404. $(function () {
  405. $('body').on('click.collapse.data-api', '[data-toggle=collapse]', function ( e ) {
  406. var $this = $(this), href
  407. , target = $this.attr('data-target')
  408. || e.preventDefault()
  409. || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
  410. , option = $(target).data('collapse') ? 'toggle' : $this.data()
  411. $(target).collapse(option)
  412. })
  413. })
  414. }( window.jQuery )
  415. /* ============================================================
  416. * bootstrap-dropdown.js v2.0.0
  417. * http://twitter.github.com/bootstrap/javascript.html#dropdowns
  418. * ============================================================
  419. * Copyright 2012 Twitter, Inc.
  420. *
  421. * Licensed under the Apache License, Version 2.0 (the "License");
  422. * you may not use this file except in compliance with the License.
  423. * You may obtain a copy of the License at
  424. *
  425. * http://www.apache.org/licenses/LICENSE-2.0
  426. *
  427. * Unless required by applicable law or agreed to in writing, software
  428. * distributed under the License is distributed on an "AS IS" BASIS,
  429. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  430. * See the License for the specific language governing permissions and
  431. * limitations under the License.
  432. * ============================================================ */
  433. !function( $ ){
  434. "use strict"
  435. /* DROPDOWN CLASS DEFINITION
  436. * ========================= */
  437. var toggle = '[data-toggle="dropdown"]'
  438. , Dropdown = function ( element ) {
  439. var $el = $(element).on('click.dropdown.data-api', this.toggle)
  440. $('html').on('click.dropdown.data-api', function () {
  441. $el.parent().removeClass('open')
  442. })
  443. }
  444. Dropdown.prototype = {
  445. constructor: Dropdown
  446. , toggle: function ( e ) {
  447. var $this = $(this)
  448. , selector = $this.attr('data-target')
  449. , $parent
  450. , isActive
  451. if (!selector) {
  452. selector = $this.attr('href')
  453. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
  454. }
  455. $parent = $(selector)
  456. $parent.length || ($parent = $this.parent())
  457. isActive = $parent.hasClass('open')
  458. clearMenus()
  459. !isActive && $parent.toggleClass('open')
  460. return false
  461. }
  462. }
  463. function clearMenus() {
  464. $(toggle).parent().removeClass('open')
  465. }
  466. /* DROPDOWN PLUGIN DEFINITION
  467. * ========================== */
  468. $.fn.dropdown = function ( option ) {
  469. return this.each(function () {
  470. var $this = $(this)
  471. , data = $this.data('dropdown')
  472. if (!data) $this.data('dropdown', (data = new Dropdown(this)))
  473. if (typeof option == 'string') data[option].call($this)
  474. })
  475. }
  476. $.fn.dropdown.Constructor = Dropdown
  477. /* APPLY TO STANDARD DROPDOWN ELEMENTS
  478. * =================================== */
  479. $(function () {
  480. $('html').on('click.dropdown.data-api', clearMenus)
  481. $('body').on('click.dropdown.data-api', toggle, Dropdown.prototype.toggle)
  482. })
  483. }( window.jQuery )
  484. /* =========================================================
  485. * bootstrap-modal.js v2.0.0
  486. * http://twitter.github.com/bootstrap/javascript.html#modals
  487. * =========================================================
  488. * Copyright 2012 Twitter, Inc.
  489. *
  490. * Licensed under the Apache License, Version 2.0 (the "License");
  491. * you may not use this file except in compliance with the License.
  492. * You may obtain a copy of the License at
  493. *
  494. * http://www.apache.org/licenses/LICENSE-2.0
  495. *
  496. * Unless required by applicable law or agreed to in writing, software
  497. * distributed under the License is distributed on an "AS IS" BASIS,
  498. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  499. * See the License for the specific language governing permissions and
  500. * limitations under the License.
  501. * ========================================================= */
  502. !function( $ ){
  503. "use strict"
  504. /* MODAL CLASS DEFINITION
  505. * ====================== */
  506. var Modal = function ( content, options ) {
  507. this.options = $.extend({}, $.fn.modal.defaults, options)
  508. this.$element = $(content)
  509. .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
  510. }
  511. Modal.prototype = {
  512. constructor: Modal
  513. , toggle: function () {
  514. return this[!this.isShown ? 'show' : 'hide']()
  515. }
  516. , show: function () {
  517. var that = this
  518. if (this.isShown) return
  519. $('body').addClass('modal-open')
  520. this.isShown = true
  521. this.$element.trigger('show')
  522. escape.call(this)
  523. backdrop.call(this, function () {
  524. var transition = $.support.transition && that.$element.hasClass('fade')
  525. !that.$element.parent().length && that.$element.appendTo(document.body) //don't move modals dom position
  526. that.$element
  527. .show()
  528. if (transition) {
  529. that.$element[0].offsetWidth // force reflow
  530. }
  531. that.$element.addClass('in')
  532. transition ?
  533. that.$element.one($.support.transition.end, function () { that.$element.trigger('shown') }) :
  534. that.$element.trigger('shown')
  535. })
  536. }
  537. , hide: function ( e ) {
  538. e && e.preventDefault()
  539. if (!this.isShown) return
  540. var that = this
  541. this.isShown = false
  542. $('body').removeClass('modal-open')
  543. escape.call(this)
  544. this.$element
  545. .trigger('hide')
  546. .removeClass('in')
  547. $.support.transition && this.$element.hasClass('fade') ?
  548. hideWithTransition.call(this) :
  549. hideModal.call(this)
  550. }
  551. }
  552. /* MODAL PRIVATE METHODS
  553. * ===================== */
  554. function hideWithTransition() {
  555. var that = this
  556. , timeout = setTimeout(function () {
  557. that.$element.off($.support.transition.end)
  558. hideModal.call(that)
  559. }, 500)
  560. this.$element.one($.support.transition.end, function () {
  561. clearTimeout(timeout)
  562. hideModal.call(that)
  563. })
  564. }
  565. function hideModal( that ) {
  566. this.$element
  567. .hide()
  568. .trigger('hidden')
  569. backdrop.call(this)
  570. }
  571. function backdrop( callback ) {
  572. var that = this
  573. , animate = this.$element.hasClass('fade') ? 'fade' : ''
  574. if (this.isShown && this.options.backdrop) {
  575. var doAnimate = $.support.transition && animate
  576. this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
  577. .appendTo(document.body)
  578. if (this.options.backdrop != 'static') {
  579. this.$backdrop.click($.proxy(this.hide, this))
  580. }
  581. if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
  582. this.$backdrop.addClass('in')
  583. doAnimate ?
  584. this.$backdrop.one($.support.transition.end, callback) :
  585. callback()
  586. } else if (!this.isShown && this.$backdrop) {
  587. this.$backdrop.removeClass('in')
  588. $.support.transition && this.$element.hasClass('fade')?
  589. this.$backdrop.one($.support.transition.end, $.proxy(removeBackdrop, this)) :
  590. removeBackdrop.call(this)
  591. } else if (callback) {
  592. callback()
  593. }
  594. }
  595. function removeBackdrop() {
  596. this.$backdrop.remove()
  597. this.$backdrop = null
  598. }
  599. function escape() {
  600. var that = this
  601. if (this.isShown && this.options.keyboard) {
  602. $(document).on('keyup.dismiss.modal', function ( e ) {
  603. e.which == 27 && that.hide()
  604. })
  605. } else if (!this.isShown) {
  606. $(document).off('keyup.dismiss.modal')
  607. }
  608. }
  609. /* MODAL PLUGIN DEFINITION
  610. * ======================= */
  611. $.fn.modal = function ( option ) {
  612. return this.each(function () {
  613. var $this = $(this)
  614. , data = $this.data('modal')
  615. , options = typeof option == 'object' && option
  616. if (!data) $this.data('modal', (data = new Modal(this, options)))
  617. if (typeof option == 'string') data[option]()
  618. else data.show()
  619. })
  620. }
  621. $.fn.modal.defaults = {
  622. backdrop: true
  623. , keyboard: true
  624. }
  625. $.fn.modal.Constructor = Modal
  626. /* MODAL DATA-API
  627. * ============== */
  628. $(function () {
  629. $('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
  630. var $this = $(this), href
  631. , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
  632. , option = $target.data('modal') ? 'toggle' : $.extend({}, $target.data(), $this.data())
  633. e.preventDefault()
  634. $target.modal(option)
  635. })
  636. })
  637. }( window.jQuery )
  638. /* ===========================================================
  639. * bootstrap-tooltip.js v2.0.0
  640. * http://twitter.github.com/bootstrap/javascript.html#tooltips
  641. * Inspired by the original jQuery.tipsy by Jason Frame
  642. * ===========================================================
  643. * Copyright 2012 Twitter, Inc.
  644. *
  645. * Licensed under the Apache License, Version 2.0 (the "License");
  646. * you may not use this file except in compliance with the License.
  647. * You may obtain a copy of the License at
  648. *
  649. * http://www.apache.org/licenses/LICENSE-2.0
  650. *
  651. * Unless required by applicable law or agreed to in writing, software
  652. * distributed under the License is distributed on an "AS IS" BASIS,
  653. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  654. * See the License for the specific language governing permissions and
  655. * limitations under the License.
  656. * ========================================================== */
  657. !function( $ ) {
  658. "use strict"
  659. /* TOOLTIP PUBLIC CLASS DEFINITION
  660. * =============================== */
  661. var Tooltip = function ( element, options ) {
  662. this.init('tooltip', element, options)
  663. }
  664. Tooltip.prototype = {
  665. constructor: Tooltip
  666. , init: function ( type, element, options ) {
  667. var eventIn
  668. , eventOut
  669. this.type = type
  670. this.$element = $(element)
  671. this.options = this.getOptions(options)
  672. this.enabled = true
  673. if (this.options.trigger != 'manual') {
  674. eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
  675. eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
  676. this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
  677. this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
  678. }
  679. this.options.selector ?
  680. (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
  681. this.fixTitle()
  682. }
  683. , getOptions: function ( options ) {
  684. options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
  685. if (options.delay && typeof options.delay == 'number') {
  686. options.delay = {
  687. show: options.delay
  688. , hide: options.delay
  689. }
  690. }
  691. return options
  692. }
  693. , enter: function ( e ) {
  694. var self = $(e.currentTarget)[this.type](this._options).data(this.type)
  695. if (!self.options.delay || !self.options.delay.show) {
  696. self.show()
  697. } else {
  698. self.hoverState = 'in'
  699. setTimeout(function() {
  700. if (self.hoverState == 'in') {
  701. self.show()
  702. }
  703. }, self.options.delay.show)
  704. }
  705. }
  706. , leave: function ( e ) {
  707. var self = $(e.currentTarget)[this.type](this._options).data(this.type)
  708. if (!self.options.delay || !self.options.delay.hide) {
  709. self.hide()
  710. } else {
  711. self.hoverState = 'out'
  712. setTimeout(function() {
  713. if (self.hoverState == 'out') {
  714. self.hide()
  715. }
  716. }, self.options.delay.hide)
  717. }
  718. }
  719. , show: function () {
  720. var $tip
  721. , inside
  722. , pos
  723. , actualWidth
  724. , actualHeight
  725. , placement
  726. , tp
  727. if (this.hasContent() && this.enabled) {
  728. $tip = this.tip()
  729. this.setContent()
  730. if (this.options.animation) {
  731. $tip.addClass('fade')
  732. }
  733. placement = typeof this.options.placement == 'function' ?
  734. this.options.placement.call(this, $tip[0], this.$element[0]) :
  735. this.options.placement
  736. inside = /in/.test(placement)
  737. $tip
  738. .remove()
  739. .css({ top: 0, left: 0, display: 'block' })
  740. .appendTo(inside ? this.$element : document.body)
  741. pos = this.getPosition(inside)
  742. actualWidth = $tip[0].offsetWidth
  743. actualHeight = $tip[0].offsetHeight
  744. switch (inside ? placement.split(' ')[1] : placement) {
  745. case 'bottom':
  746. tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
  747. break
  748. case 'top':
  749. tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
  750. break
  751. case 'left':
  752. tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
  753. break
  754. case 'right':
  755. tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
  756. break
  757. }
  758. $tip
  759. .css(tp)
  760. .addClass(placement)
  761. .addClass('in')
  762. }
  763. }
  764. , setContent: function () {
  765. var $tip = this.tip()
  766. $tip.find('.tooltip-inner').html(this.getTitle())
  767. $tip.removeClass('fade in top bottom left right')
  768. }
  769. , hide: function () {
  770. var that = this
  771. , $tip = this.tip()
  772. $tip.removeClass('in')
  773. function removeWithAnimation() {
  774. var timeout = setTimeout(function () {
  775. $tip.off($.support.transition.end).remove()
  776. }, 500)
  777. $tip.one($.support.transition.end, function () {
  778. clearTimeout(timeout)
  779. $tip.remove()
  780. })
  781. }
  782. $.support.transition && this.$tip.hasClass('fade') ?
  783. removeWithAnimation() :
  784. $tip.remove()
  785. }
  786. , fixTitle: function () {
  787. var $e = this.$element
  788. if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
  789. $e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
  790. }
  791. }
  792. , hasContent: function () {
  793. return this.getTitle()
  794. }
  795. , getPosition: function (inside) {
  796. return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
  797. width: this.$element[0].offsetWidth
  798. , height: this.$element[0].offsetHeight
  799. })
  800. }
  801. , getTitle: function () {
  802. var title
  803. , $e = this.$element
  804. , o = this.options
  805. title = $e.attr('data-original-title')
  806. || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
  807. title = title.toString().replace(/(^\s*|\s*$)/, "")
  808. return title
  809. }
  810. , tip: function () {
  811. return this.$tip = this.$tip || $(this.options.template)
  812. }
  813. , validate: function () {
  814. if (!this.$element[0].parentNode) {
  815. this.hide()
  816. this.$element = null
  817. this.options = null
  818. }
  819. }
  820. , enable: function () {
  821. this.enabled = true
  822. }
  823. , disable: function () {
  824. this.enabled = false
  825. }
  826. , toggleEnabled: function () {
  827. this.enabled = !this.enabled
  828. }
  829. , toggle: function () {
  830. this[this.tip().hasClass('in') ? 'hide' : 'show']()
  831. }
  832. }
  833. /* TOOLTIP PLUGIN DEFINITION
  834. * ========================= */
  835. $.fn.tooltip = function ( option ) {
  836. return this.each(function () {
  837. var $this = $(this)
  838. , data = $this.data('tooltip')
  839. , options = typeof option == 'object' && option
  840. if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
  841. if (typeof option == 'string') data[option]()
  842. })
  843. }
  844. $.fn.tooltip.Constructor = Tooltip
  845. $.fn.tooltip.defaults = {
  846. animation: true
  847. , delay: 0
  848. , selector: false
  849. , placement: 'top'
  850. , trigger: 'hover'
  851. , title: ''
  852. , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
  853. }
  854. }( window.jQuery )
  855. /* ===========================================================
  856. * bootstrap-popover.js v2.0.0
  857. * http://twitter.github.com/bootstrap/javascript.html#popovers
  858. * ===========================================================
  859. * Copyright 2012 Twitter, Inc.
  860. *
  861. * Licensed under the Apache License, Version 2.0 (the "License");
  862. * you may not use this file except in compliance with the License.
  863. * You may obtain a copy of the License at
  864. *
  865. * http://www.apache.org/licenses/LICENSE-2.0
  866. *
  867. * Unless required by applicable law or agreed to in writing, software
  868. * distributed under the License is distributed on an "AS IS" BASIS,
  869. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  870. * See the License for the specific language governing permissions and
  871. * limitations under the License.
  872. * =========================================================== */
  873. !function( $ ) {
  874. "use strict"
  875. var Popover = function ( element, options ) {
  876. this.init('popover', element, options)
  877. }
  878. /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
  879. ========================================== */
  880. Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
  881. constructor: Popover
  882. , setContent: function () {
  883. var $tip = this.tip()
  884. , title = this.getTitle()
  885. , content = this.getContent()
  886. $tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title)
  887. $tip.find('.popover-content > *')[ $.type(content) == 'object' ? 'append' : 'html' ](content)
  888. $tip.removeClass('fade top bottom left right in')
  889. }
  890. , hasContent: function () {
  891. return this.getTitle() || this.getContent()
  892. }
  893. , getContent: function () {
  894. var content
  895. , $e = this.$element
  896. , o = this.options
  897. content = $e.attr('data-content')
  898. || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
  899. content = content.toString().replace(/(^\s*|\s*$)/, "")
  900. return content
  901. }
  902. , tip: function() {
  903. if (!this.$tip) {
  904. this.$tip = $(this.options.template)
  905. }
  906. return this.$tip
  907. }
  908. })
  909. /* POPOVER PLUGIN DEFINITION
  910. * ======================= */
  911. $.fn.popover = function ( option ) {
  912. return this.each(function () {
  913. var $this = $(this)
  914. , data = $this.data('popover')
  915. , options = typeof option == 'object' && option
  916. if (!data) $this.data('popover', (data = new Popover(this, options)))
  917. if (typeof option == 'string') data[option]()
  918. })
  919. }
  920. $.fn.popover.Constructor = Popover
  921. $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
  922. placement: 'right'
  923. , content: ''
  924. , template: '<div class="popover"><div class="arrow"></div><div class="popover-inner"><h3 class="popover-title"></h3><div class="popover-content"><p></p></div></div></div>'
  925. })
  926. }( window.jQuery )
  927. /* =============================================================
  928. * bootstrap-scrollspy.js v2.0.0
  929. * http://twitter.github.com/bootstrap/javascript.html#scrollspy
  930. * =============================================================
  931. * Copyright 2012 Twitter, Inc.
  932. *
  933. * Licensed under the Apache License, Version 2.0 (the "License");
  934. * you may not use this file except in compliance with the License.
  935. * You may obtain a copy of the License at
  936. *
  937. * http://www.apache.org/licenses/LICENSE-2.0
  938. *
  939. * Unless required by applicable law or agreed to in writing, software
  940. * distributed under the License is distributed on an "AS IS" BASIS,
  941. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  942. * See the License for the specific language governing permissions and
  943. * limitations under the License.
  944. * ============================================================== */
  945. !function ( $ ) {
  946. "use strict"
  947. /* SCROLLSPY CLASS DEFINITION
  948. * ========================== */
  949. function ScrollSpy( element, options) {
  950. var process = $.proxy(this.process, this)
  951. , $element = $(element).is('body') ? $(window) : $(element)
  952. , href
  953. this.options = $.extend({}, $.fn.scrollspy.defaults, options)
  954. this.$scrollElement = $element.on('scroll.scroll.data-api', process)
  955. this.selector = (this.options.target
  956. || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
  957. || '') + ' .nav li > a'
  958. this.$body = $('body').on('click.scroll.data-api', this.selector, process)
  959. this.refresh()
  960. this.process()
  961. }
  962. ScrollSpy.prototype = {
  963. constructor: ScrollSpy
  964. , refresh: function () {
  965. this.targets = this.$body
  966. .find(this.selector)
  967. .map(function () {
  968. var href = $(this).attr('href')
  969. return /^#\w/.test(href) && $(href).length ? href : null
  970. })
  971. this.offsets = $.map(this.targets, function (id) {
  972. return $(id).position().top
  973. })
  974. }
  975. , process: function () {
  976. var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
  977. , offsets = this.offsets
  978. , targets = this.targets
  979. , activeTarget = this.activeTarget
  980. , i
  981. for (i = offsets.length; i--;) {
  982. activeTarget != targets[i]
  983. && scrollTop >= offsets[i]
  984. && (!offsets[i + 1] || scrollTop <= offsets[i + 1])
  985. && this.activate( targets[i] )
  986. }
  987. }
  988. , activate: function (target) {
  989. var active
  990. this.activeTarget = target
  991. this.$body
  992. .find(this.selector).parent('.active')
  993. .removeClass('active')
  994. active = this.$body
  995. .find(this.selector + '[href="' + target + '"]')
  996. .parent('li')
  997. .addClass('active')
  998. if ( active.parent('.dropdown-menu') ) {
  999. active.closest('li.dropdown').addClass('active')
  1000. }
  1001. }
  1002. }
  1003. /* SCROLLSPY PLUGIN DEFINITION
  1004. * =========================== */
  1005. $.fn.scrollspy = function ( option ) {
  1006. return this.each(function () {
  1007. var $this = $(this)
  1008. , data = $this.data('scrollspy')
  1009. , options = typeof option == 'object' && option
  1010. if (!data) $this.data('scrollspy', (data = new ScrollSpy(this, options)))
  1011. if (typeof option == 'string') data[option]()
  1012. })
  1013. }
  1014. $.fn.scrollspy.Constructor = ScrollSpy
  1015. $.fn.scrollspy.defaults = {
  1016. offset: 10
  1017. }
  1018. /* SCROLLSPY DATA-API
  1019. * ================== */
  1020. $(function () {
  1021. $('[data-spy="scroll"]').each(function () {
  1022. var $spy = $(this)
  1023. $spy.scrollspy($spy.data())
  1024. })
  1025. })
  1026. }( window.jQuery )
  1027. /* ========================================================
  1028. * bootstrap-tab.js v2.0.0
  1029. * http://twitter.github.com/bootstrap/javascript.html#tabs
  1030. * ========================================================
  1031. * Copyright 2012 Twitter, Inc.
  1032. *
  1033. * Licensed under the Apache License, Version 2.0 (the "License");
  1034. * you may not use this file except in compliance with the License.
  1035. * You may obtain a copy of the License at
  1036. *
  1037. * http://www.apache.org/licenses/LICENSE-2.0
  1038. *
  1039. * Unless required by applicable law or agreed to in writing, software
  1040. * distributed under the License is distributed on an "AS IS" BASIS,
  1041. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1042. * See the License for the specific language governing permissions and
  1043. * limitations under the License.
  1044. * ======================================================== */
  1045. !function( $ ){
  1046. "use strict"
  1047. /* TAB CLASS DEFINITION
  1048. * ==================== */
  1049. var Tab = function ( element ) {
  1050. this.element = $(element)
  1051. }
  1052. Tab.prototype = {
  1053. constructor: Tab
  1054. , show: function () {
  1055. var $this = this.element
  1056. , $ul = $this.closest('ul:not(.dropdown-menu)')
  1057. , selector = $this.attr('data-target')
  1058. , previous
  1059. , $target
  1060. if (!selector) {
  1061. selector = $this.attr('href')
  1062. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
  1063. }
  1064. if ( $this.parent('li').hasClass('active') ) return
  1065. previous = $ul.find('.active a').last()[0]
  1066. $this.trigger({
  1067. type: 'show'
  1068. , relatedTarget: previous
  1069. })
  1070. $target = $(selector)
  1071. this.activate($this.parent('li'), $ul)
  1072. this.activate($target, $target.parent(), function () {
  1073. $this.trigger({
  1074. type: 'shown'
  1075. , relatedTarget: previous
  1076. })
  1077. })
  1078. }
  1079. , activate: function ( element, container, callback) {
  1080. var $active = container.find('> .active')
  1081. , transition = callback
  1082. && $.support.transition
  1083. && $active.hasClass('fade')
  1084. function next() {
  1085. $active
  1086. .removeClass('active')
  1087. .find('> .dropdown-menu > .active')
  1088. .removeClass('active')
  1089. element.addClass('active')
  1090. if (transition) {
  1091. element[0].offsetWidth // reflow for transition
  1092. element.addClass('in')
  1093. } else {
  1094. element.removeClass('fade')
  1095. }
  1096. if ( element.parent('.dropdown-menu') ) {
  1097. element.closest('li.dropdown').addClass('active')
  1098. }
  1099. callback && callback()
  1100. }
  1101. transition ?
  1102. $active.one($.support.transition.end, next) :
  1103. next()
  1104. $active.removeClass('in')
  1105. }
  1106. }
  1107. /* TAB PLUGIN DEFINITION
  1108. * ===================== */
  1109. $.fn.tab = function ( option ) {
  1110. return this.each(function () {
  1111. var $this = $(this)
  1112. , data = $this.data('tab')
  1113. if (!data) $this.data('tab', (data = new Tab(this)))
  1114. if (typeof option == 'string') data[option]()
  1115. })
  1116. }
  1117. $.fn.tab.Constructor = Tab
  1118. /* TAB DATA-API
  1119. * ============ */
  1120. $(function () {
  1121. $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
  1122. e.preventDefault()
  1123. $(this).tab('show')
  1124. })
  1125. })
  1126. }( window.jQuery )
  1127. /* =============================================================
  1128. * bootstrap-typeahead.js v2.0.0
  1129. * http://twitter.github.com/bootstrap/javascript.html#typeahead
  1130. * =============================================================
  1131. * Copyright 2012 Twitter, Inc.
  1132. *
  1133. * Licensed under the Apache License, Version 2.0 (the "License");
  1134. * you may not use this file except in compliance with the License.
  1135. * You may obtain a copy of the License at
  1136. *
  1137. * http://www.apache.org/licenses/LICENSE-2.0
  1138. *
  1139. * Unless required by applicable law or agreed to in writing, software
  1140. * distributed under the License is distributed on an "AS IS" BASIS,
  1141. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1142. * See the License for the specific language governing permissions and
  1143. * limitations under the License.
  1144. * ============================================================ */
  1145. !function( $ ){
  1146. "use strict"
  1147. var Typeahead = function ( element, options ) {
  1148. this.$element = $(element)
  1149. this.options = $.extend({}, $.fn.typeahead.defaults, options)
  1150. this.matcher = this.options.matcher || this.matcher
  1151. this.sorter = this.options.sorter || this.sorter
  1152. this.highlighter = this.options.highlighter || this.highlighter
  1153. this.$menu = $(this.options.menu).appendTo('body')
  1154. this.source = this.options.source
  1155. this.shown = false
  1156. this.listen()
  1157. }
  1158. Typeahead.prototype = {
  1159. constructor: Typeahead
  1160. , select: function () {
  1161. var val = this.$menu.find('.active').attr('data-value')
  1162. this.$element.val(val)
  1163. return this.hide()
  1164. }
  1165. , show: function () {
  1166. var pos = $.extend({}, this.$element.offset(), {
  1167. height: this.$element[0].offsetHeight
  1168. })
  1169. this.$menu.css({
  1170. top: pos.top + pos.height
  1171. , left: pos.left
  1172. })
  1173. this.$menu.show()
  1174. this.shown = true
  1175. return this
  1176. }
  1177. , hide: function () {
  1178. this.$menu.hide()
  1179. this.shown = false
  1180. return this
  1181. }
  1182. , lookup: function (event) {
  1183. var that = this
  1184. , items
  1185. , q
  1186. this.query = this.$element.val()
  1187. if (!this.query) {
  1188. return this.shown ? this.hide() : this
  1189. }
  1190. items = $.grep(this.source, function (item) {
  1191. if (that.matcher(item)) return item
  1192. })
  1193. items = this.sorter(items)
  1194. if (!items.length) {
  1195. return this.shown ? this.hide() : this
  1196. }
  1197. return this.render(items.slice(0, this.options.items)).show()
  1198. }
  1199. , matcher: function (item) {
  1200. return ~item.toLowerCase().indexOf(this.query.toLowerCase())
  1201. }
  1202. , sorter: function (items) {
  1203. var beginswith = []
  1204. , caseSensitive = []
  1205. , caseInsensitive = []
  1206. , item
  1207. while (item = items.shift()) {
  1208. if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item)
  1209. else if (~item.indexOf(this.query)) caseSensitive.push(item)
  1210. else caseInsensitive.push(item)
  1211. }
  1212. return beginswith.concat(caseSensitive, caseInsensitive)
  1213. }
  1214. , highlighter: function (item) {
  1215. return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) {
  1216. return '<strong>' + match + '</strong>'
  1217. })
  1218. }
  1219. , render: function (items) {
  1220. var that = this
  1221. items = $(items).map(function (i, item) {
  1222. i = $(that.options.item).attr('data-value', item)
  1223. i.find('a').html(that.highlighter(item))
  1224. return i[0]
  1225. })
  1226. items.first().addClass('active')
  1227. this.$menu.html(items)
  1228. return this
  1229. }
  1230. , next: function (event) {
  1231. var active = this.$menu.find('.active').removeClass('active')
  1232. , next = active.next()
  1233. if (!next.length) {
  1234. next = $(this.$menu.find('li')[0])
  1235. }
  1236. next.addClass('active')
  1237. }
  1238. , prev: function (event) {
  1239. var active = this.$menu.find('.active').removeClass('active')
  1240. , prev = active.prev()
  1241. if (!prev.length) {
  1242. prev = this.$menu.find('li').last()
  1243. }
  1244. prev.addClass('active')
  1245. }
  1246. , listen: function () {
  1247. this.$element
  1248. .on('blur', $.proxy(this.blur, this))
  1249. .on('keypress', $.proxy(this.keypress, this))
  1250. .on('keyup', $.proxy(this.keyup, this))
  1251. if ($.browser.webkit || $.browser.msie) {
  1252. this.$element.on('keydown', $.proxy(this.keypress, this))
  1253. }
  1254. this.$menu
  1255. .on('click', $.proxy(this.click, this))
  1256. .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
  1257. }
  1258. , keyup: function (e) {
  1259. e.stopPropagation()
  1260. e.preventDefault()
  1261. switch(e.keyCode) {
  1262. case 40: // down arrow
  1263. case 38: // up arrow
  1264. break
  1265. case 9: // tab
  1266. case 13: // enter
  1267. if (!this.shown) return
  1268. this.select()
  1269. break
  1270. case 27: // escape
  1271. this.hide()
  1272. break
  1273. default:
  1274. this.lookup()
  1275. }
  1276. }
  1277. , keypress: function (e) {
  1278. e.stopPropagation()
  1279. if (!this.shown) return
  1280. switch(e.keyCode) {
  1281. case 9: // tab
  1282. case 13: // enter
  1283. case 27: // escape
  1284. e.preventDefault()
  1285. break
  1286. case 38: // up arrow
  1287. e.preventDefault()
  1288. this.prev()
  1289. break
  1290. case 40: // down arrow
  1291. e.preventDefault()
  1292. this.next()
  1293. break
  1294. }
  1295. }
  1296. , blur: function (e) {
  1297. var that = this
  1298. e.stopPropagation()
  1299. e.preventDefault()
  1300. setTimeout(function () { that.hide() }, 150)
  1301. }
  1302. , click: function (e) {
  1303. e.stopPropagation()
  1304. e.preventDefault()
  1305. this.select()
  1306. }
  1307. , mouseenter: function (e) {
  1308. this.$menu.find('.active').removeClass('active')
  1309. $(e.currentTarget).addClass('active')
  1310. }
  1311. }
  1312. /* TYPEAHEAD PLUGIN DEFINITION
  1313. * =========================== */
  1314. $.fn.typeahead = function ( option ) {
  1315. return this.each(function () {
  1316. var $this = $(this)
  1317. , data = $this.data('typeahead')
  1318. , options = typeof option == 'object' && option
  1319. if (!data) $this.data('typeahead', (data = new Typeahead(this, options)))
  1320. if (typeof option == 'string') data[option]()
  1321. })
  1322. }
  1323. $.fn.typeahead.defaults = {
  1324. source: []
  1325. , items: 8
  1326. , menu: '<ul class="typeahead dropdown-menu"></ul>'
  1327. , item: '<li><a href="#"></a></li>'
  1328. }
  1329. $.fn.typeahead.Constructor = Typeahead
  1330. /* TYPEAHEAD DATA-API
  1331. * ================== */
  1332. $(function () {
  1333. $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
  1334. var $this = $(this)
  1335. if ($this.data('typeahead')) return
  1336. e.preventDefault()
  1337. $this.typeahead($this.data())
  1338. })
  1339. })
  1340. }( window.jQuery )