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