bootstrap.js 97.5 KB
Newer Older
XhmikosR's avatar
XhmikosR committed
1
/*!
Mark Otto's avatar
grunt    
Mark Otto committed
2
 * Bootstrap v4.0.0-alpha (http://getbootstrap.com)
Mark Otto's avatar
Mark Otto committed
3
 * Copyright 2011-2015 Twitter, Inc.
XhmikosR's avatar
XhmikosR committed
4
5
6
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 */

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
7
8
9
10
11
12
13
14
15
16
if (typeof jQuery === 'undefined') {
  throw new Error('Bootstrap\'s JavaScript requires jQuery')
}

+function ($) {
  var version = $.fn.jquery.split(' ')[0].split('.')
  if ((version[0] < 2 && version[1] < 9) || (version[0] == 1 && version[1] == 9 && version[2] < 1)) {
    throw new Error('Bootstrap\'s JavaScript requires jQuery version 1.9.1 or higher')
  }
}(jQuery);
XhmikosR's avatar
XhmikosR committed
17

Mark Otto's avatar
Mark Otto committed
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
/** =======================================================================
 * Bootstrap: util.js v4.0.0
 * http://getbootstrap.com/javascript/#alerts
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's private util helper. Adds private util
 * helpers for things like accesibility and transitions. These methods are
 * shared across all bootstrap plugins.
 * ========================================================================
 */

'use strict';


/**
 * @type {Object}
 */
var Bootstrap = {}


/**
 * @const
 * @type {string}
 */
Bootstrap.TRANSITION_END = 'bsTransitionEnd'


/**
 * @const
 * @type {Object}
 */
Bootstrap.TransitionEndEvent = {
  'WebkitTransition' : 'webkitTransitionEnd',
  'MozTransition'    : 'transitionend',
  'OTransition'      : 'oTransitionEnd otransitionend',
  'transition'       : 'transitionend'
}


/**
 * @param {Function} childConstructor
 * @param {Function} parentConstructor
 */
Bootstrap.inherits = function(childConstructor, parentConstructor) {
  /** @constructor */
  function tempConstructor() {}
  tempConstructor.prototype = parentConstructor.prototype
  childConstructor.prototype = new tempConstructor()
  /** @override */
  childConstructor.prototype.constructor = childConstructor
}


/**
 * @param {Element} element
 * @return {string|null}
 */
Bootstrap.getSelectorFromElement = function (element) {
  var selector = element.getAttribute('data-target')

  if (!selector) {
    selector = element.getAttribute('href') || ''
    selector = /^#[a-z]/i.test(selector) ? selector : null
  }

  return selector
}


/**
 * @param {string} prefix
 * @return {string}
 */
Bootstrap.getUID = function (prefix) {
  do prefix += ~~(Math.random() * 1000000)
  while (document.getElementById(prefix))
  return prefix
}


/**
 * @return {Object}
 */
Bootstrap.getSpecialTransitionEndEvent = function () {
  return {
    bindType: Bootstrap.transition.end,
    delegateType: Bootstrap.transition.end,
    handle: /** @param {jQuery.Event} event */ (function (event) {
      if ($(event.target).is(this)) {
        return event.handleObj.handler.apply(this, arguments)
      }
    })
  }
}


/**
 * @param {Element} element
 */
Bootstrap.reflow = function (element) {
  new Function('bs',"return bs")(element.offsetHeight)
}


/**
 * @return {Object|boolean}
 */
Bootstrap.transitionEndTest = function () {
  if (window['QUnit']) {
    return false
  }

  var el = document.createElement('bootstrap')
  for (var name in Bootstrap.TransitionEndEvent) {
    if (el.style[name] !== undefined) {
      return { end: Bootstrap.TransitionEndEvent[name] }
    }
  }
  return false
}


/**
 * @param {number} duration
 * @this {Element}
 * @return {Object}
 */
Bootstrap.transitionEndEmulator = function (duration) {
  var called = false

  $(this).one(Bootstrap.TRANSITION_END, function () {
    called = true
  })

  var callback = function () {
    if (!called) {
      $(this).trigger(Bootstrap.transition.end)
    }
  }.bind(this)

  setTimeout(callback, duration)

  return this
}


/**
 * ------------------------------------------------------------------------
 * jQuery Interface
 * ------------------------------------------------------------------------
 */

$.fn.emulateTransitionEnd = Bootstrap.transitionEndEmulator

$(function () {
  Bootstrap.transition = Bootstrap.transitionEndTest()

  if (!Bootstrap.transition) {
    return
  }

  $.event.special[Bootstrap.TRANSITION_END] = Bootstrap.getSpecialTransitionEndEvent()
})

/** =======================================================================
 * Bootstrap: alert.js v4.0.0
 * http://getbootstrap.com/javascript/#alerts
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's generic alert component. Add dismiss
 * functionality to all alert messages with this plugin.
 *
 * Public Methods & Properties:
 *
 *   + $.alert
 *   + $.alert.noConflict
 *   + $.alert.Constructor
 *   + $.alert.Constructor.VERSION
 *   + $.alert.Constructor.prototype.close
 *
 * ========================================================================
 */

'use strict';


/**
 * Our Alert class.
 * @param {Element=} opt_element
 * @constructor
 */
var Alert = function (opt_element) {
  if (opt_element) {
    $(opt_element).on('click', Alert._DISMISS_SELECTOR, Alert._handleDismiss(this))
  }
}


/**
 * @const
 * @type {string}
 */
Alert['VERSION'] = '4.0.0'


/**
 * @const
 * @type {string}
 * @private
 */
Alert._NAME = 'alert'


/**
 * @const
 * @type {string}
 * @private
 */
Alert._DATA_KEY = 'bs.alert'


/**
 * @const
 * @type {string}
 * @private
 */
Alert._DISMISS_SELECTOR = '[data-dismiss="alert"]'


/**
 * @const
 * @type {number}
 * @private
 */
Alert._TRANSITION_DURATION = 150


/**
 * @const
 * @type {Function}
 * @private
 */
Alert._JQUERY_NO_CONFLICT = $.fn[Alert._NAME]


/**
 * @const
 * @enum {string}
 * @private
 */
