bootstrap.js 101 KB
Newer Older
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.
Mark Otto's avatar
Mark Otto committed
4
 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
Jacob Thornton's avatar
Jacob Thornton committed
5
6
 */

7
8
'use strict';

Jacob Thornton's avatar
Jacob Thornton committed
9
if (typeof jQuery === 'undefined') {
10
  throw new Error('Bootstrap\'s JavaScript requires jQuery');
Jacob Thornton's avatar
Jacob Thornton committed
11
12
}

13
14
15
16
+(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');
Jacob Thornton's avatar
Jacob Thornton committed
17
  }
18
})(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
19

20
+(function ($) {
Jacob Thornton's avatar
Jacob Thornton committed
21

22
23
24
25
26
27
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.0.0): util.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
Jacob Thornton's avatar
Jacob Thornton committed
28

29
  'use strict';
Jacob Thornton's avatar
Jacob Thornton committed
30

31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
  var _get = function get(_x, _x2, _x3) {
    var _again = true;_function: while (_again) {
      var object = _x,
          property = _x2,
          receiver = _x3;desc = parent = getter = undefined;_again = false;if (object === null) object = Function.prototype;var desc = Object.getOwnPropertyDescriptor(object, property);if (desc === undefined) {
        var parent = Object.getPrototypeOf(object);if (parent === null) {
          return undefined;
        } else {
          _x = parent;_x2 = property;_x3 = receiver;_again = true;continue _function;
        }
      } else if ('value' in desc) {
        return desc.value;
      } else {
        var getter = desc.get;if (getter === undefined) {
          return undefined;
        }return getter.call(receiver);
      }
    }
  };
Jacob Thornton's avatar
Jacob Thornton committed
50

51
52
53
54
55
56
57
58
59
  var _createClass = (function () {
    function defineProperties(target, props) {
      for (var i = 0; i < props.length; i++) {
        var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ('value' in descriptor) descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);
      }
    }return function (Constructor, protoProps, staticProps) {
      if (protoProps) defineProperties(Constructor.prototype, protoProps);if (staticProps) defineProperties(Constructor, staticProps);return Constructor;
    };
  })();
Jacob Thornton's avatar
Jacob Thornton committed
60

61
62
63
64
65
  function _inherits(subClass, superClass) {
    if (typeof superClass !== 'function' && superClass !== null) {
      throw new TypeError('Super expression must either be null or a function, not ' + typeof superClass);
    }subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } });if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass;
  }
Jacob Thornton's avatar
Jacob Thornton committed
66

67
68
69
70
71
  function _classCallCheck(instance, Constructor) {
    if (!(instance instanceof Constructor)) {
      throw new TypeError('Cannot call a class as a function');
    }
  }
Jacob Thornton's avatar
Jacob Thornton committed
72

