bootstrap.js 46 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723
  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.currentTarget).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 = 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 = $.extend({}, $.fn.modal.defaults, typeof option == 'object' && option)
  616. if (!data) $this.data('modal', (data = new Modal(this, options)))
  617. if (typeof option == 'string') data[option]()
  618. else if (options.show) data.show()
  619. })
  620. }
  621. $.fn.modal.defaults = {
  622. backdrop: true
  623. , keyboard: true
  624. , show: true
  625. }
  626. $.fn.modal.Constructor = Modal
  627. /* MODAL DATA-API
  628. * ============== */
  629. $(function () {
  630. $('body').on('click.modal.data-api', '[data-toggle="modal"]', function ( e ) {
  631. var $this = $(this), href
  632. , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
  633. , option = $target.data('modal') ? 'toggle' : $.extend({}, $target.data(), $this.data())
  634. e.preventDefault()
  635. $target.modal(option)
  636. })
  637. })
  638. }( window.jQuery )
  639. /* ===========================================================
  640. * bootstrap-tooltip.js v2.0.0
  641. * http://twitter.github.com/bootstrap/javascript.html#tooltips
  642. * Inspired by the original jQuery.tipsy by Jason Frame
  643. * ===========================================================
  644. * Copyright 2012 Twitter, Inc.
  645. *
  646. * Licensed under the Apache License, Version 2.0 (the "License");
  647. * you may not use this file except in compliance with the License.
  648. * You may obtain a copy of the License at
  649. *
  650. * http://www.apache.org/licenses/LICENSE-2.0
  651. *
  652. * Unless required by applicable law or agreed to in writing, software
  653. * distributed under the License is distributed on an "AS IS" BASIS,
  654. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  655. * See the License for the specific language governing permissions and
  656. * limitations under the License.
  657. * ========================================================== */
  658. !function( $ ) {
  659. "use strict"
  660. /* TOOLTIP PUBLIC CLASS DEFINITION
  661. * =============================== */
  662. var Tooltip = function ( element, options ) {
  663. this.init('tooltip', element, options)
  664. }
  665. Tooltip.prototype = {
  666. constructor: Tooltip
  667. , init: function ( type, element, options ) {
  668. var eventIn
  669. , eventOut
  670. this.type = type
  671. this.$element = $(element)
  672. this.options = this.getOptions(options)
  673. this.enabled = true
  674. if (this.options.trigger != 'manual') {
  675. eventIn = this.options.trigger == 'hover' ? 'mouseenter' : 'focus'
  676. eventOut = this.options.trigger == 'hover' ? 'mouseleave' : 'blur'
  677. this.$element.on(eventIn, this.options.selector, $.proxy(this.enter, this))
  678. this.$element.on(eventOut, this.options.selector, $.proxy(this.leave, this))
  679. }
  680. this.options.selector ?
  681. (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
  682. this.fixTitle()
  683. }
  684. , getOptions: function ( options ) {
  685. options = $.extend({}, $.fn[this.type].defaults, options, this.$element.data())
  686. if (options.delay && typeof options.delay == 'number') {
  687. options.delay = {
  688. show: options.delay
  689. , hide: options.delay
  690. }
  691. }
  692. return options
  693. }
  694. , enter: function ( e ) {
  695. var self = $(e.currentTarget)[this.type](this._options).data(this.type)
  696. if (!self.options.delay || !self.options.delay.show) {
  697. self.show()
  698. } else {
  699. self.hoverState = 'in'
  700. setTimeout(function() {
  701. if (self.hoverState == 'in') {
  702. self.show()
  703. }
  704. }, self.options.delay.show)
  705. }
  706. }
  707. , leave: function ( e ) {
  708. var self = $(e.currentTarget)[this.type](this._options).data(this.type)
  709. if (!self.options.delay || !self.options.delay.hide) {
  710. self.hide()
  711. } else {
  712. self.hoverState = 'out'
  713. setTimeout(function() {
  714. if (self.hoverState == 'out') {
  715. self.hide()
  716. }
  717. }, self.options.delay.hide)
  718. }
  719. }
  720. , show: function () {
  721. var $tip
  722. , inside
  723. , pos
  724. , actualWidth
  725. , actualHeight
  726. , placement
  727. , tp
  728. if (this.hasContent() && this.enabled) {
  729. $tip = this.tip()
  730. this.setContent()
  731. if (this.options.animation) {
  732. $tip.addClass('fade')
  733. }
  734. placement = typeof this.options.placement == 'function' ?
  735. this.options.placement.call(this, $tip[0], this.$element[0]) :
  736. this.options.placement
  737. inside = /in/.test(placement)
  738. $tip
  739. .remove()
  740. .css({ top: 0, left: 0, display: 'block' })
  741. .appendTo(inside ? this.$element : document.body)
  742. pos = this.getPosition(inside)
  743. actualWidth = $tip[0].offsetWidth
  744. actualHeight = $tip[0].offsetHeight
  745. switch (inside ? placement.split(' ')[1] : placement) {
  746. case 'bottom':
  747. tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
  748. break
  749. case 'top':
  750. tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
  751. break
  752. case 'left':
  753. tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
  754. break
  755. case 'right':
  756. tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
  757. break
  758. }
  759. $tip
  760. .css(tp)
  761. .addClass(placement)
  762. .addClass('in')
  763. }
  764. }
  765. , setContent: function () {
  766. var $tip = this.tip()
  767. $tip.find('.tooltip-inner').html(this.getTitle())
  768. $tip.removeClass('fade in top bottom left right')
  769. }
  770. , hide: function () {
  771. var that = this
  772. , $tip = this.tip()
  773. $tip.removeClass('in')
  774. function removeWithAnimation() {
  775. var timeout = setTimeout(function () {
  776. $tip.off($.support.transition.end).remove()
  777. }, 500)
  778. $tip.one($.support.transition.end, function () {
  779. clearTimeout(timeout)
  780. $tip.remove()
  781. })
  782. }
  783. $.support.transition && this.$tip.hasClass('fade') ?
  784. removeWithAnimation() :
  785. $tip.remove()
  786. }
  787. , fixTitle: function () {
  788. var $e = this.$element
  789. if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
  790. $e.attr('data-original-title', $e.attr('title') || '').removeAttr('title')
  791. }
  792. }
  793. , hasContent: function () {
  794. return this.getTitle()
  795. }
  796. , getPosition: function (inside) {
  797. return $.extend({}, (inside ? {top: 0, left: 0} : this.$element.offset()), {
  798. width: this.$element[0].offsetWidth
  799. , height: this.$element[0].offsetHeight
  800. })
  801. }
  802. , getTitle: function () {
  803. var title
  804. , $e = this.$element
  805. , o = this.options
  806. title = $e.attr('data-original-title')
  807. || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
  808. title = title.toString().replace(/(^\s*|\s*$)/, "")
  809. return title
  810. }
  811. , tip: function () {
  812. return this.$tip = this.$tip || $(this.options.template)
  813. }
  814. , validate: function () {
  815. if (!this.$element[0].parentNode) {
  816. this.hide()
  817. this.$element = null
  818. this.options = null
  819. }
  820. }
  821. , enable: function () {
  822. this.enabled = true
  823. }
  824. , disable: function () {
  825. this.enabled = false
  826. }
  827. , toggleEnabled: function () {
  828. this.enabled = !this.enabled
  829. }
  830. , toggle: function () {
  831. this[this.tip().hasClass('in') ? 'hide' : 'show']()
  832. }
  833. }
  834. /* TOOLTIP PLUGIN DEFINITION
  835. * ========================= */
  836. $.fn.tooltip = function ( option ) {
  837. return this.each(function () {
  838. var $this = $(this)
  839. , data = $this.data('tooltip')
  840. , options = typeof option == 'object' && option
  841. if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
  842. if (typeof option == 'string') data[option]()
  843. })
  844. }
  845. $.fn.tooltip.Constructor = Tooltip
  846. $.fn.tooltip.defaults = {
  847. animation: true
  848. , delay: 0
  849. , selector: false
  850. , placement: 'top'
  851. , trigger: 'hover'
  852. , title: ''
  853. , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
  854. }
  855. }( window.jQuery )
  856. /* ===========================================================
  857. * bootstrap-popover.js v2.0.0
  858. * http://twitter.github.com/bootstrap/javascript.html#popovers
  859. * ===========================================================
  860. * Copyright 2012 Twitter, Inc.
  861. *
  862. * Licensed under the Apache License, Version 2.0 (the "License");
  863. * you may not use this file except in compliance with the License.
  864. * You may obtain a copy of the License at
  865. *
  866. * http://www.apache.org/licenses/LICENSE-2.0
  867. *
  868. * Unless required by applicable law or agreed to in writing, software
  869. * distributed under the License is distributed on an "AS IS" BASIS,
  870. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  871. * See the License for the specific language governing permissions and
  872. * limitations under the License.
  873. * =========================================================== */
  874. !function( $ ) {
  875. "use strict"
  876. var Popover = function ( element, options ) {
  877. this.init('popover', element, options)
  878. }
  879. /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
  880. ========================================== */
  881. Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
  882. constructor: Popover
  883. , setContent: function () {
  884. var $tip = this.tip()
  885. , title = this.getTitle()
  886. , content = this.getContent()
  887. $tip.find('.popover-title')[ $.type(title) == 'object' ? 'append' : 'html' ](title)
  888. $tip.find('.popover-content > *')[ $.type(content) == 'object' ? 'append' : 'html' ](content)
  889. $tip.removeClass('fade top bottom left right in')
  890. }
  891. , hasContent: function () {
  892. return this.getTitle() || this.getContent()
  893. }
  894. , getContent: function () {
  895. var content
  896. , $e = this.$element
  897. , o = this.options
  898. content = $e.attr('data-content')
  899. || (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
  900. content = content.toString().replace(/(^\s*|\s*$)/, "")
  901. return content
  902. }
  903. , tip: function() {
  904. if (!this.$tip) {
  905. this.$tip = $(this.options.template)
  906. }
  907. return this.$tip
  908. }
  909. })
  910. /* POPOVER PLUGIN DEFINITION
  911. * ======================= */
  912. $.fn.popover = function ( option ) {
  913. return this.each(function () {
  914. var $this = $(this)
  915. , data = $this.data('popover')
  916. , options = typeof option == 'object' && option
  917. if (!data) $this.data('popover', (data = new Popover(this, options)))
  918. if (typeof option == 'string') data[option]()
  919. })
  920. }
  921. $.fn.popover.Constructor = Popover
  922. $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
  923. placement: 'right'
  924. , content: ''
  925. , 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>'
  926. })
  927. }( window.jQuery )
  928. /* =============================================================
  929. * bootstrap-scrollspy.js v2.0.0
  930. * http://twitter.github.com/bootstrap/javascript.html#scrollspy
  931. * =============================================================
  932. * Copyright 2012 Twitter, Inc.
  933. *
  934. * Licensed under the Apache License, Version 2.0 (the "License");
  935. * you may not use this file except in compliance with the License.
  936. * You may obtain a copy of the License at
  937. *
  938. * http://www.apache.org/licenses/LICENSE-2.0
  939. *
  940. * Unless required by applicable law or agreed to in writing, software
  941. * distributed under the License is distributed on an "AS IS" BASIS,
  942. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  943. * See the License for the specific language governing permissions and
  944. * limitations under the License.
  945. * ============================================================== */
  946. !function ( $ ) {
  947. "use strict"
  948. /* SCROLLSPY CLASS DEFINITION
  949. * ========================== */
  950. function ScrollSpy( element, options) {
  951. var process = $.proxy(this.process, this)
  952. , $element = $(element).is('body') ? $(window) : $(element)
  953. , href
  954. this.options = $.extend({}, $.fn.scrollspy.defaults, options)
  955. this.$scrollElement = $element.on('scroll.scroll.data-api', process)
  956. this.selector = (this.options.target
  957. || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
  958. || '') + ' .nav li > a'
  959. this.$body = $('body').on('click.scroll.data-api', this.selector, process)
  960. this.refresh()
  961. this.process()
  962. }
  963. ScrollSpy.prototype = {
  964. constructor: ScrollSpy
  965. , refresh: function () {
  966. this.targets = this.$body
  967. .find(this.selector)
  968. .map(function () {
  969. var href = $(this).attr('href')
  970. return /^#\w/.test(href) && $(href).length ? href : null
  971. })
  972. this.offsets = $.map(this.targets, function (id) {
  973. return $(id).position().top
  974. })
  975. }
  976. , process: function () {
  977. var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
  978. , offsets = this.offsets
  979. , targets = this.targets
  980. , activeTarget = this.activeTarget
  981. , i
  982. for (i = offsets.length; i--;) {
  983. activeTarget != targets[i]
  984. && scrollTop >= offsets[i]
  985. && (!offsets[i + 1] || scrollTop <= offsets[i + 1])
  986. && this.activate( targets[i] )
  987. }
  988. }
  989. , activate: function (target) {
  990. var active
  991. this.activeTarget = target
  992. this.$body
  993. .find(this.selector).parent('.active')
  994. .removeClass('active')
  995. active = this.$body
  996. .find(this.selector + '[href="' + target + '"]')
  997. .parent('li')
  998. .addClass('active')
  999. if ( active.parent('.dropdown-menu') ) {
  1000. active.closest('li.dropdown').addClass('active')
  1001. }
  1002. }
  1003. }
  1004. /* SCROLLSPY PLUGIN DEFINITION
  1005. * =========================== */
  1006. $.fn.scrollspy = function ( option ) {
  1007. return this.each(function () {
  1008. var $this = $(this)
  1009. , data = $this.data('scrollspy')
  1010. , options = typeof option == 'object' && option
  1011. if (!data) $this.data('scrollspy', (data = new ScrollSpy(this, options)))
  1012. if (typeof option == 'string') data[option]()
  1013. })
  1014. }
  1015. $.fn.scrollspy.Constructor = ScrollSpy
  1016. $.fn.scrollspy.defaults = {
  1017. offset: 10
  1018. }
  1019. /* SCROLLSPY DATA-API
  1020. * ================== */
  1021. $(function () {
  1022. $('[data-spy="scroll"]').each(function () {
  1023. var $spy = $(this)
  1024. $spy.scrollspy($spy.data())
  1025. })
  1026. })
  1027. }( window.jQuery )
  1028. /* ========================================================
  1029. * bootstrap-tab.js v2.0.0
  1030. * http://twitter.github.com/bootstrap/javascript.html#tabs
  1031. * ========================================================
  1032. * Copyright 2012 Twitter, Inc.
  1033. *
  1034. * Licensed under the Apache License, Version 2.0 (the "License");
  1035. * you may not use this file except in compliance with the License.
  1036. * You may obtain a copy of the License at
  1037. *
  1038. * http://www.apache.org/licenses/LICENSE-2.0
  1039. *
  1040. * Unless required by applicable law or agreed to in writing, software
  1041. * distributed under the License is distributed on an "AS IS" BASIS,
  1042. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1043. * See the License for the specific language governing permissions and
  1044. * limitations under the License.
  1045. * ======================================================== */
  1046. !function( $ ){
  1047. "use strict"
  1048. /* TAB CLASS DEFINITION
  1049. * ==================== */
  1050. var Tab = function ( element ) {
  1051. this.element = $(element)
  1052. }
  1053. Tab.prototype = {
  1054. constructor: Tab
  1055. , show: function () {
  1056. var $this = this.element
  1057. , $ul = $this.closest('ul:not(.dropdown-menu)')
  1058. , selector = $this.attr('data-target')
  1059. , previous
  1060. , $target
  1061. if (!selector) {
  1062. selector = $this.attr('href')
  1063. selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
  1064. }
  1065. if ( $this.parent('li').hasClass('active') ) return
  1066. previous = $ul.find('.active a').last()[0]
  1067. $this.trigger({
  1068. type: 'show'
  1069. , relatedTarget: previous
  1070. })
  1071. $target = $(selector)
  1072. this.activate($this.parent('li'), $ul)
  1073. this.activate($target, $target.parent(), function () {
  1074. $this.trigger({
  1075. type: 'shown'
  1076. , relatedTarget: previous
  1077. })
  1078. })
  1079. }
  1080. , activate: function ( element, container, callback) {
  1081. var $active = container.find('> .active')
  1082. , transition = callback
  1083. && $.support.transition
  1084. && $active.hasClass('fade')
  1085. function next() {
  1086. $active
  1087. .removeClass('active')
  1088. .find('> .dropdown-menu > .active')
  1089. .removeClass('active')
  1090. element.addClass('active')
  1091. if (transition) {
  1092. element[0].offsetWidth // reflow for transition
  1093. element.addClass('in')
  1094. } else {
  1095. element.removeClass('fade')
  1096. }
  1097. if ( element.parent('.dropdown-menu') ) {
  1098. element.closest('li.dropdown').addClass('active')
  1099. }
  1100. callback && callback()
  1101. }
  1102. transition ?
  1103. $active.one($.support.transition.end, next) :
  1104. next()
  1105. $active.removeClass('in')
  1106. }
  1107. }
  1108. /* TAB PLUGIN DEFINITION
  1109. * ===================== */
  1110. $.fn.tab = function ( option ) {
  1111. return this.each(function () {
  1112. var $this = $(this)
  1113. , data = $this.data('tab')
  1114. if (!data) $this.data('tab', (data = new Tab(this)))
  1115. if (typeof option == 'string') data[option]()
  1116. })
  1117. }
  1118. $.fn.tab.Constructor = Tab
  1119. /* TAB DATA-API
  1120. * ============ */
  1121. $(function () {
  1122. $('body').on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
  1123. e.preventDefault()
  1124. $(this).tab('show')
  1125. })
  1126. })
  1127. }( window.jQuery )
  1128. /* =============================================================
  1129. * bootstrap-typeahead.js v2.0.0
  1130. * http://twitter.github.com/bootstrap/javascript.html#typeahead
  1131. * =============================================================
  1132. * Copyright 2012 Twitter, Inc.
  1133. *
  1134. * Licensed under the Apache License, Version 2.0 (the "License");
  1135. * you may not use this file except in compliance with the License.
  1136. * You may obtain a copy of the License at
  1137. *
  1138. * http://www.apache.org/licenses/LICENSE-2.0
  1139. *
  1140. * Unless required by applicable law or agreed to in writing, software
  1141. * distributed under the License is distributed on an "AS IS" BASIS,
  1142. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  1143. * See the License for the specific language governing permissions and
  1144. * limitations under the License.
  1145. * ============================================================ */
  1146. !function( $ ){
  1147. "use strict"
  1148. var Typeahead = function ( element, options ) {
  1149. this.$element = $(element)
  1150. this.options = $.extend({}, $.fn.typeahead.defaults, options)
  1151. this.matcher = this.options.matcher || this.matcher
  1152. this.sorter = this.options.sorter || this.sorter
  1153. this.highlighter = this.options.highlighter || this.highlighter
  1154. this.$menu = $(this.options.menu).appendTo('body')
  1155. this.source = this.options.source
  1156. this.shown = false
  1157. this.listen()
  1158. }
  1159. Typeahead.prototype = {
  1160. constructor: Typeahead
  1161. , select: function () {
  1162. var val = this.$menu.find('.active').attr('data-value')
  1163. this.$element.val(val)
  1164. return this.hide()
  1165. }
  1166. , show: function () {
  1167. var pos = $.extend({}, this.$element.offset(), {
  1168. height: this.$element[0].offsetHeight
  1169. })
  1170. this.$menu.css({
  1171. top: pos.top + pos.height
  1172. , left: pos.left
  1173. })
  1174. this.$menu.show()
  1175. this.shown = true
  1176. return this
  1177. }
  1178. , hide: function () {
  1179. this.$menu.hide()
  1180. this.shown = false
  1181. return this
  1182. }
  1183. , lookup: function (event) {
  1184. var that = this
  1185. , items
  1186. , q
  1187. this.query = this.$element.val()
  1188. if (!this.query) {
  1189. return this.shown ? this.hide() : this
  1190. }
  1191. items = $.grep(this.source, function (item) {
  1192. if (that.matcher(item)) return item
  1193. })
  1194. items = this.sorter(items)
  1195. if (!items.length) {
  1196. return this.shown ? this.hide() : this
  1197. }
  1198. return this.render(items.slice(0, this.options.items)).show()
  1199. }
  1200. , matcher: function (item) {
  1201. return ~item.toLowerCase().indexOf(this.query.toLowerCase())
  1202. }
  1203. , sorter: function (items) {
  1204. var beginswith = []
  1205. , caseSensitive = []
  1206. , caseInsensitive = []
  1207. , item
  1208. while (item = items.shift()) {
  1209. if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item)
  1210. else if (~item.indexOf(this.query)) caseSensitive.push(item)
  1211. else caseInsensitive.push(item)
  1212. }
  1213. return beginswith.concat(caseSensitive, caseInsensitive)
  1214. }
  1215. , highlighter: function (item) {
  1216. return item.replace(new RegExp('(' + this.query + ')', 'ig'), function ($1, match) {
  1217. return '<strong>' + match + '</strong>'
  1218. })
  1219. }
  1220. , render: function (items) {
  1221. var that = this
  1222. items = $(items).map(function (i, item) {
  1223. i = $(that.options.item).attr('data-value', item)
  1224. i.find('a').html(that.highlighter(item))
  1225. return i[0]
  1226. })
  1227. items.first().addClass('active')
  1228. this.$menu.html(items)
  1229. return this
  1230. }
  1231. , next: function (event) {
  1232. var active = this.$menu.find('.active').removeClass('active')
  1233. , next = active.next()
  1234. if (!next.length) {
  1235. next = $(this.$menu.find('li')[0])
  1236. }
  1237. next.addClass('active')
  1238. }
  1239. , prev: function (event) {
  1240. var active = this.$menu.find('.active').removeClass('active')
  1241. , prev = active.prev()
  1242. if (!prev.length) {
  1243. prev = this.$menu.find('li').last()
  1244. }
  1245. prev.addClass('active')
  1246. }
  1247. , listen: function () {
  1248. this.$element
  1249. .on('blur', $.proxy(this.blur, this))
  1250. .on('keypress', $.proxy(this.keypress, this))
  1251. .on('keyup', $.proxy(this.keyup, this))
  1252. if ($.browser.webkit || $.browser.msie) {
  1253. this.$element.on('keydown', $.proxy(this.keypress, this))
  1254. }
  1255. this.$menu
  1256. .on('click', $.proxy(this.click, this))
  1257. .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
  1258. }
  1259. , keyup: function (e) {
  1260. e.stopPropagation()
  1261. e.preventDefault()
  1262. switch(e.keyCode) {
  1263. case 40: // down arrow
  1264. case 38: // up arrow
  1265. break
  1266. case 9: // tab
  1267. case 13: // enter
  1268. if (!this.shown) return
  1269. this.select()
  1270. break
  1271. case 27: // escape
  1272. this.hide()
  1273. break
  1274. default:
  1275. this.lookup()
  1276. }
  1277. }
  1278. , keypress: function (e) {
  1279. e.stopPropagation()
  1280. if (!this.shown) return
  1281. switch(e.keyCode) {
  1282. case 9: // tab
  1283. case 13: // enter
  1284. case 27: // escape
  1285. e.preventDefault()
  1286. break
  1287. case 38: // up arrow
  1288. e.preventDefault()
  1289. this.prev()
  1290. break
  1291. case 40: // down arrow
  1292. e.preventDefault()
  1293. this.next()
  1294. break
  1295. }
  1296. }
  1297. , blur: function (e) {
  1298. var that = this
  1299. e.stopPropagation()
  1300. e.preventDefault()
  1301. setTimeout(function () { that.hide() }, 150)
  1302. }
  1303. , click: function (e) {
  1304. e.stopPropagation()
  1305. e.preventDefault()
  1306. this.select()
  1307. }
  1308. , mouseenter: function (e) {
  1309. this.$menu.find('.active').removeClass('active')
  1310. $(e.currentTarget).addClass('active')
  1311. }
  1312. }
  1313. /* TYPEAHEAD PLUGIN DEFINITION
  1314. * =========================== */
  1315. $.fn.typeahead = function ( option ) {
  1316. return this.each(function () {
  1317. var $this = $(this)
  1318. , data = $this.data('typeahead')
  1319. , options = typeof option == 'object' && option
  1320. if (!data) $this.data('typeahead', (data = new Typeahead(this, options)))
  1321. if (typeof option == 'string') data[option]()
  1322. })
  1323. }
  1324. $.fn.typeahead.defaults = {
  1325. source: []
  1326. , items: 8
  1327. , menu: '<ul class="typeahead dropdown-menu"></ul>'
  1328. , item: '<li><a href="#"></a></li>'
  1329. }
  1330. $.fn.typeahead.Constructor = Typeahead
  1331. /* TYPEAHEAD DATA-API
  1332. * ================== */
  1333. $(function () {
  1334. $('body').on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
  1335. var $this = $(this)
  1336. if ($this.data('typeahead')) return
  1337. e.preventDefault()
  1338. $this.typeahead($this.data())
  1339. })
  1340. })
  1341. }( window.jQuery )