1 /* ===================================================
2 * bootstrap-transition.js v2.3.1
3 * http://twitter.github.com/bootstrap/javascript.html#transitions
4 * ===================================================
5 * Copyright 2012 Twitter, Inc.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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 * ========================================================== */
23 "use strict"; // jshint ;_;
26 /* CSS TRANSITION SUPPORT (http://www.modernizr.com/)
27 * ======================================================= */
31 $.support.transition = (function () {
33 var transitionEnd = (function () {
35 var el = document.createElement('bootstrap')
36 , transEndEventNames = {
37 'WebkitTransition' : 'webkitTransitionEnd'
38 , 'MozTransition' : 'transitionend'
39 , 'OTransition' : 'oTransitionEnd otransitionend'
40 , 'transition' : 'transitionend'
44 for (name in transEndEventNames){
45 if (el.style[name] !== undefined) {
46 return transEndEventNames[name]
52 return transitionEnd && {
61 /* =========================================================
62 * bootstrap-modal.js v2.3.1
63 * http://twitter.github.com/bootstrap/javascript.html#modals
64 * =========================================================
65 * Copyright 2012 Twitter, Inc.
67 * Licensed under the Apache License, Version 2.0 (the "License");
68 * you may not use this file except in compliance with the License.
69 * You may obtain a copy of the License at
71 * http://www.apache.org/licenses/LICENSE-2.0
73 * Unless required by applicable law or agreed to in writing, software
74 * distributed under the License is distributed on an "AS IS" BASIS,
75 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
76 * See the License for the specific language governing permissions and
77 * limitations under the License.
78 * ========================================================= */
83 "use strict"; // jshint ;_;
86 /* MODAL CLASS DEFINITION
87 * ====================== */
89 var Modal = function (element, options) {
90 this.options = options
91 this.$element = $(element)
92 .delegate('[data-dismiss="modal"]', 'click.dismiss.modal', $.proxy(this.hide, this))
93 this.options.remote && this.$element.find('.modal-body').load(this.options.remote)
100 , toggle: function () {
101 return this[!this.isShown ? 'show' : 'hide']()
104 , show: function () {
106 , e = $.Event('show')
108 this.$element.trigger(e)
110 if (this.isShown || e.isDefaultPrevented()) return
116 this.backdrop(function () {
117 var transition = $.support.transition && that.$element.hasClass('fade')
119 if (!that.$element.parent().length) {
120 that.$element.appendTo(document.body) //don't move modals dom position
126 that.$element[0].offsetWidth // force reflow
131 .attr('aria-hidden', false)
136 that.$element.one($.support.transition.end, function () { that.$element.focus().trigger('shown') }) :
137 that.$element.focus().trigger('shown')
142 , hide: function (e) {
143 e && e.preventDefault()
149 this.$element.trigger(e)
151 if (!this.isShown || e.isDefaultPrevented()) return
157 $(document).off('focusin.modal')
161 .attr('aria-hidden', true)
163 $.support.transition && this.$element.hasClass('fade') ?
164 this.hideWithTransition() :
168 , enforceFocus: function () {
170 $(document).on('focusin.modal', function (e) {
171 if (that.$element[0] !== e.target && !that.$element.has(e.target).length) {
172 that.$element.focus()
177 , escape: function () {
179 if (this.isShown && this.options.keyboard) {
180 this.$element.on('keyup.dismiss.modal', function ( e ) {
181 e.which == 27 && that.hide()
183 } else if (!this.isShown) {
184 this.$element.off('keyup.dismiss.modal')
188 , hideWithTransition: function () {
190 , timeout = setTimeout(function () {
191 that.$element.off($.support.transition.end)
195 this.$element.one($.support.transition.end, function () {
196 clearTimeout(timeout)
201 , hideModal: function () {
204 this.backdrop(function () {
205 that.removeBackdrop()
206 that.$element.trigger('hidden')
210 , removeBackdrop: function () {
211 this.$backdrop && this.$backdrop.remove()
212 this.$backdrop = null
215 , backdrop: function (callback) {
217 , animate = this.$element.hasClass('fade') ? 'fade' : ''
219 if (this.isShown && this.options.backdrop) {
220 var doAnimate = $.support.transition && animate
222 this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
223 .appendTo(document.body)
225 this.$backdrop.click(
226 this.options.backdrop == 'static' ?
227 $.proxy(this.$element[0].focus, this.$element[0])
228 : $.proxy(this.hide, this)
231 if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
233 this.$backdrop.addClass('in')
235 if (!callback) return
238 this.$backdrop.one($.support.transition.end, callback) :
241 } else if (!this.isShown && this.$backdrop) {
242 this.$backdrop.removeClass('in')
244 $.support.transition && this.$element.hasClass('fade')?
245 this.$backdrop.one($.support.transition.end, callback) :
248 } else if (callback) {
255 /* MODAL PLUGIN DEFINITION
256 * ======================= */
260 $.fn.modal = function (option) {
261 return this.each(function () {
263 , data = $this.data('modal')
264 , options = $.extend({}, $.fn.modal.defaults, $this.data(), typeof option == 'object' && option)
265 if (!data) $this.data('modal', (data = new Modal(this, options)))
266 if (typeof option == 'string') data[option]()
267 else if (options.show) data.show()
271 $.fn.modal.defaults = {
277 $.fn.modal.Constructor = Modal
281 * ================= */
283 $.fn.modal.noConflict = function () {
292 $(document).on('click.modal.data-api', '[data-toggle="modal"]', function (e) {
294 , href = $this.attr('href')
295 , $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
296 , option = $target.data('modal') ? 'toggle' : $.extend({ remote:!/#/.test(href) && href }, $target.data(), $this.data())
302 .one('hide', function () {
309 /* ============================================================
310 * bootstrap-dropdown.js v2.3.1
311 * http://twitter.github.com/bootstrap/javascript.html#dropdowns
312 * ============================================================
313 * Copyright 2012 Twitter, Inc.
315 * Licensed under the Apache License, Version 2.0 (the "License");
316 * you may not use this file except in compliance with the License.
317 * You may obtain a copy of the License at
319 * http://www.apache.org/licenses/LICENSE-2.0
321 * Unless required by applicable law or agreed to in writing, software
322 * distributed under the License is distributed on an "AS IS" BASIS,
323 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
324 * See the License for the specific language governing permissions and
325 * limitations under the License.
326 * ============================================================ */
331 "use strict"; // jshint ;_;
334 /* DROPDOWN CLASS DEFINITION
335 * ========================= */
337 var toggle = '[data-toggle=dropdown]'
338 , Dropdown = function (element) {
339 var $el = $(element).on('click.dropdown.data-api', this.toggle)
340 $('html').on('click.dropdown.data-api', function () {
341 $el.parent().removeClass('open')
345 Dropdown.prototype = {
347 constructor: Dropdown
349 , toggle: function (e) {
354 if ($this.is('.disabled, :disabled')) return
356 $parent = getParent($this)
358 isActive = $parent.hasClass('open')
363 $parent.toggleClass('open')
371 , keydown: function (e) {
379 if (!/(38|40|27)/.test(e.keyCode)) return
386 if ($this.is('.disabled, :disabled')) return
388 $parent = getParent($this)
390 isActive = $parent.hasClass('open')
392 if (!isActive || (isActive && e.keyCode == 27)) {
393 if (e.which == 27) $parent.find(toggle).focus()
397 $items = $('[role=menu] li:not(.divider):visible a', $parent)
399 if (!$items.length) return
401 index = $items.index($items.filter(':focus'))
403 if (e.keyCode == 38 && index > 0) index-- // up
404 if (e.keyCode == 40 && index < $items.length - 1) index++ // down
405 if (!~index) index = 0
414 function clearMenus() {
415 $(toggle).each(function () {
416 getParent($(this)).removeClass('open')
420 function getParent($this) {
421 var selector = $this.attr('data-target')
425 selector = $this.attr('href')
426 selector = selector && /#/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
429 $parent = selector && $(selector)
431 if (!$parent || !$parent.length) $parent = $this.parent()
437 /* DROPDOWN PLUGIN DEFINITION
438 * ========================== */
440 var old = $.fn.dropdown
442 $.fn.dropdown = function (option) {
443 return this.each(function () {
445 , data = $this.data('dropdown')
446 if (!data) $this.data('dropdown', (data = new Dropdown(this)))
447 if (typeof option == 'string') data[option].call($this)
451 $.fn.dropdown.Constructor = Dropdown
454 /* DROPDOWN NO CONFLICT
455 * ==================== */
457 $.fn.dropdown.noConflict = function () {
463 /* APPLY TO STANDARD DROPDOWN ELEMENTS
464 * =================================== */
467 .on('click.dropdown.data-api', clearMenus)
468 .on('click.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
469 .on('click.dropdown-menu', function (e) { e.stopPropagation() })
470 .on('click.dropdown.data-api' , toggle, Dropdown.prototype.toggle)
471 .on('keydown.dropdown.data-api', toggle + ', [role=menu]' , Dropdown.prototype.keydown)
475 /* =============================================================
476 * bootstrap-scrollspy.js v2.3.1
477 * http://twitter.github.com/bootstrap/javascript.html#scrollspy
478 * =============================================================
479 * Copyright 2012 Twitter, Inc.
481 * Licensed under the Apache License, Version 2.0 (the "License");
482 * you may not use this file except in compliance with the License.
483 * You may obtain a copy of the License at
485 * http://www.apache.org/licenses/LICENSE-2.0
487 * Unless required by applicable law or agreed to in writing, software
488 * distributed under the License is distributed on an "AS IS" BASIS,
489 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
490 * See the License for the specific language governing permissions and
491 * limitations under the License.
492 * ============================================================== */
497 "use strict"; // jshint ;_;
500 /* SCROLLSPY CLASS DEFINITION
501 * ========================== */
503 function ScrollSpy(element, options) {
504 var process = $.proxy(this.process, this)
505 , $element = $(element).is('body') ? $(window) : $(element)
507 this.options = $.extend({}, $.fn.scrollspy.defaults, options)
508 this.$scrollElement = $element.on('scroll.scroll-spy.data-api', process)
509 this.selector = (this.options.target
510 || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
511 || '') + ' .nav li > a'
512 this.$body = $('body')
517 ScrollSpy.prototype = {
519 constructor: ScrollSpy
521 , refresh: function () {
528 $targets = this.$body
532 , href = $el.data('target') || $el.attr('href')
533 , $href = /^#\w/.test(href) && $(href)
536 && [[ $href.position().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]] ) || null
538 .sort(function (a, b) { return a[0] - b[0] })
540 self.offsets.push(this[0])
541 self.targets.push(this[1])
545 , process: function () {
546 var scrollTop = this.$scrollElement.scrollTop() + this.options.offset
547 , scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight
548 , maxScroll = scrollHeight - this.$scrollElement.height()
549 , offsets = this.offsets
550 , targets = this.targets
551 , activeTarget = this.activeTarget
554 if (scrollTop >= maxScroll) {
555 return activeTarget != (i = targets.last()[0])
556 && this.activate ( i )
559 for (i = offsets.length; i--;) {
560 activeTarget != targets[i]
561 && scrollTop >= offsets[i]
562 && (!offsets[i + 1] || scrollTop <= offsets[i + 1])
563 && this.activate( targets[i] )
567 , activate: function (target) {
571 this.activeTarget = target
575 .removeClass('active')
577 selector = this.selector
578 + '[data-target="' + target + '"],'
579 + this.selector + '[href="' + target + '"]'
585 if (active.parent('.dropdown-menu').length) {
586 active = active.closest('li.dropdown').addClass('active')
589 active.trigger('activate')
595 /* SCROLLSPY PLUGIN DEFINITION
596 * =========================== */
598 var old = $.fn.scrollspy
600 $.fn.scrollspy = function (option) {
601 return this.each(function () {
603 , data = $this.data('scrollspy')
604 , options = typeof option == 'object' && option
605 if (!data) $this.data('scrollspy', (data = new ScrollSpy(this, options)))
606 if (typeof option == 'string') data[option]()
610 $.fn.scrollspy.Constructor = ScrollSpy
612 $.fn.scrollspy.defaults = {
617 /* SCROLLSPY NO CONFLICT
618 * ===================== */
620 $.fn.scrollspy.noConflict = function () {
626 /* SCROLLSPY DATA-API
627 * ================== */
629 $(window).on('load', function () {
630 $('[data-spy="scroll"]').each(function () {
632 $spy.scrollspy($spy.data())
637 /* ========================================================
638 * bootstrap-tab.js v2.3.1
639 * http://twitter.github.com/bootstrap/javascript.html#tabs
640 * ========================================================
641 * Copyright 2012 Twitter, Inc.
643 * Licensed under the Apache License, Version 2.0 (the "License");
644 * you may not use this file except in compliance with the License.
645 * You may obtain a copy of the License at
647 * http://www.apache.org/licenses/LICENSE-2.0
649 * Unless required by applicable law or agreed to in writing, software
650 * distributed under the License is distributed on an "AS IS" BASIS,
651 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
652 * See the License for the specific language governing permissions and
653 * limitations under the License.
654 * ======================================================== */
659 "use strict"; // jshint ;_;
662 /* TAB CLASS DEFINITION
663 * ==================== */
665 var Tab = function (element) {
666 this.element = $(element)
673 , show: function () {
674 var $this = this.element
675 , $ul = $this.closest('ul:not(.dropdown-menu)')
676 , selector = $this.attr('data-target')
682 selector = $this.attr('href')
683 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
686 if ( $this.parent('li').hasClass('active') ) return
688 previous = $ul.find('.active:last a')[0]
690 e = $.Event('show', {
691 relatedTarget: previous
696 if (e.isDefaultPrevented()) return
698 $target = $(selector)
700 this.activate($this.parent('li'), $ul)
701 this.activate($target, $target.parent(), function () {
704 , relatedTarget: previous
709 , activate: function ( element, container, callback) {
710 var $active = container.find('> .active')
711 , transition = callback
712 && $.support.transition
713 && $active.hasClass('fade')
717 .removeClass('active')
718 .find('> .dropdown-menu > .active')
719 .removeClass('active')
721 element.addClass('active')
724 element[0].offsetWidth // reflow for transition
725 element.addClass('in')
727 element.removeClass('fade')
730 if ( element.parent('.dropdown-menu') ) {
731 element.closest('li.dropdown').addClass('active')
734 callback && callback()
738 $active.one($.support.transition.end, next) :
741 $active.removeClass('in')
746 /* TAB PLUGIN DEFINITION
747 * ===================== */
751 $.fn.tab = function ( option ) {
752 return this.each(function () {
754 , data = $this.data('tab')
755 if (!data) $this.data('tab', (data = new Tab(this)))
756 if (typeof option == 'string') data[option]()
760 $.fn.tab.Constructor = Tab
766 $.fn.tab.noConflict = function () {
775 $(document).on('click.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
781 /* ===========================================================
782 * bootstrap-tooltip.js v2.3.1
783 * http://twitter.github.com/bootstrap/javascript.html#tooltips
784 * Inspired by the original jQuery.tipsy by Jason Frame
785 * ===========================================================
786 * Copyright 2012 Twitter, Inc.
788 * Licensed under the Apache License, Version 2.0 (the "License");
789 * you may not use this file except in compliance with the License.
790 * You may obtain a copy of the License at
792 * http://www.apache.org/licenses/LICENSE-2.0
794 * Unless required by applicable law or agreed to in writing, software
795 * distributed under the License is distributed on an "AS IS" BASIS,
796 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
797 * See the License for the specific language governing permissions and
798 * limitations under the License.
799 * ========================================================== */
804 "use strict"; // jshint ;_;
807 /* TOOLTIP PUBLIC CLASS DEFINITION
808 * =============================== */
810 var Tooltip = function (element, options) {
811 this.init('tooltip', element, options)
814 Tooltip.prototype = {
818 , init: function (type, element, options) {
826 this.$element = $(element)
827 this.options = this.getOptions(options)
830 triggers = this.options.trigger.split(' ')
832 for (i = triggers.length; i--;) {
833 trigger = triggers[i]
834 if (trigger == 'click') {
835 this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
836 } else if (trigger != 'manual') {
837 eventIn = trigger == 'hover' ? 'mouseenter' : 'focus'
838 eventOut = trigger == 'hover' ? 'mouseleave' : 'blur'
839 this.$element.on(eventIn + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
840 this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
844 this.options.selector ?
845 (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
849 , getOptions: function (options) {
850 options = $.extend({}, $.fn[this.type].defaults, this.$element.data(), options)
852 if (options.delay && typeof options.delay == 'number') {
855 , hide: options.delay
862 , enter: function (e) {
863 var defaults = $.fn[this.type].defaults
867 this._options && $.each(this._options, function (key, value) {
868 if (defaults[key] != value) options[key] = value
871 self = $(e.currentTarget)[this.type](options).data(this.type)
873 if (!self.options.delay || !self.options.delay.show) return self.show()
875 clearTimeout(this.timeout)
876 self.hoverState = 'in'
877 this.timeout = setTimeout(function() {
878 if (self.hoverState == 'in') self.show()
879 }, self.options.delay.show)
882 , leave: function (e) {
883 var self = $(e.currentTarget)[this.type](this._options).data(this.type)
885 if (this.timeout) clearTimeout(this.timeout)
886 if (!self.options.delay || !self.options.delay.hide) return self.hide()
888 self.hoverState = 'out'
889 this.timeout = setTimeout(function() {
890 if (self.hoverState == 'out') self.hide()
891 }, self.options.delay.hide)
894 , show: function () {
901 , e = $.Event('show')
903 if (this.hasContent() && this.enabled) {
904 this.$element.trigger(e)
905 if (e.isDefaultPrevented()) return
909 if (this.options.animation) {
910 $tip.addClass('fade')
913 placement = typeof this.options.placement == 'function' ?
914 this.options.placement.call(this, $tip[0], this.$element[0]) :
915 this.options.placement
919 .css({ top: 0, left: 0, display: 'block' })
921 this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
923 pos = this.getPosition()
925 actualWidth = $tip[0].offsetWidth
926 actualHeight = $tip[0].offsetHeight
930 tp = {top: pos.top + pos.height, left: pos.left + pos.width / 2 - actualWidth / 2}
933 tp = {top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2}
936 tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth}
939 tp = {top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width}
943 this.applyPlacement(tp, placement)
944 this.$element.trigger('shown')
948 , applyPlacement: function(offset, placement){
949 var $tip = this.tip()
950 , width = $tip[0].offsetWidth
951 , height = $tip[0].offsetHeight
962 actualWidth = $tip[0].offsetWidth
963 actualHeight = $tip[0].offsetHeight
965 if (placement == 'top' && actualHeight != height) {
966 offset.top = offset.top + height - actualHeight
970 if (placement == 'bottom' || placement == 'top') {
973 if (offset.left < 0){
974 delta = offset.left * -2
977 actualWidth = $tip[0].offsetWidth
978 actualHeight = $tip[0].offsetHeight
981 this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
983 this.replaceArrow(actualHeight - height, actualHeight, 'top')
986 if (replace) $tip.offset(offset)
989 , replaceArrow: function(delta, dimension, position){
992 .css(position, delta ? (50 * (1 - delta / dimension) + "%") : '')
995 , setContent: function () {
996 var $tip = this.tip()
997 , title = this.getTitle()
999 $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
1000 $tip.removeClass('fade in top bottom left right')
1003 , hide: function () {
1006 , e = $.Event('hide')
1008 this.$element.trigger(e)
1009 if (e.isDefaultPrevented()) return
1011 $tip.removeClass('in')
1013 function removeWithAnimation() {
1014 var timeout = setTimeout(function () {
1015 $tip.off($.support.transition.end).detach()
1018 $tip.one($.support.transition.end, function () {
1019 clearTimeout(timeout)
1024 $.support.transition && this.$tip.hasClass('fade') ?
1025 removeWithAnimation() :
1028 this.$element.trigger('hidden')
1033 , fixTitle: function () {
1034 var $e = this.$element
1035 if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
1036 $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
1040 , hasContent: function () {
1041 return this.getTitle()
1044 , getPosition: function () {
1045 var el = this.$element[0]
1046 return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : {
1047 width: el.offsetWidth
1048 , height: el.offsetHeight
1049 }, this.$element.offset())
1052 , getTitle: function () {
1054 , $e = this.$element
1057 title = $e.attr('data-original-title')
1058 || (typeof o.title == 'function' ? o.title.call($e[0]) : o.title)
1063 , tip: function () {
1064 return this.$tip = this.$tip || $(this.options.template)
1067 , arrow: function(){
1068 return this.$arrow = this.$arrow || this.tip().find(".tooltip-arrow")
1071 , validate: function () {
1072 if (!this.$element[0].parentNode) {
1074 this.$element = null
1079 , enable: function () {
1083 , disable: function () {
1084 this.enabled = false
1087 , toggleEnabled: function () {
1088 this.enabled = !this.enabled
1091 , toggle: function (e) {
1092 var self = e ? $(e.currentTarget)[this.type](this._options).data(this.type) : this
1093 self.tip().hasClass('in') ? self.hide() : self.show()
1096 , destroy: function () {
1097 this.hide().$element.off('.' + this.type).removeData(this.type)
1103 /* TOOLTIP PLUGIN DEFINITION
1104 * ========================= */
1106 var old = $.fn.tooltip
1108 $.fn.tooltip = function ( option ) {
1109 return this.each(function () {
1111 , data = $this.data('tooltip')
1112 , options = typeof option == 'object' && option
1113 if (!data) $this.data('tooltip', (data = new Tooltip(this, options)))
1114 if (typeof option == 'string') data[option]()
1118 $.fn.tooltip.Constructor = Tooltip
1120 $.fn.tooltip.defaults = {
1124 , template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>'
1125 , trigger: 'hover focus'
1133 /* TOOLTIP NO CONFLICT
1134 * =================== */
1136 $.fn.tooltip.noConflict = function () {
1143 /* ===========================================================
1144 * bootstrap-popover.js v2.3.1
1145 * http://twitter.github.com/bootstrap/javascript.html#popovers
1146 * ===========================================================
1147 * Copyright 2012 Twitter, Inc.
1149 * Licensed under the Apache License, Version 2.0 (the "License");
1150 * you may not use this file except in compliance with the License.
1151 * You may obtain a copy of the License at
1153 * http://www.apache.org/licenses/LICENSE-2.0
1155 * Unless required by applicable law or agreed to in writing, software
1156 * distributed under the License is distributed on an "AS IS" BASIS,
1157 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1158 * See the License for the specific language governing permissions and
1159 * limitations under the License.
1160 * =========================================================== */
1165 "use strict"; // jshint ;_;
1168 /* POPOVER PUBLIC CLASS DEFINITION
1169 * =============================== */
1171 var Popover = function (element, options) {
1172 this.init('popover', element, options)
1176 /* NOTE: POPOVER EXTENDS BOOTSTRAP-TOOLTIP.js
1177 ========================================== */
1179 Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype, {
1181 constructor: Popover
1183 , setContent: function () {
1184 var $tip = this.tip()
1185 , title = this.getTitle()
1186 , content = this.getContent()
1188 $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
1189 $tip.find('.popover-content')[this.options.html ? 'html' : 'text'](content)
1191 $tip.removeClass('fade top bottom left right in')
1194 , hasContent: function () {
1195 return this.getTitle() || this.getContent()
1198 , getContent: function () {
1200 , $e = this.$element
1203 content = (typeof o.content == 'function' ? o.content.call($e[0]) : o.content)
1204 || $e.attr('data-content')
1209 , tip: function () {
1211 this.$tip = $(this.options.template)
1216 , destroy: function () {
1217 this.hide().$element.off('.' + this.type).removeData(this.type)
1223 /* POPOVER PLUGIN DEFINITION
1224 * ======================= */
1226 var old = $.fn.popover
1228 $.fn.popover = function (option) {
1229 return this.each(function () {
1231 , data = $this.data('popover')
1232 , options = typeof option == 'object' && option
1233 if (!data) $this.data('popover', (data = new Popover(this, options)))
1234 if (typeof option == 'string') data[option]()
1238 $.fn.popover.Constructor = Popover
1240 $.fn.popover.defaults = $.extend({} , $.fn.tooltip.defaults, {
1244 , template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
1248 /* POPOVER NO CONFLICT
1249 * =================== */
1251 $.fn.popover.noConflict = function () {
1258 /* ==========================================================
1259 * bootstrap-affix.js v2.3.1
1260 * http://twitter.github.com/bootstrap/javascript.html#affix
1261 * ==========================================================
1262 * Copyright 2012 Twitter, Inc.
1264 * Licensed under the Apache License, Version 2.0 (the "License");
1265 * you may not use this file except in compliance with the License.
1266 * You may obtain a copy of the License at
1268 * http://www.apache.org/licenses/LICENSE-2.0
1270 * Unless required by applicable law or agreed to in writing, software
1271 * distributed under the License is distributed on an "AS IS" BASIS,
1272 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1273 * See the License for the specific language governing permissions and
1274 * limitations under the License.
1275 * ========================================================== */
1280 "use strict"; // jshint ;_;
1283 /* AFFIX CLASS DEFINITION
1284 * ====================== */
1286 var Affix = function (element, options) {
1287 this.options = $.extend({}, $.fn.affix.defaults, options)
1288 this.$window = $(window)
1289 .on('scroll.affix.data-api', $.proxy(this.checkPosition, this))
1290 .on('click.affix.data-api', $.proxy(function () { setTimeout($.proxy(this.checkPosition, this), 1) }, this))
1291 this.$element = $(element)
1292 this.checkPosition()
1295 Affix.prototype.checkPosition = function () {
1296 if (!this.$element.is(':visible')) return
1298 var scrollHeight = $(document).height()
1299 , scrollTop = this.$window.scrollTop()
1300 , position = this.$element.offset()
1301 , offset = this.options.offset
1302 , offsetBottom = offset.bottom
1303 , offsetTop = offset.top
1304 , reset = 'affix affix-top affix-bottom'
1307 if (typeof offset != 'object') offsetBottom = offsetTop = offset
1308 if (typeof offsetTop == 'function') offsetTop = offset.top()
1309 if (typeof offsetBottom == 'function') offsetBottom = offset.bottom()
1311 affix = this.unpin != null && (scrollTop + this.unpin <= position.top) ?
1312 false : offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ?
1313 'bottom' : offsetTop != null && scrollTop <= offsetTop ?
1316 if (this.affixed === affix) return
1318 this.affixed = affix
1319 this.unpin = affix == 'bottom' ? position.top - scrollTop : null
1321 this.$element.removeClass(reset).addClass('affix' + (affix ? '-' + affix : ''))
1325 /* AFFIX PLUGIN DEFINITION
1326 * ======================= */
1328 var old = $.fn.affix
1330 $.fn.affix = function (option) {
1331 return this.each(function () {
1333 , data = $this.data('affix')
1334 , options = typeof option == 'object' && option
1335 if (!data) $this.data('affix', (data = new Affix(this, options)))
1336 if (typeof option == 'string') data[option]()
1340 $.fn.affix.Constructor = Affix
1342 $.fn.affix.defaults = {
1347 /* AFFIX NO CONFLICT
1348 * ================= */
1350 $.fn.affix.noConflict = function () {
1359 $(window).on('load', function () {
1360 $('[data-spy="affix"]').each(function () {
1362 , data = $spy.data()
1364 data.offset = data.offset || {}
1366 data.offsetBottom && (data.offset.bottom = data.offsetBottom)
1367 data.offsetTop && (data.offset.top = data.offsetTop)
1375 /* ==========================================================
1376 * bootstrap-alert.js v2.3.1
1377 * http://twitter.github.com/bootstrap/javascript.html#alerts
1378 * ==========================================================
1379 * Copyright 2012 Twitter, Inc.
1381 * Licensed under the Apache License, Version 2.0 (the "License");
1382 * you may not use this file except in compliance with the License.
1383 * You may obtain a copy of the License at
1385 * http://www.apache.org/licenses/LICENSE-2.0
1387 * Unless required by applicable law or agreed to in writing, software
1388 * distributed under the License is distributed on an "AS IS" BASIS,
1389 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1390 * See the License for the specific language governing permissions and
1391 * limitations under the License.
1392 * ========================================================== */
1397 "use strict"; // jshint ;_;
1400 /* ALERT CLASS DEFINITION
1401 * ====================== */
1403 var dismiss = '[data-dismiss="alert"]'
1404 , Alert = function (el) {
1405 $(el).on('click', dismiss, this.close)
1408 Alert.prototype.close = function (e) {
1410 , selector = $this.attr('data-target')
1414 selector = $this.attr('href')
1415 selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
1418 $parent = $(selector)
1420 e && e.preventDefault()
1422 $parent.length || ($parent = $this.hasClass('alert') ? $this : $this.parent())
1424 $parent.trigger(e = $.Event('close'))
1426 if (e.isDefaultPrevented()) return
1428 $parent.removeClass('in')
1430 function removeElement() {
1436 $.support.transition && $parent.hasClass('fade') ?
1437 $parent.on($.support.transition.end, removeElement) :
1442 /* ALERT PLUGIN DEFINITION
1443 * ======================= */
1445 var old = $.fn.alert
1447 $.fn.alert = function (option) {
1448 return this.each(function () {
1450 , data = $this.data('alert')
1451 if (!data) $this.data('alert', (data = new Alert(this)))
1452 if (typeof option == 'string') data[option].call($this)
1456 $.fn.alert.Constructor = Alert
1459 /* ALERT NO CONFLICT
1460 * ================= */
1462 $.fn.alert.noConflict = function () {
1471 $(document).on('click.alert.data-api', dismiss, Alert.prototype.close)
1474 /* ============================================================
1475 * bootstrap-button.js v2.3.1
1476 * http://twitter.github.com/bootstrap/javascript.html#buttons
1477 * ============================================================
1478 * Copyright 2012 Twitter, Inc.
1480 * Licensed under the Apache License, Version 2.0 (the "License");
1481 * you may not use this file except in compliance with the License.
1482 * You may obtain a copy of the License at
1484 * http://www.apache.org/licenses/LICENSE-2.0
1486 * Unless required by applicable law or agreed to in writing, software
1487 * distributed under the License is distributed on an "AS IS" BASIS,
1488 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1489 * See the License for the specific language governing permissions and
1490 * limitations under the License.
1491 * ============================================================ */
1496 "use strict"; // jshint ;_;
1499 /* BUTTON PUBLIC CLASS DEFINITION
1500 * ============================== */
1502 var Button = function (element, options) {
1503 this.$element = $(element)
1504 this.options = $.extend({}, $.fn.button.defaults, options)
1507 Button.prototype.setState = function (state) {
1509 , $el = this.$element
1511 , val = $el.is('input') ? 'val' : 'html'
1513 state = state + 'Text'
1514 data.resetText || $el.data('resetText', $el[val]())
1516 $el[val](data[state] || this.options[state])
1518 // push to event loop to allow forms to submit
1519 setTimeout(function () {
1520 state == 'loadingText' ?
1521 $el.addClass(d).attr(d, d) :
1522 $el.removeClass(d).removeAttr(d)
1526 Button.prototype.toggle = function () {
1527 var $parent = this.$element.closest('[data-toggle="buttons-radio"]')
1531 .removeClass('active')
1533 this.$element.toggleClass('active')
1537 /* BUTTON PLUGIN DEFINITION
1538 * ======================== */
1540 var old = $.fn.button
1542 $.fn.button = function (option) {
1543 return this.each(function () {
1545 , data = $this.data('button')
1546 , options = typeof option == 'object' && option
1547 if (!data) $this.data('button', (data = new Button(this, options)))
1548 if (option == 'toggle') data.toggle()
1549 else if (option) data.setState(option)
1553 $.fn.button.defaults = {
1554 loadingText: 'loading...'
1557 $.fn.button.Constructor = Button
1560 /* BUTTON NO CONFLICT
1561 * ================== */
1563 $.fn.button.noConflict = function () {
1570 * =============== */
1572 $(document).on('click.button.data-api', '[data-toggle^=button]', function (e) {
1573 var $btn = $(e.target)
1574 if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
1575 $btn.button('toggle')
1579 /* =============================================================
1580 * bootstrap-collapse.js v2.3.1
1581 * http://twitter.github.com/bootstrap/javascript.html#collapse
1582 * =============================================================
1583 * Copyright 2012 Twitter, Inc.
1585 * Licensed under the Apache License, Version 2.0 (the "License");
1586 * you may not use this file except in compliance with the License.
1587 * You may obtain a copy of the License at
1589 * http://www.apache.org/licenses/LICENSE-2.0
1591 * Unless required by applicable law or agreed to in writing, software
1592 * distributed under the License is distributed on an "AS IS" BASIS,
1593 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1594 * See the License for the specific language governing permissions and
1595 * limitations under the License.
1596 * ============================================================ */
1601 "use strict"; // jshint ;_;
1604 /* COLLAPSE PUBLIC CLASS DEFINITION
1605 * ================================ */
1607 var Collapse = function (element, options) {
1608 this.$element = $(element)
1609 this.options = $.extend({}, $.fn.collapse.defaults, options)
1611 if (this.options.parent) {
1612 this.$parent = $(this.options.parent)
1615 this.options.toggle && this.toggle()
1618 Collapse.prototype = {
1620 constructor: Collapse
1622 , dimension: function () {
1623 var hasWidth = this.$element.hasClass('width')
1624 return hasWidth ? 'width' : 'height'
1627 , show: function () {
1633 if (this.transitioning || this.$element.hasClass('in')) return
1635 dimension = this.dimension()
1636 scroll = $.camelCase(['scroll', dimension].join('-'))
1637 actives = this.$parent && this.$parent.find('> .accordion-group > .in')
1639 if (actives && actives.length) {
1640 hasData = actives.data('collapse')
1641 if (hasData && hasData.transitioning) return
1642 actives.collapse('hide')
1643 hasData || actives.data('collapse', null)
1646 this.$element[dimension](0)
1647 this.transition('addClass', $.Event('show'), 'shown')
1648 $.support.transition && this.$element[dimension](this.$element[0][scroll])
1651 , hide: function () {
1653 if (this.transitioning || !this.$element.hasClass('in')) return
1654 dimension = this.dimension()
1655 this.reset(this.$element[dimension]())
1656 this.transition('removeClass', $.Event('hide'), 'hidden')
1657 this.$element[dimension](0)
1660 , reset: function (size) {
1661 var dimension = this.dimension()
1664 .removeClass('collapse')
1665 [dimension](size || 'auto')
1668 this.$element[size !== null ? 'addClass' : 'removeClass']('collapse')
1673 , transition: function (method, startEvent, completeEvent) {
1675 , complete = function () {
1676 if (startEvent.type == 'show') that.reset()
1677 that.transitioning = 0
1678 that.$element.trigger(completeEvent)
1681 this.$element.trigger(startEvent)
1683 if (startEvent.isDefaultPrevented()) return
1685 this.transitioning = 1
1687 this.$element[method]('in')
1689 $.support.transition && this.$element.hasClass('collapse') ?
1690 this.$element.one($.support.transition.end, complete) :
1694 , toggle: function () {
1695 this[this.$element.hasClass('in') ? 'hide' : 'show']()
1701 /* COLLAPSE PLUGIN DEFINITION
1702 * ========================== */
1704 var old = $.fn.collapse
1706 $.fn.collapse = function (option) {
1707 return this.each(function () {
1709 , data = $this.data('collapse')
1710 , options = $.extend({}, $.fn.collapse.defaults, $this.data(), typeof option == 'object' && option)
1711 if (!data) $this.data('collapse', (data = new Collapse(this, options)))
1712 if (typeof option == 'string') data[option]()
1716 $.fn.collapse.defaults = {
1720 $.fn.collapse.Constructor = Collapse
1723 /* COLLAPSE NO CONFLICT
1724 * ==================== */
1726 $.fn.collapse.noConflict = function () {
1732 /* COLLAPSE DATA-API
1733 * ================= */
1735 $(document).on('click.collapse.data-api', '[data-toggle=collapse]', function (e) {
1736 var $this = $(this), href
1737 , target = $this.attr('data-target')
1738 || e.preventDefault()
1739 || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
1740 , option = $(target).data('collapse') ? 'toggle' : $this.data()
1741 $this[$(target).hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
1742 $(target).collapse(option)
1746 /* ==========================================================
1747 * bootstrap-carousel.js v2.3.1
1748 * http://twitter.github.com/bootstrap/javascript.html#carousel
1749 * ==========================================================
1750 * Copyright 2012 Twitter, Inc.
1752 * Licensed under the Apache License, Version 2.0 (the "License");
1753 * you may not use this file except in compliance with the License.
1754 * You may obtain a copy of the License at
1756 * http://www.apache.org/licenses/LICENSE-2.0
1758 * Unless required by applicable law or agreed to in writing, software
1759 * distributed under the License is distributed on an "AS IS" BASIS,
1760 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1761 * See the License for the specific language governing permissions and
1762 * limitations under the License.
1763 * ========================================================== */
1768 "use strict"; // jshint ;_;
1771 /* CAROUSEL CLASS DEFINITION
1772 * ========================= */
1774 var Carousel = function (element, options) {
1775 this.$element = $(element)
1776 this.$indicators = this.$element.find('.carousel-indicators')
1777 this.options = options
1778 this.options.pause == 'hover' && this.$element
1779 .on('mouseenter', $.proxy(this.pause, this))
1780 .on('mouseleave', $.proxy(this.cycle, this))
1783 Carousel.prototype = {
1785 cycle: function (e) {
1786 if (!e) this.paused = false
1787 if (this.interval) clearInterval(this.interval);
1788 this.options.interval
1790 && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
1794 , getActiveIndex: function () {
1795 this.$active = this.$element.find('.item.active')
1796 this.$items = this.$active.parent().children()
1797 return this.$items.index(this.$active)
1800 , to: function (pos) {
1801 var activeIndex = this.getActiveIndex()
1804 if (pos > (this.$items.length - 1) || pos < 0) return
1807 return this.$element.one('slid', function () {
1812 if (activeIndex == pos) {
1813 return this.pause().cycle()
1816 return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
1819 , pause: function (e) {
1820 if (!e) this.paused = true
1821 if (this.$element.find('.next, .prev').length && $.support.transition.end) {
1822 this.$element.trigger($.support.transition.end)
1825 clearInterval(this.interval)
1826 this.interval = null
1830 , next: function () {
1831 if (this.sliding) return
1832 return this.slide('next')
1835 , prev: function () {
1836 if (this.sliding) return
1837 return this.slide('prev')
1840 , slide: function (type, next) {
1841 var $active = this.$element.find('.item.active')
1842 , $next = next || $active[type]()
1843 , isCycling = this.interval
1844 , direction = type == 'next' ? 'left' : 'right'
1845 , fallback = type == 'next' ? 'first' : 'last'
1851 isCycling && this.pause()
1853 $next = $next.length ? $next : this.$element.find('.item')[fallback]()
1855 e = $.Event('slide', {
1856 relatedTarget: $next[0]
1857 , direction: direction
1860 if ($next.hasClass('active')) return
1862 if (this.$indicators.length) {
1863 this.$indicators.find('.active').removeClass('active')
1864 this.$element.one('slid', function () {
1865 var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
1866 $nextIndicator && $nextIndicator.addClass('active')
1870 if ($.support.transition && this.$element.hasClass('slide')) {
1871 this.$element.trigger(e)
1872 if (e.isDefaultPrevented()) return
1873 $next.addClass(type)
1874 $next[0].offsetWidth // force reflow
1875 $active.addClass(direction)
1876 $next.addClass(direction)
1877 this.$element.one($.support.transition.end, function () {
1878 $next.removeClass([type, direction].join(' ')).addClass('active')
1879 $active.removeClass(['active', direction].join(' '))
1880 that.sliding = false
1881 setTimeout(function () { that.$element.trigger('slid') }, 0)
1884 this.$element.trigger(e)
1885 if (e.isDefaultPrevented()) return
1886 $active.removeClass('active')
1887 $next.addClass('active')
1888 this.sliding = false
1889 this.$element.trigger('slid')
1892 isCycling && this.cycle()
1900 /* CAROUSEL PLUGIN DEFINITION
1901 * ========================== */
1903 var old = $.fn.carousel
1905 $.fn.carousel = function (option) {
1906 return this.each(function () {
1908 , data = $this.data('carousel')
1909 , options = $.extend({}, $.fn.carousel.defaults, typeof option == 'object' && option)
1910 , action = typeof option == 'string' ? option : options.slide
1911 if (!data) $this.data('carousel', (data = new Carousel(this, options)))
1912 if (typeof option == 'number') data.to(option)
1913 else if (action) data[action]()
1914 else if (options.interval) data.pause().cycle()
1918 $.fn.carousel.defaults = {
1923 $.fn.carousel.Constructor = Carousel
1926 /* CAROUSEL NO CONFLICT
1927 * ==================== */
1929 $.fn.carousel.noConflict = function () {
1934 /* CAROUSEL DATA-API
1935 * ================= */
1937 $(document).on('click.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
1938 var $this = $(this), href
1939 , $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
1940 , options = $.extend({}, $target.data(), $this.data())
1943 $target.carousel(options)
1945 if (slideIndex = $this.attr('data-slide-to')) {
1946 $target.data('carousel').pause().to(slideIndex).cycle()
1953 /* =============================================================
1954 * bootstrap-typeahead.js v2.3.1
1955 * http://twitter.github.com/bootstrap/javascript.html#typeahead
1956 * =============================================================
1957 * Copyright 2012 Twitter, Inc.
1959 * Licensed under the Apache License, Version 2.0 (the "License");
1960 * you may not use this file except in compliance with the License.
1961 * You may obtain a copy of the License at
1963 * http://www.apache.org/licenses/LICENSE-2.0
1965 * Unless required by applicable law or agreed to in writing, software
1966 * distributed under the License is distributed on an "AS IS" BASIS,
1967 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1968 * See the License for the specific language governing permissions and
1969 * limitations under the License.
1970 * ============================================================ */
1975 "use strict"; // jshint ;_;
1978 /* TYPEAHEAD PUBLIC CLASS DEFINITION
1979 * ================================= */
1981 var Typeahead = function (element, options) {
1982 this.$element = $(element)
1983 this.options = $.extend({}, $.fn.typeahead.defaults, options)
1984 this.matcher = this.options.matcher || this.matcher
1985 this.sorter = this.options.sorter || this.sorter
1986 this.highlighter = this.options.highlighter || this.highlighter
1987 this.updater = this.options.updater || this.updater
1988 this.source = this.options.source
1989 this.$menu = $(this.options.menu)
1994 Typeahead.prototype = {
1996 constructor: Typeahead
1998 , select: function () {
1999 var val = this.$menu.find('.active').attr('data-value')
2001 .val(this.updater(val))
2006 , updater: function (item) {
2010 , show: function () {
2011 var pos = $.extend({}, this.$element.position(), {
2012 height: this.$element[0].offsetHeight
2016 .insertAfter(this.$element)
2018 top: pos.top + pos.height
2027 , hide: function () {
2033 , lookup: function (event) {
2036 this.query = this.$element.val()
2038 if (!this.query || this.query.length < this.options.minLength) {
2039 return this.shown ? this.hide() : this
2042 items = $.isFunction(this.source) ? this.source(this.query, $.proxy(this.process, this)) : this.source
2044 return items ? this.process(items) : this
2047 , process: function (items) {
2050 items = $.grep(items, function (item) {
2051 return that.matcher(item)
2054 items = this.sorter(items)
2056 if (!items.length) {
2057 return this.shown ? this.hide() : this
2060 return this.render(items.slice(0, this.options.items)).show()
2063 , matcher: function (item) {
2064 return ~item.toLowerCase().indexOf(this.query.toLowerCase())
2067 , sorter: function (items) {
2069 , caseSensitive = []
2070 , caseInsensitive = []
2073 while (item = items.shift()) {
2074 if (!item.toLowerCase().indexOf(this.query.toLowerCase())) beginswith.push(item)
2075 else if (~item.indexOf(this.query)) caseSensitive.push(item)
2076 else caseInsensitive.push(item)
2079 return beginswith.concat(caseSensitive, caseInsensitive)
2082 , highlighter: function (item) {
2083 var query = this.query.replace(/[\-\[\]{}()*+?.,\\\^$|#\s]/g, '\\$&')
2084 return item.replace(new RegExp('(' + query + ')', 'ig'), function ($1, match) {
2085 return '<strong>' + match + '</strong>'
2089 , render: function (items) {
2092 items = $(items).map(function (i, item) {
2093 i = $(that.options.item).attr('data-value', item)
2094 i.find('a').html(that.highlighter(item))
2098 items.first().addClass('active')
2099 this.$menu.html(items)
2103 , next: function (event) {
2104 var active = this.$menu.find('.active').removeClass('active')
2105 , next = active.next()
2108 next = $(this.$menu.find('li')[0])
2111 next.addClass('active')
2114 , prev: function (event) {
2115 var active = this.$menu.find('.active').removeClass('active')
2116 , prev = active.prev()
2119 prev = this.$menu.find('li').last()
2122 prev.addClass('active')
2125 , listen: function () {
2127 .on('focus', $.proxy(this.focus, this))
2128 .on('blur', $.proxy(this.blur, this))
2129 .on('keypress', $.proxy(this.keypress, this))
2130 .on('keyup', $.proxy(this.keyup, this))
2132 if (this.eventSupported('keydown')) {
2133 this.$element.on('keydown', $.proxy(this.keydown, this))
2137 .on('click', $.proxy(this.click, this))
2138 .on('mouseenter', 'li', $.proxy(this.mouseenter, this))
2139 .on('mouseleave', 'li', $.proxy(this.mouseleave, this))
2142 , eventSupported: function(eventName) {
2143 var isSupported = eventName in this.$element
2145 this.$element.setAttribute(eventName, 'return;')
2146 isSupported = typeof this.$element[eventName] === 'function'
2151 , move: function (e) {
2152 if (!this.shown) return
2161 case 38: // up arrow
2166 case 40: // down arrow
2175 , keydown: function (e) {
2176 this.suppressKeyPressRepeat = ~$.inArray(e.keyCode, [40,38,9,13,27])
2180 , keypress: function (e) {
2181 if (this.suppressKeyPressRepeat) return
2185 , keyup: function (e) {
2187 case 40: // down arrow
2188 case 38: // up arrow
2196 if (!this.shown) return
2201 if (!this.shown) return
2213 , focus: function (e) {
2217 , blur: function (e) {
2218 this.focused = false
2219 if (!this.mousedover && this.shown) this.hide()
2222 , click: function (e) {
2226 this.$element.focus()
2229 , mouseenter: function (e) {
2230 this.mousedover = true
2231 this.$menu.find('.active').removeClass('active')
2232 $(e.currentTarget).addClass('active')
2235 , mouseleave: function (e) {
2236 this.mousedover = false
2237 if (!this.focused && this.shown) this.hide()
2243 /* TYPEAHEAD PLUGIN DEFINITION
2244 * =========================== */
2246 var old = $.fn.typeahead
2248 $.fn.typeahead = function (option) {
2249 return this.each(function () {
2251 , data = $this.data('typeahead')
2252 , options = typeof option == 'object' && option
2253 if (!data) $this.data('typeahead', (data = new Typeahead(this, options)))
2254 if (typeof option == 'string') data[option]()
2258 $.fn.typeahead.defaults = {
2261 , menu: '<ul class="typeahead dropdown-menu"></ul>'
2262 , item: '<li><a href="#"></a></li>'
2266 $.fn.typeahead.Constructor = Typeahead
2269 /* TYPEAHEAD NO CONFLICT
2270 * =================== */
2272 $.fn.typeahead.noConflict = function () {
2273 $.fn.typeahead = old
2278 /* TYPEAHEAD DATA-API
2279 * ================== */
2281 $(document).on('focus.typeahead.data-api', '[data-provide="typeahead"]', function (e) {
2283 if ($this.data('typeahead')) return
2284 $this.typeahead($this.data())