73
  var Util = (function ($) {
Jacob Thornton's avatar
Jacob Thornton committed
74

75
76
77
78
79
    /**
     * ------------------------------------------------------------------------
     * Private TransitionEnd Helpers
     * ------------------------------------------------------------------------
     */
Jacob Thornton's avatar
Jacob Thornton committed
80

81
    var transition = false;
Jacob Thornton's avatar
Jacob Thornton committed
82

83
84
85
86
87
88
    var TransitionEndEvent = {
      WebkitTransition: 'webkitTransitionEnd',
      MozTransition: 'transitionend',
      OTransition: 'oTransitionEnd otransitionend',
      transition: 'transitionend'
    };
Jacob Thornton's avatar
Jacob Thornton committed
89

90
91
92
93
    // shoutout AngusCroll (https://goo.gl/pxwQGp)
    function toType(obj) {
      return ({}).toString.call(obj).match(/\s([a-zA-Z]+)/)[1].toLowerCase();
    }
Jacob Thornton's avatar
Jacob Thornton committed
94

95
96
97
    function isElement(obj) {
      return (obj[0] || obj).nodeType;
    }
Jacob Thornton's avatar
Jacob Thornton committed
98

99
100
101
102
103
104
105
106
    function getSpecialTransitionEndEvent() {
      return {
        bindType: transition.end,
        delegateType: transition.end,
        handle: function handle(event) {
          if ($(event.target).is(this)) {
            return event.handleObj.handler.apply(this, arguments);
          }
Jacob Thornton's avatar
Jacob Thornton committed
107
        }
108
      };
Jacob Thornton's avatar
Jacob Thornton committed
109
110
    }

111
112
113
114
    function transitionEndTest() {
      if (window.QUnit) {
        return false;
      }
Jacob Thornton's avatar
Jacob Thornton committed
115

116
117
118
119
120
121
      var el = document.createElement('bootstrap');

      for (var _name in TransitionEndEvent) {
        if (el.style[_name] !== undefined) {
          return { end: TransitionEndEvent[_name] };
        }
Jacob Thornton's avatar
Jacob Thornton committed
122
123
      }

124
125
      return false;
    }
Jacob Thornton's avatar
Jacob Thornton committed
126

127
128
    function transitionEndEmulator(duration) {
      var _this = this;
Jacob Thornton's avatar
Jacob Thornton committed
129

130
      var called = false;
Jacob Thornton's avatar
Jacob Thornton committed
131

132
133
134
      $(this).one(Util.TRANSITION_END, function () {
        called = true;
      });
Jacob Thornton's avatar
Jacob Thornton committed
135

136
137
138
139
140
      setTimeout(function () {
        if (!called) {
          Util.triggerTransitionEnd(_this);
        }
      }, duration);
Jacob Thornton's avatar
Jacob Thornton committed
141

142
143
      return this;
    }
Jacob Thornton's avatar
Jacob Thornton committed
144

145
146
    function setTransitionEndSupport() {
      transition = transitionEndTest();
Jacob Thornton's avatar
Jacob Thornton committed
147

148
      $.fn.emulateTransitionEnd = transitionEndEmulator;
Jacob Thornton's avatar
Jacob Thornton committed
149

150
151
152
      if (Util.supportsTransitionEnd()) {
        $.event.special[Util.TRANSITION_END] = getSpecialTransitionEndEvent();
      }
Jacob Thornton's avatar
Jacob Thornton committed
153
154
    }

155
156
157
158
159
    /**
     * --------------------------------------------------------------------------
     * Public Util Api
     * --------------------------------------------------------------------------
     */
Jacob Thornton's avatar
Jacob Thornton committed
160

161
    var Util = {
Jacob Thornton's avatar
Jacob Thornton committed
162

163
      TRANSITION_END: 'bsTransitionEnd',
Jacob Thornton's avatar
Jacob Thornton committed
164

165
166
167
168
169
170
      getUID: function getUID(prefix) {
        do {
          prefix += ~ ~(Math.random() * 1000000);
        } while (document.getElementById(prefix));
        return prefix;
      },
Jacob Thornton's avatar
Jacob Thornton committed
171

172
173
      getSelectorFromElement: function getSelectorFromElement(element) {
        var selector = element.getAttribute('data-target');
Jacob Thornton's avatar
Jacob Thornton committed
174

175
176
177
178
        if (!selector) {
          selector = element.getAttribute('href') || '';
          selector = /^#[a-z]/i.test(selector) ? selector : null;
        }
Jacob Thornton's avatar
Jacob Thornton committed
179

180
181
        return selector;
      },
Jacob Thornton's avatar
Jacob Thornton committed
182

183
184
185
      reflow: function reflow(element) {
        new Function('bs', 'return bs')(element.offsetHeight);
      },
Jacob Thornton's avatar
Jacob Thornton committed
186

187
188
189
      triggerTransitionEnd: function triggerTransitionEnd(element) {
        $(element).trigger(transition.end);
      },
Jacob Thornton's avatar
Jacob Thornton committed
190

191
192
193
      supportsTransitionEnd: function supportsTransitionEnd() {
        return Boolean(transition);
      },
Jacob Thornton's avatar
Jacob Thornton committed
194

195
196
197
198
199
200
      typeCheckConfig: function typeCheckConfig(componentName, config, configTypes) {
        for (var property in configTypes) {
          if (configTypes.hasOwnProperty(property)) {
            var expectedTypes = configTypes[property];
            var value = config[property];
            var valueType = undefined;
Jacob Thornton's avatar
Jacob Thornton committed
201

202
203
204
205
206
            if (value && isElement(value)) {
              valueType = 'element';
            } else {
              valueType = toType(value);
            }
Jacob Thornton's avatar
Jacob Thornton committed
207

208
209
210
            if (!new RegExp(expectedTypes).test(valueType)) {
              throw new Error(componentName.toUpperCase() + ': ' + ('Option "' + property + '" provided type "' + valueType + '" ') + ('but expected type "' + expectedTypes + '".'));
            }
Jacob Thornton's avatar
Jacob Thornton committed
211
          }
Jacob Thornton's avatar
Jacob Thornton committed
212
213
        }
      }
214
    };
Jacob Thornton's avatar
Jacob Thornton committed
215

216
    setTransitionEndSupport();
Jacob Thornton's avatar
Jacob Thornton committed
217

218
219
    return Util;
  })(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
220
221

  /**
222
223
224
225
   * --------------------------------------------------------------------------
   * Bootstrap (v4.0.0): alert.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
Jacob Thornton's avatar
Jacob Thornton committed
226
227
   */

228
  var Alert = (function ($) {
Jacob Thornton's avatar
Jacob Thornton committed
229

230
231
232
233
234
    /**
     * ------------------------------------------------------------------------
     * Constants
     * ------------------------------------------------------------------------
     */
Jacob Thornton's avatar
Jacob Thornton committed
235

236
237
238
239
240
241
242
    var NAME = 'alert';
    var VERSION = '4.0.0';
    var DATA_KEY = 'bs.alert';
    var EVENT_KEY = '.' + DATA_KEY;
    var DATA_API_KEY = '.data-api';
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    var TRANSITION_DURATION = 150;
Jacob Thornton's avatar
Jacob Thornton committed
243

244
245
246
    var Selector = {
      DISMISS: '[data-dismiss="alert"]'
    };
Jacob Thornton's avatar
Jacob Thornton committed
247

248
249
250
251
252
    var Event = {
      CLOSE: 'close' + EVENT_KEY,
      CLOSED: 'closed' + EVENT_KEY,
      CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
    };
Jacob Thornton's avatar
Jacob Thornton committed
253

254
255
256
257
258
    var ClassName = {
      ALERT: 'alert',
      FADE: 'fade',
      IN: 'in'
    };
Jacob Thornton's avatar
Jacob Thornton committed
259
260
261

    /**
     * ------------------------------------------------------------------------
262
     * Class Definition
Jacob Thornton's avatar
Jacob Thornton committed
263
264
265
     * ------------------------------------------------------------------------
     */

266
267
268
    var Alert = (function () {
      function Alert(element) {
        _classCallCheck(this, Alert);
Jacob Thornton's avatar
Jacob Thornton committed
269

270
271
        this._element = element;
      }
Jacob Thornton's avatar
Jacob Thornton committed
272

273
274
275
276
277
      /**
       * ------------------------------------------------------------------------
       * Data Api implementation
       * ------------------------------------------------------------------------
       */
Jacob Thornton's avatar
Jacob Thornton committed
278

279
      // getters
Jacob Thornton's avatar
Jacob Thornton committed
280

281
282
      _createClass(Alert, [{
        key: 'close',
Jacob Thornton's avatar
Jacob Thornton committed
283

284
        // public
Jacob Thornton's avatar
Jacob Thornton committed
285

286
287
        value: function close(element) {
          element = element || this._element;
Jacob Thornton's avatar
Jacob Thornton committed
288

289
290
          var rootElement = this._getRootElement(element);
          var customEvent = this._triggerCloseEvent(rootElement);
Jacob Thornton's avatar
Jacob Thornton committed
291

292
293
294
          if (customEvent.isDefaultPrevented()) {
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
295

296
          this._removeElement(rootElement);
Jacob Thornton's avatar
Jacob Thornton committed
297
        }
298
299
300
301
302
      }, {
        key: 'dispose',
        value: function dispose() {
          $.removeData(this._element, DATA_KEY);
          this._element = null;
Jacob Thornton's avatar
Jacob Thornton committed
303
304
        }

305
        // private
Jacob Thornton's avatar
Jacob Thornton committed
306

307
308
309
310
311
      }, {
        key: '_getRootElement',
        value: function _getRootElement(element) {
          var selector = Util.getSelectorFromElement(element);
          var parent = false;
Jacob Thornton's avatar
Jacob Thornton committed
312

313
314
315
          if (selector) {
            parent = $(selector)[0];
          }
Jacob Thornton's avatar
Jacob Thornton committed
316

317
318
319
          if (!parent) {
            parent = $(element).closest('.' + ClassName.ALERT)[0];
          }
Jacob Thornton's avatar
Jacob Thornton committed
320

321
322
323
324
325
326
          return parent;
        }
      }, {
        key: '_triggerCloseEvent',
        value: function _triggerCloseEvent(element) {
          var closeEvent = $.Event(Event.CLOSE);
Jacob Thornton's avatar
Jacob Thornton committed
327

328
329
330
331
332
333
334
          $(element).trigger(closeEvent);
          return closeEvent;
        }
      }, {
        key: '_removeElement',
        value: function _removeElement(element) {
          $(element).removeClass(ClassName.IN);
Jacob Thornton's avatar
Jacob Thornton committed
335

336
337
338
          if (!Util.supportsTransitionEnd() || !$(element).hasClass(ClassName.FADE)) {
            this._destroyElement(element);
            return;
Jacob Thornton's avatar
Jacob Thornton committed
339
340
          }

341
342
343
344
345
346
347
          $(element).one(Util.TRANSITION_END, $.proxy(this._destroyElement, this, element)).emulateTransitionEnd(TRANSITION_DURATION);
        }
      }, {
        key: '_destroyElement',
        value: function _destroyElement(element) {
          $(element).detach().trigger(Event.CLOSED).remove();
        }
Jacob Thornton's avatar
Jacob Thornton committed
348

349
        // static
Jacob Thornton's avatar
Jacob Thornton committed
350

351
352
353
354
355
356
      }], [{
        key: '_jQueryInterface',
        value: function _jQueryInterface(config) {
          return this.each(function () {
            var $element = $(this);
            var data = $element.data(DATA_KEY);
Jacob Thornton's avatar
Jacob Thornton committed
357

358
359
360
361
            if (!data) {
              data = new Alert(this);
              $element.data(DATA_KEY, data);
            }
Jacob Thornton's avatar
Jacob Thornton committed
362

363
364
365
366
367
368
369
370
371
372
373
374
            if (config === 'close') {
              data[config](this);
            }
          });
        }
      }, {
        key: '_handleDismiss',
        value: function _handleDismiss(alertInstance) {
          return function (event) {
            if (event) {
              event.preventDefault();
            }
Jacob Thornton's avatar
Jacob Thornton committed
375

376
377
378
379
380
381
382
383
384
            alertInstance.close(this);
          };
        }
      }, {
        key: 'VERSION',
        get: function get() {
          return VERSION;
        }
      }]);
Jacob Thornton's avatar
Jacob Thornton committed
385

386
387
      return Alert;
    })();
Jacob Thornton's avatar
Jacob Thornton committed
388

389
390
391
392
393
394
395
396
397
398
399
400
401
402
    $(document).on(Event.CLICK_DATA_API, Selector.DISMISS, Alert._handleDismiss(new Alert()));

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

    $.fn[NAME] = Alert._jQueryInterface;
    $.fn[NAME].Constructor = Alert;
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Alert._jQueryInterface;
    };
Jacob Thornton's avatar
Jacob Thornton committed
403

404
405
    return Alert;
  })(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
406
407

  /**
408
409
410
411
   * --------------------------------------------------------------------------
   * Bootstrap (v4.0.0): button.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
Jacob Thornton's avatar
Jacob Thornton committed
412
413
   */

414
  var Button = (function ($) {
Jacob Thornton's avatar
Jacob Thornton committed
415

416
417
418
419
420
    /**
     * ------------------------------------------------------------------------
     * Constants
     * ------------------------------------------------------------------------
     */
Jacob Thornton's avatar
Jacob Thornton committed
421

422
423
424
425
426
427
428
429
430
431
432
433
    var NAME = 'button';
    var VERSION = '4.0.0';
    var DATA_KEY = 'bs.button';
    var EVENT_KEY = '.' + DATA_KEY;
    var DATA_API_KEY = '.data-api';
    var JQUERY_NO_CONFLICT = $.fn[NAME];

    var ClassName = {
      ACTIVE: 'active',
      BUTTON: 'btn',
      FOCUS: 'focus'
    };
Jacob Thornton's avatar
Jacob Thornton committed
434

435
436
437
438
439
440
441
    var Selector = {
      DATA_TOGGLE_CARROT: '[data-toggle^="button"]',
      DATA_TOGGLE: '[data-toggle="buttons"]',
      INPUT: 'input',
      ACTIVE: '.active',
      BUTTON: '.btn'
    };
Jacob Thornton's avatar
Jacob Thornton committed
442

443
444
445
446
    var Event = {
      CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY,
      FOCUS_BLUR_DATA_API: 'focus' + EVENT_KEY + DATA_API_KEY + ' ' + ('blur' + EVENT_KEY + DATA_API_KEY)
    };
Jacob Thornton's avatar
Jacob Thornton committed
447
448
449

    /**
     * ------------------------------------------------------------------------
450
     * Class Definition
Jacob Thornton's avatar
Jacob Thornton committed
451
452
453
     * ------------------------------------------------------------------------
     */

454
455
456
    var Button = (function () {
      function Button(element) {
        _classCallCheck(this, Button);
Jacob Thornton's avatar
Jacob Thornton committed
457

458
459
        this._element = element;
      }
Jacob Thornton's avatar
Jacob Thornton committed
460

461
462
463
464
465
      /**
       * ------------------------------------------------------------------------
       * Data Api implementation
       * ------------------------------------------------------------------------
       */
Jacob Thornton's avatar
Jacob Thornton committed
466

467
      // getters
Jacob Thornton's avatar
Jacob Thornton committed
468

469
470
      _createClass(Button, [{
        key: 'toggle',
Jacob Thornton's avatar
Jacob Thornton committed
471

472
        // public
Jacob Thornton's avatar
Jacob Thornton committed
473

474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
        value: function toggle() {
          var triggerChangeEvent = true;
          var rootElement = $(this._element).closest(Selector.DATA_TOGGLE)[0];

          if (rootElement) {
            var input = $(this._element).find(Selector.INPUT)[0];

            if (input) {
              if (input.type === 'radio') {
                if (input.checked && $(this._element).hasClass(ClassName.ACTIVE)) {
                  triggerChangeEvent = false;
                } else {
                  var activeElement = $(rootElement).find(Selector.ACTIVE)[0];

                  if (activeElement) {
                    $(activeElement).removeClass(ClassName.ACTIVE);
                  }
Jacob Thornton's avatar
Jacob Thornton committed
491
492
493
                }
              }

494
495
496
497
              if (triggerChangeEvent) {
                input.checked = !$(this._element).hasClass(ClassName.ACTIVE);
                $(this._element).trigger('change');
              }
Jacob Thornton's avatar
Jacob Thornton committed
498
            }
499
500
          } else {
            this._element.setAttribute('aria-pressed', !$(this._element).hasClass(ClassName.ACTIVE));
Jacob Thornton's avatar
Jacob Thornton committed
501
502
          }

503
504
505
506
507
508
509
510
511
          if (triggerChangeEvent) {
            $(this._element).toggleClass(ClassName.ACTIVE);
          }
        }
      }, {
        key: 'dispose',
        value: function dispose() {
          $.removeData(this._element, DATA_KEY);
          this._element = null;
Jacob Thornton's avatar
Jacob Thornton committed
512
513
        }

514
        // static
Jacob Thornton's avatar
Jacob Thornton committed
515

516
517
518
519
520
      }], [{
        key: '_jQueryInterface',
        value: function _jQueryInterface(config) {
          return this.each(function () {
            var data = $(this).data(DATA_KEY);
Jacob Thornton's avatar
Jacob Thornton committed
521

522
523
524
525
            if (!data) {
              data = new Button(this);
              $(this).data(DATA_KEY, data);
            }
Jacob Thornton's avatar
Jacob Thornton committed
526

527
528
529
530
531
532
533
534
535
536
537
            if (config === 'toggle') {
              data[config]();
            }
          });
        }
      }, {
        key: 'VERSION',
        get: function get() {
          return VERSION;
        }
      }]);
Jacob Thornton's avatar
Jacob Thornton committed
538

539
540
      return Button;
    })();
Jacob Thornton's avatar
Jacob Thornton committed
541

542
543
    $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
      event.preventDefault();
Jacob Thornton's avatar
Jacob Thornton committed
544

545
      var button = event.target;
Jacob Thornton's avatar
Jacob Thornton committed
546

547
548
549
      if (!$(button).hasClass(ClassName.BUTTON)) {
        button = $(button).closest(Selector.BUTTON);
      }
Jacob Thornton's avatar
Jacob Thornton committed
550

551
552
553
554
555
      Button._jQueryInterface.call($(button), 'toggle');
    }).on(Event.FOCUS_BLUR_DATA_API, Selector.DATA_TOGGLE_CARROT, function (event) {
      var button = $(event.target).closest(Selector.BUTTON)[0];
      $(button).toggleClass(ClassName.FOCUS, /^focus(in)?$/.test(event.type));
    });
Jacob Thornton's avatar
Jacob Thornton committed
556

557
558
559
560
561
    /**
     * ------------------------------------------------------------------------
     * jQuery
     * ------------------------------------------------------------------------
     */
Jacob Thornton's avatar
Jacob Thornton committed
562

563
564
565
566
567
568
    $.fn[NAME] = Button._jQueryInterface;
    $.fn[NAME].Constructor = Button;
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Button._jQueryInterface;
    };
Jacob Thornton's avatar
Jacob Thornton committed
569

570
571
    return Button;
  })(jQuery);
