migrate discovery source codes from OPEN-O
[msb/discovery.git] / discovery-ui / src / main / resources / iui / microservices / js / bootstrap / js / bootstrap.js
1 /*
2  * Copyright 2016 ZTE, Inc. and others.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 if (typeof jQuery === 'undefined') { throw new Error('Bootstrap\'s JavaScript requires jQuery') }
17
18 /* ========================================================================
19  * Bootstrap: transition.js v3.1.1
20  * http://getbootstrap.com/javascript/#transitions
21  * ========================================================================
22  * Copyright 2011-2014 Twitter, Inc.
23  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
24  * ======================================================================== */
25
26
27 +function ($) {
28   'use strict';
29
30   // CSS TRANSITION SUPPORT (Shoutout: http://www.modernizr.com/)
31   // ============================================================
32
33   function transitionEnd() {
34     var el = document.createElement('bootstrap')
35
36     var transEndEventNames = {
37       'WebkitTransition' : 'webkitTransitionEnd',
38       'MozTransition'    : 'transitionend',
39       'OTransition'      : 'oTransitionEnd otransitionend',
40       'transition'       : 'transitionend'
41     }
42
43     for (var name in transEndEventNames) {
44       if (el.style[name] !== undefined) {
45         return { end: transEndEventNames[name] }
46       }
47     }
48
49     return false // explicit for ie8 (  ._.)
50   }
51
52   // http://blog.alexmaccaw.com/css-transitions
53   $.fn.emulateTransitionEnd = function (duration) {
54     var called = false, $el = this
55     $(this).one($.support.transition.end, function () { called = true })
56     var callback = function () { if (!called) $($el).trigger($.support.transition.end) }
57     setTimeout(callback, duration)
58     return this
59   }
60
61   $(function () {
62     $.support.transition = transitionEnd()
63   })
64
65 }(jQuery);
66
67 /* ========================================================================
68  * Bootstrap: alert.js v3.1.1
69  * http://getbootstrap.com/javascript/#alerts
70  * ========================================================================
71  * Copyright 2011-2014 Twitter, Inc.
72  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
73  * ======================================================================== */
74
75
76 +function ($) {
77   'use strict';
78
79   // ALERT CLASS DEFINITION
80   // ======================
81
82   var dismiss = '[data-dismiss="alert"]'
83   var Alert   = function (el) {
84     $(el).on('click', dismiss, this.close)
85   }
86
87   Alert.prototype.close = function (e) {
88     var $this    = $(this)
89     var selector = $this.attr('data-target')
90
91     if (!selector) {
92       selector = $this.attr('href')
93       selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') // strip for ie7
94     }
95
96     var $parent = $(selector)
97
98     if (e) e.preventDefault()
99
100     if (!$parent.length) {
101       $parent = $this.hasClass('alert') ? $this : $this.parent()
102     }
103
104     $parent.trigger(e = $.Event('close.bs.alert'))
105
106     if (e.isDefaultPrevented()) return
107
108     $parent.removeClass('in')
109
110     function removeElement() {
111       $parent.trigger('closed.bs.alert').remove()
112     }
113
114     $.support.transition && $parent.hasClass('fade') ?
115       $parent
116         .one($.support.transition.end, removeElement)
117         .emulateTransitionEnd(150) :
118       removeElement()
119   }
120
121
122   // ALERT PLUGIN DEFINITION
123   // =======================
124
125   var old = $.fn.alert
126
127   $.fn.alert = function (option) {
128     return this.each(function () {
129       var $this = $(this)
130       var data  = $this.data('bs.alert')
131
132       if (!data) $this.data('bs.alert', (data = new Alert(this)))
133       if (typeof option == 'string') data[option].call($this)
134     })
135   }
136
137   $.fn.alert.Constructor = Alert
138
139
140   // ALERT NO CONFLICT
141   // =================
142
143   $.fn.alert.noConflict = function () {
144     $.fn.alert = old
145     return this
146   }
147
148
149   // ALERT DATA-API
150   // ==============
151
152   $(document).on('click.bs.alert.data-api', dismiss, Alert.prototype.close)
153
154 }(jQuery);
155
156 /* ========================================================================
157  * Bootstrap: button.js v3.1.1
158  * http://getbootstrap.com/javascript/#buttons
159  * ========================================================================
160  * Copyright 2011-2014 Twitter, Inc.
161  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
162  * ======================================================================== */
163
164
165 +function ($) {
166   'use strict';
167
168   // BUTTON PUBLIC CLASS DEFINITION
169   // ==============================
170
171   var Button = function (element, options) {
172     this.$element  = $(element)
173     this.options   = $.extend({}, Button.DEFAULTS, options)
174     this.isLoading = false
175   }
176
177   Button.DEFAULTS = {
178     loadingText: 'loading...'
179   }
180
181   Button.prototype.setState = function (state) {
182     var d    = 'disabled'
183     var $el  = this.$element
184     var val  = $el.is('input') ? 'val' : 'html'
185     var data = $el.data()
186
187     state = state + 'Text'
188
189     if (!data.resetText) $el.data('resetText', $el[val]())
190
191     $el[val](data[state] || this.options[state])
192
193     // push to event loop to allow forms to submit
194     setTimeout($.proxy(function () {
195       if (state == 'loadingText') {
196         this.isLoading = true
197         $el.addClass(d).attr(d, d)
198       } else if (this.isLoading) {
199         this.isLoading = false
200         $el.removeClass(d).removeAttr(d)
201       }
202     }, this), 0)
203   }
204
205   Button.prototype.toggle = function () {
206     var changed = true
207     var $parent = this.$element.closest('[data-toggle="buttons"]')
208
209     if ($parent.length) {
210       var $input = this.$element.find('input')
211       if ($input.prop('type') == 'radio') {
212         if ($input.prop('checked') && this.$element.hasClass('active')) changed = false
213         else $parent.find('.active').removeClass('active')
214       }
215       if (changed) $input.prop('checked', !this.$element.hasClass('active')).trigger('change')
216     }
217
218     if (changed) this.$element.toggleClass('active')
219   }
220
221
222   // BUTTON PLUGIN DEFINITION
223   // ========================
224
225   var old = $.fn.button
226
227   $.fn.button = function (option) {
228     return this.each(function () {
229       var $this   = $(this)
230       var data    = $this.data('bs.button')
231       var options = typeof option == 'object' && option
232
233       if (!data) $this.data('bs.button', (data = new Button(this, options)))
234
235       if (option == 'toggle') data.toggle()
236       else if (option) data.setState(option)
237     })
238   }
239
240   $.fn.button.Constructor = Button
241
242
243   // BUTTON NO CONFLICT
244   // ==================
245
246   $.fn.button.noConflict = function () {
247     $.fn.button = old
248     return this
249   }
250
251
252   // BUTTON DATA-API
253   // ===============
254
255   $(document).on('click.bs.button.data-api', '[data-toggle^=button]', function (e) {
256     var $btn = $(e.target)
257     if (!$btn.hasClass('btn')) $btn = $btn.closest('.btn')
258     $btn.button('toggle')
259     e.preventDefault()
260   })
261
262 }(jQuery);
263
264 /* ========================================================================
265  * Bootstrap: carousel.js v3.1.1
266  * http://getbootstrap.com/javascript/#carousel
267  * ========================================================================
268  * Copyright 2011-2014 Twitter, Inc.
269  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
270  * ======================================================================== */
271
272
273 +function ($) {
274   'use strict';
275
276   // CAROUSEL CLASS DEFINITION
277   // =========================
278
279   var Carousel = function (element, options) {
280     this.$element    = $(element)
281     this.$indicators = this.$element.find('.carousel-indicators')
282     this.options     = options
283     this.paused      =
284     this.sliding     =
285     this.interval    =
286     this.$active     =
287     this.$items      = null
288
289     this.options.pause == 'hover' && this.$element
290       .on('mouseenter', $.proxy(this.pause, this))
291       .on('mouseleave', $.proxy(this.cycle, this))
292   }
293
294   Carousel.DEFAULTS = {
295     interval: 5000,
296     pause: 'hover',
297     wrap: true
298   }
299
300   Carousel.prototype.cycle =  function (e) {
301     e || (this.paused = false)
302
303     this.interval && clearInterval(this.interval)
304
305     this.options.interval
306       && !this.paused
307       && (this.interval = setInterval($.proxy(this.next, this), this.options.interval))
308
309     return this
310   }
311
312   Carousel.prototype.getActiveIndex = function () {
313     this.$active = this.$element.find('.item.active')
314     this.$items  = this.$active.parent().children()
315
316     return this.$items.index(this.$active)
317   }
318
319   Carousel.prototype.to = function (pos) {
320     var that        = this
321     var activeIndex = this.getActiveIndex()
322
323     if (pos > (this.$items.length - 1) || pos < 0) return
324
325     if (this.sliding)       return this.$element.one('slid.bs.carousel', function () { that.to(pos) })
326     if (activeIndex == pos) return this.pause().cycle()
327
328     return this.slide(pos > activeIndex ? 'next' : 'prev', $(this.$items[pos]))
329   }
330
331   Carousel.prototype.pause = function (e) {
332     e || (this.paused = true)
333
334     if (this.$element.find('.next, .prev').length && $.support.transition) {
335       this.$element.trigger($.support.transition.end)
336       this.cycle(true)
337     }
338
339     this.interval = clearInterval(this.interval)
340
341     return this
342   }
343
344   Carousel.prototype.next = function () {
345     if (this.sliding) return
346     return this.slide('next')
347   }
348
349   Carousel.prototype.prev = function () {
350     if (this.sliding) return
351     return this.slide('prev')
352   }
353
354   Carousel.prototype.slide = function (type, next) {
355     var $active   = this.$element.find('.item.active')
356     var $next     = next || $active[type]()
357     var isCycling = this.interval
358     var direction = type == 'next' ? 'left' : 'right'
359     var fallback  = type == 'next' ? 'first' : 'last'
360     var that      = this
361
362     if (!$next.length) {
363       if (!this.options.wrap) return
364       $next = this.$element.find('.item')[fallback]()
365     }
366
367     if ($next.hasClass('active')) return this.sliding = false
368
369     var e = $.Event('slide.bs.carousel', { relatedTarget: $next[0], direction: direction })
370     this.$element.trigger(e)
371     if (e.isDefaultPrevented()) return
372
373     this.sliding = true
374
375     isCycling && this.pause()
376
377     if (this.$indicators.length) {
378       this.$indicators.find('.active').removeClass('active')
379       this.$element.one('slid.bs.carousel', function () {
380         var $nextIndicator = $(that.$indicators.children()[that.getActiveIndex()])
381         $nextIndicator && $nextIndicator.addClass('active')
382       })
383     }
384
385     if ($.support.transition && this.$element.hasClass('slide')) {
386       $next.addClass(type)
387       $next[0].offsetWidth // force reflow
388       $active.addClass(direction)
389       $next.addClass(direction)
390       $active
391         .one($.support.transition.end, function () {
392           $next.removeClass([type, direction].join(' ')).addClass('active')
393           $active.removeClass(['active', direction].join(' '))
394           that.sliding = false
395           setTimeout(function () { that.$element.trigger('slid.bs.carousel') }, 0)
396         })
397         .emulateTransitionEnd($active.css('transition-duration').slice(0, -1) * 1000)
398     } else {
399       $active.removeClass('active')
400       $next.addClass('active')
401       this.sliding = false
402       this.$element.trigger('slid.bs.carousel')
403     }
404
405     isCycling && this.cycle()
406
407     return this
408   }
409
410
411   // CAROUSEL PLUGIN DEFINITION
412   // ==========================
413
414   var old = $.fn.carousel
415
416   $.fn.carousel = function (option) {
417     return this.each(function () {
418       var $this   = $(this)
419       var data    = $this.data('bs.carousel')
420       var options = $.extend({}, Carousel.DEFAULTS, $this.data(), typeof option == 'object' && option)
421       var action  = typeof option == 'string' ? option : options.slide
422
423       if (!data) $this.data('bs.carousel', (data = new Carousel(this, options)))
424       if (typeof option == 'number') data.to(option)
425       else if (action) data[action]()
426       else if (options.interval) data.pause().cycle()
427     })
428   }
429
430   $.fn.carousel.Constructor = Carousel
431
432
433   // CAROUSEL NO CONFLICT
434   // ====================
435
436   $.fn.carousel.noConflict = function () {
437     $.fn.carousel = old
438     return this
439   }
440
441
442   // CAROUSEL DATA-API
443   // =================
444
445   $(document).on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', function (e) {
446     var $this   = $(this), href
447     var $target = $($this.attr('data-target') || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
448     var options = $.extend({}, $target.data(), $this.data())
449     var slideIndex = $this.attr('data-slide-to')
450     if (slideIndex) options.interval = false
451
452     $target.carousel(options)
453
454     if (slideIndex = $this.attr('data-slide-to')) {
455       $target.data('bs.carousel').to(slideIndex)
456     }
457
458     e.preventDefault()
459   })
460
461   $(window).on('load', function () {
462     $('[data-ride="carousel"]').each(function () {
463       var $carousel = $(this)
464       $carousel.carousel($carousel.data())
465     })
466   })
467
468 }(jQuery);
469
470 /* ========================================================================
471  * Bootstrap: collapse.js v3.1.1
472  * http://getbootstrap.com/javascript/#collapse
473  * ========================================================================
474  * Copyright 2011-2014 Twitter, Inc.
475  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
476  * ======================================================================== */
477
478
479 +function ($) {
480   'use strict';
481
482   // COLLAPSE PUBLIC CLASS DEFINITION
483   // ================================
484
485   var Collapse = function (element, options) {
486     this.$element      = $(element)
487     this.options       = $.extend({}, Collapse.DEFAULTS, options)
488     this.transitioning = null
489
490     if (this.options.parent) this.$parent = $(this.options.parent)
491     if (this.options.toggle) this.toggle()
492   }
493
494   Collapse.DEFAULTS = {
495     toggle: true
496   }
497
498   Collapse.prototype.dimension = function () {
499     var hasWidth = this.$element.hasClass('width')
500     return hasWidth ? 'width' : 'height'
501   }
502
503   Collapse.prototype.show = function () {
504     if (this.transitioning || this.$element.hasClass('in')) return
505
506     var startEvent = $.Event('show.bs.collapse')
507     this.$element.trigger(startEvent)
508     if (startEvent.isDefaultPrevented()) return
509
510     var actives = this.$parent && this.$parent.find('> .panel > .in')
511
512     if (actives && actives.length) {
513       var hasData = actives.data('bs.collapse')
514       if (hasData && hasData.transitioning) return
515       actives.collapse('hide')
516       hasData || actives.data('bs.collapse', null)
517     }
518
519     var dimension = this.dimension()
520
521     this.$element
522       .removeClass('collapse')
523       .addClass('collapsing')
524       [dimension](0)
525
526     this.transitioning = 1
527
528     var complete = function () {
529       this.$element
530         .removeClass('collapsing')
531         .addClass('collapse in')
532         [dimension]('auto')
533       this.transitioning = 0
534       this.$element.trigger('shown.bs.collapse')
535     }
536
537     if (!$.support.transition) return complete.call(this)
538
539     var scrollSize = $.camelCase(['scroll', dimension].join('-'))
540
541     this.$element
542       .one($.support.transition.end, $.proxy(complete, this))
543       .emulateTransitionEnd(350)
544       [dimension](this.$element[0][scrollSize])
545   }
546
547   Collapse.prototype.hide = function () {
548     if (this.transitioning || !this.$element.hasClass('in')) return
549
550     var startEvent = $.Event('hide.bs.collapse')
551     this.$element.trigger(startEvent)
552     if (startEvent.isDefaultPrevented()) return
553
554     var dimension = this.dimension()
555
556     this.$element
557       [dimension](this.$element[dimension]())
558       [0].offsetHeight
559
560     this.$element
561       .addClass('collapsing')
562       .removeClass('collapse')
563       .removeClass('in')
564
565     this.transitioning = 1
566
567     var complete = function () {
568       this.transitioning = 0
569       this.$element
570         .trigger('hidden.bs.collapse')
571         .removeClass('collapsing')
572         .addClass('collapse')
573     }
574
575     if (!$.support.transition) return complete.call(this)
576
577     this.$element
578       [dimension](0)
579       .one($.support.transition.end, $.proxy(complete, this))
580       .emulateTransitionEnd(350)
581   }
582
583   Collapse.prototype.toggle = function () {
584     this[this.$element.hasClass('in') ? 'hide' : 'show']()
585   }
586
587
588   // COLLAPSE PLUGIN DEFINITION
589   // ==========================
590
591   var old = $.fn.collapse
592
593   $.fn.collapse = function (option) {
594     return this.each(function () {
595       var $this   = $(this)
596       var data    = $this.data('bs.collapse')
597       var options = $.extend({}, Collapse.DEFAULTS, $this.data(), typeof option == 'object' && option)
598
599       if (!data && options.toggle && option == 'show') option = !option
600       if (!data) $this.data('bs.collapse', (data = new Collapse(this, options)))
601       if (typeof option == 'string') data[option]()
602     })
603   }
604
605   $.fn.collapse.Constructor = Collapse
606
607
608   // COLLAPSE NO CONFLICT
609   // ====================
610
611   $.fn.collapse.noConflict = function () {
612     $.fn.collapse = old
613     return this
614   }
615
616
617   // COLLAPSE DATA-API
618   // =================
619
620   $(document).on('click.bs.collapse.data-api', '[data-toggle=collapse]', function (e) {
621     var $this   = $(this), href
622     var target  = $this.attr('data-target')
623         || e.preventDefault()
624         || (href = $this.attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '') //strip for ie7
625     var $target = $(target)
626     var data    = $target.data('bs.collapse')
627     var option  = data ? 'toggle' : $this.data()
628     var parent  = $this.attr('data-parent')
629     var $parent = parent && $(parent)
630
631     if (!data || !data.transitioning) {
632       if ($parent) $parent.find('[data-toggle=collapse][data-parent="' + parent + '"]').not($this).addClass('collapsed')
633       $this[$target.hasClass('in') ? 'addClass' : 'removeClass']('collapsed')
634     }
635
636     $target.collapse(option)
637   })
638
639 }(jQuery);
640
641 /* ========================================================================
642  * Bootstrap: dropdown.js v3.1.1
643  * http://getbootstrap.com/javascript/#dropdowns
644  * ========================================================================
645  * Copyright 2011-2014 Twitter, Inc.
646  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
647  * ======================================================================== */
648
649
650 +function ($) {
651   'use strict';
652
653   // DROPDOWN CLASS DEFINITION
654   // =========================
655
656   var backdrop = '.dropdown-backdrop'
657   var toggle   = '[data-toggle=dropdown]'
658   var Dropdown = function (element) {
659     $(element).on('click.bs.dropdown', this.toggle)
660   }
661
662   Dropdown.prototype.toggle = function (e) {
663     var $this = $(this)
664
665     if ($this.is('.disabled, :disabled')) return
666
667     var $parent  = getParent($this)
668     var isActive = $parent.hasClass('open')
669
670     clearMenus()
671
672     if (!isActive) {
673       if ('ontouchstart' in document.documentElement && !$parent.closest('.navbar-nav').length) {
674         // if mobile we use a backdrop because click events don't delegate
675         $('<div class="dropdown-backdrop"/>').insertAfter($(this)).on('click', clearMenus)
676       }
677
678       var relatedTarget = { relatedTarget: this }
679       $parent.trigger(e = $.Event('show.bs.dropdown', relatedTarget))
680
681       if (e.isDefaultPrevented()) return
682
683       $parent
684         .toggleClass('open')
685         .trigger('shown.bs.dropdown', relatedTarget)
686
687       $this.focus()
688     }
689
690     return false
691   }
692
693   Dropdown.prototype.keydown = function (e) {
694     if (!/(38|40|27)/.test(e.keyCode)) return
695
696     var $this = $(this)
697
698     e.preventDefault()
699     e.stopPropagation()
700
701     if ($this.is('.disabled, :disabled')) return
702
703     var $parent  = getParent($this)
704     var isActive = $parent.hasClass('open')
705
706     if (!isActive || (isActive && e.keyCode == 27)) {
707       if (e.which == 27) $parent.find(toggle).focus()
708       return $this.click()
709     }
710
711     var desc = ' li:not(.divider):visible a'
712     var $items = $parent.find('[role=menu]' + desc + ', [role=listbox]' + desc)
713
714     if (!$items.length) return
715
716     var index = $items.index($items.filter(':focus'))
717
718     if (e.keyCode == 38 && index > 0)                 index--                        // up
719     if (e.keyCode == 40 && index < $items.length - 1) index++                        // down
720     if (!~index)                                      index = 0
721
722     $items.eq(index).focus()
723   }
724
725   function clearMenus(e) {
726     $(backdrop).remove()
727     $(toggle).each(function () {
728       var $parent = getParent($(this))
729       var relatedTarget = { relatedTarget: this }
730       if (!$parent.hasClass('open')) return
731       $parent.trigger(e = $.Event('hide.bs.dropdown', relatedTarget))
732       if (e.isDefaultPrevented()) return
733       $parent.removeClass('open').trigger('hidden.bs.dropdown', relatedTarget)
734     })
735   }
736
737   function getParent($this) {
738     var selector = $this.attr('data-target')
739
740     if (!selector) {
741       selector = $this.attr('href')
742       selector = selector && /#[A-Za-z]/.test(selector) && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
743     }
744
745     var $parent = selector && $(selector)
746
747     return $parent && $parent.length ? $parent : $this.parent()
748   }
749
750
751   // DROPDOWN PLUGIN DEFINITION
752   // ==========================
753
754   var old = $.fn.dropdown
755
756   $.fn.dropdown = function (option) {
757     return this.each(function () {
758       var $this = $(this)
759       var data  = $this.data('bs.dropdown')
760
761       if (!data) $this.data('bs.dropdown', (data = new Dropdown(this)))
762       if (typeof option == 'string') data[option].call($this)
763     })
764   }
765
766   $.fn.dropdown.Constructor = Dropdown
767
768
769   // DROPDOWN NO CONFLICT
770   // ====================
771
772   $.fn.dropdown.noConflict = function () {
773     $.fn.dropdown = old
774     return this
775   }
776
777
778   // APPLY TO STANDARD DROPDOWN ELEMENTS
779   // ===================================
780
781   $(document)
782     .on('click.bs.dropdown.data-api', clearMenus)
783     .on('click.bs.dropdown.data-api', '.dropdown form', function (e) { e.stopPropagation() })
784     .on('click.bs.dropdown.data-api', toggle, Dropdown.prototype.toggle)
785     .on('keydown.bs.dropdown.data-api', toggle + ', [role=menu], [role=listbox]', Dropdown.prototype.keydown)
786
787 }(jQuery);
788
789 /* ========================================================================
790  * Bootstrap: modal.js v3.1.1
791  * http://getbootstrap.com/javascript/#modals
792  * ========================================================================
793  * Copyright 2011-2014 Twitter, Inc.
794  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
795  * ======================================================================== */
796
797
798 +function ($) {
799   'use strict';
800
801   // MODAL CLASS DEFINITION
802   // ======================
803
804   var Modal = function (element, options) {
805     this.options   = options
806     this.$element  = $(element)
807     this.$backdrop =
808     this.isShown   = null
809
810     if (this.options.remote) {
811       this.$element
812         .find('.modal-content')
813         .load(this.options.remote, $.proxy(function () {
814           this.$element.trigger('loaded.bs.modal')
815         }, this))
816     }
817   }
818
819   Modal.DEFAULTS = {
820     backdrop: true,
821     keyboard: true,
822     show: true
823   }
824
825   Modal.prototype.toggle = function (_relatedTarget) {
826     return this[!this.isShown ? 'show' : 'hide'](_relatedTarget)
827   }
828
829   Modal.prototype.show = function (_relatedTarget) {
830     var that = this
831     var e    = $.Event('show.bs.modal', { relatedTarget: _relatedTarget })
832
833     this.$element.trigger(e)
834
835     if (this.isShown || e.isDefaultPrevented()) return
836
837     this.isShown = true
838
839     this.escape()
840
841     this.$element.on('click.dismiss.bs.modal', '[data-dismiss="modal"]', $.proxy(this.hide, this))
842
843     this.backdrop(function () {
844       var transition = $.support.transition && that.$element.hasClass('fade')
845
846       if (!that.$element.parent().length) {
847         that.$element.appendTo(document.body) // don't move modals dom position
848       }
849
850       that.$element
851         .show()
852         .scrollTop(0)
853
854       if (transition) {
855         that.$element[0].offsetWidth // force reflow
856       }
857
858       that.$element
859         .addClass('in')
860         .attr('aria-hidden', false)
861
862       that.enforceFocus()
863
864       var e = $.Event('shown.bs.modal', { relatedTarget: _relatedTarget })
865
866       transition ?
867         that.$element.find('.modal-dialog') // wait for modal to slide in
868           .one($.support.transition.end, function () {
869             that.$element.focus().trigger(e)
870           })
871           .emulateTransitionEnd(300) :
872         that.$element.focus().trigger(e)
873     })
874   }
875
876   Modal.prototype.hide = function (e) {
877     if (e) e.preventDefault()
878
879     e = $.Event('hide.bs.modal')
880
881     this.$element.trigger(e)
882
883     if (!this.isShown || e.isDefaultPrevented()) return
884
885     this.isShown = false
886
887     this.escape()
888
889     $(document).off('focusin.bs.modal')
890
891     this.$element
892       .removeClass('in')
893       .attr('aria-hidden', true)
894       .off('click.dismiss.bs.modal')
895
896     $.support.transition && this.$element.hasClass('fade') ?
897       this.$element
898         .one($.support.transition.end, $.proxy(this.hideModal, this))
899         .emulateTransitionEnd(300) :
900       this.hideModal()
901   }
902
903   Modal.prototype.enforceFocus = function () {
904     $(document)
905       .off('focusin.bs.modal') // guard against infinite focus loop
906       .on('focusin.bs.modal', $.proxy(function (e) {
907         if (this.$element[0] !== e.target && !this.$element.has(e.target).length) {
908           this.$element.focus()
909         }
910       }, this))
911   }
912
913   Modal.prototype.escape = function () {
914     if (this.isShown && this.options.keyboard) {
915       this.$element.on('keyup.dismiss.bs.modal', $.proxy(function (e) {
916         e.which == 27 && this.hide()
917       }, this))
918     } else if (!this.isShown) {
919       this.$element.off('keyup.dismiss.bs.modal')
920     }
921   }
922
923   Modal.prototype.hideModal = function () {
924     var that = this
925     this.$element.hide()
926     this.backdrop(function () {
927       that.removeBackdrop()
928       that.$element.trigger('hidden.bs.modal')
929     })
930   }
931
932   Modal.prototype.removeBackdrop = function () {
933     this.$backdrop && this.$backdrop.remove()
934     this.$backdrop = null
935   }
936
937   Modal.prototype.backdrop = function (callback) {
938     var animate = this.$element.hasClass('fade') ? 'fade' : ''
939
940     if (this.isShown && this.options.backdrop) {
941       var doAnimate = $.support.transition && animate
942
943       this.$backdrop = $('<div class="modal-backdrop ' + animate + '" />')
944         .appendTo(document.body)
945
946       this.$element.on('click.dismiss.bs.modal', $.proxy(function (e) {
947         if (e.target !== e.currentTarget) return
948         this.options.backdrop == 'static'
949           ? this.$element[0].focus.call(this.$element[0])
950           : this.hide.call(this)
951       }, this))
952
953       if (doAnimate) this.$backdrop[0].offsetWidth // force reflow
954
955       this.$backdrop.addClass('in')
956
957       if (!callback) return
958
959       doAnimate ?
960         this.$backdrop
961           .one($.support.transition.end, callback)
962           .emulateTransitionEnd(150) :
963         callback()
964
965     } else if (!this.isShown && this.$backdrop) {
966       this.$backdrop.removeClass('in')
967
968       $.support.transition && this.$element.hasClass('fade') ?
969         this.$backdrop
970           .one($.support.transition.end, callback)
971           .emulateTransitionEnd(150) :
972         callback()
973
974     } else if (callback) {
975       callback()
976     }
977   }
978
979
980   // MODAL PLUGIN DEFINITION
981   // =======================
982
983   var old = $.fn.modal
984
985   $.fn.modal = function (option, _relatedTarget) {
986     return this.each(function () {
987       var $this   = $(this)
988       var data    = $this.data('bs.modal')
989       var options = $.extend({}, Modal.DEFAULTS, $this.data(), typeof option == 'object' && option)
990
991       if (!data) $this.data('bs.modal', (data = new Modal(this, options)))
992       if (typeof option == 'string') data[option](_relatedTarget)
993       else if (options.show) data.show(_relatedTarget)
994     })
995   }
996
997   $.fn.modal.Constructor = Modal
998
999
1000   // MODAL NO CONFLICT
1001   // =================
1002
1003   $.fn.modal.noConflict = function () {
1004     $.fn.modal = old
1005     return this
1006   }
1007
1008
1009   // MODAL DATA-API
1010   // ==============
1011
1012   $(document).on('click.bs.modal.data-api', '[data-toggle="modal"]', function (e) {
1013     var $this   = $(this)
1014     var href    = $this.attr('href')
1015     var $target = $($this.attr('data-target') || (href && href.replace(/.*(?=#[^\s]+$)/, ''))) //strip for ie7
1016     var option  = $target.data('bs.modal') ? 'toggle' : $.extend({ remote: !/#/.test(href) && href }, $target.data(), $this.data())
1017
1018     if ($this.is('a')) e.preventDefault()
1019
1020     $target
1021       .modal(option, this)
1022       .one('hide', function () {
1023         $this.is(':visible') && $this.focus()
1024       })
1025   })
1026
1027   $(document)
1028     .on('show.bs.modal', '.modal', function () { $(document.body).addClass('modal-open') })
1029     .on('hidden.bs.modal', '.modal', function () { $(document.body).removeClass('modal-open') })
1030
1031 }(jQuery);
1032
1033 /* ========================================================================
1034  * Bootstrap: tooltip.js v3.1.1
1035  * http://getbootstrap.com/javascript/#tooltip
1036  * Inspired by the original jQuery.tipsy by Jason Frame
1037  * ========================================================================
1038  * Copyright 2011-2014 Twitter, Inc.
1039  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1040  * ======================================================================== */
1041
1042
1043 +function ($) {
1044   'use strict';
1045
1046   // TOOLTIP PUBLIC CLASS DEFINITION
1047   // ===============================
1048
1049   var Tooltip = function (element, options) {
1050     this.type       =
1051     this.options    =
1052     this.enabled    =
1053     this.timeout    =
1054     this.hoverState =
1055     this.$element   = null
1056
1057     this.init('tooltip', element, options)
1058   }
1059
1060   Tooltip.DEFAULTS = {
1061     animation: true,
1062     placement: 'top',
1063     selector: false,
1064     template: '<div class="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
1065     trigger: 'hover focus',
1066     title: '',
1067     delay: 0,
1068     html: false,
1069     container: false
1070   }
1071
1072   Tooltip.prototype.init = function (type, element, options) {
1073     this.enabled  = true
1074     this.type     = type
1075     this.$element = $(element)
1076     this.options  = this.getOptions(options)
1077
1078     var triggers = this.options.trigger.split(' ')
1079
1080     for (var i = triggers.length; i--;) {
1081       var trigger = triggers[i]
1082
1083       if (trigger == 'click') {
1084         this.$element.on('click.' + this.type, this.options.selector, $.proxy(this.toggle, this))
1085       } else if (trigger != 'manual') {
1086         var eventIn  = trigger == 'hover' ? 'mouseenter' : 'focusin'
1087         var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
1088
1089         this.$element.on(eventIn  + '.' + this.type, this.options.selector, $.proxy(this.enter, this))
1090         this.$element.on(eventOut + '.' + this.type, this.options.selector, $.proxy(this.leave, this))
1091       }
1092     }
1093
1094     this.options.selector ?
1095       (this._options = $.extend({}, this.options, { trigger: 'manual', selector: '' })) :
1096       this.fixTitle()
1097   }
1098
1099   Tooltip.prototype.getDefaults = function () {
1100     return Tooltip.DEFAULTS
1101   }
1102
1103   Tooltip.prototype.getOptions = function (options) {
1104     options = $.extend({}, this.getDefaults(), this.$element.data(), options)
1105
1106     if (options.delay && typeof options.delay == 'number') {
1107       options.delay = {
1108         show: options.delay,
1109         hide: options.delay
1110       }
1111     }
1112
1113     return options
1114   }
1115
1116   Tooltip.prototype.getDelegateOptions = function () {
1117     var options  = {}
1118     var defaults = this.getDefaults()
1119
1120     this._options && $.each(this._options, function (key, value) {
1121       if (defaults[key] != value) options[key] = value
1122     })
1123
1124     return options
1125   }
1126
1127   Tooltip.prototype.enter = function (obj) {
1128     var self = obj instanceof this.constructor ?
1129       obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
1130
1131     clearTimeout(self.timeout)
1132
1133     self.hoverState = 'in'
1134
1135     if (!self.options.delay || !self.options.delay.show) return self.show()
1136
1137     self.timeout = setTimeout(function () {
1138       if (self.hoverState == 'in') self.show()
1139     }, self.options.delay.show)
1140   }
1141
1142   Tooltip.prototype.leave = function (obj) {
1143     var self = obj instanceof this.constructor ?
1144       obj : $(obj.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type)
1145
1146     clearTimeout(self.timeout)
1147
1148     self.hoverState = 'out'
1149
1150     if (!self.options.delay || !self.options.delay.hide) return self.hide()
1151
1152     self.timeout = setTimeout(function () {
1153       if (self.hoverState == 'out') self.hide()
1154     }, self.options.delay.hide)
1155   }
1156
1157   Tooltip.prototype.show = function () {
1158     var e = $.Event('show.bs.' + this.type)
1159
1160     if (this.hasContent() && this.enabled) {
1161       this.$element.trigger(e)
1162
1163       if (e.isDefaultPrevented()) return
1164       var that = this;
1165
1166       var $tip = this.tip()
1167
1168       this.setContent()
1169
1170       if (this.options.animation) $tip.addClass('fade')
1171
1172       var placement = typeof this.options.placement == 'function' ?
1173         this.options.placement.call(this, $tip[0], this.$element[0]) :
1174         this.options.placement
1175
1176       var autoToken = /\s?auto?\s?/i
1177       var autoPlace = autoToken.test(placement)
1178       if (autoPlace) placement = placement.replace(autoToken, '') || 'top'
1179
1180       $tip
1181         .detach()
1182         .css({ top: 0, left: 0, display: 'block' })
1183         .addClass(placement)
1184
1185       this.options.container ? $tip.appendTo(this.options.container) : $tip.insertAfter(this.$element)
1186
1187       var pos          = this.getPosition()
1188       var actualWidth  = $tip[0].offsetWidth
1189       var actualHeight = $tip[0].offsetHeight
1190
1191       if (autoPlace) {
1192         var $parent = this.$element.parent()
1193
1194         var orgPlacement = placement
1195         var docScroll    = document.documentElement.scrollTop || document.body.scrollTop
1196         var parentWidth  = this.options.container == 'body' ? window.innerWidth  : $parent.outerWidth()
1197         var parentHeight = this.options.container == 'body' ? window.innerHeight : $parent.outerHeight()
1198         var parentLeft   = this.options.container == 'body' ? 0 : $parent.offset().left
1199
1200         placement = placement == 'bottom' && pos.top   + pos.height  + actualHeight - docScroll > parentHeight  ? 'top'    :
1201                     placement == 'top'    && pos.top   - docScroll   - actualHeight < 0                         ? 'bottom' :
1202                     placement == 'right'  && pos.right + actualWidth > parentWidth                              ? 'left'   :
1203                     placement == 'left'   && pos.left  - actualWidth < parentLeft                               ? 'right'  :
1204                     placement
1205
1206         $tip
1207           .removeClass(orgPlacement)
1208           .addClass(placement)
1209       }
1210
1211       var calculatedOffset = this.getCalculatedOffset(placement, pos, actualWidth, actualHeight)
1212
1213       this.applyPlacement(calculatedOffset, placement)
1214       this.hoverState = null
1215
1216       var complete = function() {
1217         that.$element.trigger('shown.bs.' + that.type)
1218       }
1219
1220       $.support.transition && this.$tip.hasClass('fade') ?
1221         $tip
1222           .one($.support.transition.end, complete)
1223           .emulateTransitionEnd(150) :
1224         complete()
1225     }
1226   }
1227
1228   Tooltip.prototype.applyPlacement = function (offset, placement) {
1229     var replace
1230     var $tip   = this.tip()
1231     var width  = $tip[0].offsetWidth
1232     var height = $tip[0].offsetHeight
1233
1234     // manually read margins because getBoundingClientRect includes difference
1235     var marginTop = parseInt($tip.css('margin-top'), 10)
1236     var marginLeft = parseInt($tip.css('margin-left'), 10)
1237
1238     // we must check for NaN for ie 8/9
1239     if (isNaN(marginTop))  marginTop  = 0
1240     if (isNaN(marginLeft)) marginLeft = 0
1241
1242     offset.top  = offset.top  + marginTop
1243     offset.left = offset.left + marginLeft
1244
1245     // $.fn.offset doesn't round pixel values
1246     // so we use setOffset directly with our own function B-0
1247     $.offset.setOffset($tip[0], $.extend({
1248       using: function (props) {
1249         $tip.css({
1250           top: Math.round(props.top),
1251           left: Math.round(props.left)
1252         })
1253       }
1254     }, offset), 0)
1255
1256     $tip.addClass('in')
1257
1258     // check to see if placing tip in new offset caused the tip to resize itself
1259     var actualWidth  = $tip[0].offsetWidth
1260     var actualHeight = $tip[0].offsetHeight
1261
1262     if (placement == 'top' && actualHeight != height) {
1263       replace = true
1264       offset.top = offset.top + height - actualHeight
1265     }
1266
1267     if (/bottom|top/.test(placement)) {
1268       var delta = 0
1269
1270       if (offset.left < 0) {
1271         delta       = offset.left * -2
1272         offset.left = 0
1273
1274         $tip.offset(offset)
1275
1276         actualWidth  = $tip[0].offsetWidth
1277         actualHeight = $tip[0].offsetHeight
1278       }
1279
1280       this.replaceArrow(delta - width + actualWidth, actualWidth, 'left')
1281     } else {
1282       this.replaceArrow(actualHeight - height, actualHeight, 'top')
1283     }
1284
1285     if (replace) $tip.offset(offset)
1286   }
1287
1288   Tooltip.prototype.replaceArrow = function (delta, dimension, position) {
1289     this.arrow().css(position, delta ? (50 * (1 - delta / dimension) + '%') : '')
1290   }
1291
1292   Tooltip.prototype.setContent = function () {
1293     var $tip  = this.tip()
1294     var title = this.getTitle()
1295
1296     $tip.find('.tooltip-inner')[this.options.html ? 'html' : 'text'](title)
1297     $tip.removeClass('fade in top bottom left right')
1298   }
1299
1300   Tooltip.prototype.hide = function () {
1301     var that = this
1302     var $tip = this.tip()
1303     var e    = $.Event('hide.bs.' + this.type)
1304
1305     function complete() {
1306       if (that.hoverState != 'in') $tip.detach()
1307       that.$element.trigger('hidden.bs.' + that.type)
1308     }
1309
1310     this.$element.trigger(e)
1311
1312     if (e.isDefaultPrevented()) return
1313
1314     $tip.removeClass('in')
1315
1316     $.support.transition && this.$tip.hasClass('fade') ?
1317       $tip
1318         .one($.support.transition.end, complete)
1319         .emulateTransitionEnd(150) :
1320       complete()
1321
1322     this.hoverState = null
1323
1324     return this
1325   }
1326
1327   Tooltip.prototype.fixTitle = function () {
1328     var $e = this.$element
1329     if ($e.attr('title') || typeof($e.attr('data-original-title')) != 'string') {
1330       $e.attr('data-original-title', $e.attr('title') || '').attr('title', '')
1331     }
1332   }
1333
1334   Tooltip.prototype.hasContent = function () {
1335     return this.getTitle()
1336   }
1337
1338   Tooltip.prototype.getPosition = function () {
1339     var el = this.$element[0]
1340     return $.extend({}, (typeof el.getBoundingClientRect == 'function') ? el.getBoundingClientRect() : {
1341       width: el.offsetWidth,
1342       height: el.offsetHeight
1343     }, this.$element.offset())
1344   }
1345
1346   Tooltip.prototype.getCalculatedOffset = function (placement, pos, actualWidth, actualHeight) {
1347     return placement == 'bottom' ? { top: pos.top + pos.height,   left: pos.left + pos.width / 2 - actualWidth / 2  } :
1348            placement == 'top'    ? { top: pos.top - actualHeight, left: pos.left + pos.width / 2 - actualWidth / 2  } :
1349            placement == 'left'   ? { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left - actualWidth } :
1350         /* placement == 'right' */ { top: pos.top + pos.height / 2 - actualHeight / 2, left: pos.left + pos.width   }
1351   }
1352
1353   Tooltip.prototype.getTitle = function () {
1354     var title
1355     var $e = this.$element
1356     var o  = this.options
1357
1358     title = $e.attr('data-original-title')
1359       || (typeof o.title == 'function' ? o.title.call($e[0]) :  o.title)
1360
1361     return title
1362   }
1363
1364   Tooltip.prototype.tip = function () {
1365     return this.$tip = this.$tip || $(this.options.template)
1366   }
1367
1368   Tooltip.prototype.arrow = function () {
1369     return this.$arrow = this.$arrow || this.tip().find('.tooltip-arrow')
1370   }
1371
1372   Tooltip.prototype.validate = function () {
1373     if (!this.$element[0].parentNode) {
1374       this.hide()
1375       this.$element = null
1376       this.options  = null
1377     }
1378   }
1379
1380   Tooltip.prototype.enable = function () {
1381     this.enabled = true
1382   }
1383
1384   Tooltip.prototype.disable = function () {
1385     this.enabled = false
1386   }
1387
1388   Tooltip.prototype.toggleEnabled = function () {
1389     this.enabled = !this.enabled
1390   }
1391
1392   Tooltip.prototype.toggle = function (e) {
1393     var self = e ? $(e.currentTarget)[this.type](this.getDelegateOptions()).data('bs.' + this.type) : this
1394     self.tip().hasClass('in') ? self.leave(self) : self.enter(self)
1395   }
1396
1397   Tooltip.prototype.destroy = function () {
1398     clearTimeout(this.timeout)
1399     this.hide().$element.off('.' + this.type).removeData('bs.' + this.type)
1400   }
1401
1402
1403   // TOOLTIP PLUGIN DEFINITION
1404   // =========================
1405
1406   var old = $.fn.tooltip
1407
1408   $.fn.tooltip = function (option) {
1409     return this.each(function () {
1410       var $this   = $(this)
1411       var data    = $this.data('bs.tooltip')
1412       var options = typeof option == 'object' && option
1413
1414       if (!data && option == 'destroy') return
1415       if (!data) $this.data('bs.tooltip', (data = new Tooltip(this, options)))
1416       if (typeof option == 'string') data[option]()
1417     })
1418   }
1419
1420   $.fn.tooltip.Constructor = Tooltip
1421
1422
1423   // TOOLTIP NO CONFLICT
1424   // ===================
1425
1426   $.fn.tooltip.noConflict = function () {
1427     $.fn.tooltip = old
1428     return this
1429   }
1430
1431 }(jQuery);
1432
1433 /* ========================================================================
1434  * Bootstrap: popover.js v3.1.1
1435  * http://getbootstrap.com/javascript/#popovers
1436  * ========================================================================
1437  * Copyright 2011-2014 Twitter, Inc.
1438  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1439  * ======================================================================== */
1440
1441
1442 +function ($) {
1443   'use strict';
1444
1445   // POPOVER PUBLIC CLASS DEFINITION
1446   // ===============================
1447
1448   var Popover = function (element, options) {
1449     this.init('popover', element, options)
1450   }
1451
1452   if (!$.fn.tooltip) throw new Error('Popover requires tooltip.js')
1453
1454   Popover.DEFAULTS = $.extend({}, $.fn.tooltip.Constructor.DEFAULTS, {
1455     placement: 'right',
1456     trigger: 'click',
1457     content: '',
1458     template: '<div class="popover"><div class="arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
1459   })
1460
1461
1462   // NOTE: POPOVER EXTENDS tooltip.js
1463   // ================================
1464
1465   Popover.prototype = $.extend({}, $.fn.tooltip.Constructor.prototype)
1466
1467   Popover.prototype.constructor = Popover
1468
1469   Popover.prototype.getDefaults = function () {
1470     return Popover.DEFAULTS
1471   }
1472
1473   Popover.prototype.setContent = function () {
1474     var $tip    = this.tip()
1475     var title   = this.getTitle()
1476     var content = this.getContent()
1477
1478     $tip.find('.popover-title')[this.options.html ? 'html' : 'text'](title)
1479     $tip.find('.popover-content')[ // we use append for html objects to maintain js events
1480       this.options.html ? (typeof content == 'string' ? 'html' : 'append') : 'text'
1481     ](content)
1482
1483     $tip.removeClass('fade top bottom left right in')
1484
1485     // IE8 doesn't accept hiding via the `:empty` pseudo selector, we have to do
1486     // this manually by checking the contents.
1487     if (!$tip.find('.popover-title').html()) $tip.find('.popover-title').hide()
1488   }
1489
1490   Popover.prototype.hasContent = function () {
1491     return this.getTitle() || this.getContent()
1492   }
1493
1494   Popover.prototype.getContent = function () {
1495     var $e = this.$element
1496     var o  = this.options
1497
1498     return $e.attr('data-content')
1499       || (typeof o.content == 'function' ?
1500             o.content.call($e[0]) :
1501             o.content)
1502   }
1503
1504   Popover.prototype.arrow = function () {
1505     return this.$arrow = this.$arrow || this.tip().find('.arrow')
1506   }
1507
1508   Popover.prototype.tip = function () {
1509     if (!this.$tip) this.$tip = $(this.options.template)
1510     return this.$tip
1511   }
1512
1513
1514   // POPOVER PLUGIN DEFINITION
1515   // =========================
1516
1517   var old = $.fn.popover
1518
1519   $.fn.popover = function (option) {
1520     return this.each(function () {
1521       var $this   = $(this)
1522       var data    = $this.data('bs.popover')
1523       var options = typeof option == 'object' && option
1524
1525       if (!data && option == 'destroy') return
1526       if (!data) $this.data('bs.popover', (data = new Popover(this, options)))
1527       if (typeof option == 'string') data[option]()
1528     })
1529   }
1530
1531   $.fn.popover.Constructor = Popover
1532
1533
1534   // POPOVER NO CONFLICT
1535   // ===================
1536
1537   $.fn.popover.noConflict = function () {
1538     $.fn.popover = old
1539     return this
1540   }
1541
1542 }(jQuery);
1543
1544 /* ========================================================================
1545  * Bootstrap: scrollspy.js v3.1.1
1546  * http://getbootstrap.com/javascript/#scrollspy
1547  * ========================================================================
1548  * Copyright 2011-2014 Twitter, Inc.
1549  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1550  * ======================================================================== */
1551
1552
1553 +function ($) {
1554   'use strict';
1555
1556   // SCROLLSPY CLASS DEFINITION
1557   // ==========================
1558
1559   function ScrollSpy(element, options) {
1560     var href
1561     var process  = $.proxy(this.process, this)
1562
1563     this.$element       = $(element).is('body') ? $(window) : $(element)
1564     this.$body          = $('body')
1565     this.$scrollElement = this.$element.on('scroll.bs.scroll-spy.data-api', process)
1566     this.options        = $.extend({}, ScrollSpy.DEFAULTS, options)
1567     this.selector       = (this.options.target
1568       || ((href = $(element).attr('href')) && href.replace(/.*(?=#[^\s]+$)/, '')) //strip for ie7
1569       || '') + ' .nav li > a'
1570     this.offsets        = $([])
1571     this.targets        = $([])
1572     this.activeTarget   = null
1573
1574     this.refresh()
1575     this.process()
1576   }
1577
1578   ScrollSpy.DEFAULTS = {
1579     offset: 10
1580   }
1581
1582   ScrollSpy.prototype.refresh = function () {
1583     var offsetMethod = this.$element[0] == window ? 'offset' : 'position'
1584
1585     this.offsets = $([])
1586     this.targets = $([])
1587
1588     var self     = this
1589     var $targets = this.$body
1590       .find(this.selector)
1591       .map(function () {
1592         var $el   = $(this)
1593         var href  = $el.data('target') || $el.attr('href')
1594         var $href = /^#./.test(href) && $(href)
1595
1596         return ($href
1597           && $href.length
1598           && $href.is(':visible')
1599           && [[ $href[offsetMethod]().top + (!$.isWindow(self.$scrollElement.get(0)) && self.$scrollElement.scrollTop()), href ]]) || null
1600       })
1601       .sort(function (a, b) { return a[0] - b[0] })
1602       .each(function () {
1603         self.offsets.push(this[0])
1604         self.targets.push(this[1])
1605       })
1606   }
1607
1608   ScrollSpy.prototype.process = function () {
1609     var scrollTop    = this.$scrollElement.scrollTop() + this.options.offset
1610     var scrollHeight = this.$scrollElement[0].scrollHeight || this.$body[0].scrollHeight
1611     var maxScroll    = scrollHeight - this.$scrollElement.height()
1612     var offsets      = this.offsets
1613     var targets      = this.targets
1614     var activeTarget = this.activeTarget
1615     var i
1616
1617     if (scrollTop >= maxScroll) {
1618       return activeTarget != (i = targets.last()[0]) && this.activate(i)
1619     }
1620
1621     if (activeTarget && scrollTop <= offsets[0]) {
1622       return activeTarget != (i = targets[0]) && this.activate(i)
1623     }
1624
1625     for (i = offsets.length; i--;) {
1626       activeTarget != targets[i]
1627         && scrollTop >= offsets[i]
1628         && (!offsets[i + 1] || scrollTop <= offsets[i + 1])
1629         && this.activate( targets[i] )
1630     }
1631   }
1632
1633   ScrollSpy.prototype.activate = function (target) {
1634     this.activeTarget = target
1635
1636     $(this.selector)
1637       .parentsUntil(this.options.target, '.active')
1638       .removeClass('active')
1639
1640     var selector = this.selector +
1641         '[data-target="' + target + '"],' +
1642         this.selector + '[href="' + target + '"]'
1643
1644     var active = $(selector)
1645       .parents('li')
1646       .addClass('active')
1647
1648     if (active.parent('.dropdown-menu').length) {
1649       active = active
1650         .closest('li.dropdown')
1651         .addClass('active')
1652     }
1653
1654     active.trigger('activate.bs.scrollspy')
1655   }
1656
1657
1658   // SCROLLSPY PLUGIN DEFINITION
1659   // ===========================
1660
1661   var old = $.fn.scrollspy
1662
1663   $.fn.scrollspy = function (option) {
1664     return this.each(function () {
1665       var $this   = $(this)
1666       var data    = $this.data('bs.scrollspy')
1667       var options = typeof option == 'object' && option
1668
1669       if (!data) $this.data('bs.scrollspy', (data = new ScrollSpy(this, options)))
1670       if (typeof option == 'string') data[option]()
1671     })
1672   }
1673
1674   $.fn.scrollspy.Constructor = ScrollSpy
1675
1676
1677   // SCROLLSPY NO CONFLICT
1678   // =====================
1679
1680   $.fn.scrollspy.noConflict = function () {
1681     $.fn.scrollspy = old
1682     return this
1683   }
1684
1685
1686   // SCROLLSPY DATA-API
1687   // ==================
1688
1689   $(window).on('load', function () {
1690     $('[data-spy="scroll"]').each(function () {
1691       var $spy = $(this)
1692       $spy.scrollspy($spy.data())
1693     })
1694   })
1695
1696 }(jQuery);
1697
1698 /* ========================================================================
1699  * Bootstrap: tab.js v3.1.1
1700  * http://getbootstrap.com/javascript/#tabs
1701  * ========================================================================
1702  * Copyright 2011-2014 Twitter, Inc.
1703  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1704  * ======================================================================== */
1705
1706
1707 +function ($) {
1708   'use strict';
1709
1710   // TAB CLASS DEFINITION
1711   // ====================
1712
1713   var Tab = function (element) {
1714     this.element = $(element)
1715   }
1716
1717   Tab.prototype.show = function () {
1718     var $this    = this.element
1719     var $ul      = $this.closest('ul:not(.dropdown-menu)')
1720     var selector = $this.data('target')
1721
1722     if (!selector) {
1723       selector = $this.attr('href')
1724       selector = selector && selector.replace(/.*(?=#[^\s]*$)/, '') //strip for ie7
1725     }
1726
1727     if ($this.parent('li').hasClass('active')) return
1728
1729     var previous = $ul.find('.active:last a')[0]
1730     var e        = $.Event('show.bs.tab', {
1731       relatedTarget: previous
1732     })
1733
1734     $this.trigger(e)
1735
1736     if (e.isDefaultPrevented()) return
1737
1738     var $target = $(selector)
1739
1740     this.activate($this.parent('li'), $ul)
1741     this.activate($target, $target.parent(), function () {
1742       $this.trigger({
1743         type: 'shown.bs.tab',
1744         relatedTarget: previous
1745       })
1746     })
1747   }
1748
1749   Tab.prototype.activate = function (element, container, callback) {
1750     var $active    = container.find('> .active')
1751     var transition = callback
1752       && $.support.transition
1753       && $active.hasClass('fade')
1754
1755     function next() {
1756       $active
1757         .removeClass('active')
1758         .find('> .dropdown-menu > .active')
1759         .removeClass('active')
1760
1761       element.addClass('active')
1762
1763       if (transition) {
1764         element[0].offsetWidth // reflow for transition
1765         element.addClass('in')
1766       } else {
1767         element.removeClass('fade')
1768       }
1769
1770       if (element.parent('.dropdown-menu')) {
1771         element.closest('li.dropdown').addClass('active')
1772       }
1773
1774       callback && callback()
1775     }
1776
1777     transition ?
1778       $active
1779         .one($.support.transition.end, next)
1780         .emulateTransitionEnd(150) :
1781       next()
1782
1783     $active.removeClass('in')
1784   }
1785
1786
1787   // TAB PLUGIN DEFINITION
1788   // =====================
1789
1790   var old = $.fn.tab
1791
1792   $.fn.tab = function ( option ) {
1793     return this.each(function () {
1794       var $this = $(this)
1795       var data  = $this.data('bs.tab')
1796
1797       if (!data) $this.data('bs.tab', (data = new Tab(this)))
1798       if (typeof option == 'string') data[option]()
1799     })
1800   }
1801
1802   $.fn.tab.Constructor = Tab
1803
1804
1805   // TAB NO CONFLICT
1806   // ===============
1807
1808   $.fn.tab.noConflict = function () {
1809     $.fn.tab = old
1810     return this
1811   }
1812
1813
1814   // TAB DATA-API
1815   // ============
1816
1817   $(document).on('click.bs.tab.data-api', '[data-toggle="tab"], [data-toggle="pill"]', function (e) {
1818     e.preventDefault()
1819     $(this).tab('show')
1820   })
1821
1822 }(jQuery);
1823
1824 /* ========================================================================
1825  * Bootstrap: affix.js v3.1.1
1826  * http://getbootstrap.com/javascript/#affix
1827  * ========================================================================
1828  * Copyright 2011-2014 Twitter, Inc.
1829  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
1830  * ======================================================================== */
1831
1832
1833 +function ($) {
1834   'use strict';
1835
1836   // AFFIX CLASS DEFINITION
1837   // ======================
1838
1839   var Affix = function (element, options) {
1840     this.options = $.extend({}, Affix.DEFAULTS, options)
1841     this.$window = $(window)
1842       .on('scroll.bs.affix.data-api', $.proxy(this.checkPosition, this))
1843       .on('click.bs.affix.data-api',  $.proxy(this.checkPositionWithEventLoop, this))
1844
1845     this.$element     = $(element)
1846     this.affixed      =
1847     this.unpin        =
1848     this.pinnedOffset = null
1849
1850     this.checkPosition()
1851   }
1852
1853   Affix.RESET = 'affix affix-top affix-bottom'
1854
1855   Affix.DEFAULTS = {
1856     offset: 0
1857   }
1858
1859   Affix.prototype.getPinnedOffset = function () {
1860     if (this.pinnedOffset) return this.pinnedOffset
1861     this.$element.removeClass(Affix.RESET).addClass('affix')
1862     var scrollTop = this.$window.scrollTop()
1863     var position  = this.$element.offset()
1864     return (this.pinnedOffset = position.top - scrollTop)
1865   }
1866
1867   Affix.prototype.checkPositionWithEventLoop = function () {
1868     setTimeout($.proxy(this.checkPosition, this), 1)
1869   }
1870
1871   Affix.prototype.checkPosition = function () {
1872     if (!this.$element.is(':visible')) return
1873
1874     var scrollHeight = $(document).height()
1875     var scrollTop    = this.$window.scrollTop()
1876     var position     = this.$element.offset()
1877     var offset       = this.options.offset
1878     var offsetTop    = offset.top
1879     var offsetBottom = offset.bottom
1880
1881     if (this.affixed == 'top') position.top += scrollTop
1882
1883     if (typeof offset != 'object')         offsetBottom = offsetTop = offset
1884     if (typeof offsetTop == 'function')    offsetTop    = offset.top(this.$element)
1885     if (typeof offsetBottom == 'function') offsetBottom = offset.bottom(this.$element)
1886
1887     var affix = this.unpin   != null && (scrollTop + this.unpin <= position.top) ? false :
1888                 offsetBottom != null && (position.top + this.$element.height() >= scrollHeight - offsetBottom) ? 'bottom' :
1889                 offsetTop    != null && (scrollTop <= offsetTop) ? 'top' : false
1890
1891     if (this.affixed === affix) return
1892     if (this.unpin) this.$element.css('top', '')
1893
1894     var affixType = 'affix' + (affix ? '-' + affix : '')
1895     var e         = $.Event(affixType + '.bs.affix')
1896
1897     this.$element.trigger(e)
1898
1899     if (e.isDefaultPrevented()) return
1900
1901     this.affixed = affix
1902     this.unpin = affix == 'bottom' ? this.getPinnedOffset() : null
1903
1904     this.$element
1905       .removeClass(Affix.RESET)
1906       .addClass(affixType)
1907       .trigger($.Event(affixType.replace('affix', 'affixed')))
1908
1909     if (affix == 'bottom') {
1910       this.$element.offset({ top: scrollHeight - offsetBottom - this.$element.height() })
1911     }
1912   }
1913
1914
1915   // AFFIX PLUGIN DEFINITION
1916   // =======================
1917
1918   var old = $.fn.affix
1919
1920   $.fn.affix = function (option) {
1921     return this.each(function () {
1922       var $this   = $(this)
1923       var data    = $this.data('bs.affix')
1924       var options = typeof option == 'object' && option
1925
1926       if (!data) $this.data('bs.affix', (data = new Affix(this, options)))
1927       if (typeof option == 'string') data[option]()
1928     })
1929   }
1930
1931   $.fn.affix.Constructor = Affix
1932
1933
1934   // AFFIX NO CONFLICT
1935   // =================
1936
1937   $.fn.affix.noConflict = function () {
1938     $.fn.affix = old
1939     return this
1940   }
1941
1942
1943   // AFFIX DATA-API
1944   // ==============
1945
1946   $(window).on('load', function () {
1947     $('[data-spy="affix"]').each(function () {
1948       var $spy = $(this)
1949       var data = $spy.data()
1950
1951       data.offset = data.offset || {}
1952
1953       if (data.offsetBottom) data.offset.bottom = data.offsetBottom
1954       if (data.offsetTop)    data.offset.top    = data.offsetTop
1955
1956       $spy.affix(data)
1957     })
1958   })
1959
1960 }(jQuery);