Alert._Event = {
  CLOSE  : 'close.bs.alert',
  CLOSED : 'closed.bs.alert'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Alert._ClassName = {
  ALERT : 'alert',
  FADE  : 'fade',
  IN    : 'in'
}


/**
 * Provides the jQuery Interface for the alert component.
 * @param {string=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Alert._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var $this = $(this)
    var data  = $this.data(Alert._DATA_KEY)

    if (!data) {
      data = new Alert(this)
      $this.data(Alert._DATA_KEY, data)
    }

    if (opt_config === 'close') {
      data[opt_config](this)
    }
  })
}


/**
 * Close the alert component
 * @param {Alert} alertInstance
 * @return {Function}
 * @private
 */
Alert._handleDismiss = function (alertInstance) {
  return function (event) {
    if (event) {
      event.preventDefault()
    }

    alertInstance['close'](this)
  }
}


/**
 * Close the alert component
 * @param {Element} element
 */
Alert.prototype['close'] = function (element) {
  var rootElement = this._getRootElement(element)
  var customEvent = this._triggerCloseEvent(rootElement)

  if (customEvent.isDefaultPrevented()) return

  this._removeElement(rootElement)
}


/**
 * Tries to get the alert's root element
 * @return {Element}
 * @private
 */
Alert.prototype._getRootElement = function (element) {
  var parent   = false
  var selector = Bootstrap.getSelectorFromElement(element)

  if (selector) {
    parent = $(selector)[0]
  }

  if (!parent) {
    parent = $(element).closest('.' + Alert._ClassName.ALERT)[0]
  }

  return parent
}


/**
 * Trigger close event on element
 * @return {$.Event}
 * @private
 */
Alert.prototype._triggerCloseEvent = function (element) {
  var closeEvent = $.Event(Alert._Event.CLOSE)
  $(element).trigger(closeEvent)
  return closeEvent
}


/**
 * Trigger closed event and remove element from dom
 * @private
 */
Alert.prototype._removeElement = function (element) {
  $(element).removeClass(Alert._ClassName.IN)

  if (!Bootstrap.transition || !$(element).hasClass(Alert._ClassName.FADE)) {
    this._destroyElement(element)
    return
  }

  $(element)
    .one(Bootstrap.TRANSITION_END, this._destroyElement.bind(this, element))
    .emulateTransitionEnd(Alert._TRANSITION_DURATION)
}


/**
 * clean up any lingering jquery data and kill element
 * @private
 */
Alert.prototype._destroyElement = function (element) {
  $(element)
    .detach()
    .trigger(Alert._Event.CLOSED)
    .remove()
}


/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */

/**
 * @const
 * @type {Function}
 */
$.fn[Alert._NAME] = Alert._jQueryInterface


/**
 * @const
 * @type {Function}
 */
$.fn[Alert._NAME]['Constructor'] = Alert


/**
 * @return {Function}
 */
$.fn[Alert._NAME]['noConflict'] = function () {
  $.fn[Alert._NAME] = Alert._JQUERY_NO_CONFLICT
  return Alert._jQueryInterface
}


/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */

$(document).on('click.bs.alert.data-api', Alert._DISMISS_SELECTOR, Alert._handleDismiss(new Alert))

/** =======================================================================
 * Bootstrap: button.js v4.0.0
 * http://getbootstrap.com/javascript/#buttons
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's generic button component.
 *
 * Note (@fat): Deprecated "setState" – imo, better solutions for managing a
 * buttons state should exist outside this plugin.
 *
 * Public Methods & Properties:
 *
 *   + $.button
 *   + $.button.noConflict
 *   + $.button.Constructor
 *   + $.button.Constructor.VERSION
 *   + $.button.Constructor.prototype.toggle
 *
 * ========================================================================
 */

'use strict';


/**
 * Our Button class.
 * @param {Element!} element
 * @constructor
 */
var Button = function (element) {

  /** @private {Element} */
  this._element = element

}


/**
 * @const
 * @type {string}
 */
Button['VERSION']  = '4.0.0'


/**
 * @const
 * @type {string}
 * @private
 */
Button._NAME  = 'button'


/**
 * @const
 * @type {string}
 * @private
 */
Button._DATA_KEY = 'bs.button'


/**
 * @const
 * @type {Function}
 * @private
 */
Button._JQUERY_NO_CONFLICT = $.fn[Button._NAME]


/**
 * @const
 * @enum {string}
 * @private
 */
Button._ClassName = {
  ACTIVE : 'active',
  BUTTON : 'btn',
  FOCUS  : 'focus'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Button._Selector = {
  DATA_TOGGLE_CARROT : '[data-toggle^="button"]',
  DATA_TOGGLE        : '[data-toggle="buttons"]',
  INPUT              : 'input',
  ACTIVE             : '.active',
  BUTTON             : '.btn'
}


/**
 * Provides the jQuery Interface for the Button component.
 * @param {string=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Button._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var data  = $(this).data(Button._DATA_KEY)

    if (!data) {
      data = new Button(this)
      $(this).data(Button._DATA_KEY, data)
    }

    if (opt_config === 'toggle') {
      data[opt_config]()
    }
  })
}


/**
 * Toggle's the button active state
 */
Button.prototype['toggle'] = function () {
  var triggerChangeEvent = true
  var rootElement = $(this._element).closest(Button._Selector.DATA_TOGGLE)[0]

  if (rootElement) {
    var input = $(this._element).find(Button._Selector.INPUT)[0]
    if (input) {
      if (input.type == 'radio') {
        if (input.checked && $(this._element).hasClass(Button._ClassName.ACTIVE)) {
          triggerChangeEvent = false
        } else {
          var activeElement = $(rootElement).find(Button._Selector.ACTIVE)[0]
          if (activeElement) {
            $(activeElement).removeClass(Button._ClassName.ACTIVE)
          }
        }
      }

      if (triggerChangeEvent) {
        input.checked = !$(this._element).hasClass(Button._ClassName.ACTIVE)
        $(this._element).trigger('change')
      }
    }
  } else {
    this._element.setAttribute('aria-pressed', !$(this._element).hasClass(Button._ClassName.ACTIVE))
  }

  if (triggerChangeEvent) {
    $(this._element).toggleClass(Button._ClassName.ACTIVE)
  }
}


/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */

/**
 * @const
 * @type {Function}
 */
$.fn[Button._NAME] = Button._jQueryInterface


/**
 * @const
 * @type {Function}
 */
$.fn[Button._NAME]['Constructor'] = Button


/**
 * @const
 * @type {Function}
 */
$.fn[Button._NAME]['noConflict'] = function () {
  $.fn[Button._NAME] = Button._JQUERY_NO_CONFLICT
  return this
}


/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */

$(document)
  .on('click.bs.button.data-api', Button._Selector.DATA_TOGGLE_CARROT, function (event) {
    event.preventDefault()

    var button = event.target

    if (!$(button).hasClass(Button._ClassName.BUTTON)) {
      button = $(button).closest(Button._Selector.BUTTON)
    }

    Button._jQueryInterface.call($(button), 'toggle')
  })
  .on('focus.bs.button.data-api blur.bs.button.data-api', Button._Selector.DATA_TOGGLE_CARROT, function (event) {
    var button = $(event.target).closest(Button._Selector.BUTTON)[0]
    $(button).toggleClass(Button._ClassName.FOCUS, /^focus(in)?$/.test(event.type))
  })

/** =======================================================================
 * Bootstrap: carousel.js v4.0.0
 * http://getbootstrap.com/javascript/#carousel
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's carousel. A slideshow component for cycling
 * through elements, like a carousel. Nested carousels are not supported.
 *
 * Public Methods & Properties:
 *
 *   + $.carousel
 *   + $.carousel.noConflict
 *   + $.carousel.Constructor
 *   + $.carousel.Constructor.VERSION
 *   + $.carousel.Constructor.Defaults
 *   + $.carousel.Constructor.Defaults.interval
 *   + $.carousel.Constructor.Defaults.pause
 *   + $.carousel.Constructor.Defaults.wrap
 *   + $.carousel.Constructor.Defaults.keyboard
 *   + $.carousel.Constructor.Defaults.slide
 *   + $.carousel.Constructor.prototype.next
 *   + $.carousel.Constructor.prototype.prev
 *   + $.carousel.Constructor.prototype.pause
 *   + $.carousel.Constructor.prototype.cycle
 *
 * ========================================================================
 */

'use strict';


/**
 * Our carousel class.
 * @param {Element!} element
 * @param {Object=} opt_config
 * @constructor
 */
var Carousel = function (element, opt_config) {

  /** @private {Element} */
  this._element = $(element)[0]

  /** @private {Element} */
  this._indicatorsElement = $(this._element).find(Carousel._Selector.INDICATORS)[0]

  /** @private {?Object} */
  this._config = opt_config || null

  /** @private {boolean} */
  this._isPaused = false

  /** @private {boolean} */
  this._isSliding = false

  /** @private {?number} */
  this._interval = null

  /** @private {?Element} */
  this._activeElement = null

  /** @private {?Array} */
  this._items = null

  this._addEventListeners()

}


/**
 * @const
 * @type {string}
 */
Carousel['VERSION'] = '4.0.0'


/**
 * @const
 * @type {Object}
 */
Carousel['Defaults'] = {
  'interval' : 5000,
  'pause'    : 'hover',
  'wrap'     : true,
  'keyboard' : true,
  'slide'    : false
}


/**
 * @const
 * @type {string}
 * @private
 */
Carousel._NAME  = 'carousel'


/**
 * @const
 * @type {string}
 * @private
 */
Carousel._DATA_KEY = 'bs.carousel'


/**
 * @const
 * @type {number}
 * @private
 */
Carousel._TRANSITION_DURATION = 600


/**
 * @const
 * @enum {string}
 * @private
 */
Carousel._Direction = {
  NEXT     : 'next',
  PREVIOUS : 'prev'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Carousel._Event = {
  SLIDE : 'slide.bs.carousel',
  SLID  : 'slid.bs.carousel'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Carousel._ClassName = {
  CAROUSEL : 'carousel',
  ACTIVE   : 'active',
  SLIDE    : 'slide',
  RIGHT    : 'right',
  LEFT     : 'left',
  ITEM     : 'carousel-item'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Carousel._Selector = {
  ACTIVE      : '.active',
  ACTIVE_ITEM : '.active.carousel-item',
  ITEM        : '.carousel-item',
  NEXT_PREV   : '.next, .prev',
  INDICATORS  : '.carousel-indicators'
}


/**
 * @const
 * @type {Function}
 * @private
 */
Carousel._JQUERY_NO_CONFLICT = $.fn[Carousel._NAME]


/**
 * @param {Object=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Carousel._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var data   = $(this).data(Carousel._DATA_KEY)
    var config = $.extend({}, Carousel['Defaults'], $(this).data(), typeof opt_config == 'object' && opt_config)
    var action = typeof opt_config == 'string' ? opt_config : config.slide

    if (!data) {
      data = new Carousel(this, config)
      $(this).data(Carousel._DATA_KEY, data)
    }

    if (typeof opt_config == 'number') {
      data.to(opt_config)

    } else if (action) {
      data[action]()

    } else if (config.interval) {
      data['pause']()
      data['cycle']()
    }
  })
}


/**
 * Click handler for data api
 * @param {Event} event
 * @this {Element}
 * @private
 */
Carousel._dataApiClickHandler = function (event) {
  var selector = Bootstrap.getSelectorFromElement(this)

  if (!selector) {
    return
  }

  var target = $(selector)[0]

  if (!target || !$(target).hasClass(Carousel._ClassName.CAROUSEL)) {
    return
  }

  var config = $.extend({}, $(target).data(), $(this).data())

  var slideIndex = this.getAttribute('data-slide-to')
  if (slideIndex) {
    config.interval = false
  }

  Carousel._jQueryInterface.call($(target), config)

  if (slideIndex) {
    $(target).data(Carousel._DATA_KEY).to(slideIndex)
  }

  event.preventDefault()
}


/**
 * Advance the carousel to the next slide
 */
Carousel.prototype['next'] = function () {
  if (!this._isSliding) {
    this._slide(Carousel._Direction.NEXT)
  }
}


/**
 * Return the carousel to the previous slide
 */
Carousel.prototype['prev'] = function () {
  if (!this._isSliding) {
    this._slide(Carousel._Direction.PREVIOUS)
  }
}


/**
 * Pause the carousel cycle
 * @param {Event=} opt_event
 */
Carousel.prototype['pause'] = function (opt_event) {
  if (!opt_event) {
    this._isPaused = true
  }

  if ($(this._element).find(Carousel._Selector.NEXT_PREV)[0] && Bootstrap.transition) {
    $(this._element).trigger(Bootstrap.transition.end)
    this['cycle'](true)
  }

  clearInterval(this._interval)
  this._interval = null
}


/**
 * Cycle to the next carousel item
 * @param {Event|boolean=} opt_event
 */
Carousel.prototype['cycle'] = function (opt_event) {
  if (!opt_event) {
    this._isPaused = false
  }

  if (this._interval) {
    clearInterval(this._interval)
    this._interval = null
  }

  if (this._config['interval'] && !this._isPaused) {
    this._interval = setInterval(this['next'].bind(this), this._config['interval'])
  }
}


/**
 * @return {Object}
 */
Carousel.prototype['getConfig'] = function () {
  return this._config
}


/**
 * Move active carousel item to specified index
 * @param {number} index
 */
Carousel.prototype.to = function (index) {
  this._activeElement = $(this._element).find(Carousel._Selector.ACTIVE_ITEM)[0]

  var activeIndex = this._getItemIndex(this._activeElement)

  if (index > (this._items.length - 1) || index < 0) {
    return
  }

  if (this._isSliding) {
    $(this._element).one(Carousel._Event.SLID, function () { this.to(index) }.bind(this))
    return
  }

  if (activeIndex == index) {
    this['pause']()
    this['cycle']()
    return
  }

  var direction = index > activeIndex ?
    Carousel._Direction.NEXT :
    Carousel._Direction.PREVIOUS

  this._slide(direction, this._items[index])
}


/**
 * Add event listeners to root element
 * @private
 */
Carousel.prototype._addEventListeners = function () {
  if (this._config['keyboard']) {
    $(this._element).on('keydown.bs.carousel', this._keydown.bind(this))
  }

  if (this._config['pause'] == 'hover' && !('ontouchstart' in document.documentElement)) {
    $(this._element)
      .on('mouseenter.bs.carousel', this['pause'].bind(this))
      .on('mouseleave.bs.carousel', this['cycle'].bind(this))
  }
}


/**
 * Keydown handler
 * @param {Event} event
 * @private
 */
Carousel.prototype._keydown = function (event) {
  event.preventDefault()

  if (/input|textarea/i.test(event.target.tagName)) return

  switch (event.which) {
    case 37: this['prev'](); break
    case 39: this['next'](); break
    default: return
  }
}


/**
 * Get item index
 * @param {Element} element
 * @return {number}
 * @private
 */
Carousel.prototype._getItemIndex = function (element) {
  this._items = $.makeArray($(element).parent().find(Carousel._Selector.ITEM))

  return this._items.indexOf(element)
}


/**
 * Get next displayed item based on direction
 * @param {Carousel._Direction} direction
 * @param {Element} activeElement
 * @return {Element}
 * @private
 */
Carousel.prototype._getItemByDirection = function (direction, activeElement) {
  var activeIndex   = this._getItemIndex(activeElement)
  var isGoingToWrap = (direction === Carousel._Direction.PREVIOUS && activeIndex === 0) ||
                      (direction === Carousel._Direction.NEXT && activeIndex == (this._items.length - 1))

  if (isGoingToWrap && !this._config['wrap']) {
    return activeElement
  }

  var delta     = direction == Carousel._Direction.PREVIOUS ? -1 : 1
  var itemIndex = (activeIndex + delta) % this._items.length

  return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex]
}


/**
 * Trigger slide event on element
 * @param {Element} relatedTarget
 * @param {Carousel._ClassName} directionalClassname
 * @return {$.Event}
 * @private
 */
Carousel.prototype._triggerSlideEvent = function (relatedTarget, directionalClassname) {
  var slideEvent = $.Event(Carousel._Event.SLIDE, {
    relatedTarget: relatedTarget,
    direction: directionalClassname
  })

  $(this._element).trigger(slideEvent)

  return slideEvent
}


/**
 * Set the active indicator if available
 * @param {Element} element
 * @private
 */
Carousel.prototype._setActiveIndicatorElement = function (element) {
  if (this._indicatorsElement) {
    $(this._indicatorsElement)
      .find(Carousel._Selector.ACTIVE)
      .removeClass(Carousel._ClassName.ACTIVE)

    var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)]
    if (nextIndicator) {
      $(nextIndicator).addClass(Carousel._ClassName.ACTIVE)
    }
  }
}


/**
 * Slide the carousel element in a direction
 * @param {Carousel._Direction} direction
 * @param {Element=} opt_nextElement
 */
Carousel.prototype._slide = function (direction, opt_nextElement) {
  var activeElement = $(this._element).find(Carousel._Selector.ACTIVE_ITEM)[0]
  var nextElement   = opt_nextElement || activeElement && this._getItemByDirection(direction, activeElement)

  var isCycling = !!this._interval

  var directionalClassName = direction == Carousel._Direction.NEXT ?
    Carousel._ClassName.LEFT :
    Carousel._ClassName.RIGHT

  if (nextElement && $(nextElement).hasClass(Carousel._ClassName.ACTIVE)) {
    this._isSliding = false
    return
  }

  var slideEvent = this._triggerSlideEvent(nextElement, directionalClassName)
  if (slideEvent.isDefaultPrevented()) {
    return
  }

  if (!activeElement || !nextElement) {
    // some weirdness is happening, so we bail (maybe throw exception here alerting user that they're dom is off
    return
  }

  this._isSliding = true

  if (isCycling) {
    this['pause']()
  }

  this._setActiveIndicatorElement(nextElement)

  var slidEvent = $.Event(Carousel._Event.SLID, { relatedTarget: nextElement, direction: directionalClassName })

  if (Bootstrap.transition && $(this._element).hasClass(Carousel._ClassName.SLIDE)) {
    $(nextElement).addClass(direction)

    Bootstrap.reflow(nextElement)

    $(activeElement).addClass(directionalClassName)
    $(nextElement).addClass(directionalClassName)

    $(activeElement)
      .one(Bootstrap.TRANSITION_END, function () {
        $(nextElement)
          .removeClass(directionalClassName)
          .removeClass(direction)

        $(nextElement).addClass(Carousel._ClassName.ACTIVE)

        $(activeElement)
          .removeClass(Carousel._ClassName.ACTIVE)
          .removeClass(direction)
          .removeClass(directionalClassName)

        this._isSliding = false

        setTimeout(function () {
          $(this._element).trigger(slidEvent)
        }.bind(this), 0)
      }.bind(this))
      .emulateTransitionEnd(Carousel._TRANSITION_DURATION)

  } else {
    $(activeElement).removeClass(Carousel._ClassName.ACTIVE)
    $(nextElement).addClass(Carousel._ClassName.ACTIVE)

    this._isSliding = false
    $(this._element).trigger(slidEvent)
  }

  if (isCycling) {
    this['cycle']()
  }
}


/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */

/**
 * @const
 * @type {Function}
 */
$.fn[Carousel._NAME] = Carousel._jQueryInterface


/**
 * @const
 * @type {Function}
 */
$.fn[Carousel._NAME]['Constructor'] = Carousel


/**
 * @const
 * @type {Function}
 */
$.fn[Carousel._NAME]['noConflict'] = function () {
  $.fn[Carousel._NAME] = Carousel._JQUERY_NO_CONFLICT
  return this
}


/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */

$(document)
  .on('click.bs.carousel.data-api', '[data-slide], [data-slide-to]', Carousel._dataApiClickHandler)

$(window).on('load', function () {
  $('[data-ride="carousel"]').each(function () {
    var $carousel = $(this)
    Carousel._jQueryInterface.call($carousel, /** @type {Object} */ ($carousel.data()))
  })
})

/** =======================================================================
 * Bootstrap: collapse.js v4.0.0
 * http://getbootstrap.com/javascript/#collapse
XhmikosR's avatar
XhmikosR committed
1233
 * ========================================================================
Mark Otto's avatar
Mark Otto committed
1234
 * Copyright 2011-2015 Twitter, Inc.
XhmikosR's avatar
XhmikosR committed
1235
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
Mark Otto's avatar
Mark Otto committed
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
1429
1430
1431
 * ========================================================================
 * @fileoverview - Bootstrap's collapse plugin. Flexible support for
 * collapsible components like accordions and navigation.
 *
 * Public Methods & Properties:
 *
 *   + $.carousel
 *   + $.carousel.noConflict
 *   + $.carousel.Constructor
 *   + $.carousel.Constructor.VERSION
 *   + $.carousel.Constructor.Defaults
 *   + $.carousel.Constructor.Defaults.toggle
 *   + $.carousel.Constructor.Defaults.trigger
 *   + $.carousel.Constructor.Defaults.parent
 *   + $.carousel.Constructor.prototype.toggle
 *   + $.carousel.Constructor.prototype.show
 *   + $.carousel.Constructor.prototype.hide
 *
 * ========================================================================
 */

'use strict';


/**
 * Our collapse class.
 * @param {Element!} element
 * @param {Object=} opt_config
 * @constructor
 */
var Collapse = function (element, opt_config) {

  /** @private {Element} */
  this._element  = element

  /** @private {Object} */
  this._config = $.extend({}, Collapse['Defaults'], opt_config)

  /** @private {Element} */
  this._trigger = typeof this._config['trigger'] == 'string' ?
    $(this._config['trigger'])[0] : this._config['trigger']

  /** @private {boolean} */
  this._isTransitioning = false

  /** @private {?Element} */
  this._parent = this._config['parent'] ? this._getParent() : null

  if (!this._config['parent']) {
    this._addAriaAndCollapsedClass(this._element, this._trigger)
  }

  if (this._config['toggle']) {
    this['toggle']()
  }

}


/**
 * @const
 * @type {string}
 */
Collapse['VERSION'] = '4.0.0'


/**
 * @const
 * @type {Object}
 */
Collapse['Defaults'] = {
  'toggle'  : true,
  'trigger' : '[data-toggle="collapse"]',
  'parent'  : null
}


/**
 * @const
 * @type {string}
 * @private
 */
Collapse._NAME = 'collapse'


/**
 * @const
 * @type {string}
 * @private
 */
Collapse._DATA_KEY = 'bs.collapse'


/**
 * @const
 * @type {number}
 * @private
 */
Collapse._TRANSITION_DURATION = 600


/**
 * @const
 * @type {Function}
 * @private
 */
Collapse._JQUERY_NO_CONFLICT = $.fn[Collapse._NAME]


/**
 * @const
 * @enum {string}
 * @private
 */
Collapse._Event = {
  SHOW   : 'show.bs.collapse',
  SHOWN  : 'shown.bs.collapse',
  HIDE   : 'hide.bs.collapse',
  HIDDEN : 'hidden.bs.collapse'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Collapse._ClassName = {
  IN         : 'in',
  COLLAPSE   : 'collapse',
  COLLAPSING : 'collapsing',
  COLLAPSED  : 'collapsed'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Collapse._Dimension = {
  WIDTH  : 'width',
  HEIGHT : 'height'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Collapse._Selector = {
  ACTIVES : '.panel > .in, .panel > .collapsing'
}


/**
 * Provides the jQuery Interface for the alert component.
 * @param {Object|string=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Collapse._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var $this   = $(this)
    var data    = $this.data(Collapse._DATA_KEY)
    var config = $.extend({}, Collapse['Defaults'], $this.data(), typeof opt_config == 'object' && opt_config)

    if (!data && config['toggle'] && opt_config == 'show') {
      config['toggle'] = false
    }

    if (!data) {
      data = new Collapse(this, config)
      $this.data(Collapse._DATA_KEY, data)
    }

    if (typeof opt_config == 'string') {
      data[opt_config]()
    }
  })
}


/**
 * Function for getting target element from element
 * @return {Element}
 * @private
 */
Collapse._getTargetFromElement = function (element) {
  var selector = Bootstrap.getSelectorFromElement(element)

  return selector ? $(selector)[0] : null
}

XhmikosR's avatar
XhmikosR committed
1432

Mark Otto's avatar
Mark Otto committed
1433
1434
1435
1436
1437
1438
1439
1440
1441
1442
/**
 * Toggles the collapse element based on the presence of the 'in' class
 */
Collapse.prototype['toggle'] = function () {
  if ($(this._element).hasClass(Collapse._ClassName.IN)) {
    this['hide']()
  } else {
    this['show']()
  }
}
XhmikosR's avatar
XhmikosR committed
1443
1444


Mark Otto's avatar
Mark Otto committed
1445
1446
1447
1448
1449
1450
1451
/**
 * Show's the collapsing element
 */
Collapse.prototype['show'] = function () {
  if (this._isTransitioning || $(this._element).hasClass(Collapse._ClassName.IN)) {
    return
  }
XhmikosR's avatar
XhmikosR committed
1452

Mark Otto's avatar
Mark Otto committed
1453
  var activesData, actives
XhmikosR's avatar
XhmikosR committed
1454

Mark Otto's avatar
Mark Otto committed
1455
1456
1457
1458
  if (this._parent) {
    actives = $.makeArray($(Collapse._Selector.ACTIVES))
    if (!actives.length) {
      actives = null
XhmikosR's avatar
XhmikosR committed
1459
    }
Mark Otto's avatar
Mark Otto committed
1460
  }
XhmikosR's avatar
XhmikosR committed
1461

Mark Otto's avatar
Mark Otto committed
1462
1463
1464
1465
  if (actives) {
    activesData = $(actives).data(Collapse._DATA_KEY)
    if (activesData && activesData._isTransitioning) {
      return
XhmikosR's avatar
XhmikosR committed
1466
    }
Mark Otto's avatar
Mark Otto committed
1467
  }
XhmikosR's avatar
XhmikosR committed
1468

Mark Otto's avatar
Mark Otto committed
1469
1470
1471
1472
  var startEvent = $.Event(Collapse._Event.SHOW)
  $(this._element).trigger(startEvent)
  if (startEvent.isDefaultPrevented()) {
    return
XhmikosR's avatar
XhmikosR committed
1473
1474
  }

Mark Otto's avatar
Mark Otto committed
1475
1476
1477
1478
1479
  if (actives) {
    Collapse._jQueryInterface.call($(actives), 'hide')
    if (!activesData) {
      $(actives).data(Collapse._DATA_KEY, null)
    }
XhmikosR's avatar
XhmikosR committed
1480
1481
  }

Mark Otto's avatar
Mark Otto committed
1482
  var dimension = this._getDimension()
XhmikosR's avatar
XhmikosR committed
1483

Mark Otto's avatar
Mark Otto committed
1484
1485
1486
  $(this._element)
    .removeClass(Collapse._ClassName.COLLAPSE)
    .addClass(Collapse._ClassName.COLLAPSING)
XhmikosR's avatar
XhmikosR committed
1487

Mark Otto's avatar
Mark Otto committed
1488
1489
  this._element.style[dimension] = 0
  this._element.setAttribute('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
1490

Mark Otto's avatar
Mark Otto committed
1491
1492
1493
1494
  if (this._trigger) {
    $(this._trigger).removeClass(Collapse._ClassName.COLLAPSED)
    this._trigger.setAttribute('aria-expanded', true)
  }
XhmikosR's avatar
XhmikosR committed
1495

Mark Otto's avatar
Mark Otto committed
1496
  this['setTransitioning'](true)
XhmikosR's avatar
XhmikosR committed
1497

Mark Otto's avatar
Mark Otto committed
1498
1499
1500
1501
1502
  var complete = function () {
    $(this._element)
      .removeClass(Collapse._ClassName.COLLAPSING)
      .addClass(Collapse._ClassName.COLLAPSE)
      .addClass(Collapse._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
1503

Mark Otto's avatar
Mark Otto committed
1504
1505
1506
    this._element.style[dimension] = ''

    this['setTransitioning'](false)
XhmikosR's avatar
XhmikosR committed
1507

Mark Otto's avatar
Mark Otto committed
1508
1509
    $(this._element).trigger(Collapse._Event.SHOWN)
  }.bind(this)
XhmikosR's avatar
XhmikosR committed
1510

Mark Otto's avatar
Mark Otto committed
1511
1512
1513
  if (!Bootstrap.transition) {
    complete()
    return
XhmikosR's avatar
XhmikosR committed
1514
1515
  }

Mark Otto's avatar
Mark Otto committed
1516
  var scrollSize = 'scroll' + (dimension[0].toUpperCase() + dimension.slice(1))
XhmikosR's avatar
XhmikosR committed
1517

Mark Otto's avatar
Mark Otto committed
1518
1519
1520
  $(this._element)
    .one(Bootstrap.TRANSITION_END, complete)
    .emulateTransitionEnd(Collapse._TRANSITION_DURATION)
1521

Mark Otto's avatar
Mark Otto committed
1522
1523
  this._element.style[dimension] = this._element[scrollSize] + 'px'
}
XhmikosR's avatar
XhmikosR committed
1524
1525


Mark Otto's avatar
Mark Otto committed
1526
1527
1528
1529
1530
1531
1532
/**
 * Hides's the collapsing element
 */
Collapse.prototype['hide'] = function () {
  if (this._isTransitioning || !$(this._element).hasClass(Collapse._ClassName.IN)) {
    return
  }
XhmikosR's avatar
XhmikosR committed
1533

Mark Otto's avatar
Mark Otto committed
1534
1535
1536
  var startEvent = $.Event(Collapse._Event.HIDE)
  $(this._element).trigger(startEvent)
  if (startEvent.isDefaultPrevented()) return
XhmikosR's avatar
XhmikosR committed
1537

Mark Otto's avatar
Mark Otto committed
1538
1539
1540
  var dimension = this._getDimension()
  var offsetDimension = dimension === Collapse._Dimension.WIDTH ?
    'offsetWidth' : 'offsetHeight'
XhmikosR's avatar
XhmikosR committed
1541

Mark Otto's avatar
Mark Otto committed
1542
  this._element.style[dimension] = this._element[offsetDimension] + 'px'
XhmikosR's avatar
XhmikosR committed
1543

Mark Otto's avatar
Mark Otto committed
1544
  Bootstrap.reflow(this._element)
XhmikosR's avatar
XhmikosR committed
1545

Mark Otto's avatar
Mark Otto committed
1546
1547
1548
1549
  $(this._element)
    .addClass(Collapse._ClassName.COLLAPSING)
    .removeClass(Collapse._ClassName.COLLAPSE)
    .removeClass(Collapse._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
1550

Mark Otto's avatar
Mark Otto committed
1551
  this._element.setAttribute('aria-expanded', false)
XhmikosR's avatar
XhmikosR committed
1552

Mark Otto's avatar
Mark Otto committed
1553
1554
1555
  if (this._trigger) {
    $(this._trigger).addClass(Collapse._ClassName.COLLAPSED)
    this._trigger.setAttribute('aria-expanded', false)
XhmikosR's avatar
XhmikosR committed
1556
1557
  }

Mark Otto's avatar
Mark Otto committed
1558
  this['setTransitioning'](true)
XhmikosR's avatar
XhmikosR committed
1559

Mark Otto's avatar
Mark Otto committed
1560
1561
1562
1563
1564
1565
  var complete = function () {
    this['setTransitioning'](false)
    $(this._element)
      .removeClass(Collapse._ClassName.COLLAPSING)
      .addClass(Collapse._ClassName.COLLAPSE)
      .trigger(Collapse._Event.HIDDEN)
XhmikosR's avatar
XhmikosR committed
1566

Mark Otto's avatar
Mark Otto committed
1567
  }.bind(this)
XhmikosR's avatar
XhmikosR committed
1568

Mark Otto's avatar
Mark Otto committed
1569
1570
1571
1572
  this._element.style[dimension] = 0

  if (!Bootstrap.transition) {
    return complete()
XhmikosR's avatar
XhmikosR committed
1573
1574
  }

Mark Otto's avatar
Mark Otto committed
1575
1576
1577
1578
1579
  $(this._element)
    .one(Bootstrap.TRANSITION_END, complete)
    .emulateTransitionEnd(Collapse._TRANSITION_DURATION)
}

XhmikosR's avatar
XhmikosR committed
1580
1581


Mark Otto's avatar
Mark Otto committed
1582
1583
1584
1585
1586
1587
1588
1589
1590
1591
1592
1593
1594
1595
1596
1597
1598
/**
 * @param {boolean} isTransitioning
 */
Collapse.prototype['setTransitioning'] = function (isTransitioning) {
  this._isTransitioning = isTransitioning
}


/**
 * Returns the collapsing dimension
 * @return {string}
 * @private
 */
Collapse.prototype._getDimension = function () {
  var hasWidth = $(this._element).hasClass(Collapse._Dimension.WIDTH)
  return hasWidth ? Collapse._Dimension.WIDTH : Collapse._Dimension.HEIGHT
}
XhmikosR's avatar
XhmikosR committed
1599
1600


Mark Otto's avatar
Mark Otto committed
1601
1602
1603
1604
1605
1606
1607
1608
1609
1610
1611
1612
/**
 * Returns the parent element
 * @return {Element}
 * @private
 */
Collapse.prototype._getParent = function () {
  var selector = '[data-toggle="collapse"][data-parent="' + this._config['parent'] + '"]'
  var parent = $(this._config['parent'])[0]
  var elements = /** @type {Array.<Element>} */ ($.makeArray($(parent).find(selector)))

  for (var i = 0; i < elements.length; i++) {
    this._addAriaAndCollapsedClass(Collapse._getTargetFromElement(elements[i]), elements[i])
XhmikosR's avatar
XhmikosR committed
1613
1614
  }

Mark Otto's avatar
Mark Otto committed
1615
1616
1617
  return parent
}

XhmikosR's avatar
XhmikosR committed
1618

Mark Otto's avatar
Mark Otto committed
1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
1631
1632
1633
1634
1635
/**
 * Returns the parent element
 * @param {Element} element
 * @param {Element} trigger
 * @private
 */
Collapse.prototype._addAriaAndCollapsedClass = function (element, trigger) {
  if (element) {
    var isOpen = $(element).hasClass(Collapse._ClassName.IN)
    element.setAttribute('aria-expanded', isOpen)

    if (trigger) {
      trigger.setAttribute('aria-expanded', isOpen)
      $(trigger).toggleClass(Collapse._ClassName.COLLAPSED, !isOpen)
    }
  }
}
XhmikosR's avatar
XhmikosR committed
1636
1637
1638



Mark Otto's avatar
Mark Otto committed
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
1669
1670
1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
1687
1688
/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */

/**
 * @const
 * @type {Function}
 */
$.fn[Collapse._NAME] = Collapse._jQueryInterface


/**
 * @const
 * @type {Function}
 */
$.fn[Collapse._NAME]['Constructor'] = Collapse


/**
 * @const
 * @type {Function}
 */
$.fn[Collapse._NAME]['noConflict'] = function () {
  $.fn[Collapse._NAME] = Collapse._JQUERY_NO_CONFLICT
  return this
}


/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */

$(document).on('click.bs.collapse.data-api', '[data-toggle="collapse"]', function (event) {
  event.preventDefault()

  var target = Collapse._getTargetFromElement(this)

  var data = $(target).data(Collapse._DATA_KEY)
  var config = data ? 'toggle' : $.extend({}, $(this).data(), { trigger: this })

  Collapse._jQueryInterface.call($(target), config)
})

/** =======================================================================
 * Bootstrap: dropdown.js v4.0.0
 * http://getbootstrap.com/javascript/#dropdown
XhmikosR's avatar
XhmikosR committed
1689
 * ========================================================================
Mark Otto's avatar
Mark Otto committed
1690
 * Copyright 2011-2015 Twitter, Inc.
XhmikosR's avatar
XhmikosR committed
1691
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
Mark Otto's avatar
Mark Otto committed
1692
1693
1694
1695
1696
1697
1698
1699
1700
1701
1702
1703
1704
1705
 * ========================================================================
 * @fileoverview - Add dropdown menus to nearly anything with this simple
 * plugin, including the navbar, tabs, and pills.
 *
 * Public Methods & Properties:
 *
 *   + $.dropdown
 *   + $.dropdown.noConflict
 *   + $.dropdown.Constructor
 *   + $.dropdown.Constructor.VERSION
 *   + $.dropdown.Constructor.prototype.toggle
 *
 * ========================================================================
 */
XhmikosR's avatar
XhmikosR committed
1706

Mark Otto's avatar
Mark Otto committed
1707
'use strict';
XhmikosR's avatar
XhmikosR committed
1708
1709


Mark Otto's avatar
Mark Otto committed
1710
1711
1712
1713
1714
1715
1716
1717
1718
1719
1720
1721
1722
1723
1724
1725
1726
1727
1728
1729
1730
1731
1732
1733
1734
1735
1736
1737
1738
1739
1740
1741
1742
1743
1744
1745
1746
1747
1748
1749
1750
1751
1752
1753
1754
1755
1756
1757
1758
1759
1760
1761
1762
1763
1764
1765
1766
1767
1768
1769
1770
1771
1772
1773
1774
1775
1776
1777
1778
1779
1780
1781
1782
1783
1784
1785
1786
1787
1788
1789
1790
1791
1792
1793
1794
1795
1796
1797
1798
1799
1800
1801
1802
1803
1804
1805
1806
1807
1808
1809
1810
1811
1812
1813
1814
1815
1816
1817
1818
1819
1820
1821
1822
1823
1824
1825
1826
1827
1828
/**
 * Our dropdown class.
 * @param {Element!} element
 * @constructor
 */
var Dropdown = function (element) {
  $(element).on('click.bs.dropdown', this['toggle'])
}


/**
 * @const
 * @type {string}
 */
Dropdown['VERSION'] = '4.0.0'


/**
 * @const
 * @type {string}
 * @private
 */
Dropdown._NAME = 'dropdown'


/**
 * @const
 * @type {string}
 * @private
 */
Dropdown._DATA_KEY = 'bs.dropdown'


/**
 * @const
 * @type {Function}
 * @private
 */
Dropdown._JQUERY_NO_CONFLICT = $.fn[Dropdown._NAME]


/**
 * @const
 * @enum {string}
 * @private
 */
Dropdown._Event = {
  HIDE   : 'hide.bs.dropdown',
  HIDDEN : 'hidden.bs.dropdown',
  SHOW   : 'show.bs.dropdown',
  SHOWN  : 'shown.bs.dropdown'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Dropdown._ClassName = {
  BACKDROP : 'dropdown-backdrop',
  DISABLED : 'disabled',
  OPEN     : 'open'
}


/**
 * @const
 * @enum {string}
 * @private
 */
Dropdown._Selector = {
  BACKDROP      : '.dropdown-backdrop',
  DATA_TOGGLE   : '[data-toggle="dropdown"]',
  FORM_CHILD    : '.dropdown form',
  ROLE_MENU     : '[role="menu"]',
  ROLE_LISTBOX  : '[role="listbox"]',
  NAVBAR_NAV    : '.navbar-nav',
  VISIBLE_ITEMS : '[role="menu"] li:not(.divider) a, [role="listbox"] li:not(.divider) a'
}


/**
 * Provides the jQuery Interface for the alert component.
 * @param {string=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Dropdown._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var data  = $(this).data(Dropdown._DATA_KEY)

    if (!data) {
      $(this).data(Dropdown._DATA_KEY, (data = new Dropdown(this)))
    }

    if (typeof opt_config === 'string') {
      data[opt_config].call(this)
    }
  })
}


/**
 * @param {Event=} opt_event
 * @private
 */
Dropdown._clearMenus = function (opt_event) {
  if (opt_event && opt_event.which == 3) {
    return
  }

  var backdrop = $(Dropdown._Selector.BACKDROP)[0]
  if (backdrop) {
    backdrop.parentNode.removeChild(backdrop)
  }

  var toggles = /** @type {Array.<Element>} */ ($.makeArray($(Dropdown._Selector.DATA_TOGGLE)))
XhmikosR's avatar
XhmikosR committed
1829

Mark Otto's avatar
Mark Otto committed
1830
1831
1832
1833
1834
1835
1836
1837
1838
1839
1840
1841
1842
1843
1844
1845
1846
1847
1848
  for (var i = 0; i < toggles.length; i++) {
    var parent = Dropdown._getParentFromElement(toggles[i])
    var relatedTarget = { 'relatedTarget': toggles[i] }

    if (!$(parent).hasClass(Dropdown._ClassName.OPEN)) {
      continue
    }

    var hideEvent = $.Event(Dropdown._Event.HIDE, relatedTarget)
    $(parent).trigger(hideEvent)
    if (hideEvent.isDefaultPrevented()) {
      continue
    }

    toggles[i].setAttribute('aria-expanded', 'false')

    $(parent)
      .removeClass(Dropdown._ClassName.OPEN)
      .trigger(Dropdown._Event.HIDDEN, relatedTarget)
XhmikosR's avatar
XhmikosR committed
1849
  }
Mark Otto's avatar
Mark Otto committed
1850
1851
}

XhmikosR's avatar
XhmikosR committed
1852

Mark Otto's avatar
Mark Otto committed
1853
1854
1855
1856
1857
1858
1859
/**
 * @param {Element} element
 * @return {Element}
 * @private
 */
Dropdown._getParentFromElement = function (element) {
  var selector = Bootstrap.getSelectorFromElement(element)
XhmikosR's avatar
XhmikosR committed
1860

Mark Otto's avatar
Mark Otto committed
1861
1862
  if (selector) {
    var parent = $(selector)[0]
XhmikosR's avatar
XhmikosR committed
1863
1864
  }

Mark Otto's avatar
Mark Otto committed
1865
1866
  return /** @type {Element} */ (parent || element.parentNode)
}
XhmikosR's avatar
XhmikosR committed
1867
1868


Mark Otto's avatar
Mark Otto committed
1869
1870
1871
1872
1873
1874
1875
1876
1877
/**
 * @param {Event} event
 * @this {Element}
 * @private
 */
Dropdown._dataApiKeydownHandler = function (event) {
  if (!/(38|40|27|32)/.test(event.which) || /input|textarea/i.test(event.target.tagName)) {
    return
  }
XhmikosR's avatar
XhmikosR committed
1878

Mark Otto's avatar
Mark Otto committed
1879
1880
  event.preventDefault()
  event.stopPropagation()
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
1881

Mark Otto's avatar
Mark Otto committed
1882
1883
  if (this.disabled || $(this).hasClass(Dropdown._ClassName.DISABLED)) {
    return
XhmikosR's avatar
XhmikosR committed
1884
1885
  }

Mark Otto's avatar
Mark Otto committed
1886
1887
  var parent  = Dropdown._getParentFromElement(this)
  var isActive = $(parent).hasClass(Dropdown._ClassName.OPEN)
XhmikosR's avatar
XhmikosR committed
1888

Mark Otto's avatar
Mark Otto committed
1889
1890
1891
1892
  if ((!isActive && event.which != 27) || (isActive && event.which == 27)) {
    if (event.which == 27) {
      var toggle = $(parent).find(Dropdown._Selector.DATA_TOGGLE)[0]
      $(toggle).trigger('focus')
XhmikosR's avatar
XhmikosR committed
1893
    }
Mark Otto's avatar
Mark Otto committed
1894
1895
1896
    $(this).trigger('click')
    return
  }
XhmikosR's avatar
XhmikosR committed
1897

Mark Otto's avatar
Mark Otto committed
1898
1899
1900
1901
1902
1903
1904
1905
  var items = $.makeArray($(Dropdown._Selector.VISIBLE_ITEMS))

  items = items.filter(function (item) {
    return item.offsetWidth || item.offsetHeight
  })

  if (!items.length) {
    return
XhmikosR's avatar
XhmikosR committed
1906
1907
  }

Mark Otto's avatar
Mark Otto committed
1908
  var index = items.indexOf(event.target)
XhmikosR's avatar
XhmikosR committed
1909

Mark Otto's avatar
Mark Otto committed
1910
1911
1912
  if (event.which == 38 && index > 0)                index--                        // up
  if (event.which == 40 && index < items.length - 1) index++                        // down
  if (!~index)                                       index = 0
XhmikosR's avatar
XhmikosR committed
1913

Mark Otto's avatar
Mark Otto committed
1914
1915
  items[index].focus()
}
XhmikosR's avatar
XhmikosR committed
1916
1917


Mark Otto's avatar
Mark Otto committed
1918
1919
1920
1921
1922
1923
1924
1925
/**
 * Toggles the dropdown
 * @this {Element}
 * @return {boolean|undefined}
 */
Dropdown.prototype['toggle'] = function () {
  if (this.disabled || $(this).hasClass(Dropdown._ClassName.DISABLED)) {
    return
XhmikosR's avatar
XhmikosR committed
1926
1927
  }

Mark Otto's avatar
Mark Otto committed
1928
1929
1930
1931
1932
1933
1934
1935
  var parent   = Dropdown._getParentFromElement(this)
  var isActive = $(parent).hasClass(Dropdown._ClassName.OPEN)

  Dropdown._clearMenus()

  if (isActive) {
    return false
  }
XhmikosR's avatar
XhmikosR committed
1936

Mark Otto's avatar
Mark Otto committed
1937
1938
1939
1940
1941
1942
1943
  if ('ontouchstart' in document.documentElement && !$(parent).closest(Dropdown._Selector.NAVBAR_NAV).length) {
    // if mobile we use a backdrop because click events don't delegate
    var dropdown       = document.createElement('div')
    dropdown.className = Dropdown._ClassName.BACKDROP
    this.parentNode.insertBefore(this, dropdown)
    $(dropdown).on('click', Dropdown._clearMenus)
  }
XhmikosR's avatar
XhmikosR committed
1944

Mark Otto's avatar
Mark Otto committed
1945
1946
  var relatedTarget = { 'relatedTarget': this }
  var showEvent     = $.Event(Dropdown._Event.SHOW, relatedTarget)
XhmikosR's avatar
XhmikosR committed
1947

Mark Otto's avatar
Mark Otto committed
1948
  $(parent).trigger(showEvent)
XhmikosR's avatar
XhmikosR committed
1949

Mark Otto's avatar
Mark Otto committed
1950
1951
  if (showEvent.isDefaultPrevented()) {
    return
XhmikosR's avatar
XhmikosR committed
1952
1953
  }

Mark Otto's avatar
Mark Otto committed
1954
1955
  this.focus()
  this.setAttribute('aria-expanded', 'true')
XhmikosR's avatar
XhmikosR committed
1956

Mark Otto's avatar
Mark Otto committed
1957
  $(parent).toggleClass(Dropdown._ClassName.OPEN)
XhmikosR's avatar
XhmikosR committed
1958

Mark Otto's avatar
Mark Otto committed
1959
  $(parent).trigger(Dropdown._Event.SHOWN, relatedTarget)
XhmikosR's avatar
XhmikosR committed
1960

Mark Otto's avatar
Mark Otto committed
1961
1962
  return false
}
XhmikosR's avatar
XhmikosR committed
1963

Mark Otto's avatar
Mark Otto committed
1964
1965
1966
1967
1968
1969
1970
1971
1972
1973
1974
1975
1976
1977
1978
1979
1980
1981
1982
1983
1984
1985
1986
1987
1988
1989
1990
1991
1992
1993
1994
1995
1996
1997
1998
1999
2000
2001
2002
2003
2004
2005
2006
2007
2008
2009
2010
2011

/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */

/**
 * @const
 * @type {Function}
 */
$.fn[Dropdown._NAME] = Dropdown._jQueryInterface


/**
 * @const
 * @type {Function}
 */
$.fn[Dropdown._NAME]['Constructor'] = Dropdown


/**
 * @const
 * @type {Function}
 */
$.fn[Dropdown._NAME]['noConflict'] = function () {
  $.fn[Dropdown._NAME] = Dropdown._JQUERY_NO_CONFLICT
  return this
}


/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */

$(document)
  .on('click.bs.dropdown.data-api',   Dropdown._clearMenus)
  .on('click.bs.dropdown.data-api',   Dropdown._Selector.FORM_CHILD,   function (e) { e.stopPropagation() })
  .on('click.bs.dropdown.data-api',   Dropdown._Selector.DATA_TOGGLE,  Dropdown.prototype['toggle'])
  .on('keydown.bs.dropdown.data-api', Dropdown._Selector.DATA_TOGGLE,  Dropdown._dataApiKeydownHandler)
  .on('keydown.bs.dropdown.data-api', Dropdown._Selector.ROLE_MENU,    Dropdown._dataApiKeydownHandler)
  .on('keydown.bs.dropdown.data-api', Dropdown._Selector.ROLE_LISTBOX, Dropdown._dataApiKeydownHandler)

/** =======================================================================
 * Bootstrap: modal.js v4.0.0
 * http://getbootstrap.com/javascript/#modal
XhmikosR's avatar
XhmikosR committed
2012
 * ========================================================================
Mark Otto's avatar
Mark Otto committed
2013
 * Copyright 2011-2015 Twitter, Inc.
XhmikosR's avatar
XhmikosR committed
2014
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
Mark Otto's avatar
Mark Otto committed
2015
2016
2017
2018
2019
2020
2021
2022
2023
2024
2025
2026
2027
2028
2029
2030
2031
2032
2033
2034
2035
 * ========================================================================
 * @fileoverview - Bootstrap's modal plugin. Modals are streamlined, but
 * flexible, dialog prompts with the minimum required functionality and
 * smart defaults.
 *
 * Public Methods & Properties:
 *
 *   + $.modal
 *   + $.modal.noConflict
 *   + $.modal.Constructor
 *   + $.modal.Constructor.VERSION
 *   + $.modal.Constructor.Defaults
 *   + $.modal.Constructor.Defaults.backdrop
 *   + $.modal.Constructor.Defaults.keyboard
 *   + $.modal.Constructor.Defaults.show
 *   + $.modal.Constructor.prototype.toggle
 *   + $.modal.Constructor.prototype.show
 *   + $.modal.Constructor.prototype.hide
 *
 * ========================================================================
 */
XhmikosR's avatar
XhmikosR committed
2036

Mark Otto's avatar
Mark Otto committed
2037
'use strict';
XhmikosR's avatar
XhmikosR committed
2038
2039


Mark Otto's avatar
Mark Otto committed
2040
2041
2042
2043
2044
2045
2046
/**
 * Our modal class.
 * @param {Element} element
 * @param {Object} config
 * @constructor
 */
var Modal = function (element, config) {
XhmikosR's avatar
XhmikosR committed
2047

Mark Otto's avatar
Mark Otto committed
2048
2049
  /** @private {Object} */
  this._config = config
XhmikosR's avatar
XhmikosR committed
2050

Mark Otto's avatar
Mark Otto committed
2051
2052
  /** @private {Element} */
  this._element = element
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2053

Mark Otto's avatar
Mark Otto committed
2054
2055
  /** @private {Element} */
  this._backdrop = null
XhmikosR's avatar
XhmikosR committed
2056

Mark Otto's avatar
Mark Otto committed
2057
2058
  /** @private {boolean} */
  this._isShown = false
XhmikosR's avatar
XhmikosR committed
2059

Mark Otto's avatar
Mark Otto committed
2060
2061
  /** @private {boolean} */
  this._isBodyOverflowing = false
2062

Mark Otto's avatar
Mark Otto committed
2063
2064
  /** @private {number} */
  this._scrollbarWidth = 0
XhmikosR's avatar
XhmikosR committed
2065

Mark Otto's avatar
Mark Otto committed
2066
}
XhmikosR's avatar
XhmikosR committed
2067
2068


Mark Otto's avatar
Mark Otto committed
2069
2070
2071
2072
2073
/**
 * @const
 * @type {string}
 */
Modal['VERSION']  = '4.0.0'
XhmikosR's avatar
XhmikosR committed
2074
2075


Mark Otto's avatar
Mark Otto committed
2076
2077
2078
2079
2080
2081
2082
2083
2084
/**
 * @const
 * @type {Object}
 */
Modal['Defaults'] = {
  'backdrop' : true,
  'keyboard' : true,
  'show'     : true
}
XhmikosR's avatar
XhmikosR committed
2085
2086


Mark Otto's avatar
Mark Otto committed
2087
2088
2089
2090
2091
2092
/**
 * @const
 * @type {string}
 * @private
 */
Modal._NAME = 'modal'
XhmikosR's avatar
XhmikosR committed
2093

XhmikosR's avatar
XhmikosR committed
2094

Mark Otto's avatar
Mark Otto committed
2095
2096
2097
2098
2099
2100
/**
 * @const
 * @type {string}
 * @private
 */
Modal._DATA_KEY = 'bs.modal'
XhmikosR's avatar
XhmikosR committed
2101
2102


Mark Otto's avatar
Mark Otto committed
2103
2104
2105
2106
2107
2108
/**
 * @const
 * @type {number}
 * @private
 */
Modal._TRANSITION_DURATION = 300
XhmikosR's avatar
XhmikosR committed
2109
2110


Mark Otto's avatar
Mark Otto committed
2111
2112
2113
2114
2115
2116
/**
 * @const
 * @type {number}
 * @private
 */
Modal._BACKDROP_TRANSITION_DURATION = 150
XhmikosR's avatar
XhmikosR committed
2117
2118


Mark Otto's avatar
Mark Otto committed
2119
2120
2121
2122
2123
2124
/**
 * @const
 * @type {Function}
 * @private
 */
Modal._JQUERY_NO_CONFLICT = $.fn[Modal._NAME]
XhmikosR's avatar
XhmikosR committed
2125
2126


Mark Otto's avatar
Mark Otto committed
2127
2128
2129
2130
2131
2132
2133
2134
2135
2136
2137
/**
 * @const
 * @enum {string}
 * @private
 */
Modal._Event = {
  HIDE   : 'hide.bs.modal',
  HIDDEN : 'hidden.bs.modal',
  SHOW   : 'show.bs.modal',
  SHOWN  : 'shown.bs.modal'
}
XhmikosR's avatar
XhmikosR committed
2138
2139


Mark Otto's avatar
Mark Otto committed
2140
2141
2142
2143
2144
2145
2146
2147
2148
2149
2150
/**
 * @const
 * @enum {string}
 * @private
 */
Modal._ClassName = {
  BACKDROP : 'modal-backdrop',
  OPEN     : 'modal-open',
  FADE     : 'fade',
  IN       : 'in'
}
XhmikosR's avatar
XhmikosR committed
2151
2152


Mark Otto's avatar
Mark Otto committed
2153
2154
2155
2156
2157
2158
2159
2160
2161
2162
2163
2164
2165
2166
2167
2168
2169
2170
2171
2172
2173
2174
2175
2176
2177
2178
2179
2180
2181
2182
2183
2184
2185
2186
2187
2188
2189
/**
 * @const
 * @enum {string}
 * @private
 */
Modal._Selector = {
  DIALOG             : '.modal-dialog',
  DATA_TOGGLE        : '[data-toggle="modal"]',
  DATA_DISMISS       : '[data-dismiss="modal"]',
  SCROLLBAR_MEASURER : 'modal-scrollbar-measure'
}



/**
 * Provides the jQuery Interface for the alert component.
 * @param {Object|string=} opt_config
 * @param {Element=} opt_relatedTarget
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Modal._jQueryInterface = function Plugin(opt_config, opt_relatedTarget) {
  return this.each(function () {
    var data   = $(this).data(Modal._DATA_KEY)
    var config = $.extend({}, Modal['Defaults'], $(this).data(), typeof opt_config == 'object' && opt_config)

    if (!data) {
      data = new Modal(this, config)
      $(this).data(Modal._DATA_KEY, data)
    }

    if (typeof opt_config == 'string') {
      data[opt_config](opt_relatedTarget)

    } else if (config['show']) {
      data['show'](opt_relatedTarget)
XhmikosR's avatar
XhmikosR committed
2190
    }
Mark Otto's avatar
Mark Otto committed
2191
2192
2193
2194
2195
2196
2197
2198
2199
2200
2201
  })
}


/**
 * @param {Element} relatedTarget
 */
Modal.prototype['toggle'] = function (relatedTarget) {
  return this._isShown ? this['hide']() : this['show'](relatedTarget)
}

XhmikosR's avatar
XhmikosR committed
2202

Mark Otto's avatar
Mark Otto committed
2203
2204
2205
2206
2207
2208
2209
/**
 * @param {Element} relatedTarget
 */
Modal.prototype['show'] = function (relatedTarget) {
  var showEvent = $.Event(Modal._Event.SHOW, { relatedTarget: relatedTarget })

  $(this._element).trigger(showEvent)
XhmikosR's avatar
XhmikosR committed
2210

Mark Otto's avatar
Mark Otto committed
2211
2212
  if (this._isShown || showEvent.isDefaultPrevented()) {
    return
XhmikosR's avatar
XhmikosR committed
2213
2214
  }

Mark Otto's avatar
Mark Otto committed
2215
  this._isShown = true
XhmikosR's avatar
XhmikosR committed
2216

Mark Otto's avatar
Mark Otto committed
2217
2218
  this._checkScrollbar()
  this._setScrollbar()
XhmikosR's avatar
XhmikosR committed
2219

Mark Otto's avatar
Mark Otto committed
2220
  $(document.body).addClass(Modal._ClassName.OPEN)
XhmikosR's avatar
XhmikosR committed
2221

Mark Otto's avatar
Mark Otto committed
2222
2223
2224
2225
2226
2227
2228
2229
2230
2231
2232
2233
2234
2235
2236
2237
2238
2239
2240
2241
2242
2243
2244
  this._escape()
  this._resize()

  $(this._element).on('click.dismiss.bs.modal', Modal._Selector.DATA_DISMISS, this['hide'].bind(this))

  this._showBackdrop(this._showElement.bind(this, relatedTarget))
}


/**
 * @param {Event} event
 */
Modal.prototype['hide'] = function (event) {
  if (event) {
    event.preventDefault()
  }

  var hideEvent = $.Event(Modal._Event.HIDE)

  $(this._element).trigger(hideEvent)

  if (!this._isShown || hideEvent.isDefaultPrevented()) {
    return
XhmikosR's avatar
XhmikosR committed
2245
2246
  }

Mark Otto's avatar
Mark Otto committed
2247
2248
2249
2250
  this._isShown = false

  this._escape()
  this._resize()
XhmikosR's avatar
XhmikosR committed
2251

Mark Otto's avatar
Mark Otto committed
2252
  $(document).off('focusin.bs.modal')
XhmikosR's avatar
XhmikosR committed
2253

Mark Otto's avatar
Mark Otto committed
2254
2255
  $(this._element).removeClass(Modal._ClassName.IN)
  this._element.setAttribute('aria-hidden', true)
XhmikosR's avatar
XhmikosR committed
2256

Mark Otto's avatar
Mark Otto committed
2257
  $(this._element).off('click.dismiss.bs.modal')
XhmikosR's avatar
XhmikosR committed
2258

Mark Otto's avatar
Mark Otto committed
2259
2260
2261
2262
2263
2264
  if (Bootstrap.transition && $(this._element).hasClass(Modal._ClassName.FADE)) {
    $(this._element)
      .one(Bootstrap.TRANSITION_END, this._hideModal.bind(this))
      .emulateTransitionEnd(Modal._TRANSITION_DURATION)
  } else {
    this._hideModal()
XhmikosR's avatar
XhmikosR committed
2265
  }
Mark Otto's avatar
Mark Otto committed
2266
}
XhmikosR's avatar
XhmikosR committed
2267
2268


Mark Otto's avatar
Mark Otto committed
2269
2270
2271
2272
2273
2274
/**
 * @param {Element} relatedTarget
 * @private
 */
Modal.prototype._showElement = function (relatedTarget) {
  var transition = Bootstrap.transition && $(this._element).hasClass(Modal._ClassName.FADE)
XhmikosR's avatar
XhmikosR committed
2275

Mark Otto's avatar
Mark Otto committed
2276
2277
2278
  if (!this._element.parentNode || this._element.parentNode.nodeType != Node.ELEMENT_NODE) {
    document.body.appendChild(this._element) // don't move modals dom position
  }
XhmikosR's avatar
XhmikosR committed
2279

Mark Otto's avatar
Mark Otto committed
2280
2281
  this._element.style.display = 'block'
  this._element.scrollTop = 0
XhmikosR's avatar
XhmikosR committed
2282

Mark Otto's avatar
Mark Otto committed
2283
2284
2285
  if (this._config['backdrop']) {
    this._adjustBackdrop()
  }
XhmikosR's avatar
XhmikosR committed
2286

Mark Otto's avatar
Mark Otto committed
2287
2288
  if (transition) {
    Bootstrap.reflow(this._element)
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2289
2290
  }

Mark Otto's avatar
Mark Otto committed
2291
2292
  $(this._element).addClass(Modal._ClassName.IN)
  this._element.setAttribute('aria-hidden', false)
XhmikosR's avatar
XhmikosR committed
2293

Mark Otto's avatar
Mark Otto committed
2294
  this._enforceFocus()
XhmikosR's avatar
XhmikosR committed
2295

Mark Otto's avatar
Mark Otto committed
2296
  var shownEvent = $.Event(Modal._Event.SHOWN, { relatedTarget: relatedTarget })
XhmikosR's avatar
XhmikosR committed
2297

Mark Otto's avatar
Mark Otto committed
2298
2299
2300
2301
2302
2303
2304
2305
2306
2307
2308
2309
2310
2311
  var transitionComplete = function () {
    this._element.focus()
    $(this._element).trigger(shownEvent)
  }.bind(this)

  if (transition) {
    var dialog = $(this._element).find(Modal._Selector.DIALOG)[0]
    $(dialog)
      .one(Bootstrap.TRANSITION_END, transitionComplete)
      .emulateTransitionEnd(Modal._TRANSITION_DURATION)
  } else {
    transitionComplete()
  }
}
XhmikosR's avatar
XhmikosR committed
2312
2313
2314



Mark Otto's avatar
Mark Otto committed
2315
2316
2317
2318
2319
2320
2321
2322
2323
2324
2325
2326
/**
 * @private
 */
Modal.prototype._enforceFocus = function () {
  $(document)
    .off('focusin.bs.modal') // guard against infinite focus loop
    .on('focusin.bs.modal', function (e) {
      if (this._element !== e.target && !$(this._element).has(e.target).length) {
        this._element.focus()
      }
    }.bind(this))
}
XhmikosR's avatar
XhmikosR committed
2327
2328


Mark Otto's avatar
Mark Otto committed
2329
2330
2331
2332
2333
2334
2335
2336
2337
2338
/**
 * @private
 */
Modal.prototype._escape = function () {
  if (this._isShown && this._config['keyboard']) {
    $(this._element).on('keydown.dismiss.bs.modal', function (event) {
      if (event.which === 27) {
        this['hide']()
      }
    }.bind(this))
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2339

Mark Otto's avatar
Mark Otto committed
2340
2341
  } else if (!this._isShown) {
    $(this._element).off('keydown.dismiss.bs.modal')
XhmikosR's avatar
XhmikosR committed
2342
  }
Mark Otto's avatar
Mark Otto committed
2343
2344
2345
2346
2347
2348
2349
2350
2351
2352
2353
2354
2355
}


/**
 * @private
 */
Modal.prototype._resize = function () {
  if (this._isShown) {
    $(window).on('resize.bs.modal', this._handleUpdate.bind(this))
  } else {
    $(window).off('resize.bs.modal')
  }
}
XhmikosR's avatar
XhmikosR committed
2356
2357


Mark Otto's avatar
Mark Otto committed
2358
2359
2360
2361
2362
2363
2364
2365
2366
2367
2368
2369
/**
 * @private
 */
Modal.prototype._hideModal = function () {
  this._element.style.display = 'none'
  this._showBackdrop(function () {
    $(document.body).removeClass(Modal._ClassName.OPEN)
    this._resetAdjustments()
    this._resetScrollbar()
    $(this._element).trigger(Modal._Event.HIDDEN)
  }.bind(this))
}
2370

XhmikosR's avatar
XhmikosR committed
2371

Mark Otto's avatar
Mark Otto committed
2372
2373
2374
2375
2376
2377
2378
/**
 * @private
 */
Modal.prototype._removeBackdrop = function () {
  if (this._backdrop) {
    this._backdrop.parentNode.removeChild(this._backdrop)
    this._backdrop = null
XhmikosR's avatar
XhmikosR committed
2379
  }
Mark Otto's avatar
Mark Otto committed
2380
}
XhmikosR's avatar
XhmikosR committed
2381
2382


Mark Otto's avatar
Mark Otto committed
2383
2384
2385
2386
2387
2388
/**
 * @param {Function} callback
 * @private
 */
Modal.prototype._showBackdrop = function (callback) {
  var animate = $(this._element).hasClass(Modal._ClassName.FADE) ? Modal._ClassName.FADE : ''
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2389

Mark Otto's avatar
Mark Otto committed
2390
2391
  if (this._isShown && this._config['backdrop']) {
    var doAnimate = Bootstrap.transition && animate
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2392

Mark Otto's avatar
Mark Otto committed
2393
2394
    this._backdrop = document.createElement('div')
    this._backdrop.className = Modal._ClassName.BACKDROP
XhmikosR's avatar
XhmikosR committed
2395

Mark Otto's avatar
Mark Otto committed
2396
2397
    if (animate) {
      $(this._backdrop).addClass(animate)
XhmikosR's avatar
XhmikosR committed
2398
2399
    }

Mark Otto's avatar
Mark Otto committed
2400
    $(this._element).prepend(this._backdrop)
XhmikosR's avatar
XhmikosR committed
2401

Mark Otto's avatar
Mark Otto committed
2402
2403
2404
2405
2406
2407
    $(this._backdrop).on('click.dismiss.bs.modal', function (event) {
      if (event.target !== event.currentTarget) return
      this._config['backdrop'] === 'static'
        ? this._element.focus()
        : this['hide']()
    }.bind(this))
XhmikosR's avatar
XhmikosR committed
2408

Mark Otto's avatar
Mark Otto committed
2409
2410
2411
    if (doAnimate) {
      Bootstrap.reflow(this._backdrop)
    }
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2412

Mark Otto's avatar
Mark Otto committed
2413
    $(this._backdrop).addClass(Modal._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
2414

Mark Otto's avatar
Mark Otto committed
2415
2416
    if (!callback) {
      return
XhmikosR's avatar
XhmikosR committed
2417
2418
    }

Mark Otto's avatar
Mark Otto committed
2419
2420
2421
2422
    if (!doAnimate) {
      callback()
      return
    }
XhmikosR's avatar
XhmikosR committed
2423

Mark Otto's avatar
Mark Otto committed
2424
2425
2426
    $(this._backdrop)
      .one(Bootstrap.TRANSITION_END, callback)
      .emulateTransitionEnd(Modal._BACKDROP_TRANSITION_DURATION)
XhmikosR's avatar
XhmikosR committed
2427

Mark Otto's avatar
Mark Otto committed
2428
2429
  } else if (!this._isShown && this._backdrop) {
    $(this._backdrop).removeClass(Modal._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
2430

Mark Otto's avatar
Mark Otto committed
2431
2432
2433
2434
2435
2436
    var callbackRemove = function () {
      this._removeBackdrop()
      if (callback) {
        callback()
      }
    }.bind(this)
XhmikosR's avatar
XhmikosR committed
2437

Mark Otto's avatar
Mark Otto committed
2438
2439
2440
2441
2442
2443
2444
    if (Bootstrap.transition && $(this._element).hasClass(Modal._ClassName.FADE)) {
      $(this._backdrop)
        .one(Bootstrap.TRANSITION_END, callbackRemove)
        .emulateTransitionEnd(Modal._BACKDROP_TRANSITION_DURATION)
    } else {
      callbackRemove()
    }
XhmikosR's avatar
XhmikosR committed
2445

Mark Otto's avatar
Mark Otto committed
2446
2447
2448
2449
  } else if (callback) {
    callback()
  }
}
XhmikosR's avatar
XhmikosR committed
2450
2451


Mark Otto's avatar
Mark Otto committed
2452
2453
2454
2455
2456
2457
/**
 * ------------------------------------------------------------------------
 * the following methods are used to handle overflowing modals
 * todo (fat): these should probably be refactored into a
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
2458

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2459

Mark Otto's avatar
Mark Otto committed
2460
2461
2462
2463
2464
2465
2466
/**
 * @private
 */
Modal.prototype._handleUpdate = function () {
  if (this._config['backdrop']) this._adjustBackdrop()
  this._adjustDialog()
}
XhmikosR's avatar
XhmikosR committed
2467

Mark Otto's avatar
Mark Otto committed
2468
2469
2470
2471
2472
2473
2474
/**
 * @private
 */
Modal.prototype._adjustBackdrop = function () {
  this._backdrop.style.height = 0 // todo (fat): no clue why we do this
  this._backdrop.style.height = this._element.scrollHeight + 'px'
}
XhmikosR's avatar
XhmikosR committed
2475
2476


Mark Otto's avatar
Mark Otto committed
2477
2478
2479
2480
2481
/**
 * @private
 */
Modal.prototype._adjustDialog = function () {
  var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
XhmikosR's avatar
XhmikosR committed
2482

Mark Otto's avatar
Mark Otto committed
2483
2484
  if (!this._isBodyOverflowing && isModalOverflowing) {
    this._element.style.paddingLeft = this._scrollbarWidth + 'px'
XhmikosR's avatar
XhmikosR committed
2485
2486
  }

Mark Otto's avatar
Mark Otto committed
2487
2488
  if (this._isBodyOverflowing && !isModalOverflowing) {
    this._element.style.paddingRight = this._scrollbarWidth + 'px'
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2489
  }
Mark Otto's avatar
Mark Otto committed
2490
}
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2491
2492


Mark Otto's avatar
Mark Otto committed
2493
2494
2495
2496
2497
2498
2499
/**
 * @private
 */
Modal.prototype._resetAdjustments = function () {
  this._element.style.paddingLeft = ''
  this._element.style.paddingRight = ''
}
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2500
2501


Mark Otto's avatar
Mark Otto committed
2502
2503
2504
2505
2506
2507
2508
/**
 * @private
 */
Modal.prototype._checkScrollbar = function () {
  this._isBodyOverflowing = document.body.scrollHeight > document.documentElement.clientHeight
  this._scrollbarWidth = this._getScrollbarWidth()
}
XhmikosR's avatar
XhmikosR committed
2509
2510


Mark Otto's avatar
Mark Otto committed
2511
2512
2513
2514
2515
/**
 * @private
 */
Modal.prototype._setScrollbar = function () {
  var bodyPadding = parseInt(($(document.body).css('padding-right') || 0), 10)
XhmikosR's avatar
XhmikosR committed
2516

Mark Otto's avatar
Mark Otto committed
2517
2518
  if (this._isBodyOverflowing) {
    document.body.style.paddingRight = bodyPadding + this._scrollbarWidth + 'px'
XhmikosR's avatar
XhmikosR committed
2519
  }
Mark Otto's avatar
Mark Otto committed
2520
}
XhmikosR's avatar
XhmikosR committed
2521
2522


Mark Otto's avatar
Mark Otto committed
2523
2524
2525
2526
2527
2528
/**
 * @private
 */
Modal.prototype._resetScrollbar = function () {
  document.body.style.paddingRight = ''
}
XhmikosR's avatar
XhmikosR committed
2529
2530


Mark Otto's avatar
Mark Otto committed
2531
2532
2533
2534
2535
2536
2537
2538
2539
2540
2541
/**
 * @private
 */
Modal.prototype._getScrollbarWidth = function () { // thx walsh
  var scrollDiv = document.createElement('div')
  scrollDiv.className = Modal._Selector.SCROLLBAR_MEASURER
  document.body.appendChild(scrollDiv)
  var scrollbarWidth = scrollDiv.offsetWidth - scrollDiv.clientWidth
  document.body.removeChild(scrollDiv)
  return scrollbarWidth
}
XhmikosR's avatar
XhmikosR committed
2542
2543


Mark Otto's avatar
Mark Otto committed
2544
2545
2546
2547
2548
/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
2549

Mark Otto's avatar
Mark Otto committed
2550
2551
2552
2553
2554
/**
 * @const
 * @type {Function}
 */
$.fn[Modal._NAME] = Modal._jQueryInterface
XhmikosR's avatar
XhmikosR committed
2555

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2556

Mark Otto's avatar
Mark Otto committed
2557
2558
2559
2560
2561
/**
 * @const
 * @type {Function}
 */
$.fn[Modal._NAME]['Constructor'] = Modal
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2562

XhmikosR's avatar
XhmikosR committed
2563

Mark Otto's avatar
Mark Otto committed
2564
2565
2566
2567
2568
2569
2570
2571
/**
 * @const
 * @type {Function}
 */
$.fn[Modal._NAME]['noConflict'] = function () {
  $.fn[Modal._NAME] = Modal._JQUERY_NO_CONFLICT
  return this
}
XhmikosR's avatar
XhmikosR committed
2572
2573


Mark Otto's avatar
Mark Otto committed
2574
2575
2576
2577
2578
/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
2579

Mark Otto's avatar
Mark Otto committed
2580
2581
$(document).on('click.bs.modal.data-api', Modal._Selector.DATA_TOGGLE, function (event) {
  var selector = Bootstrap.getSelectorFromElement(this)
XhmikosR's avatar
XhmikosR committed
2582

Mark Otto's avatar
Mark Otto committed
2583
2584
2585
  if (selector) {
    var target = $(selector)[0]
  }
XhmikosR's avatar
XhmikosR committed
2586

Mark Otto's avatar
Mark Otto committed
2587
  var config = $(target).data(Modal._DATA_KEY) ? 'toggle' : $.extend({}, $(target).data(), $(this).data())
XhmikosR's avatar
XhmikosR committed
2588

Mark Otto's avatar
Mark Otto committed
2589
2590
  if (this.tagName == 'A') {
    event.preventDefault()
XhmikosR's avatar
XhmikosR committed
2591
2592
  }

Mark Otto's avatar
Mark Otto committed
2593
2594
2595
2596
  var $target = $(target).one(Modal._Event.SHOW, function (showEvent) {
    if (showEvent.isDefaultPrevented()) {
      return // only register focus restorer if modal will actually get shown
    }
XhmikosR's avatar
XhmikosR committed
2597

Mark Otto's avatar
Mark Otto committed
2598
2599
2600
2601
2602
2603
    $target.one(Modal._Event.HIDDEN, function () {
      if ($(this).is(':visible')) {
        this.focus()
      }
    }.bind(this))
  }.bind(this))
XhmikosR's avatar
XhmikosR committed
2604

Mark Otto's avatar
Mark Otto committed
2605
2606
  Modal._jQueryInterface.call($(target), config, this)
})
XhmikosR's avatar
XhmikosR committed
2607

Mark Otto's avatar
Mark Otto committed
2608
2609
2610
2611
2612
2613
2614
2615
2616
2617
2618
2619
2620
2621
2622
2623
2624
2625
2626
2627
2628
/** =======================================================================
 * Bootstrap: scrollspy.js v4.0.0
 * http://getbootstrap.com/javascript/#scrollspy
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's scrollspy plugin.
 *
 * Public Methods & Properties:
 *
 *   + $.scrollspy
 *   + $.scrollspy.noConflict
 *   + $.scrollspy.Constructor
 *   + $.scrollspy.Constructor.VERSION
 *   + $.scrollspy.Constructor.Defaults
 *   + $.scrollspy.Constructor.Defaults.offset
 *   + $.scrollspy.Constructor.prototype.refresh
 *
 * ========================================================================
 */
XhmikosR's avatar
XhmikosR committed
2629

Mark Otto's avatar
Mark Otto committed
2630
'use strict';
XhmikosR's avatar
XhmikosR committed
2631
2632


Mark Otto's avatar
Mark Otto committed
2633
2634
2635
2636
2637
2638
2639
/**
 * Our scrollspy class.
 * @param {Element!} element
 * @param {Object=} opt_config
 * @constructor
 */
function ScrollSpy(element, opt_config) {
XhmikosR's avatar
XhmikosR committed
2640

Mark Otto's avatar
Mark Otto committed
2641
2642
  /** @private {Element|Window} */
  this._scrollElement = element.tagName == 'BODY' ? window : element
XhmikosR's avatar
XhmikosR committed
2643

Mark Otto's avatar
Mark Otto committed
2644
2645
  /** @private {Object} */
  this._config = $.extend({}, ScrollSpy['Defaults'], opt_config)
XhmikosR's avatar
XhmikosR committed
2646

Mark Otto's avatar
Mark Otto committed
2647
2648
  /** @private {string} */
  this._selector = (this._config.target || '') + ' .nav li > a'
XhmikosR's avatar
XhmikosR committed
2649

Mark Otto's avatar
Mark Otto committed
2650
2651
  /** @private {Array} */
  this._offsets = []
XhmikosR's avatar
XhmikosR committed
2652

Mark Otto's avatar
Mark Otto committed
2653
2654
  /** @private {Array} */
  this._targets = []
XhmikosR's avatar
XhmikosR committed
2655

Mark Otto's avatar
Mark Otto committed
2656
2657
  /** @private {Element} */
  this._activeTarget = null
XhmikosR's avatar
XhmikosR committed
2658

Mark Otto's avatar
Mark Otto committed
2659
2660
  /** @private {number} */
  this._scrollHeight = 0
XhmikosR's avatar
XhmikosR committed
2661

Mark Otto's avatar
Mark Otto committed
2662
  $(this._scrollElement).on('scroll.bs.scrollspy', this._process.bind(this))
XhmikosR's avatar
XhmikosR committed
2663

Mark Otto's avatar
Mark Otto committed
2664
  this['refresh']()
XhmikosR's avatar
XhmikosR committed
2665

Mark Otto's avatar
Mark Otto committed
2666
2667
  this._process()
}
XhmikosR's avatar
XhmikosR committed
2668
2669


Mark Otto's avatar
Mark Otto committed
2670
2671
2672
2673
2674
/**
 * @const
 * @type {string}
 */
ScrollSpy['VERSION'] = '4.0.0'
XhmikosR's avatar
XhmikosR committed
2675
2676


Mark Otto's avatar
Mark Otto committed
2677
2678
2679
2680
2681
2682
2683
/**
 * @const
 * @type {Object}
 */
ScrollSpy['Defaults'] = {
  'offset': 10
}
XhmikosR's avatar
XhmikosR committed
2684

2685

Mark Otto's avatar
Mark Otto committed
2686
2687
2688
2689
2690
2691
/**
 * @const
 * @type {string}
 * @private
 */
ScrollSpy._NAME = 'scrollspy'
2692
2693


Mark Otto's avatar
Mark Otto committed
2694
2695
2696
2697
2698
2699
/**
 * @const
 * @type {string}
 * @private
 */
ScrollSpy._DATA_KEY = 'bs.scrollspy'
2700

XhmikosR's avatar
XhmikosR committed
2701

Mark Otto's avatar
Mark Otto committed
2702
2703
2704
2705
2706
2707
/**
 * @const
 * @type {Function}
 * @private
 */
ScrollSpy._JQUERY_NO_CONFLICT = $.fn[ScrollSpy._NAME]
XhmikosR's avatar
XhmikosR committed
2708
2709


Mark Otto's avatar
Mark Otto committed
2710
2711
2712
2713
2714
2715
2716
2717
/**
 * @const
 * @enum {string}
 * @private
 */
ScrollSpy._Event = {
  ACTIVATE: 'activate.bs.scrollspy'
}
XhmikosR's avatar
XhmikosR committed
2718
2719


Mark Otto's avatar
Mark Otto committed
2720
2721
2722
2723
2724
2725
2726
2727
2728
/**
 * @const
 * @enum {string}
 * @private
 */
ScrollSpy._ClassName = {
  DROPDOWN_MENU : 'dropdown-menu',
  ACTIVE        : 'active'
}
XhmikosR's avatar
XhmikosR committed
2729
2730


Mark Otto's avatar
Mark Otto committed
2731
2732
2733
2734
2735
2736
2737
2738
2739
2740
2741
/**
 * @const
 * @enum {string}
 * @private
 */
ScrollSpy._Selector = {
  DATA_SPY    : '[data-spy="scroll"]',
  ACTIVE      : '.active',
  LI_DROPDOWN : 'li.dropdown',
  LI          : 'li'
}
XhmikosR's avatar
XhmikosR committed
2742
2743


Mark Otto's avatar
Mark Otto committed
2744
2745
2746
2747
2748
2749
2750
2751
2752
2753
2754
2755
2756
2757
2758
/**
 * @param {Object=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
ScrollSpy._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var data   = $(this).data(ScrollSpy._DATA_KEY)
    var config = typeof opt_config === 'object' && opt_config || null

    if (!data) {
      data = new ScrollSpy(this, config)
      $(this).data(ScrollSpy._DATA_KEY, data)
    }
XhmikosR's avatar
XhmikosR committed
2759

Mark Otto's avatar
Mark Otto committed
2760
2761
2762
2763
2764
    if (typeof opt_config === 'string') {
      data[opt_config]()
    }
  })
}
XhmikosR's avatar
XhmikosR committed
2765
2766


Mark Otto's avatar
Mark Otto committed
2767
2768
2769
2770
2771
2772
/**
 * Refresh the scrollspy target cache
 */
ScrollSpy.prototype['refresh'] = function () {
  var offsetMethod = 'offset'
  var offsetBase   = 0
XhmikosR's avatar
XhmikosR committed
2773

Mark Otto's avatar
Mark Otto committed
2774
2775
2776
  if (this._scrollElement !== this._scrollElement.window) {
    offsetMethod = 'position'
    offsetBase   = this._getScrollTop()
XhmikosR's avatar
XhmikosR committed
2777
2778
  }

Mark Otto's avatar
Mark Otto committed
2779
2780
  this._offsets = []
  this._targets = []
XhmikosR's avatar
XhmikosR committed
2781

Mark Otto's avatar
Mark Otto committed
2782
  this._scrollHeight = this._getScrollHeight()
XhmikosR's avatar
XhmikosR committed
2783

Mark Otto's avatar
Mark Otto committed
2784
  var targets = /** @type {Array.<Element>} */ ($.makeArray($(this._selector)))
XhmikosR's avatar
XhmikosR committed
2785

Mark Otto's avatar
Mark Otto committed
2786
2787
2788
2789
  targets
    .map(function (element, index) {
      var target
      var targetSelector = Bootstrap.getSelectorFromElement(element)
XhmikosR's avatar
XhmikosR committed
2790

Mark Otto's avatar
Mark Otto committed
2791
2792
2793
      if (targetSelector) {
        target = $(targetSelector)[0]
      }
XhmikosR's avatar
XhmikosR committed
2794

Mark Otto's avatar
Mark Otto committed
2795
2796
2797
2798
2799
2800
2801
2802
2803
2804
2805
2806
      if (target && (target.offsetWidth || target.offsetHeight)) {
        // todo (fat): remove sketch reliance on jQuery position/offset
        return [$(target)[offsetMethod]().top + offsetBase, targetSelector]
      }
    })
    .filter(function (item) { return item })
    .sort(function (a, b) { return a[0] - b[0] })
    .forEach(function (item, index) {
      this._offsets.push(item[0])
      this._targets.push(item[1])
    }.bind(this))
}
XhmikosR's avatar
XhmikosR committed
2807
2808


Mark Otto's avatar
Mark Otto committed
2809
2810
2811
2812
2813
2814
2815
/**
 * @private
 */
ScrollSpy.prototype._getScrollTop = function () {
  return this._scrollElement === window ?
      this._scrollElement.scrollY : this._scrollElement.scrollTop
}
XhmikosR's avatar
XhmikosR committed
2816
2817


Mark Otto's avatar
Mark Otto committed
2818
2819
2820
2821
2822
2823
2824
/**
 * @private
 */
ScrollSpy.prototype._getScrollHeight = function () {
  return this._scrollElement.scrollHeight
      || Math.max(document.body.scrollHeight, document.documentElement.scrollHeight)
}
XhmikosR's avatar
XhmikosR committed
2825
2826


Mark Otto's avatar
Mark Otto committed
2827
2828
2829
2830
2831
2832
2833
/**
 * @private
 */
ScrollSpy.prototype._process = function () {
  var scrollTop    = this._getScrollTop() + this._config.offset
  var scrollHeight = this._getScrollHeight()
  var maxScroll    = this._config.offset + scrollHeight - this._scrollElement.offsetHeight
2834

Mark Otto's avatar
Mark Otto committed
2835
2836
  if (this._scrollHeight != scrollHeight) {
    this['refresh']()
XhmikosR's avatar
XhmikosR committed
2837
2838
  }

Mark Otto's avatar
Mark Otto committed
2839
2840
  if (scrollTop >= maxScroll) {
    var target = this._targets[this._targets.length - 1]
XhmikosR's avatar
XhmikosR committed
2841

Mark Otto's avatar
Mark Otto committed
2842
2843
2844
2845
    if (this._activeTarget != target) {
      this._activate(target)
    }
  }
XhmikosR's avatar
XhmikosR committed
2846

Mark Otto's avatar
Mark Otto committed
2847
2848
2849
2850
2851
  if (this._activeTarget && scrollTop < this._offsets[0]) {
    this._activeTarget = null
    this._clear()
    return
  }
XhmikosR's avatar
XhmikosR committed
2852

Mark Otto's avatar
Mark Otto committed
2853
2854
2855
2856
  for (var i = this._offsets.length; i--;) {
    var isActiveTarget = this._activeTarget != this._targets[i]
        && scrollTop >= this._offsets[i]
        && (!this._offsets[i + 1] || scrollTop < this._offsets[i + 1])
XhmikosR's avatar
XhmikosR committed
2857

Mark Otto's avatar
Mark Otto committed
2858
2859
2860
2861
2862
    if (isActiveTarget) {
      this._activate(this._targets[i])
    }
  }
}
XhmikosR's avatar
XhmikosR committed
2863
2864


Mark Otto's avatar
Mark Otto committed
2865
2866
2867
2868
2869
2870
/**
 * @param {Element} target
 * @private
 */
ScrollSpy.prototype._activate = function (target) {
  this._activeTarget = target
XhmikosR's avatar
XhmikosR committed
2871

Mark Otto's avatar
Mark Otto committed
2872
  this._clear()
XhmikosR's avatar
XhmikosR committed
2873

Mark Otto's avatar
Mark Otto committed
2874
2875
2876
  var selector = this._selector
      + '[data-target="' + target + '"],'
      + this._selector + '[href="' + target + '"]'
XhmikosR's avatar
XhmikosR committed
2877

Mark Otto's avatar
Mark Otto committed
2878
2879
  // todo (fat): this seems horribly wrong… getting all raw li elements up the tree ,_,
  var parentListItems = $(selector).parents(ScrollSpy._Selector.LI)
XhmikosR's avatar
XhmikosR committed
2880

Mark Otto's avatar
Mark Otto committed
2881
2882
  for (var i = parentListItems.length; i--;) {
    $(parentListItems[i]).addClass(ScrollSpy._ClassName.ACTIVE)
XhmikosR's avatar
XhmikosR committed
2883

Mark Otto's avatar
Mark Otto committed
2884
    var itemParent = parentListItems[i].parentNode
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2885

Mark Otto's avatar
Mark Otto committed
2886
2887
2888
2889
2890
    if (itemParent && $(itemParent).hasClass(ScrollSpy._ClassName.DROPDOWN_MENU)) {
      var closestDropdown = $(itemParent).closest(ScrollSpy._Selector.LI_DROPDOWN)[0]
      $(closestDropdown).addClass(ScrollSpy._ClassName.ACTIVE)
    }
  }
XhmikosR's avatar
XhmikosR committed
2891

Mark Otto's avatar
Mark Otto committed
2892
2893
2894
2895
  $(this._scrollElement).trigger(ScrollSpy._Event.ACTIVATE, {
    relatedTarget: target
  })
}
XhmikosR's avatar
XhmikosR committed
2896
2897


Mark Otto's avatar
Mark Otto committed
2898
2899
2900
2901
2902
/**
 * @private
 */
ScrollSpy.prototype._clear = function () {
  var activeParents = $(this._selector).parentsUntil(this._config.target, ScrollSpy._Selector.ACTIVE)
XhmikosR's avatar
XhmikosR committed
2903

Mark Otto's avatar
Mark Otto committed
2904
2905
  for (var i = activeParents.length; i--;) {
    $(activeParents[i]).removeClass(ScrollSpy._ClassName.ACTIVE)
XhmikosR's avatar
XhmikosR committed
2906
  }
Mark Otto's avatar
Mark Otto committed
2907
}
XhmikosR's avatar
XhmikosR committed
2908
2909


Mark Otto's avatar
Mark Otto committed
2910
2911
2912
2913
2914
/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
2915

Mark Otto's avatar
Mark Otto committed
2916
2917
2918
2919
2920
/**
 * @const
 * @type {Function}
 */
$.fn[ScrollSpy._NAME] = ScrollSpy._jQueryInterface
XhmikosR's avatar
XhmikosR committed
2921
2922


Mark Otto's avatar
Mark Otto committed
2923
2924
2925
2926
2927
/**
 * @const
 * @type {Function}
 */
$.fn[ScrollSpy._NAME]['Constructor'] = ScrollSpy
XhmikosR's avatar
XhmikosR committed
2928
2929


Mark Otto's avatar
Mark Otto committed
2930
2931
2932
2933
2934
2935
2936
2937
/**
 * @const
 * @type {Function}
 */
$.fn[ScrollSpy._NAME]['noConflict'] = function () {
  $.fn[ScrollSpy._NAME] = ScrollSpy._JQUERY_NO_CONFLICT
  return this
}
XhmikosR's avatar
XhmikosR committed
2938
2939


Mark Otto's avatar
Mark Otto committed
2940
2941
2942
2943
2944
/**
 * ------------------------------------------------------------------------
 * Data Api implementation
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
2945

Mark Otto's avatar
Mark Otto committed
2946
2947
$(window).on('load.bs.scrollspy.data-api', function () {
  var scrollSpys = /** @type {Array.<Element>} */ ($.makeArray($(ScrollSpy._Selector.DATA_SPY)))
XhmikosR's avatar
XhmikosR committed
2948

Mark Otto's avatar
Mark Otto committed
2949
2950
2951
  for (var i = scrollSpys.length; i--;) {
    var $spy = $(scrollSpys[i])
    ScrollSpy._jQueryInterface.call($spy, /** @type {Object|null} */ ($spy.data()))
XhmikosR's avatar
XhmikosR committed
2952
  }
Mark Otto's avatar
Mark Otto committed
2953
})
XhmikosR's avatar
XhmikosR committed
2954

Mark Otto's avatar
Mark Otto committed
2955
2956
2957
2958
2959
2960
2961
2962
2963
2964
2965
2966
2967
2968
2969
2970
2971
2972
2973
2974
2975
2976
2977
2978
2979
2980
2981
2982
2983
2984
2985
2986
2987
2988
2989
2990
2991
2992
2993
/** =======================================================================
 * Bootstrap: tooltip.js v4.0.0
 * http://getbootstrap.com/javascript/#tooltip
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's tooltip plugin.
 * (Inspired by jQuery.tipsy by Jason Frame)
 *
 * Public Methods & Properties:
 *
 *   + $.tooltip
 *   + $.tooltip.noConflict
 *   + $.tooltip.Constructor
 *   + $.tooltip.Constructor.VERSION
 *   + $.tooltip.Constructor.Defaults
 *   + $.tooltip.Constructor.Defaults.container
 *   + $.tooltip.Constructor.Defaults.animation
 *   + $.tooltip.Constructor.Defaults.placement
 *   + $.tooltip.Constructor.Defaults.selector
 *   + $.tooltip.Constructor.Defaults.template
 *   + $.tooltip.Constructor.Defaults.trigger
 *   + $.tooltip.Constructor.Defaults.title
 *   + $.tooltip.Constructor.Defaults.delay
 *   + $.tooltip.Constructor.Defaults.html
 *   + $.tooltip.Constructor.Defaults.viewport
 *   + $.tooltip.Constructor.Defaults.viewport.selector
 *   + $.tooltip.Constructor.Defaults.viewport.padding
 *   + $.tooltip.Constructor.prototype.enable
 *   + $.tooltip.Constructor.prototype.disable
 *   + $.tooltip.Constructor.prototype.destroy
 *   + $.tooltip.Constructor.prototype.toggleEnabled
 *   + $.tooltip.Constructor.prototype.toggle
 *   + $.tooltip.Constructor.prototype.show
 *   + $.tooltip.Constructor.prototype.hide
 *
 * ========================================================================
 */
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
2994

Mark Otto's avatar
Mark Otto committed
2995
'use strict';
XhmikosR's avatar
XhmikosR committed
2996
2997


Mark Otto's avatar
Mark Otto committed
2998
2999
3000
3001
3002
3003
3004
/**
 * Our tooltip class.
 * @param {Element!} element
 * @param {Object=} opt_config
 * @constructor
 */
var Tooltip = function (element, opt_config) {
XhmikosR's avatar
XhmikosR committed
3005

Mark Otto's avatar
Mark Otto committed
3006
3007
  /** @private {boolean} */
  this._isEnabled = true
XhmikosR's avatar
XhmikosR committed
3008

Mark Otto's avatar
Mark Otto committed
3009
3010
  /** @private {number} */
  this._timeout = 0
XhmikosR's avatar
XhmikosR committed
3011

Mark Otto's avatar
Mark Otto committed
3012
3013
  /** @private {string} */
  this._hoverState = ''
XhmikosR's avatar
XhmikosR committed
3014

Mark Otto's avatar
Mark Otto committed
3015
3016
  /** @protected {Element} */
  this.element = element
XhmikosR's avatar
XhmikosR committed
3017

Mark Otto's avatar
Mark Otto committed
3018
3019
  /** @protected {Object} */
  this.config = this._getConfig(opt_config)
XhmikosR's avatar
XhmikosR committed
3020

Mark Otto's avatar
Mark Otto committed
3021
3022
  /** @protected {Element} */
  this.tip = null
XhmikosR's avatar
XhmikosR committed
3023

Mark Otto's avatar
Mark Otto committed
3024
3025
  /** @protected {Element} */
  this.arrow = null
XhmikosR's avatar
XhmikosR committed
3026

Mark Otto's avatar
Mark Otto committed
3027
3028
3029
3030
  if (this.config['viewport']) {

    /** @private {Element} */
    this._viewport = $(this.config['viewport']['selector'] || this.config['viewport'])[0]
XhmikosR's avatar
XhmikosR committed
3031
3032
3033

  }

Mark Otto's avatar
Mark Otto committed
3034
3035
  this._setListeners()
}
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3036
3037


Mark Otto's avatar
Mark Otto committed
3038
3039
3040
3041
3042
/**
 * @const
 * @type {string}
 */
Tooltip['VERSION']  = '4.0.0'
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3043

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3044

Mark Otto's avatar
Mark Otto committed
3045
3046
3047
3048
3049
3050
3051
3052
3053
3054
3055
3056
3057
3058
3059
3060
3061
/**
 * @const
 * @type {Object}
 */
Tooltip['Defaults'] = {
  'container' : false,
  'animation' : true,
  'placement' : 'top',
  'selector'  : false,
  'template'  : '<div class="tooltip" role="tooltip"><div class="tooltip-arrow"></div><div class="tooltip-inner"></div></div>',
  'trigger'   : 'hover focus',
  'title'     : '',
  'delay'     : 0,
  'html'      : false,
  'viewport': {
    'selector': 'body',
    'padding' : 0
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3062
  }
Mark Otto's avatar
Mark Otto committed
3063
}
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3064
3065


Mark Otto's avatar
Mark Otto committed
3066
3067
3068
3069
3070
3071
3072
3073
3074
3075
3076
/**
 * @const
 * @enum {string}
 * @protected
 */
Tooltip.Direction = {
  TOP: 'top',
  LEFT: 'left',
  RIGHT: 'right',
  BOTTOM: 'bottom'
}
XhmikosR's avatar
XhmikosR committed
3077
3078


Mark Otto's avatar
Mark Otto committed
3079
3080
3081
3082
3083
3084
/**
 * @const
 * @type {string}
 * @private
 */
Tooltip._NAME = 'tooltip'
XhmikosR's avatar
XhmikosR committed
3085
3086


Mark Otto's avatar
Mark Otto committed
3087
3088
3089
3090
3091
3092
/**
 * @const
 * @type {string}
 * @private
 */
Tooltip._DATA_KEY = 'bs.tooltip'
XhmikosR's avatar
XhmikosR committed
3093
3094


Mark Otto's avatar
Mark Otto committed
3095
3096
3097
3098
3099
3100
/**
 * @const
 * @type {number}
 * @private
 */
Tooltip._TRANSITION_DURATION = 150
XhmikosR's avatar
XhmikosR committed
3101
3102


Mark Otto's avatar
Mark Otto committed
3103
3104
3105
3106
3107
3108
3109
3110
3111
/**
 * @const
 * @enum {string}
 * @private
 */
Tooltip._HoverState = {
  IN: 'in',
  OUT: 'out'
}
XhmikosR's avatar
XhmikosR committed
3112
3113


Mark Otto's avatar
Mark Otto committed
3114
3115
3116
3117
3118
3119
3120
3121
3122
3123
3124
/**
 * @const
 * @enum {string}
 * @private
 */
Tooltip._Event = {
  HIDE   : 'hide.bs.tooltip',
  HIDDEN : 'hidden.bs.tooltip',
  SHOW   : 'show.bs.tooltip',
  SHOWN  : 'shown.bs.tooltip'
}
XhmikosR's avatar
XhmikosR committed
3125
3126


Mark Otto's avatar
Mark Otto committed
3127
3128
3129
3130
3131
3132
3133
3134
3135
/**
 * @const
 * @enum {string}
 * @private
 */
Tooltip._ClassName = {
  FADE : 'fade',
  IN   : 'in'
}
XhmikosR's avatar
XhmikosR committed
3136
3137


Mark Otto's avatar
Mark Otto committed
3138
3139
3140
3141
3142
3143
3144
3145
3146
3147
/**
 * @const
 * @enum {string}
 * @private
 */
Tooltip._Selector = {
  TOOLTIP       : '.tooltip',
  TOOLTIP_INNER : '.tooltip-inner',
  TOOLTIP_ARROW : '.tooltip-arrow'
}
XhmikosR's avatar
XhmikosR committed
3148
3149


Mark Otto's avatar
Mark Otto committed
3150
3151
3152
3153
3154
3155
/**
 * @const
 * @type {Function}
 * @private
 */
Tooltip._JQUERY_NO_CONFLICT = $.fn[Tooltip._NAME]
XhmikosR's avatar
XhmikosR committed
3156
3157


Mark Otto's avatar
Mark Otto committed
3158
3159
3160
3161
3162
3163
3164
3165
3166
3167
/**
 * @param {Object=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Tooltip._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var data   = $(this).data(Tooltip._DATA_KEY)
    var config = typeof opt_config == 'object' ? opt_config : null
XhmikosR's avatar
XhmikosR committed
3168

Mark Otto's avatar
Mark Otto committed
3169
3170
3171
    if (!data && opt_config == 'destroy') {
      return
    }
XhmikosR's avatar
XhmikosR committed
3172

Mark Otto's avatar
Mark Otto committed
3173
3174
3175
3176
3177
3178
3179
3180
3181
3182
    if (!data) {
      data = new Tooltip(this, config)
      $(this).data(Tooltip._DATA_KEY, data)
    }

    if (typeof opt_config === 'string') {
      data[opt_config]()
    }
  })
}
XhmikosR's avatar
XhmikosR committed
3183
3184


Mark Otto's avatar
Mark Otto committed
3185
3186
3187
3188
3189
3190
/**
 * Enable tooltip
 */
Tooltip.prototype['enable'] = function () {
  this._isEnabled = true
}
XhmikosR's avatar
XhmikosR committed
3191
3192


Mark Otto's avatar
Mark Otto committed
3193
3194
3195
3196
3197
3198
/**
 * Disable tooltip
 */
Tooltip.prototype['disable'] = function () {
  this._isEnabled = false
}
XhmikosR's avatar
XhmikosR committed
3199
3200


Mark Otto's avatar
Mark Otto committed
3201
3202
3203
3204
3205
3206
/**
 * Toggle the tooltip enable state
 */
Tooltip.prototype['toggleEnabled'] = function () {
  this._isEnabled = !this._isEnabled
}
3207

Mark Otto's avatar
Mark Otto committed
3208
3209
3210
3211
3212
3213
3214
/**
 * Toggle the tooltips display
 * @param {Event} opt_event
 */
Tooltip.prototype['toggle'] = function (opt_event) {
  var context = this
  var dataKey = this.getDataKey()
XhmikosR's avatar
XhmikosR committed
3215

Mark Otto's avatar
Mark Otto committed
3216
3217
  if (opt_event) {
    context = $(opt_event.currentTarget).data(dataKey)
XhmikosR's avatar
XhmikosR committed
3218

Mark Otto's avatar
Mark Otto committed
3219
3220
3221
    if (!context) {
      context = new this.constructor(opt_event.currentTarget, this._getDelegateConfig())
      $(opt_event.currentTarget).data(dataKey, context)
XhmikosR's avatar
XhmikosR committed
3222
    }
Mark Otto's avatar
Mark Otto committed
3223
  }
XhmikosR's avatar
XhmikosR committed
3224

Mark Otto's avatar
Mark Otto committed
3225
3226
3227
3228
  $(context.getTipElement()).hasClass(Tooltip._ClassName.IN) ?
    context._leave(null, context) :
    context._enter(null, context)
}
XhmikosR's avatar
XhmikosR committed
3229
3230


Mark Otto's avatar
Mark Otto committed
3231
3232
3233
3234
3235
3236
3237
3238
3239
3240
3241
/**
 * Remove tooltip functionality
 */
Tooltip.prototype['destroy'] = function () {
  clearTimeout(this._timeout)
  this['hide'](function () {
    $(this.element)
      .off(Tooltip._Selector.TOOLTIP)
      .removeData(this.getDataKey())
  }.bind(this))
}
XhmikosR's avatar
XhmikosR committed
3242
3243


Mark Otto's avatar
Mark Otto committed
3244
3245
3246
3247
3248
3249
3250
/**
 * Show the tooltip
 * todo (fat): ~fuck~ this is a big function - refactor out all of positioning logic
 * and replace with external lib
 */
Tooltip.prototype['show'] = function () {
  var showEvent = $.Event(this.getEventObject().SHOW)
XhmikosR's avatar
XhmikosR committed
3251

Mark Otto's avatar
Mark Otto committed
3252
3253
  if (this.isWithContent() && this._isEnabled) {
    $(this.element).trigger(showEvent)
XhmikosR's avatar
XhmikosR committed
3254

Mark Otto's avatar
Mark Otto committed
3255
    var isInTheDom = $.contains(this.element.ownerDocument.documentElement, this.element)
XhmikosR's avatar
XhmikosR committed
3256

Mark Otto's avatar
Mark Otto committed
3257
3258
    if (showEvent.isDefaultPrevented() || !isInTheDom) {
      return
XhmikosR's avatar
XhmikosR committed
3259
3260
    }

Mark Otto's avatar
Mark Otto committed
3261
3262
    var tip   = this.getTipElement()
    var tipId = Bootstrap.getUID(this.getName())
XhmikosR's avatar
XhmikosR committed
3263

Mark Otto's avatar
Mark Otto committed
3264
3265
    tip.setAttribute('id', tipId)
    this.element.setAttribute('aria-describedby', tipId)
XhmikosR's avatar
XhmikosR committed
3266

Mark Otto's avatar
Mark Otto committed
3267
    this.setContent()
XhmikosR's avatar
XhmikosR committed
3268

Mark Otto's avatar
Mark Otto committed
3269
3270
3271
    if (this.config['animation']) {
      $(tip).addClass(Tooltip._ClassName.FADE)
    }
XhmikosR's avatar
XhmikosR committed
3272

Mark Otto's avatar
Mark Otto committed
3273
3274
3275
    var placement = typeof this.config['placement'] == 'function' ?
      this.config['placement'].call(this, tip, this.element) :
      this.config['placement']
XhmikosR's avatar
XhmikosR committed
3276

Mark Otto's avatar
Mark Otto committed
3277
3278
3279
3280
3281
    var autoToken = /\s?auto?\s?/i
    var isWithAutoPlacement = autoToken.test(placement)

    if (isWithAutoPlacement) {
      placement = placement.replace(autoToken, '') || Tooltip.Direction.TOP
XhmikosR's avatar
XhmikosR committed
3282
3283
    }

Mark Otto's avatar
Mark Otto committed
3284
3285
    if (tip.parentNode && tip.parentNode.nodeType == Node.ELEMENT_NODE) {
      tip.parentNode.removeChild(tip)
XhmikosR's avatar
XhmikosR committed
3286
3287
    }

Mark Otto's avatar
Mark Otto committed
3288
3289
3290
    tip.style.top     = 0
    tip.style.left    = 0
    tip.style.display = 'block'
XhmikosR's avatar
XhmikosR committed
3291

Mark Otto's avatar
Mark Otto committed
3292
    $(tip).addClass(Tooltip._NAME + '-' + placement)
XhmikosR's avatar
XhmikosR committed
3293

Mark Otto's avatar
Mark Otto committed
3294
    $(tip).data(this.getDataKey(), this)
XhmikosR's avatar
XhmikosR committed
3295

Mark Otto's avatar
Mark Otto committed
3296
3297
3298
3299
3300
    if (this.config['container']) {
      $(this.config['container'])[0].appendChild(tip)
    } else {
      this.element.parentNode.insertBefore(tip, this.element.nextSibling)
    }
XhmikosR's avatar
XhmikosR committed
3301

Mark Otto's avatar
Mark Otto committed
3302
3303
3304
    var position            = this._getPosition()
    var actualWidth         = tip.offsetWidth
    var actualHeight        = tip.offsetHeight
XhmikosR's avatar
XhmikosR committed
3305

Mark Otto's avatar
Mark Otto committed
3306
3307
    var calculatedPlacement = this._getCalculatedAutoPlacement(isWithAutoPlacement, placement, position, actualWidth, actualHeight)
    var calculatedOffset    = this._getCalculatedOffset(calculatedPlacement, position, actualWidth, actualHeight)
XhmikosR's avatar
XhmikosR committed
3308

Mark Otto's avatar
Mark Otto committed
3309
    this._applyCalculatedPlacement(calculatedOffset, calculatedPlacement)
XhmikosR's avatar
XhmikosR committed
3310

Mark Otto's avatar
Mark Otto committed
3311
3312
3313
3314
    var complete = function () {
      var prevHoverState = this.hoverState
      $(this.element).trigger(this.getEventObject().SHOWN)
      this.hoverState = null
XhmikosR's avatar
XhmikosR committed
3315

Mark Otto's avatar
Mark Otto committed
3316
3317
      if (prevHoverState == 'out') this._leave(null, this)
    }.bind(this)
XhmikosR's avatar
XhmikosR committed
3318

Mark Otto's avatar
Mark Otto committed
3319
3320
3321
3322
3323
    Bootstrap.transition && $(this._tip).hasClass(Tooltip._ClassName.FADE) ?
      $(this._tip)
        .one(Bootstrap.TRANSITION_END, complete)
        .emulateTransitionEnd(Tooltip._TRANSITION_DURATION) :
      complete()
XhmikosR's avatar
XhmikosR committed
3324
  }
Mark Otto's avatar
Mark Otto committed
3325
}
XhmikosR's avatar
XhmikosR committed
3326
3327


Mark Otto's avatar
Mark Otto committed
3328
3329
3330
3331
3332
3333
3334
3335
3336
3337
3338
/**
 * Hide the tooltip breh
 */
Tooltip.prototype['hide'] = function (callback) {
  var tip       = this.getTipElement()
  var hideEvent = $.Event(this.getEventObject().HIDE)

  var complete  = function () {
    if (this._hoverState != Tooltip._HoverState.IN) {
      tip.parentNode.removeChild(tip)
    }
XhmikosR's avatar
XhmikosR committed
3339

Mark Otto's avatar
Mark Otto committed
3340
3341
    this.element.removeAttribute('aria-describedby')
    $(this.element).trigger(this.getEventObject().HIDDEN)
XhmikosR's avatar
XhmikosR committed
3342

Mark Otto's avatar
Mark Otto committed
3343
3344
3345
3346
    if (callback) {
      callback()
    }
  }.bind(this)
XhmikosR's avatar
XhmikosR committed
3347

Mark Otto's avatar
Mark Otto committed
3348
  $(this.element).trigger(hideEvent)
XhmikosR's avatar
XhmikosR committed
3349

Mark Otto's avatar
Mark Otto committed
3350
  if (hideEvent.isDefaultPrevented()) return
XhmikosR's avatar
XhmikosR committed
3351

Mark Otto's avatar
Mark Otto committed
3352
  $(tip).removeClass(Tooltip._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
3353

Mark Otto's avatar
Mark Otto committed
3354
3355
3356
3357
3358
3359
3360
  if (Bootstrap.transition && $(this._tip).hasClass(Tooltip._ClassName.FADE)) {
    $(tip)
      .one(Bootstrap.TRANSITION_END, complete)
      .emulateTransitionEnd(Tooltip._TRANSITION_DURATION)
  } else {
    complete()
  }
XhmikosR's avatar
XhmikosR committed
3361

Mark Otto's avatar
Mark Otto committed
3362
3363
  this._hoverState = ''
}
XhmikosR's avatar
XhmikosR committed
3364
3365


Mark Otto's avatar
Mark Otto committed
3366
3367
3368
3369
3370
3371
/**
 * @return {string}
 */
Tooltip.prototype['getHoverState'] = function (callback) {
  return this._hoverState
}
XhmikosR's avatar
XhmikosR committed
3372
3373


Mark Otto's avatar
Mark Otto committed
3374
3375
3376
3377
3378
3379
3380
/**
 * @return {string}
 * @protected
 */
Tooltip.prototype.getName = function () {
  return Tooltip._NAME
}
XhmikosR's avatar
XhmikosR committed
3381
3382


Mark Otto's avatar
Mark Otto committed
3383
3384
3385
3386
3387
3388
3389
/**
 * @return {string}
 * @protected
 */
Tooltip.prototype.getDataKey = function () {
  return Tooltip._DATA_KEY
}
XhmikosR's avatar
XhmikosR committed
3390
3391


Mark Otto's avatar
Mark Otto committed
3392
3393
3394
3395
3396
3397
3398
/**
 * @return {Object}
 * @protected
 */
Tooltip.prototype.getEventObject = function () {
  return Tooltip._Event
}
XhmikosR's avatar
XhmikosR committed
3399

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3400

Mark Otto's avatar
Mark Otto committed
3401
3402
3403
3404
3405
3406
/**
 * @return {string}
 * @protected
 */
Tooltip.prototype.getTitle = function () {
  var title = this.element.getAttribute('data-original-title')
XhmikosR's avatar
XhmikosR committed
3407

Mark Otto's avatar
Mark Otto committed
3408
3409
3410
3411
  if (!title) {
    title = typeof this.config['title'] === 'function' ?
      this.config['title'].call(this.element) :
      this.config['title']
XhmikosR's avatar
XhmikosR committed
3412
3413
  }

Mark Otto's avatar
Mark Otto committed
3414
3415
  return /** @type {string} */ (title)
}
XhmikosR's avatar
XhmikosR committed
3416
3417


Mark Otto's avatar
Mark Otto committed
3418
3419
3420
3421
3422
3423
3424
/**
 * @return {Element}
 * @protected
 */
Tooltip.prototype.getTipElement = function () {
  return (this._tip = this._tip || $(this.config['template'])[0])
}
XhmikosR's avatar
XhmikosR committed
3425
3426


Mark Otto's avatar
Mark Otto committed
3427
3428
3429
3430
3431
3432
3433
/**
 * @return {Element}
 * @protected
 */
Tooltip.prototype.getArrowElement = function () {
  return (this.arrow = this.arrow || $(this.getTipElement()).find(Tooltip._Selector.TOOLTIP_ARROW)[0])
}
XhmikosR's avatar
XhmikosR committed
3434
3435


Mark Otto's avatar
Mark Otto committed
3436
3437
3438
3439
3440
3441
3442
/**
 * @return {boolean}
 * @protected
 */
Tooltip.prototype.isWithContent = function () {
  return !!this.getTitle()
}
XhmikosR's avatar
XhmikosR committed
3443
3444


Mark Otto's avatar
Mark Otto committed
3445
3446
3447
3448
3449
3450
/**
 * @protected
 */
Tooltip.prototype.setContent = function () {
  var tip   = this.getTipElement()
  var title = this.getTitle()
XhmikosR's avatar
XhmikosR committed
3451

Mark Otto's avatar
Mark Otto committed
3452
  $(tip).find(Tooltip._Selector.TOOLTIP_INNER)[0][this.config['html'] ? 'innerHTML' : 'innerText'] = title
XhmikosR's avatar
XhmikosR committed
3453

Mark Otto's avatar
Mark Otto committed
3454
3455
3456
  $(tip)
    .removeClass(Tooltip._ClassName.FADE)
    .removeClass(Tooltip._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
3457

Mark Otto's avatar
Mark Otto committed
3458
3459
  for (var direction in Tooltip.Direction) {
    $(tip).removeClass(Tooltip._NAME + '-' + direction)
XhmikosR's avatar
XhmikosR committed
3460
  }
Mark Otto's avatar
Mark Otto committed
3461
}
XhmikosR's avatar
XhmikosR committed
3462
3463


Mark Otto's avatar
Mark Otto committed
3464
3465
3466
3467
3468
/**
 * @private
 */
Tooltip.prototype._setListeners = function () {
  var triggers = this.config['trigger'].split(' ')
XhmikosR's avatar
XhmikosR committed
3469

Mark Otto's avatar
Mark Otto committed
3470
3471
3472
  triggers.forEach(function (trigger) {
    if (trigger == 'click') {
      $(this.element).on('click.bs.tooltip', this.config['selector'], this['toggle'].bind(this))
XhmikosR's avatar
XhmikosR committed
3473

Mark Otto's avatar
Mark Otto committed
3474
3475
3476
    } else if (trigger != 'manual') {
      var eventIn  = trigger == 'hover' ? 'mouseenter' : 'focusin'
      var eventOut = trigger == 'hover' ? 'mouseleave' : 'focusout'
XhmikosR's avatar
XhmikosR committed
3477

Mark Otto's avatar
Mark Otto committed
3478
3479
3480
      $(this.element)
        .on(eventIn  + '.bs.tooltip', this.config['selector'], this._enter.bind(this))
        .on(eventOut + '.bs.tooltip', this.config['selector'], this._leave.bind(this))
XhmikosR's avatar
XhmikosR committed
3481
    }
Mark Otto's avatar
Mark Otto committed
3482
  }.bind(this))
XhmikosR's avatar
XhmikosR committed
3483

Mark Otto's avatar
Mark Otto committed
3484
3485
3486
3487
3488
3489
  if (this.config['selector']) {
    this.config = $.extend({}, this.config, { 'trigger': 'manual', 'selector': '' })
  } else {
    this._fixTitle()
  }
}
XhmikosR's avatar
XhmikosR committed
3490
3491


Mark Otto's avatar
Mark Otto committed
3492
3493
3494
3495
3496
3497
3498
/**
 * @param {Object=} opt_config
 * @return {Object}
 * @private
 */
Tooltip.prototype._getConfig = function (opt_config) {
  var config = $.extend({}, this.constructor['Defaults'], $(this.element).data(), opt_config)
XhmikosR's avatar
XhmikosR committed
3499

Mark Otto's avatar
Mark Otto committed
3500
3501
3502
3503
3504
3505
  if (config['delay'] && typeof config['delay'] == 'number') {
    config['delay'] = {
      'show': config['delay'],
      'hide': config['delay']
    }
  }
XhmikosR's avatar
XhmikosR committed
3506

Mark Otto's avatar
Mark Otto committed
3507
3508
  return config
}
XhmikosR's avatar
XhmikosR committed
3509
3510


Mark Otto's avatar
Mark Otto committed
3511
3512
3513
3514
3515
3516
3517
3518
3519
3520
3521
3522
/**
 * @return {Object}
 * @private
 */
Tooltip.prototype._getDelegateConfig = function () {
  var config  = {}
  var defaults = this.constructor['Defaults']

  if (this.config) {
    for (var key in this.config) {
      var value = this.config[key]
      if (defaults[key] != value) config[key] = value
XhmikosR's avatar
XhmikosR committed
3523
3524
3525
    }
  }

Mark Otto's avatar
Mark Otto committed
3526
3527
  return config
}
Mark Otto's avatar
grunt    
Mark Otto committed
3528
3529
3530



Mark Otto's avatar
Mark Otto committed
3531
3532
3533
3534
3535
3536
3537
3538
3539
3540
3541
3542
3543
3544
3545
3546
3547
3548
3549
3550
3551
3552
3553
3554
/**
 * @param {boolean} isWithAutoPlacement
 * @param {string} placement
 * @param {Object} position
 * @param {number} actualWidth
 * @param {number} actualHeight
 * @return {string}
 * @private
 */
Tooltip.prototype._getCalculatedAutoPlacement = function (isWithAutoPlacement, placement, position, actualWidth, actualHeight) {
  if (isWithAutoPlacement) {
    var originalPlacement = placement
    var container         = this.config['container'] ? $(this.config['container'])[0] : this.element.parentNode
    var containerDim      = this._getPosition(/** @type {Element} */ (container))

    placement = placement == Tooltip.Direction.BOTTOM && position.bottom + actualHeight > containerDim.bottom ? Tooltip.Direction.TOP    :
                placement == Tooltip.Direction.TOP    && position.top    - actualHeight < containerDim.top    ? Tooltip.Direction.BOTTOM :
                placement == Tooltip.Direction.RIGHT  && position.right  + actualWidth  > containerDim.width  ? Tooltip.Direction.LEFT   :
                placement == Tooltip.Direction.LEFT   && position.left   - actualWidth  < containerDim.left   ? Tooltip.Direction.RIGHT  :
                placement

    $(this._tip)
      .removeClass(Tooltip._NAME + '-' + originalPlacement)
      .addClass(Tooltip._NAME + '-' + placement)
XhmikosR's avatar
XhmikosR committed
3555
3556
  }

Mark Otto's avatar
Mark Otto committed
3557
3558
  return placement
}
XhmikosR's avatar
XhmikosR committed
3559
3560


Mark Otto's avatar
Mark Otto committed
3561
3562
3563
3564
3565
3566
3567
3568
3569
3570
3571
3572
3573
3574
/**
 * @param {string} placement
 * @param {Object} position
 * @param {number} actualWidth
 * @param {number} actualHeight
 * @return {{left: number, top: number}}
 * @private
 */
Tooltip.prototype._getCalculatedOffset = function (placement, position, actualWidth, actualHeight) {
  return placement == Tooltip.Direction.BOTTOM ? { top: position.top + position.height,   left: position.left + position.width / 2 - actualWidth / 2  } :
         placement == Tooltip.Direction.TOP    ? { top: position.top - actualHeight,      left: position.left + position.width / 2 - actualWidth / 2  } :
         placement == Tooltip.Direction.LEFT   ? { top: position.top + position.height / 2 - actualHeight / 2, left: position.left - actualWidth      } :
      /* placement == Tooltip.Direction.RIGHT */ { top: position.top + position.height / 2 - actualHeight / 2, left: position.left + position.width   }
}
XhmikosR's avatar
XhmikosR committed
3575
3576


Mark Otto's avatar
Mark Otto committed
3577
3578
3579
3580
3581
3582
3583
3584
3585
3586
/**
 * @param {string} placement
 * @param {Object} position
 * @param {number} actualWidth
 * @param {number} actualHeight
 * @return {Object}
 * @private
 */
Tooltip.prototype._getViewportAdjustedDelta = function (placement, position, actualWidth, actualHeight) {
  var delta = { top: 0, left: 0 }
XhmikosR's avatar
XhmikosR committed
3587

Mark Otto's avatar
Mark Otto committed
3588
  if (!this._viewport) {
XhmikosR's avatar
XhmikosR committed
3589
3590
3591
    return delta
  }

Mark Otto's avatar
Mark Otto committed
3592
3593
  var viewportPadding    = this.config['viewport'] && this.config['viewport']['padding'] || 0
  var viewportDimensions = this._getPosition(this._viewport)
XhmikosR's avatar
XhmikosR committed
3594

Mark Otto's avatar
Mark Otto committed
3595
3596
3597
  if (placement === Tooltip.Direction.RIGHT || placement === Tooltip.Direction.LEFT) {
    var topEdgeOffset    = position.top - viewportPadding - viewportDimensions.scroll
    var bottomEdgeOffset = position.top + viewportPadding - viewportDimensions.scroll + actualHeight
XhmikosR's avatar
XhmikosR committed
3598

Mark Otto's avatar
Mark Otto committed
3599
3600
    if (topEdgeOffset < viewportDimensions.top) { // top overflow
      delta.top = viewportDimensions.top - topEdgeOffset
XhmikosR's avatar
XhmikosR committed
3601

Mark Otto's avatar
Mark Otto committed
3602
3603
3604
    } else if (bottomEdgeOffset > viewportDimensions.top + viewportDimensions.height) { // bottom overflow
      delta.top = viewportDimensions.top + viewportDimensions.height - bottomEdgeOffset
    }
XhmikosR's avatar
XhmikosR committed
3605

Mark Otto's avatar
Mark Otto committed
3606
3607
3608
  } else {
    var leftEdgeOffset  = position.left - viewportPadding
    var rightEdgeOffset = position.left + viewportPadding + actualWidth
XhmikosR's avatar
XhmikosR committed
3609

Mark Otto's avatar
Mark Otto committed
3610
3611
    if (leftEdgeOffset < viewportDimensions.left) { // left overflow
      delta.left = viewportDimensions.left - leftEdgeOffset
XhmikosR's avatar
XhmikosR committed
3612

Mark Otto's avatar
Mark Otto committed
3613
3614
3615
    } else if (rightEdgeOffset > viewportDimensions.width) { // right overflow
      delta.left = viewportDimensions.left + viewportDimensions.width - rightEdgeOffset
    }
XhmikosR's avatar
XhmikosR committed
3616
3617
  }

Mark Otto's avatar
Mark Otto committed
3618
3619
  return delta
}
XhmikosR's avatar
XhmikosR committed
3620
3621


Mark Otto's avatar
Mark Otto committed
3622
3623
3624
3625
3626
3627
3628
3629
3630
3631
3632
3633
3634
3635
3636
/**
 * @param {Element=} opt_element
 * @return {Object}
 * @private
 */
Tooltip.prototype._getPosition = function (opt_element) {
  var element   = opt_element || this.element
  var isBody    = element.tagName == 'BODY'
  var rect      = element.getBoundingClientRect()
  var offset    = isBody ? { top: 0, left: 0 } : $(element).offset()
  var scroll    = { scroll: isBody ? document.documentElement.scrollTop || document.body.scrollTop : this.element.scrollTop }
  var outerDims = isBody ? { width: window.innerWidth, height: window.innerHeight } : null

  return $.extend({}, rect, scroll, outerDims, offset)
}
XhmikosR's avatar
XhmikosR committed
3637
3638


Mark Otto's avatar
Mark Otto committed
3639
3640
3641
3642
3643
3644
3645
3646
3647
3648
3649
3650
3651
3652
3653
3654
3655
/**
 * @param {{left: number, top: number}} offset
 * @param {string} placement
 * @private
 */
Tooltip.prototype._applyCalculatedPlacement = function (offset, placement) {
  var tip    = this.getTipElement()
  var width  = tip.offsetWidth
  var height = tip.offsetHeight

  // manually read margins because getBoundingClientRect includes difference
  var marginTop  = parseInt(tip.style.marginTop, 10)
  var marginLeft = parseInt(tip.style.marginLeft, 10)

  // we must check for NaN for ie 8/9
  if (isNaN(marginTop))  {
    marginTop  = 0
XhmikosR's avatar
XhmikosR committed
3656
  }
Mark Otto's avatar
Mark Otto committed
3657
3658
3659
3660
3661
3662
  if (isNaN(marginLeft)) {
    marginLeft = 0
  }

  offset.top  = offset.top  + marginTop
  offset.left = offset.left + marginLeft
XhmikosR's avatar
XhmikosR committed
3663

Mark Otto's avatar
Mark Otto committed
3664
3665
3666
3667
3668
3669
3670
3671
  // $.fn.offset doesn't round pixel values
  // so we use setOffset directly with our own function B-0
  $.offset.setOffset(tip, $.extend({
    using: function (props) {
      tip.style.top  = Math.round(props.top)  + 'px'
      tip.style.left = Math.round(props.left) + 'px'
    }
  }, offset), 0)
XhmikosR's avatar
XhmikosR committed
3672

Mark Otto's avatar
Mark Otto committed
3673
  $(tip).addClass(Tooltip._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
3674

Mark Otto's avatar
Mark Otto committed
3675
3676
3677
  // check to see if placing tip in new offset caused the tip to resize itself
  var actualWidth  = tip.offsetWidth
  var actualHeight = tip.offsetHeight
XhmikosR's avatar
XhmikosR committed
3678

Mark Otto's avatar
Mark Otto committed
3679
3680
  if (placement == Tooltip.Direction.TOP && actualHeight != height) {
    offset.top = offset.top + height - actualHeight
XhmikosR's avatar
XhmikosR committed
3681
3682
  }

Mark Otto's avatar
Mark Otto committed
3683
  var delta = this._getViewportAdjustedDelta(placement, offset, actualWidth, actualHeight)
XhmikosR's avatar
XhmikosR committed
3684

Mark Otto's avatar
Mark Otto committed
3685
3686
3687
3688
3689
  if (delta.left) {
    offset.left += delta.left
  } else {
    offset.top  += delta.top
  }
XhmikosR's avatar
XhmikosR committed
3690

Mark Otto's avatar
Mark Otto committed
3691
3692
3693
  var isVertical          = placement === Tooltip.Direction.TOP || placement === Tooltip.Direction.BOTTOM
  var arrowDelta          = isVertical ? delta.left * 2 - width + actualWidth : delta.top * 2 - height + actualHeight
  var arrowOffsetPosition = isVertical ? 'offsetWidth' : 'offsetHeight'
XhmikosR's avatar
XhmikosR committed
3694

Mark Otto's avatar
Mark Otto committed
3695
  $(tip).offset(offset)
XhmikosR's avatar
XhmikosR committed
3696

Mark Otto's avatar
Mark Otto committed
3697
3698
  this._replaceArrow(arrowDelta, tip[arrowOffsetPosition], isVertical)
}
XhmikosR's avatar
XhmikosR committed
3699
3700


Mark Otto's avatar
Mark Otto committed
3701
3702
3703
3704
3705
3706
3707
3708
/**
 * @param {number} delta
 * @param {number} dimension
 * @param {boolean} isHorizontal
 * @private
 */
Tooltip.prototype._replaceArrow = function (delta, dimension, isHorizontal) {
  var arrow = this.getArrowElement()
XhmikosR's avatar
XhmikosR committed
3709

Mark Otto's avatar
Mark Otto committed
3710
3711
3712
  arrow.style[isHorizontal ? 'left' : 'top'] =  50 * (1 - delta / dimension) + '%'
  arrow.style[isHorizontal ? 'top'  : 'left'] = ''
}
XhmikosR's avatar
XhmikosR committed
3713
3714
3715



Mark Otto's avatar
Mark Otto committed
3716
3717
3718
3719
3720
3721
3722
/**
 * @private
 */
Tooltip.prototype._fixTitle = function () {
  if (this.element.getAttribute('title') || typeof this.element.getAttribute('data-original-title') != 'string') {
    this.element.setAttribute('data-original-title', this.element.getAttribute('title') || '')
    this.element.setAttribute('title', '')
XhmikosR's avatar
XhmikosR committed
3723
  }
Mark Otto's avatar
Mark Otto committed
3724
}
XhmikosR's avatar
XhmikosR committed
3725
3726


Mark Otto's avatar
Mark Otto committed
3727
3728
3729
3730
3731
3732
3733
3734
/**
 * @param {Event=} opt_event
 * @param {Object=} opt_context
 * @private
 */
Tooltip.prototype._enter = function (opt_event, opt_context) {
  var dataKey = this.getDataKey()
  var context = opt_context || $(opt_event.currentTarget).data(dataKey)
XhmikosR's avatar
XhmikosR committed
3735

Mark Otto's avatar
Mark Otto committed
3736
3737
3738
3739
  if (context && context._tip && context._tip.offsetWidth) {
    context._hoverState = Tooltip._HoverState.IN
    return
  }
XhmikosR's avatar
XhmikosR committed
3740

Mark Otto's avatar
Mark Otto committed
3741
3742
3743
3744
  if (!context) {
    context = new this.constructor(opt_event.currentTarget, this._getDelegateConfig())
    $(opt_event.currentTarget).data(dataKey, context)
  }
XhmikosR's avatar
XhmikosR committed
3745

Mark Otto's avatar
Mark Otto committed
3746
  clearTimeout(context._timeout)
XhmikosR's avatar
XhmikosR committed
3747

Mark Otto's avatar
Mark Otto committed
3748
  context._hoverState = Tooltip._HoverState.IN
XhmikosR's avatar
XhmikosR committed
3749

Mark Otto's avatar
Mark Otto committed
3750
3751
3752
  if (!context.config['delay'] || !context.config['delay']['show']) {
    context['show']()
    return
XhmikosR's avatar
XhmikosR committed
3753
3754
  }

Mark Otto's avatar
Mark Otto committed
3755
3756
3757
3758
3759
3760
  context._timeout = setTimeout(function () {
    if (context._hoverState == Tooltip._HoverState.IN) {
      context['show']()
    }
  }, context.config['delay']['show'])
}
XhmikosR's avatar
XhmikosR committed
3761
3762


Mark Otto's avatar
Mark Otto committed
3763
3764
3765
3766
3767
3768
3769
3770
/**
 * @param {Event=} opt_event
 * @param {Object=} opt_context
 * @private
 */
Tooltip.prototype._leave = function (opt_event, opt_context) {
  var dataKey = this.getDataKey()
  var context = opt_context || $(opt_event.currentTarget).data(dataKey)
XhmikosR's avatar
XhmikosR committed
3771

Mark Otto's avatar
Mark Otto committed
3772
3773
3774
  if (!context) {
    context = new this.constructor(opt_event.currentTarget, this._getDelegateConfig())
    $(opt_event.currentTarget).data(dataKey, context)
XhmikosR's avatar
XhmikosR committed
3775
3776
  }

Mark Otto's avatar
Mark Otto committed
3777
  clearTimeout(context._timeout)
XhmikosR's avatar
XhmikosR committed
3778

Mark Otto's avatar
Mark Otto committed
3779
  context._hoverState = Tooltip._HoverState.OUT
XhmikosR's avatar
XhmikosR committed
3780

Mark Otto's avatar
Mark Otto committed
3781
3782
3783
  if (!context.config['delay'] || !context.config['delay']['hide']) {
    context['hide']()
    return
XhmikosR's avatar
XhmikosR committed
3784
3785
  }

Mark Otto's avatar
Mark Otto committed
3786
3787
3788
3789
3790
3791
  context._timeout = setTimeout(function () {
    if (context._hoverState == Tooltip._HoverState.OUT) {
      context['hide']()
    }
  }, context.config['delay']['hide'])
}
XhmikosR's avatar
XhmikosR committed
3792
3793
3794



Mark Otto's avatar
Mark Otto committed
3795
3796
3797
3798
3799
/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
3800

Mark Otto's avatar
Mark Otto committed
3801
3802
3803
3804
3805
/**
 * @const
 * @type {Function}
 */
$.fn[Tooltip._NAME] = Tooltip._jQueryInterface
XhmikosR's avatar
XhmikosR committed
3806
3807


Mark Otto's avatar
Mark Otto committed
3808
3809
3810
3811
3812
/**
 * @const
 * @type {Function}
 */
$.fn[Tooltip._NAME]['Constructor'] = Tooltip
XhmikosR's avatar
XhmikosR committed
3813
3814


Mark Otto's avatar
Mark Otto committed
3815
3816
3817
3818
3819
3820
3821
3822
/**
 * @const
 * @type {Function}
 */
$.fn[Tooltip._NAME]['noConflict'] = function () {
  $.fn[Tooltip._NAME] = Tooltip._JQUERY_NO_CONFLICT
  return this
}
XhmikosR's avatar
XhmikosR committed
3823

Mark Otto's avatar
Mark Otto committed
3824
3825
3826
/** =======================================================================
 * Bootstrap: popover.js v4.0.0
 * http://getbootstrap.com/javascript/#popovers
XhmikosR's avatar
XhmikosR committed
3827
 * ========================================================================
Mark Otto's avatar
Mark Otto committed
3828
 * Copyright 2011-2015 Twitter, Inc.
XhmikosR's avatar
XhmikosR committed
3829
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
Mark Otto's avatar
Mark Otto committed
3830
3831
3832
3833
3834
3835
3836
3837
3838
3839
3840
3841
3842
3843
3844
3845
3846
3847
3848
3849
3850
3851
3852
3853
3854
3855
3856
3857
3858
3859
3860
3861
3862
 * ========================================================================
 * @fileoverview - Bootstrap's popover plugin - extends tooltip.
 *
 * Public Methods & Properties:
 *
 *   + $.popover
 *   + $.popover.noConflict
 *   + $.popover.Constructor
 *   + $.popover.Constructor.VERSION
 *   + $.popover.Constructor.Defaults
 *   + $.popover.Constructor.Defaults.container
 *   + $.popover.Constructor.Defaults.animation
 *   + $.popover.Constructor.Defaults.placement
 *   + $.popover.Constructor.Defaults.selector
 *   + $.popover.Constructor.Defaults.template
 *   + $.popover.Constructor.Defaults.trigger
 *   + $.popover.Constructor.Defaults.title
 *   + $.popover.Constructor.Defaults.content
 *   + $.popover.Constructor.Defaults.delay
 *   + $.popover.Constructor.Defaults.html
 *   + $.popover.Constructor.Defaults.viewport
 *   + $.popover.Constructor.Defaults.viewport.selector
 *   + $.popover.Constructor.Defaults.viewport.padding
 *   + $.popover.Constructor.prototype.enable
 *   + $.popover.Constructor.prototype.disable
 *   + $.popover.Constructor.prototype.destroy
 *   + $.popover.Constructor.prototype.toggleEnabled
 *   + $.popover.Constructor.prototype.toggle
 *   + $.popover.Constructor.prototype.show
 *   + $.popover.Constructor.prototype.hide
 *
 * ========================================================================
 */
XhmikosR's avatar
XhmikosR committed
3863
3864


Mark Otto's avatar
Mark Otto committed
3865
'use strict';
XhmikosR's avatar
XhmikosR committed
3866
3867


Mark Otto's avatar
Mark Otto committed
3868
if (!Tooltip) throw new Error('Popover requires tooltip.js')
XhmikosR's avatar
XhmikosR committed
3869
3870


Mark Otto's avatar
Mark Otto committed
3871
3872
3873
3874
3875
3876
3877
3878
3879
3880
3881
/**
 * Our tooltip class.
 * @param {Element!} element
 * @param {Object=} opt_config
 * @constructor
 * @extends {Tooltip}
 */
var Popover = function (element, opt_config) {
  Tooltip.apply(this, arguments)
}
Bootstrap.inherits(Popover, Tooltip)
XhmikosR's avatar
XhmikosR committed
3882
3883


Mark Otto's avatar
Mark Otto committed
3884
3885
3886
3887
3888
/**
 * @const
 * @type {string}
 */
Popover['VERSION'] = '4.0.0'
XhmikosR's avatar
XhmikosR committed
3889

XhmikosR's avatar
XhmikosR committed
3890

Mark Otto's avatar
Mark Otto committed
3891
3892
3893
3894
3895
3896
3897
3898
3899
3900
3901
3902
3903
3904
3905
3906
3907
3908
/**
 * @const
 * @type {Object}
 */
Popover['Defaults'] = $.extend({}, $.fn['tooltip']['Constructor']['Defaults'], {
  'placement': 'right',
  'trigger': 'click',
  'content': '',
  'template': '<div class="popover" role="tooltip"><div class="popover-arrow"></div><h3 class="popover-title"></h3><div class="popover-content"></div></div>'
})


/**
 * @const
 * @type {string}
 * @private
 */
Popover._NAME = 'popover'
XhmikosR's avatar
XhmikosR committed
3909
3910


Mark Otto's avatar
Mark Otto committed
3911
3912
3913
3914
3915
3916
/**
 * @const
 * @type {string}
 * @private
 */
Popover._DATA_KEY = 'bs.popover'
XhmikosR's avatar
XhmikosR committed
3917
3918


Mark Otto's avatar
Mark Otto committed
3919
3920
3921
3922
3923
3924
3925
3926
3927
3928
3929
/**
 * @const
 * @enum {string}
 * @private
 */
Popover._Event = {
  HIDE   : 'hide.bs.popover',
  HIDDEN : 'hidden.bs.popover',
  SHOW   : 'show.bs.popover',
  SHOWN  : 'shown.bs.popover'
}
XhmikosR's avatar
XhmikosR committed
3930
3931


Mark Otto's avatar
Mark Otto committed
3932
3933
3934
3935
3936
3937
3938
3939
3940
/**
 * @const
 * @enum {string}
 * @private
 */
Popover._ClassName = {
  FADE : 'fade',
  IN  : 'in'
}
XhmikosR's avatar
XhmikosR committed
3941
3942


Mark Otto's avatar
Mark Otto committed
3943
3944
3945
3946
3947
3948
3949
3950
3951
3952
/**
 * @const
 * @enum {string}
 * @private
 */
Popover._Selector = {
  TITLE   : '.popover-title',
  CONTENT : '.popover-content',
  ARROW   : '.popover-arrow'
}
XhmikosR's avatar
XhmikosR committed
3953
3954


Mark Otto's avatar
Mark Otto committed
3955
3956
3957
3958
3959
3960
/**
 * @const
 * @type {Function}
 * @private
 */
Popover._JQUERY_NO_CONFLICT = $.fn[Popover._NAME]
XhmikosR's avatar
XhmikosR committed
3961
3962


Mark Otto's avatar
Mark Otto committed
3963
3964
3965
3966
3967
3968
3969
3970
3971
3972
/**
 * @param {Object|string=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Popover._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var data   = $(this).data(Popover._DATA_KEY)
    var config = typeof opt_config === 'object' ? opt_config : null
XhmikosR's avatar
XhmikosR committed
3973

Mark Otto's avatar
Mark Otto committed
3974
3975
    if (!data && opt_config === 'destroy') {
      return
XhmikosR's avatar
XhmikosR committed
3976
3977
    }

Mark Otto's avatar
Mark Otto committed
3978
3979
3980
3981
    if (!data) {
      data = new Popover(this, config)
      $(this).data(Popover._DATA_KEY, data)
    }
XhmikosR's avatar
XhmikosR committed
3982

Mark Otto's avatar
Mark Otto committed
3983
3984
3985
3986
3987
    if (typeof opt_config === 'string') {
      data[opt_config]()
    }
  })
}
Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
3988

XhmikosR's avatar
XhmikosR committed
3989

Mark Otto's avatar
Mark Otto committed
3990
3991
3992
3993
3994
3995
3996
/**
 * @return {string}
 * @protected
 */
Popover.prototype.getName = function () {
  return Popover._NAME
}
XhmikosR's avatar
XhmikosR committed
3997
3998


Mark Otto's avatar
Mark Otto committed
3999
4000
4001
4002
4003
4004
4005
/**
 * @override
 */
Popover.prototype.getDataKey = function () {
  return Popover._DATA_KEY
}

XhmikosR's avatar
XhmikosR committed
4006

Mark Otto's avatar
Mark Otto committed
4007
4008
4009
4010
4011
4012
/**
 * @override
 */
Popover.prototype.getEventObject = function () {
  return Popover._Event
}
XhmikosR's avatar
XhmikosR committed
4013
4014


Mark Otto's avatar
Mark Otto committed
4015
4016
4017
4018
4019
4020
/**
 * @override
 */
Popover.prototype.getArrowElement = function () {
  return (this.arrow = this.arrow || $(this.getTipElement()).find(Popover._Selector.ARROW)[0])
}
XhmikosR's avatar
XhmikosR committed
4021
4022


Mark Otto's avatar
Mark Otto committed
4023
4024
4025
4026
4027
4028
4029
4030
4031
4032
4033
/**
 * @override
 */
Popover.prototype.setContent = function () {
  var tip          = this.getTipElement()
  var title        = this.getTitle()
  var content      = this._getContent()
  var titleElement = $(tip).find(Popover._Selector.TITLE)[0]

  if (titleElement) {
    titleElement[this.config['html'] ? 'innerHTML' : 'innerText'] = title
XhmikosR's avatar
XhmikosR committed
4034
4035
  }

Mark Otto's avatar
Mark Otto committed
4036
4037
4038
4039
  // we use append for html objects to maintain js events
  $(tip).find(Popover._Selector.CONTENT).children().detach().end()[
    this.config['html'] ? (typeof content == 'string' ? 'html' : 'append') : 'text'
  ](content)
XhmikosR's avatar
XhmikosR committed
4040

Mark Otto's avatar
Mark Otto committed
4041
4042
4043
  $(tip)
    .removeClass(Popover._ClassName.FADE)
    .removeClass(Popover._ClassName.IN)
XhmikosR's avatar
XhmikosR committed
4044

Mark Otto's avatar
Mark Otto committed
4045
4046
4047
4048
  for (var direction in Tooltip.Direction) {
    $(tip).removeClass(Popover._NAME + '-' + Tooltip.Direction[direction])
  }
}
XhmikosR's avatar
XhmikosR committed
4049
4050


Mark Otto's avatar
Mark Otto committed
4051
4052
4053
4054
4055
4056
/**
 * @override
 */
Popover.prototype.isWithContent = function () {
  return this.getTitle() || this._getContent()
}
XhmikosR's avatar
XhmikosR committed
4057
4058


Mark Otto's avatar
Mark Otto committed
4059
4060
4061
4062
4063
4064
/**
 * @override
 */
Popover.prototype.getTipElement = function () {
  return (this.tip = this.tip || $(this.config['template'])[0])
}
XhmikosR's avatar
XhmikosR committed
4065
4066


Mark Otto's avatar
Mark Otto committed
4067
4068
4069
4070
4071
4072
4073
4074
4075
/**
 * @private
 */
Popover.prototype._getContent = function () {
  return this.element.getAttribute('data-content')
    || (typeof this.config['content'] == 'function' ?
          this.config['content'].call(this.element) :
          this.config['content'])
}
XhmikosR's avatar
XhmikosR committed
4076
4077


4078

Mark Otto's avatar
Mark Otto committed
4079
4080
4081
4082
4083
/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
4084

Mark Otto's avatar
Mark Otto committed
4085
4086
4087
4088
4089
/**
 * @const
 * @type {Function}
 */
$.fn[Popover._NAME] = Popover._jQueryInterface
XhmikosR's avatar
XhmikosR committed
4090
4091


Mark Otto's avatar
Mark Otto committed
4092
4093
4094
4095
4096
/**
 * @const
 * @type {Function}
 */
$.fn[Popover._NAME]['Constructor'] = Popover
XhmikosR's avatar
XhmikosR committed
4097
4098


Mark Otto's avatar
Mark Otto committed
4099
4100
4101
4102
4103
4104
4105
4106
/**
 * @const
 * @type {Function}
 */
$.fn[Popover._NAME]['noConflict'] = function () {
  $.fn[Popover._NAME] = Popover._JQUERY_NO_CONFLICT
  return this
}
XhmikosR's avatar
XhmikosR committed
4107

Mark Otto's avatar
Mark Otto committed
4108
4109
4110
4111
4112
4113
4114
4115
4116
4117
4118
4119
4120
4121
4122
4123
4124
4125
4126
/** =======================================================================
 * Bootstrap: tab.js v4.0.0
 * http://getbootstrap.com/javascript/#tabs
 * ========================================================================
 * Copyright 2011-2015 Twitter, Inc.
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
 * ========================================================================
 * @fileoverview - Bootstrap's tab plugin. Tab O_O
 *
 * Public Methods & Properties:
 *
 *   + $.tab
 *   + $.tab.noConflict
 *   + $.tab.Constructor
 *   + $.tab.Constructor.VERSION
 *   + $.tab.Constructor.prototype.show
 *
 * ========================================================================
 */
XhmikosR's avatar
XhmikosR committed
4127
4128


Mark Otto's avatar
Mark Otto committed
4129
'use strict';
XhmikosR's avatar
XhmikosR committed
4130

Mark Otto's avatar
Mark Otto committed
4131
4132
4133
4134
4135
4136
/**
 * Our Tab class.
 * @param {Element!} element
 * @constructor
 */
var Tab = function (element) {
XhmikosR's avatar
XhmikosR committed
4137

Mark Otto's avatar
Mark Otto committed
4138
4139
  /** @type {Element} */
  this._element = element
XhmikosR's avatar
XhmikosR committed
4140

Mark Otto's avatar
Mark Otto committed
4141
}
XhmikosR's avatar
XhmikosR committed
4142
4143


Mark Otto's avatar
Mark Otto committed
4144
4145
4146
4147
4148
/**
 * @const
 * @type {string}
 */
Tab['VERSION'] = '4.0.0'
XhmikosR's avatar
XhmikosR committed
4149
4150


Mark Otto's avatar
Mark Otto committed
4151
4152
4153
4154
4155
4156
/**
 * @const
 * @type {string}
 * @private
 */
Tab._NAME = 'tab'
XhmikosR's avatar
XhmikosR committed
4157
4158


Mark Otto's avatar
Mark Otto committed
4159
4160
4161
4162
4163
4164
/**
 * @const
 * @type {string}
 * @private
 */
Tab._DATA_KEY = 'bs.tab'
XhmikosR's avatar
XhmikosR committed
4165
4166


Mark Otto's avatar
Mark Otto committed
4167
4168
4169
4170
4171
4172
/**
 * @const
 * @type {number}
 * @private
 */
Tab._TRANSITION_DURATION = 150
XhmikosR's avatar
XhmikosR committed
4173
4174


Mark Otto's avatar
Mark Otto committed
4175
4176
4177
4178
4179
4180
4181
4182
4183
4184
4185
/**
 * @const
 * @enum {string}
 * @private
 */
Tab._Event = {
  HIDE   : 'hide.bs.tab',
  HIDDEN : 'hidden.bs.tab',
  SHOW   : 'show.bs.tab',
  SHOWN  : 'shown.bs.tab'
}
XhmikosR's avatar
XhmikosR committed
4186
4187


Mark Otto's avatar
Mark Otto committed
4188
4189
4190
4191
4192
4193
4194
4195
4196
4197
4198
/**
 * @const
 * @enum {string}
 * @private
 */
Tab._ClassName = {
  DROPDOWN_MENU : 'dropdown-menu',
  ACTIVE        : 'active',
  FADE          : 'fade',
  IN            : 'in'
}
XhmikosR's avatar
XhmikosR committed
4199

Heinrich Fenkart's avatar
grunt    
Heinrich Fenkart committed
4200

Mark Otto's avatar
Mark Otto committed
4201
4202
4203
4204
4205
4206
4207
4208
4209
4210
4211
4212
4213
4214
4215
4216
/**
 * @const
 * @enum {string}
 * @private
 */
Tab._Selector = {
  A                     : 'a',
  LI                    : 'li',
  LI_DROPDOWN           : 'li.dropdown',
  UL                    : 'ul:not(.dropdown-menu)',
  FADE_CHILD            : ':scope > .fade',
  ACTIVE                : '.active',
  ACTIVE_CHILD          : ':scope > .active',
  DATA_TOGGLE           : '[data-toggle="tab"], [data-toggle="pill"]',
  DROPDOWN_ACTIVE_CHILD : ':scope > .dropdown-menu > .active'
}
XhmikosR's avatar
XhmikosR committed
4217
4218


Mark Otto's avatar
Mark Otto committed
4219
4220
4221
4222
4223
4224
4225
4226
4227
4228
/**
 * @param {Object|string=} opt_config
 * @this {jQuery}
 * @return {jQuery}
 * @private
 */
Tab._jQueryInterface = function (opt_config) {
  return this.each(function () {
    var $this = $(this)
    var data  = $this.data(Tab._DATA_KEY)
XhmikosR's avatar
XhmikosR committed
4229

Mark Otto's avatar
Mark Otto committed
4230
4231
4232
4233
    if (!data) {
      data = data = new Tab(this)
      $this.data(Tab._DATA_KEY, data)
    }
XhmikosR's avatar
XhmikosR committed
4234

Mark Otto's avatar
Mark Otto committed
4235
4236
4237
4238
4239
    if (typeof opt_config === 'string') {
      data[opt_config]()
    }
  })
}
XhmikosR's avatar
XhmikosR committed
4240
4241


Mark Otto's avatar
Mark Otto committed
4242
4243
4244
4245
4246
4247
4248
4249
4250
/**
 * Show the tab
 */
Tab.prototype['show'] = function () {
  if ( this._element.parentNode
    && this._element.parentNode.nodeType == Node.ELEMENT_NODE
    && $(this._element).parent().hasClass(Tab._ClassName.ACTIVE)) {
    return
  }
XhmikosR's avatar
XhmikosR committed
4251

Mark Otto's avatar
Mark Otto committed
4252
4253
  var ulElement = $(this._element).closest(Tab._Selector.UL)[0]
  var selector  = Bootstrap.getSelectorFromElement(this._element)
XhmikosR's avatar
XhmikosR committed
4254

Mark Otto's avatar
Mark Otto committed
4255
4256
4257
  if (ulElement) {
    var previous = /** @type {Array.<Element>} */ ($.makeArray($(ulElement).find(Tab._Selector.ACTIVE)))
    previous = previous[previous.length - 1]
XhmikosR's avatar
XhmikosR committed
4258

Mark Otto's avatar
Mark Otto committed
4259
4260
4261
    if (previous) {
      previous = $(previous).find('a')[0]
    }
XhmikosR's avatar
XhmikosR committed
4262
4263
  }

Mark Otto's avatar
Mark Otto committed
4264
4265
4266
  var hideEvent = $.Event(Tab._Event.HIDE, {
    relatedTarget: this._element
  })
XhmikosR's avatar
XhmikosR committed
4267

Mark Otto's avatar
Mark Otto committed
4268
4269
4270
  var showEvent = $.Event(Tab._Event.SHOW, {
    relatedTarget: previous
  })
XhmikosR's avatar
XhmikosR committed
4271

Mark Otto's avatar
Mark Otto committed
4272
4273
  if (previous) {
    $(previous).trigger(hideEvent)
XhmikosR's avatar
XhmikosR committed
4274
4275
  }

Mark Otto's avatar
Mark Otto committed
4276
  $(this._element).trigger(showEvent)
4277

Mark Otto's avatar
Mark Otto committed
4278
  if (showEvent.isDefaultPrevented() || hideEvent.isDefaultPrevented()) return
4279

Mark Otto's avatar
Mark Otto committed
4280
4281
4282
  if (selector) {
    var target = $(selector)[0]
  }
4283

Mark Otto's avatar
Mark Otto committed
4284
  this._activate($(this._element).closest(Tab._Selector.LI)[0], ulElement)
4285

Mark Otto's avatar
Mark Otto committed
4286
4287
4288
4289
  var complete = function () {
    var hiddenEvent = $.Event(Tab._Event.HIDDEN, {
      relatedTarget: this._element
    })
4290

Mark Otto's avatar
Mark Otto committed
4291
4292
4293
    var shownEvent  = $.Event(Tab._Event.SHOWN, {
      relatedTarget: previous
    })
4294

Mark Otto's avatar
Mark Otto committed
4295
4296
4297
    $(previous).trigger(hiddenEvent)
    $(this._element).trigger(shownEvent)
  }.bind(this)
XhmikosR's avatar
XhmikosR committed
4298

Mark Otto's avatar
Mark Otto committed
4299
4300
4301
4302
  if (target) {
    this._activate(target, /** @type {Element} */ (target.parentNode), complete)
  } else {
    complete()
XhmikosR's avatar
XhmikosR committed
4303
  }
Mark Otto's avatar
Mark Otto committed
4304
}
XhmikosR's avatar
XhmikosR committed
4305
4306


Mark Otto's avatar
Mark Otto committed
4307
4308
4309
4310
4311
4312
4313
4314
4315
4316
4317
4318
4319
4320
4321
4322
4323
4324
4325
4326
4327
4328
4329
4330
4331
4332
4333
4334
/**
 * @param {Element} element
 * @param {Element} container
 * @param {Function=} opt_callback
 * @private
 */
Tab.prototype._activate = function (element, container, opt_callback) {
  var active          = $(container).find(Tab._Selector.ACTIVE_CHILD)[0]
  var isTransitioning = opt_callback
    && Bootstrap.transition
    && ((active && $(active).hasClass(Tab._ClassName.FADE))
       || !!$(container).find(Tab._Selector.FADE_CHILD)[0])

  var complete = this._transitionComplete.bind(this, element, active, isTransitioning, opt_callback)

  if (active && isTransitioning) {
    $(active)
      .one(Bootstrap.TRANSITION_END, complete)
      .emulateTransitionEnd(Tab._TRANSITION_DURATION)

  } else {
    complete()
  }

  if (active) {
    $(active).removeClass(Tab._ClassName.IN)
  }
}
XhmikosR's avatar
XhmikosR committed
4335
4336


Mark Otto's avatar
Mark Otto committed
4337
4338
4339
4340
4341
4342
4343
4344
4345
4346
/**
 * @param {Element} element
 * @param {Element} active
 * @param {boolean} isTransitioning
 * @param {Function=} opt_callback
 * @private
 */
Tab.prototype._transitionComplete = function (element, active, isTransitioning, opt_callback) {
  if (active) {
    $(active).removeClass(Tab._ClassName.ACTIVE)
XhmikosR's avatar
XhmikosR committed
4347

Mark Otto's avatar
Mark Otto committed
4348
4349
4350
4351
    var dropdownChild = $(active).find(Tab._Selector.DROPDOWN_ACTIVE_CHILD)[0]
    if (dropdownChild) {
      $(dropdownChild).removeClass(Tab._ClassName.ACTIVE)
    }
XhmikosR's avatar
XhmikosR committed
4352

Mark Otto's avatar
Mark Otto committed
4353
4354
4355
4356
4357
    var activeToggle = $(active).find(Tab._Selector.DATA_TOGGLE)[0]
    if (activeToggle) {
      activeToggle.setAttribute('aria-expanded', false)
    }
  }
XhmikosR's avatar
XhmikosR committed
4358

Mark Otto's avatar
Mark Otto committed
4359
  $(element).addClass(Tab._ClassName.ACTIVE)
XhmikosR's avatar
XhmikosR committed
4360

Mark Otto's avatar
Mark Otto committed
4361
4362
4363
4364
  var elementToggle = $(element).find(Tab._Selector.DATA_TOGGLE)[0]
  if (elementToggle) {
    elementToggle.setAttribute('aria-expanded', true)
  }
XhmikosR's avatar
XhmikosR committed
4365

Mark Otto's avatar
Mark Otto committed
4366
4367
4368
4369
4370
4371
  if (isTransitioning) {
    Bootstrap.reflow(element)
    $(element).addClass(Tab._ClassName.IN)
  } else {
    $(element).removeClass(Tab._ClassName.FADE)
  }
XhmikosR's avatar
XhmikosR committed
4372

Mark Otto's avatar
Mark Otto committed
4373
4374
4375
4376
  if (element.parentNode && $(element.parentNode).hasClass(Tab._ClassName.DROPDOWN_MENU)) {
    var dropdownElement = $(element).closest(Tab._Selector.LI_DROPDOWN)[0]
    if (dropdownElement) {
      $(dropdownElement).addClass(Tab._ClassName.ACTIVE)
4377
    }
XhmikosR's avatar
XhmikosR committed
4378

Mark Otto's avatar
Mark Otto committed
4379
4380
4381
    elementToggle = $(element).find(Tab._Selector.DATA_TOGGLE)[0]
    if (elementToggle) {
      elementToggle.setAttribute('aria-expanded', true)
XhmikosR's avatar
XhmikosR committed
4382
4383
4384
    }
  }

Mark Otto's avatar
Mark Otto committed
4385
4386
  if (opt_callback) {
    opt_callback()
XhmikosR's avatar
XhmikosR committed
4387
  }
Mark Otto's avatar
Mark Otto committed
4388
}
XhmikosR's avatar
XhmikosR committed
4389
4390


Mark Otto's avatar
Mark Otto committed
4391
4392
4393
4394
4395
/**
 * ------------------------------------------------------------------------
 * jQuery Interface + noConflict implementaiton
 * ------------------------------------------------------------------------
 */
XhmikosR's avatar
XhmikosR committed
4396

Mark Otto's avatar
Mark Otto committed
4397
4398
4399
4400
4401
/**
 * @const
 * @type {Function}
 */
$.fn[Tab._NAME] = Tab._jQueryInterface
XhmikosR's avatar
XhmikosR committed
4402
4403


Mark Otto's avatar
Mark Otto committed
4404
4405
4406
4407
4408
/**
 * @const
 * @type {Function}
 */
$.fn[Tab._NAME]['Constructor'] = Tab
XhmikosR's avatar
XhmikosR committed
4409
4410


Mark Otto's avatar
Mark Otto committed
4411
4412
4413
4414
4415
4416
4417
4418
/**
 * @const
 * @type {Function}
 */
$.fn[Tab._NAME]['noConflict'] = function () {
  $.fn[Tab._NAME] = Tab._JQUERY_NO_CONFLICT
  return this
}
XhmikosR's avatar
XhmikosR committed
4419
4420
4421



Mark Otto's avatar
Mark Otto committed
4422
4423
// TAB DATA-API
// ============
XhmikosR's avatar
XhmikosR committed
4424

Mark Otto's avatar
Mark Otto committed
4425
4426
4427
4428
var clickHandler = function (e) {
  e.preventDefault()
  Tab._jQueryInterface.call($(this), 'show')
}
XhmikosR's avatar
XhmikosR committed
4429

Mark Otto's avatar
Mark Otto committed
4430
4431
$(document)
  .on('click.bs.tab.data-api', Tab._Selector.DATA_TOGGLE, clickHandler)