Jacob Thornton's avatar
Jacob Thornton committed
572
573

  /**
574
575
576
577
   * --------------------------------------------------------------------------
   * Bootstrap (v4.0.0): carousel.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
Jacob Thornton's avatar
Jacob Thornton committed
578
579
   */

580
  var Carousel = (function ($) {
Jacob Thornton's avatar
Jacob Thornton committed
581

582
583
584
585
586
    /**
     * ------------------------------------------------------------------------
     * Constants
     * ------------------------------------------------------------------------
     */
Jacob Thornton's avatar
Jacob Thornton committed
587

588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
    var NAME = 'carousel';
    var VERSION = '4.0.0';
    var DATA_KEY = 'bs.carousel';
    var EVENT_KEY = '.' + DATA_KEY;
    var DATA_API_KEY = '.data-api';
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    var TRANSITION_DURATION = 600;

    var Default = {
      interval: 5000,
      keyboard: true,
      slide: false,
      pause: 'hover',
      wrap: true
    };
Jacob Thornton's avatar
Jacob Thornton committed
603

604
605
606
607
608
609
610
    var DefaultType = {
      interval: '(number|boolean)',
      keyboard: 'boolean',
      slide: '(boolean|string)',
      pause: '(string|boolean)',
      wrap: 'boolean'
    };
Jacob Thornton's avatar
Jacob Thornton committed
611

612
613
614
615
    var Direction = {
      NEXT: 'next',
      PREVIOUS: 'prev'
    };
Jacob Thornton's avatar
Jacob Thornton committed
616

617
618
619
620
621
622
623
624
625
    var Event = {
      SLIDE: 'slide' + EVENT_KEY,
      SLID: 'slid' + EVENT_KEY,
      KEYDOWN: 'keydown' + EVENT_KEY,
      MOUSEENTER: 'mouseenter' + EVENT_KEY,
      MOUSELEAVE: 'mouseleave' + EVENT_KEY,
      LOAD_DATA_API: 'load' + EVENT_KEY + DATA_API_KEY,
      CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
    };
Jacob Thornton's avatar
Jacob Thornton committed
626

627
628
629
630
631
632
633
634
    var ClassName = {
      CAROUSEL: 'carousel',
      ACTIVE: 'active',
      SLIDE: 'slide',
      RIGHT: 'right',
      LEFT: 'left',
      ITEM: 'carousel-item'
    };
Jacob Thornton's avatar
Jacob Thornton committed
635

636
637
638
639
640
641
642
643
644
    var Selector = {
      ACTIVE: '.active',
      ACTIVE_ITEM: '.active.carousel-item',
      ITEM: '.carousel-item',
      NEXT_PREV: '.next, .prev',
      INDICATORS: '.carousel-indicators',
      DATA_SLIDE: '[data-slide], [data-slide-to]',
      DATA_RIDE: '[data-ride="carousel"]'
    };
Jacob Thornton's avatar
Jacob Thornton committed
645
646
647

    /**
     * ------------------------------------------------------------------------
648
     * Class Definition
Jacob Thornton's avatar
Jacob Thornton committed
649
650
651
     * ------------------------------------------------------------------------
     */

652
653
654
    var Carousel = (function () {
      function Carousel(element, config) {
        _classCallCheck(this, Carousel);
Jacob Thornton's avatar
Jacob Thornton committed
655

656
657
658
        this._items = null;
        this._interval = null;
        this._activeElement = null;
Jacob Thornton's avatar
Jacob Thornton committed
659

660
661
        this._isPaused = false;
        this._isSliding = false;
Jacob Thornton's avatar
Jacob Thornton committed
662

663
664
665
        this._config = this._getConfig(config);
        this._element = $(element)[0];
        this._indicatorsElement = $(this._element).find(Selector.INDICATORS)[0];
Jacob Thornton's avatar
Jacob Thornton committed
666

667
        this._addEventListeners();
Jacob Thornton's avatar
Jacob Thornton committed
668
669
      }

670
671
672
673
674
      /**
       * ------------------------------------------------------------------------
       * Data Api implementation
       * ------------------------------------------------------------------------
       */
Jacob Thornton's avatar
Jacob Thornton committed
675

676
      // getters
Jacob Thornton's avatar
Jacob Thornton committed
677

678
679
      _createClass(Carousel, [{
        key: 'next',
Jacob Thornton's avatar
Jacob Thornton committed
680

681
        // public
Jacob Thornton's avatar
Jacob Thornton committed
682

683
684
685
686
        value: function next() {
          if (!this._isSliding) {
            this._slide(Direction.NEXT);
          }
Jacob Thornton's avatar
Jacob Thornton committed
687
        }
688
689
690
691
692
693
      }, {
        key: 'prev',
        value: function prev() {
          if (!this._isSliding) {
            this._slide(Direction.PREVIOUS);
          }
Jacob Thornton's avatar
Jacob Thornton committed
694
        }
695
696
697
698
699
700
      }, {
        key: 'pause',
        value: function pause(event) {
          if (!event) {
            this._isPaused = true;
          }
Jacob Thornton's avatar
Jacob Thornton committed
701

702
703
704
705
          if ($(this._element).find(Selector.NEXT_PREV)[0] && Util.supportsTransitionEnd()) {
            Util.triggerTransitionEnd(this._element);
            this.cycle(true);
          }
Jacob Thornton's avatar
Jacob Thornton committed
706

707
708
709
710
711
712
713
714
715
          clearInterval(this._interval);
          this._interval = null;
        }
      }, {
        key: 'cycle',
        value: function cycle(event) {
          if (!event) {
            this._isPaused = false;
          }
Jacob Thornton's avatar
Jacob Thornton committed
716

717
718
719
720
          if (this._interval) {
            clearInterval(this._interval);
            this._interval = null;
          }
Jacob Thornton's avatar
Jacob Thornton committed
721

722
723
724
725
726
727
728
729
          if (this._config.interval && !this._isPaused) {
            this._interval = setInterval($.proxy(this.next, this), this._config.interval);
          }
        }
      }, {
        key: 'to',
        value: function to(index) {
          var _this2 = this;
Jacob Thornton's avatar
Jacob Thornton committed
730

731
          this._activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
Jacob Thornton's avatar
Jacob Thornton committed
732

733
          var activeIndex = this._getItemIndex(this._activeElement);
Jacob Thornton's avatar
Jacob Thornton committed
734

735
736
737
          if (index > this._items.length - 1 || index < 0) {
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
738

739
740
741
742
743
744
          if (this._isSliding) {
            $(this._element).one(Event.SLID, function () {
              return _this2.to(index);
            });
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
745

746
747
748
          if (activeIndex === index) {
            this.pause();
            this.cycle();
Jacob Thornton's avatar
Jacob Thornton committed
749
            return;
750
751
752
          }

          var direction = index > activeIndex ? Direction.NEXT : Direction.PREVIOUS;
Jacob Thornton's avatar
Jacob Thornton committed
753

754
          this._slide(direction, this._items[index]);
Jacob Thornton's avatar
Jacob Thornton committed
755
        }
756
757
758
759
760
      }, {
        key: 'dispose',
        value: function dispose() {
          $(this._element).off(EVENT_KEY);
          $.removeData(this._element, DATA_KEY);
Jacob Thornton's avatar
Jacob Thornton committed
761

762
763
764
765
766
767
768
769
770
          this._items = null;
          this._config = null;
          this._element = null;
          this._interval = null;
          this._isPaused = null;
          this._isSliding = null;
          this._activeElement = null;
          this._indicatorsElement = null;
        }
Jacob Thornton's avatar
Jacob Thornton committed
771

772
        // private
Jacob Thornton's avatar
Jacob Thornton committed
773

774
775
776
777
778
779
780
781
782
783
784
785
786
      }, {
        key: '_getConfig',
        value: function _getConfig(config) {
          config = $.extend({}, Default, config);
          Util.typeCheckConfig(NAME, config, DefaultType);
          return config;
        }
      }, {
        key: '_addEventListeners',
        value: function _addEventListeners() {
          if (this._config.keyboard) {
            $(this._element).on(Event.KEYDOWN, $.proxy(this._keydown, this));
          }
Jacob Thornton's avatar
Jacob Thornton committed
787

788
789
790
791
792
793
794
795
          if (this._config.pause === 'hover' && !('ontouchstart' in document.documentElement)) {
            $(this._element).on(Event.MOUSEENTER, $.proxy(this.pause, this)).on(Event.MOUSELEAVE, $.proxy(this.cycle, this));
          }
        }
      }, {
        key: '_keydown',
        value: function _keydown(event) {
          event.preventDefault();
Jacob Thornton's avatar
Jacob Thornton committed
796

797
798
799
          if (/input|textarea/i.test(event.target.tagName)) {
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
800

801
802
803
804
805
806
807
          switch (event.which) {
            case 37:
              this.prev();break;
            case 39:
              this.next();break;
            default:
              return;
Jacob Thornton's avatar
Jacob Thornton committed
808
809
          }
        }
810
811
812
813
814
815
816
817
818
819
820
821
822
823
      }, {
        key: '_getItemIndex',
        value: function _getItemIndex(element) {
          this._items = $.makeArray($(element).parent().find(Selector.ITEM));
          return this._items.indexOf(element);
        }
      }, {
        key: '_getItemByDirection',
        value: function _getItemByDirection(direction, activeElement) {
          var isNextDirection = direction === Direction.NEXT;
          var isPrevDirection = direction === Direction.PREVIOUS;
          var activeIndex = this._getItemIndex(activeElement);
          var lastItemIndex = this._items.length - 1;
          var isGoingToWrap = isPrevDirection && activeIndex === 0 || isNextDirection && activeIndex === lastItemIndex;
Jacob Thornton's avatar
Jacob Thornton committed
824

825
826
827
          if (isGoingToWrap && !this._config.wrap) {
            return activeElement;
          }
Jacob Thornton's avatar
Jacob Thornton committed
828

829
830
          var delta = direction === Direction.PREVIOUS ? -1 : 1;
          var itemIndex = (activeIndex + delta) % this._items.length;
Jacob Thornton's avatar
Jacob Thornton committed
831

832
          return itemIndex === -1 ? this._items[this._items.length - 1] : this._items[itemIndex];
Jacob Thornton's avatar
Jacob Thornton committed
833
        }
834
835
836
837
838
839
840
      }, {
        key: '_triggerSlideEvent',
        value: function _triggerSlideEvent(relatedTarget, directionalClassname) {
          var slideEvent = $.Event(Event.SLIDE, {
            relatedTarget: relatedTarget,
            direction: directionalClassname
          });
Jacob Thornton's avatar
Jacob Thornton committed
841

842
          $(this._element).trigger(slideEvent);
Jacob Thornton's avatar
Jacob Thornton committed
843

844
          return slideEvent;
Jacob Thornton's avatar
Jacob Thornton committed
845
        }
846
847
848
849
850
      }, {
        key: '_setActiveIndicatorElement',
        value: function _setActiveIndicatorElement(element) {
          if (this._indicatorsElement) {
            $(this._indicatorsElement).find(Selector.ACTIVE).removeClass(ClassName.ACTIVE);
Jacob Thornton's avatar
Jacob Thornton committed
851

852
            var nextIndicator = this._indicatorsElement.children[this._getItemIndex(element)];
Jacob Thornton's avatar
Jacob Thornton committed
853

854
855
856
857
            if (nextIndicator) {
              $(nextIndicator).addClass(ClassName.ACTIVE);
            }
          }
Jacob Thornton's avatar
Jacob Thornton committed
858
        }
859
860
861
862
      }, {
        key: '_slide',
        value: function _slide(direction, element) {
          var _this3 = this;
Jacob Thornton's avatar
Jacob Thornton committed
863

864
865
          var activeElement = $(this._element).find(Selector.ACTIVE_ITEM)[0];
          var nextElement = element || activeElement && this._getItemByDirection(direction, activeElement);
Jacob Thornton's avatar
Jacob Thornton committed
866

867
868
869
870
871
872
873
874
          var isCycling = Boolean(this._interval);

          var directionalClassName = direction === Direction.NEXT ? ClassName.LEFT : ClassName.RIGHT;

          if (nextElement && $(nextElement).hasClass(ClassName.ACTIVE)) {
            this._isSliding = false;
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
875

876
877
878
879
          var slideEvent = this._triggerSlideEvent(nextElement, directionalClassName);
          if (slideEvent.isDefaultPrevented()) {
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
880

881
882
883
884
          if (!activeElement || !nextElement) {
            // some weirdness is happening, so we bail
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
885

886
          this._isSliding = true;
Jacob Thornton's avatar
Jacob Thornton committed
887

888
889
890
          if (isCycling) {
            this.pause();
          }
Jacob Thornton's avatar
Jacob Thornton committed
891

892
          this._setActiveIndicatorElement(nextElement);
Jacob Thornton's avatar
Jacob Thornton committed
893

894
895
896
897
          var slidEvent = $.Event(Event.SLID, {
            relatedTarget: nextElement,
            direction: directionalClassName
          });
Jacob Thornton's avatar
Jacob Thornton committed
898

899
          if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.SLIDE)) {
Jacob Thornton's avatar
Jacob Thornton committed
900

901
            $(nextElement).addClass(direction);
Jacob Thornton's avatar
Jacob Thornton committed
902

903
            Util.reflow(nextElement);
Jacob Thornton's avatar
Jacob Thornton committed
904

905
906
            $(activeElement).addClass(directionalClassName);
            $(nextElement).addClass(directionalClassName);
Jacob Thornton's avatar
Jacob Thornton committed
907

908
909
            $(activeElement).one(Util.TRANSITION_END, function () {
              $(nextElement).removeClass(directionalClassName).removeClass(direction);
Jacob Thornton's avatar
Jacob Thornton committed
910

911
              $(nextElement).addClass(ClassName.ACTIVE);
Jacob Thornton's avatar
Jacob Thornton committed
912

913
              $(activeElement).removeClass(ClassName.ACTIVE).removeClass(direction).removeClass(directionalClassName);
Jacob Thornton's avatar
Jacob Thornton committed
914

915
              _this3._isSliding = false;
Jacob Thornton's avatar
Jacob Thornton committed
916

917
918
919
920
921
922
923
              setTimeout(function () {
                return $(_this3._element).trigger(slidEvent);
              }, 0);
            }).emulateTransitionEnd(TRANSITION_DURATION);
          } else {
            $(activeElement).removeClass(ClassName.ACTIVE);
            $(nextElement).addClass(ClassName.ACTIVE);
Jacob Thornton's avatar
Jacob Thornton committed
924

925
926
            this._isSliding = false;
            $(this._element).trigger(slidEvent);
Jacob Thornton's avatar
Jacob Thornton committed
927
928
          }

929
930
          if (isCycling) {
            this.cycle();
Jacob Thornton's avatar
Jacob Thornton committed
931
932
933
          }
        }

934
        // static
Jacob Thornton's avatar
Jacob Thornton committed
935

936
937
938
939
940
941
      }], [{
        key: '_jQueryInterface',
        value: function _jQueryInterface(config) {
          return this.each(function () {
            var data = $(this).data(DATA_KEY);
            var _config = $.extend({}, Default, $(this).data());
Jacob Thornton's avatar
Jacob Thornton committed
942

943
944
945
            if (typeof config === 'object') {
              $.extend(_config, config);
            }
Jacob Thornton's avatar
Jacob Thornton committed
946

947
            var action = typeof config === 'string' ? config : _config.slide;
Jacob Thornton's avatar
Jacob Thornton committed
948

949
950
951
952
            if (!data) {
              data = new Carousel(this, _config);
              $(this).data(DATA_KEY, data);
            }
Jacob Thornton's avatar
Jacob Thornton committed
953

954
955
956
957
958
959
960
961
962
            if (typeof config === 'number') {
              data.to(config);
            } else if (action) {
              data[action]();
            } else if (_config.interval) {
              data.pause();
              data.cycle();
            }
          });
Jacob Thornton's avatar
Jacob Thornton committed
963
        }
964
965
966
967
      }, {
        key: '_dataApiClickHandler',
        value: function _dataApiClickHandler(event) {
          var selector = Util.getSelectorFromElement(this);
Jacob Thornton's avatar
Jacob Thornton committed
968

969
970
971
          if (!selector) {
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
972

973
          var target = $(selector)[0];
Jacob Thornton's avatar
Jacob Thornton committed
974

975
976
977
          if (!target || !$(target).hasClass(ClassName.CAROUSEL)) {
            return;
          }
Jacob Thornton's avatar
Jacob Thornton committed
978

979
980
          var config = $.extend({}, $(target).data(), $(this).data());
          var slideIndex = this.getAttribute('data-slide-to');
Jacob Thornton's avatar
Jacob Thornton committed
981

982
983
984
          if (slideIndex) {
            config.interval = false;
          }
Jacob Thornton's avatar
Jacob Thornton committed
985

986
          Carousel._jQueryInterface.call($(target), config);
Jacob Thornton's avatar
Jacob Thornton committed
987

988
989
990
          if (slideIndex) {
            $(target).data(DATA_KEY).to(slideIndex);
          }
Jacob Thornton's avatar
Jacob Thornton committed
991

992
993
994
995
996
997
998
999
1000
          event.preventDefault();
        }
      }, {
        key: 'VERSION',
        get: function get() {
          return VERSION;
        }
      }, {
        key: 'Default',
For faster browsing, not all history is shown. View entire blame