bootstrap.js 47 KB

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