modal.js 25.1 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
/*!
XhmikosR's avatar
XhmikosR committed
2
  * Bootstrap modal.js v4.3.1 (https://getbootstrap.com/)
Mark Otto's avatar
Mark Otto committed
3
  * Copyright 2011-2019 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
XhmikosR's avatar
Dist    
XhmikosR committed
4
5
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
(function (global, factory) {
7
8
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('../dom/data.js'), require('../dom/event-handler.js'), require('../dom/manipulator.js'), require('../dom/selector-engine.js')) :
  typeof define === 'function' && define.amd ? define(['../dom/data.js', '../dom/event-handler.js', '../dom/manipulator.js', '../dom/selector-engine.js'], factory) :
XhmikosR's avatar
XhmikosR committed
9
10
  (global = global || self, global.Modal = factory(global.Data, global.EventHandler, global.Manipulator, global.SelectorEngine));
}(this, function (Data, EventHandler, Manipulator, SelectorEngine) { 'use strict';
Mark Otto's avatar
dist    
Mark Otto committed
11

XhmikosR's avatar
XhmikosR committed
12
13
14
15
  Data = Data && Data.hasOwnProperty('default') ? Data['default'] : Data;
  EventHandler = EventHandler && EventHandler.hasOwnProperty('default') ? EventHandler['default'] : EventHandler;
  Manipulator = Manipulator && Manipulator.hasOwnProperty('default') ? Manipulator['default'] : Manipulator;
  SelectorEngine = SelectorEngine && SelectorEngine.hasOwnProperty('default') ? SelectorEngine['default'] : SelectorEngine;
Mark Otto's avatar
dist    
Mark Otto committed
16
17
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

  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);
    }
  }

  function _createClass(Constructor, protoProps, staticProps) {
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
    if (staticProps) _defineProperties(Constructor, staticProps);
    return Constructor;
  }

  function _defineProperty(obj, key, value) {
    if (key in obj) {
      Object.defineProperty(obj, key, {
        value: value,
        enumerable: true,
        configurable: true,
        writable: true
      });
    } else {
      obj[key] = value;
    }
Mark Otto's avatar
dist    
Mark Otto committed
44

Mark Otto's avatar
dist    
Mark Otto committed
45
46
    return obj;
  }
Mark Otto's avatar
dist    
Mark Otto committed
47

48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
  function ownKeys(object, enumerableOnly) {
    var keys = Object.keys(object);

    if (Object.getOwnPropertySymbols) {
      var symbols = Object.getOwnPropertySymbols(object);
      if (enumerableOnly) symbols = symbols.filter(function (sym) {
        return Object.getOwnPropertyDescriptor(object, sym).enumerable;
      });
      keys.push.apply(keys, symbols);
    }

    return keys;
  }

  function _objectSpread2(target) {
Mark Otto's avatar
dist    
Mark Otto committed
63
64
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
Mark Otto's avatar
dist    
Mark Otto committed
65

66
67
68
69
70
71
72
73
74
75
      if (i % 2) {
        ownKeys(source, true).forEach(function (key) {
          _defineProperty(target, key, source[key]);
        });
      } else if (Object.getOwnPropertyDescriptors) {
        Object.defineProperties(target, Object.getOwnPropertyDescriptors(source));
      } else {
        ownKeys(source).forEach(function (key) {
          Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key));
        });
Mark Otto's avatar
dist    
Mark Otto committed
76
77
78
79
80
      }
    }

    return target;
  }
81

XhmikosR's avatar
XhmikosR committed
82
83
84
85
86
87
88
  /**
   * --------------------------------------------------------------------------
   * Bootstrap (v4.3.1): util/index.js
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
   */
  var MILLISECONDS_MULTIPLIER = 1000;
XhmikosR's avatar
XhmikosR committed
89
  var TRANSITION_END = 'transitionend'; // Shoutout AngusCroll (https://goo.gl/pxwQGp)
XhmikosR's avatar
XhmikosR committed
90
91
92
93
94

  var toType = function toType(obj) {
    return {}.toString.call(obj).match(/\s([a-z]+)/i)[1].toLowerCase();
  };

XhmikosR's avatar
XhmikosR committed
95
  var getSelector = function getSelector(element) {
XhmikosR's avatar
XhmikosR committed
96
97
98
99
    var selector = element.getAttribute('data-target');

    if (!selector || selector === '#') {
      var hrefAttr = element.getAttribute('href');
XhmikosR's avatar
XhmikosR committed
100
      selector = hrefAttr && hrefAttr !== '#' ? hrefAttr.trim() : null;
XhmikosR's avatar
XhmikosR committed
101
102
    }

XhmikosR's avatar
XhmikosR committed
103
104
105
106
107
108
    return selector;
  };

  var getElementFromSelector = function getElementFromSelector(element) {
    var selector = getSelector(element);
    return selector ? document.querySelector(selector) : null;
XhmikosR's avatar
XhmikosR committed
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
  };

  var getTransitionDurationFromElement = function getTransitionDurationFromElement(element) {
    if (!element) {
      return 0;
    } // Get transition-duration of the element


    var _window$getComputedSt = window.getComputedStyle(element),
        transitionDuration = _window$getComputedSt.transitionDuration,
        transitionDelay = _window$getComputedSt.transitionDelay;

    var floatTransitionDuration = parseFloat(transitionDuration);
    var floatTransitionDelay = parseFloat(transitionDelay); // Return 0 if element or transition duration is not found

    if (!floatTransitionDuration && !floatTransitionDelay) {
      return 0;
    } // If multiple durations are defined, take the first


    transitionDuration = transitionDuration.split(',')[0];
    transitionDelay = transitionDelay.split(',')[0];
    return (parseFloat(transitionDuration) + parseFloat(transitionDelay)) * MILLISECONDS_MULTIPLIER;
  };

  var triggerTransitionEnd = function triggerTransitionEnd(element) {
XhmikosR's avatar
XhmikosR committed
135
136
137
    var evt = document.createEvent('HTMLEvents');
    evt.initEvent(TRANSITION_END, true, true);
    element.dispatchEvent(evt);
XhmikosR's avatar
XhmikosR committed
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
  };

  var isElement = function isElement(obj) {
    return (obj[0] || obj).nodeType;
  };

  var emulateTransitionEnd = function emulateTransitionEnd(element, duration) {
    var called = false;
    var durationPadding = 5;
    var emulatedDuration = duration + durationPadding;

    function listener() {
      called = true;
      element.removeEventListener(TRANSITION_END, listener);
    }

    element.addEventListener(TRANSITION_END, listener);
    setTimeout(function () {
      if (!called) {
        triggerTransitionEnd(element);
      }
    }, emulatedDuration);
  };

  var typeCheckConfig = function typeCheckConfig(componentName, config, configTypes) {
    Object.keys(configTypes).forEach(function (property) {
      var expectedTypes = configTypes[property];
      var value = config[property];
      var valueType = value && isElement(value) ? 'element' : toType(value);

      if (!new RegExp(expectedTypes).test(valueType)) {
        throw new Error(componentName.toUpperCase() + ": " + ("Option \"" + property + "\" provided type \"" + valueType + "\" ") + ("but expected type \"" + expectedTypes + "\"."));
      }
    });
  };

  var makeArray = function makeArray(nodeList) {
    if (!nodeList) {
      return [];
    }

    return [].slice.call(nodeList);
  };

  var isVisible = function isVisible(element) {
    if (!element) {
      return false;
    }

    if (element.style && element.parentNode && element.parentNode.style) {
      return element.style.display !== 'none' && element.parentNode.style.display !== 'none' && element.style.visibility !== 'hidden';
    }

    return false;
  };

  var reflow = function reflow(element) {
    return element.offsetHeight;
  };

XhmikosR's avatar
XhmikosR committed
198
199
200
201
202
203
204
205
206
207
208
  var getjQuery = function getjQuery() {
    var _window = window,
        jQuery = _window.jQuery;

    if (jQuery && !document.body.hasAttribute('data-no-jquery')) {
      return jQuery;
    }

    return null;
  };

XhmikosR's avatar
Dist    
XhmikosR committed
209
210
211
212
213
214
215
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'modal';
XhmikosR's avatar
XhmikosR committed
216
  var VERSION = '4.3.1';
XhmikosR's avatar
Dist    
XhmikosR committed
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
  var DATA_KEY = 'bs.modal';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key

  var Default = {
    backdrop: true,
    keyboard: true,
    focus: true,
    show: true
  };
  var DefaultType = {
    backdrop: '(boolean|string)',
    keyboard: 'boolean',
    focus: 'boolean',
    show: 'boolean'
  };
XhmikosR's avatar
XhmikosR committed
234
  var Event = {
XhmikosR's avatar
Dist    
XhmikosR committed
235
236
237
238
239
240
241
242
243
244
245
246
247
    HIDE: "hide" + EVENT_KEY,
    HIDDEN: "hidden" + EVENT_KEY,
    SHOW: "show" + EVENT_KEY,
    SHOWN: "shown" + EVENT_KEY,
    FOCUSIN: "focusin" + EVENT_KEY,
    RESIZE: "resize" + EVENT_KEY,
    CLICK_DISMISS: "click.dismiss" + EVENT_KEY,
    KEYDOWN_DISMISS: "keydown.dismiss" + EVENT_KEY,
    MOUSEUP_DISMISS: "mouseup.dismiss" + EVENT_KEY,
    MOUSEDOWN_DISMISS: "mousedown.dismiss" + EVENT_KEY,
    CLICK_DATA_API: "click" + EVENT_KEY + DATA_API_KEY
  };
  var ClassName = {
Mark Otto's avatar
Mark Otto committed
248
    SCROLLABLE: 'modal-dialog-scrollable',
XhmikosR's avatar
Dist    
XhmikosR committed
249
250
251
252
253
254
255
256
    SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
    BACKDROP: 'modal-backdrop',
    OPEN: 'modal-open',
    FADE: 'fade',
    SHOW: 'show'
  };
  var Selector = {
    DIALOG: '.modal-dialog',
Mark Otto's avatar
Mark Otto committed
257
    MODAL_BODY: '.modal-body',
XhmikosR's avatar
Dist    
XhmikosR committed
258
259
260
261
    DATA_TOGGLE: '[data-toggle="modal"]',
    DATA_DISMISS: '[data-dismiss="modal"]',
    FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
    STICKY_CONTENT: '.sticky-top'
Mark Otto's avatar
dist    
Mark Otto committed
262
263
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
264
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
265
266
     * ------------------------------------------------------------------------
     */
267

XhmikosR's avatar
Dist    
XhmikosR committed
268
269
270
271
272
273
274
275
  };

  var Modal =
  /*#__PURE__*/
  function () {
    function Modal(element, config) {
      this._config = this._getConfig(config);
      this._element = element;
XhmikosR's avatar
XhmikosR committed
276
      this._dialog = SelectorEngine.findOne(Selector.DIALOG, element);
XhmikosR's avatar
Dist    
XhmikosR committed
277
278
279
280
281
282
      this._backdrop = null;
      this._isShown = false;
      this._isBodyOverflowing = false;
      this._ignoreBackdropClick = false;
      this._isTransitioning = false;
      this._scrollbarWidth = 0;
XhmikosR's avatar
XhmikosR committed
283
      Data.setData(element, DATA_KEY, this);
XhmikosR's avatar
Dist    
XhmikosR committed
284
285
286
287
288
289
290
291
    } // Getters


    var _proto = Modal.prototype;

    // Public
    _proto.toggle = function toggle(relatedTarget) {
      return this._isShown ? this.hide() : this.show(relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
292
    };
293

XhmikosR's avatar
Dist    
XhmikosR committed
294
295
    _proto.show = function show(relatedTarget) {
      var _this = this;
Jacob Thornton's avatar
Jacob Thornton committed
296

XhmikosR's avatar
Dist    
XhmikosR committed
297
298
299
      if (this._isShown || this._isTransitioning) {
        return;
      }
300

XhmikosR's avatar
XhmikosR committed
301
      if (this._element.classList.contains(ClassName.FADE)) {
XhmikosR's avatar
Dist    
XhmikosR committed
302
303
        this._isTransitioning = true;
      }
304

XhmikosR's avatar
XhmikosR committed
305
      var showEvent = EventHandler.trigger(this._element, Event.SHOW, {
XhmikosR's avatar
Dist    
XhmikosR committed
306
307
        relatedTarget: relatedTarget
      });
Mark Otto's avatar
grunt    
Mark Otto committed
308

XhmikosR's avatar
XhmikosR committed
309
      if (this._isShown || showEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
310
311
        return;
      }
312

XhmikosR's avatar
Dist    
XhmikosR committed
313
      this._isShown = true;
Mark Otto's avatar
grunt    
Mark Otto committed
314

XhmikosR's avatar
Dist    
XhmikosR committed
315
      this._checkScrollbar();
316

XhmikosR's avatar
Dist    
XhmikosR committed
317
      this._setScrollbar();
Mark Otto's avatar
grunt    
Mark Otto committed
318

XhmikosR's avatar
Dist    
XhmikosR committed
319
      this._adjustDialog();
Mark Otto's avatar
grunt    
Mark Otto committed
320

XhmikosR's avatar
Dist    
XhmikosR committed
321
      this._setEscapeEvent();
322

XhmikosR's avatar
Dist    
XhmikosR committed
323
      this._setResizeEvent();
Mark Otto's avatar
grunt    
Mark Otto committed
324

XhmikosR's avatar
XhmikosR committed
325
      EventHandler.on(this._element, Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
326
327
        return _this.hide(event);
      });
XhmikosR's avatar
XhmikosR committed
328
329
      EventHandler.on(this._dialog, Event.MOUSEDOWN_DISMISS, function () {
        EventHandler.one(_this._element, Event.MOUSEUP_DISMISS, function (event) {
XhmikosR's avatar
XhmikosR committed
330
          if (event.target === _this._element) {
XhmikosR's avatar
Dist    
XhmikosR committed
331
332
            _this._ignoreBackdropClick = true;
          }
Mark Otto's avatar
dist    
Mark Otto committed
333
        });
XhmikosR's avatar
Dist    
XhmikosR committed
334
      });
335

XhmikosR's avatar
Dist    
XhmikosR committed
336
337
338
339
      this._showBackdrop(function () {
        return _this._showElement(relatedTarget);
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
340

XhmikosR's avatar
Dist    
XhmikosR committed
341
342
    _proto.hide = function hide(event) {
      var _this2 = this;
343

XhmikosR's avatar
Dist    
XhmikosR committed
344
345
346
      if (event) {
        event.preventDefault();
      }
347

XhmikosR's avatar
Dist    
XhmikosR committed
348
349
350
      if (!this._isShown || this._isTransitioning) {
        return;
      }
351

XhmikosR's avatar
XhmikosR committed
352
      var hideEvent = EventHandler.trigger(this._element, Event.HIDE);
353

354
      if (hideEvent.defaultPrevented) {
XhmikosR's avatar
Dist    
XhmikosR committed
355
356
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
357

XhmikosR's avatar
Dist    
XhmikosR committed
358
      this._isShown = false;
XhmikosR's avatar
XhmikosR committed
359
360

      var transition = this._element.classList.contains(ClassName.FADE);
Mark Otto's avatar
grunt    
Mark Otto committed
361

XhmikosR's avatar
Dist    
XhmikosR committed
362
363
364
      if (transition) {
        this._isTransitioning = true;
      }
365

XhmikosR's avatar
Dist    
XhmikosR committed
366
      this._setEscapeEvent();
367

XhmikosR's avatar
Dist    
XhmikosR committed
368
      this._setResizeEvent();
Mark Otto's avatar
grunt    
Mark Otto committed
369

XhmikosR's avatar
XhmikosR committed
370
      EventHandler.off(document, Event.FOCUSIN);
XhmikosR's avatar
XhmikosR committed
371
372
373

      this._element.classList.remove(ClassName.SHOW);

XhmikosR's avatar
XhmikosR committed
374
375
      EventHandler.off(this._element, Event.CLICK_DISMISS);
      EventHandler.off(this._dialog, Event.MOUSEDOWN_DISMISS);
Mark Otto's avatar
dist    
Mark Otto committed
376

XhmikosR's avatar
Dist    
XhmikosR committed
377
      if (transition) {
XhmikosR's avatar
XhmikosR committed
378
379
        var transitionDuration = getTransitionDurationFromElement(this._element);
        EventHandler.one(this._element, TRANSITION_END, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
380
          return _this2._hideModal(event);
XhmikosR's avatar
XhmikosR committed
381
382
        });
        emulateTransitionEnd(this._element, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
383
384
385
386
      } else {
        this._hideModal();
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
387

XhmikosR's avatar
Dist    
XhmikosR committed
388
389
    _proto.dispose = function dispose() {
      [window, this._element, this._dialog].forEach(function (htmlElement) {
XhmikosR's avatar
XhmikosR committed
390
        return EventHandler.off(htmlElement, EVENT_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
391
392
393
394
395
396
      });
      /**
       * `document` has 2 events `Event.FOCUSIN` and `Event.CLICK_DATA_API`
       * Do not move `document` in `htmlElements` array
       * It will remove `Event.CLICK_DATA_API` event that should remain
       */
Mark Otto's avatar
grunt    
Mark Otto committed
397

XhmikosR's avatar
XhmikosR committed
398
      EventHandler.off(document, Event.FOCUSIN);
XhmikosR's avatar
XhmikosR committed
399
      Data.removeData(this._element, DATA_KEY);
XhmikosR's avatar
Dist    
XhmikosR committed
400
401
402
403
404
405
406
407
408
409
      this._config = null;
      this._element = null;
      this._dialog = null;
      this._backdrop = null;
      this._isShown = null;
      this._isBodyOverflowing = null;
      this._ignoreBackdropClick = null;
      this._isTransitioning = null;
      this._scrollbarWidth = null;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
410

XhmikosR's avatar
Dist    
XhmikosR committed
411
412
    _proto.handleUpdate = function handleUpdate() {
      this._adjustDialog();
Mark Otto's avatar
Mark Otto committed
413
414
    } // Private
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
415

XhmikosR's avatar
Dist    
XhmikosR committed
416
    _proto._getConfig = function _getConfig(config) {
417
      config = _objectSpread2({}, Default, {}, config);
XhmikosR's avatar
XhmikosR committed
418
      typeCheckConfig(NAME, config, DefaultType);
XhmikosR's avatar
Dist    
XhmikosR committed
419
420
      return config;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
421

XhmikosR's avatar
Dist    
XhmikosR committed
422
423
    _proto._showElement = function _showElement(relatedTarget) {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
424

XhmikosR's avatar
XhmikosR committed
425
      var transition = this._element.classList.contains(ClassName.FADE);
Mark Otto's avatar
dist    
Mark Otto committed
426

XhmikosR's avatar
XhmikosR committed
427
428
      var modalBody = SelectorEngine.findOne(Selector.MODAL_BODY, this._dialog);

XhmikosR's avatar
Dist    
XhmikosR committed
429
430
431
432
      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
        // Don't move modal's DOM position
        document.body.appendChild(this._element);
      }
Mark Otto's avatar
dist    
Mark Otto committed
433

XhmikosR's avatar
Dist    
XhmikosR committed
434
      this._element.style.display = 'block';
Mark Otto's avatar
dist    
Mark Otto committed
435

XhmikosR's avatar
Dist    
XhmikosR committed
436
      this._element.removeAttribute('aria-hidden');
437

Mark Otto's avatar
dist    
Mark Otto committed
438
439
      this._element.setAttribute('aria-modal', true);

XhmikosR's avatar
XhmikosR committed
440
441
      if (this._dialog.classList.contains(ClassName.SCROLLABLE) && modalBody) {
        modalBody.scrollTop = 0;
Mark Otto's avatar
Mark Otto committed
442
443
444
      } else {
        this._element.scrollTop = 0;
      }
445

XhmikosR's avatar
Dist    
XhmikosR committed
446
      if (transition) {
XhmikosR's avatar
XhmikosR committed
447
        reflow(this._element);
XhmikosR's avatar
Dist    
XhmikosR committed
448
      }
449

XhmikosR's avatar
XhmikosR committed
450
      this._element.classList.add(ClassName.SHOW);
Mark Otto's avatar
dist    
Mark Otto committed
451

XhmikosR's avatar
Dist    
XhmikosR committed
452
453
454
      if (this._config.focus) {
        this._enforceFocus();
      }
455

XhmikosR's avatar
Dist    
XhmikosR committed
456
457
458
      var transitionComplete = function transitionComplete() {
        if (_this3._config.focus) {
          _this3._element.focus();
Mark Otto's avatar
dist    
Mark Otto committed
459
        }
460

XhmikosR's avatar
Dist    
XhmikosR committed
461
        _this3._isTransitioning = false;
XhmikosR's avatar
XhmikosR committed
462
        EventHandler.trigger(_this3._element, Event.SHOWN, {
XhmikosR's avatar
XhmikosR committed
463
464
          relatedTarget: relatedTarget
        });
Mark Otto's avatar
dist    
Mark Otto committed
465
      };
466

XhmikosR's avatar
Dist    
XhmikosR committed
467
      if (transition) {
XhmikosR's avatar
XhmikosR committed
468
469
470
        var transitionDuration = getTransitionDurationFromElement(this._dialog);
        EventHandler.one(this._dialog, TRANSITION_END, transitionComplete);
        emulateTransitionEnd(this._dialog, transitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
471
472
473
474
      } else {
        transitionComplete();
      }
    };
475

XhmikosR's avatar
Dist    
XhmikosR committed
476
477
    _proto._enforceFocus = function _enforceFocus() {
      var _this4 = this;
478

XhmikosR's avatar
XhmikosR committed
479
      EventHandler.off(document, Event.FOCUSIN); // guard against infinite focus loop
XhmikosR's avatar
XhmikosR committed
480

XhmikosR's avatar
XhmikosR committed
481
      EventHandler.on(document, Event.FOCUSIN, function (event) {
XhmikosR's avatar
XhmikosR committed
482
        if (document !== event.target && _this4._element !== event.target && !_this4._element.contains(event.target)) {
XhmikosR's avatar
Dist    
XhmikosR committed
483
          _this4._element.focus();
484
        }
XhmikosR's avatar
Dist    
XhmikosR committed
485
486
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
487

XhmikosR's avatar
Dist    
XhmikosR committed
488
489
    _proto._setEscapeEvent = function _setEscapeEvent() {
      var _this5 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
490

XhmikosR's avatar
Dist    
XhmikosR committed
491
      if (this._isShown && this._config.keyboard) {
XhmikosR's avatar
XhmikosR committed
492
        EventHandler.on(this._element, Event.KEYDOWN_DISMISS, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
493
494
          if (event.which === ESCAPE_KEYCODE) {
            event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
495

XhmikosR's avatar
Dist    
XhmikosR committed
496
497
498
            _this5.hide();
          }
        });
499
      } else {
XhmikosR's avatar
XhmikosR committed
500
        EventHandler.off(this._element, Event.KEYDOWN_DISMISS);
XhmikosR's avatar
Dist    
XhmikosR committed
501
502
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
503

XhmikosR's avatar
Dist    
XhmikosR committed
504
505
    _proto._setResizeEvent = function _setResizeEvent() {
      var _this6 = this;
506

XhmikosR's avatar
Dist    
XhmikosR committed
507
      if (this._isShown) {
508
509
        EventHandler.on(window, Event.RESIZE, function () {
          return _this6._adjustDialog();
XhmikosR's avatar
Dist    
XhmikosR committed
510
511
        });
      } else {
XhmikosR's avatar
XhmikosR committed
512
        EventHandler.off(window, Event.RESIZE);
XhmikosR's avatar
Dist    
XhmikosR committed
513
514
      }
    };
515

XhmikosR's avatar
Dist    
XhmikosR committed
516
517
    _proto._hideModal = function _hideModal() {
      var _this7 = this;
518

XhmikosR's avatar
Dist    
XhmikosR committed
519
      this._element.style.display = 'none';
520

XhmikosR's avatar
Dist    
XhmikosR committed
521
      this._element.setAttribute('aria-hidden', true);
522

Mark Otto's avatar
dist    
Mark Otto committed
523
524
      this._element.removeAttribute('aria-modal');

XhmikosR's avatar
Dist    
XhmikosR committed
525
      this._isTransitioning = false;
Mark Otto's avatar
dist    
Mark Otto committed
526

XhmikosR's avatar
Dist    
XhmikosR committed
527
      this._showBackdrop(function () {
XhmikosR's avatar
XhmikosR committed
528
        document.body.classList.remove(ClassName.OPEN);
529

XhmikosR's avatar
Dist    
XhmikosR committed
530
        _this7._resetAdjustments();
Mark Otto's avatar
dist    
Mark Otto committed
531

XhmikosR's avatar
Dist    
XhmikosR committed
532
        _this7._resetScrollbar();
Mark Otto's avatar
dist    
Mark Otto committed
533

XhmikosR's avatar
XhmikosR committed
534
        EventHandler.trigger(_this7._element, Event.HIDDEN);
XhmikosR's avatar
Dist    
XhmikosR committed
535
536
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
537

XhmikosR's avatar
Dist    
XhmikosR committed
538
    _proto._removeBackdrop = function _removeBackdrop() {
539
      this._backdrop.parentNode.removeChild(this._backdrop);
XhmikosR's avatar
XhmikosR committed
540

541
      this._backdrop = null;
XhmikosR's avatar
Dist    
XhmikosR committed
542
    };
Mark Otto's avatar
dist    
Mark Otto committed
543

XhmikosR's avatar
Dist    
XhmikosR committed
544
545
    _proto._showBackdrop = function _showBackdrop(callback) {
      var _this8 = this;
Mark Otto's avatar
dist    
Mark Otto committed
546

XhmikosR's avatar
XhmikosR committed
547
      var animate = this._element.classList.contains(ClassName.FADE) ? ClassName.FADE : '';
XhmikosR's avatar
Dist    
XhmikosR committed
548
549
550
551

      if (this._isShown && this._config.backdrop) {
        this._backdrop = document.createElement('div');
        this._backdrop.className = ClassName.BACKDROP;
Mark Otto's avatar
dist    
Mark Otto committed
552

XhmikosR's avatar
Dist    
XhmikosR committed
553
554
555
        if (animate) {
          this._backdrop.classList.add(animate);
        }
556

XhmikosR's avatar
XhmikosR committed
557
        document.body.appendChild(this._backdrop);
XhmikosR's avatar
XhmikosR committed
558
        EventHandler.on(this._element, Event.CLICK_DISMISS, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
559
560
          if (_this8._ignoreBackdropClick) {
            _this8._ignoreBackdropClick = false;
561
562
            return;
          }
Mark Otto's avatar
dist    
Mark Otto committed
563

XhmikosR's avatar
Dist    
XhmikosR committed
564
          if (event.target !== event.currentTarget) {
565
566
567
            return;
          }

XhmikosR's avatar
Dist    
XhmikosR committed
568
569
570
571
572
573
          if (_this8._config.backdrop === 'static') {
            _this8._element.focus();
          } else {
            _this8.hide();
          }
        });
Mark Otto's avatar
dist    
Mark Otto committed
574

XhmikosR's avatar
Dist    
XhmikosR committed
575
        if (animate) {
XhmikosR's avatar
XhmikosR committed
576
          reflow(this._backdrop);
XhmikosR's avatar
Dist    
XhmikosR committed
577
        }
578

XhmikosR's avatar
XhmikosR committed
579
        this._backdrop.classList.add(ClassName.SHOW);
580

XhmikosR's avatar
Dist    
XhmikosR committed
581
        if (!animate) {
Mark Otto's avatar
dist    
Mark Otto committed
582
          callback();
XhmikosR's avatar
Dist    
XhmikosR committed
583
          return;
584
        }
Mark Otto's avatar
grunt    
Mark Otto committed
585

XhmikosR's avatar
XhmikosR committed
586
587
588
        var backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
        EventHandler.one(this._backdrop, TRANSITION_END, callback);
        emulateTransitionEnd(this._backdrop, backdropTransitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
589
      } else if (!this._isShown && this._backdrop) {
XhmikosR's avatar
XhmikosR committed
590
        this._backdrop.classList.remove(ClassName.SHOW);
Mark Otto's avatar
dist    
Mark Otto committed
591

XhmikosR's avatar
Dist    
XhmikosR committed
592
593
        var callbackRemove = function callbackRemove() {
          _this8._removeBackdrop();
Mark Otto's avatar
dist    
Mark Otto committed
594

595
          callback();
XhmikosR's avatar
Dist    
XhmikosR committed
596
        };
Mark Otto's avatar
dist    
Mark Otto committed
597

XhmikosR's avatar
XhmikosR committed
598
599
        if (this._element.classList.contains(ClassName.FADE)) {
          var _backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop);
XhmikosR's avatar
Dist    
XhmikosR committed
600

XhmikosR's avatar
XhmikosR committed
601
602
          EventHandler.one(this._backdrop, TRANSITION_END, callbackRemove);
          emulateTransitionEnd(this._backdrop, _backdropTransitionDuration);
XhmikosR's avatar
Dist    
XhmikosR committed
603
604
        } else {
          callbackRemove();
Mark Otto's avatar
dist    
Mark Otto committed
605
        }
606
      } else {
XhmikosR's avatar
Dist    
XhmikosR committed
607
608
        callback();
      }
Mark Otto's avatar
Mark Otto committed
609
    } // ----------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
610
611
    // the following methods are used to handle overflowing modals
    // ----------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
612
    ;
Mark Otto's avatar
dist    
Mark Otto committed
613

XhmikosR's avatar
Dist    
XhmikosR committed
614
615
    _proto._adjustDialog = function _adjustDialog() {
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
Mark Otto's avatar
dist    
Mark Otto committed
616

XhmikosR's avatar
Dist    
XhmikosR committed
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
      if (!this._isBodyOverflowing && isModalOverflowing) {
        this._element.style.paddingLeft = this._scrollbarWidth + "px";
      }

      if (this._isBodyOverflowing && !isModalOverflowing) {
        this._element.style.paddingRight = this._scrollbarWidth + "px";
      }
    };

    _proto._resetAdjustments = function _resetAdjustments() {
      this._element.style.paddingLeft = '';
      this._element.style.paddingRight = '';
    };

    _proto._checkScrollbar = function _checkScrollbar() {
      var rect = document.body.getBoundingClientRect();
      this._isBodyOverflowing = rect.left + rect.right < window.innerWidth;
      this._scrollbarWidth = this._getScrollbarWidth();
    };

    _proto._setScrollbar = function _setScrollbar() {
      var _this9 = this;
Mark Otto's avatar
dist    
Mark Otto committed
639

XhmikosR's avatar
Dist    
XhmikosR committed
640
641
642
      if (this._isBodyOverflowing) {
        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
XhmikosR's avatar
XhmikosR committed
643
644
        // Adjust fixed content padding
        makeArray(SelectorEngine.find(Selector.FIXED_CONTENT)).forEach(function (element) {
XhmikosR's avatar
Dist    
XhmikosR committed
645
          var actualPadding = element.style.paddingRight;
XhmikosR's avatar
XhmikosR committed
646
647
648
          var calculatedPadding = window.getComputedStyle(element)['padding-right'];
          Manipulator.setDataAttribute(element, 'padding-right', actualPadding);
          element.style.paddingRight = parseFloat(calculatedPadding) + _this9._scrollbarWidth + "px";
XhmikosR's avatar
Dist    
XhmikosR committed
649
650
        }); // Adjust sticky content margin

XhmikosR's avatar
XhmikosR committed
651
        makeArray(SelectorEngine.find(Selector.STICKY_CONTENT)).forEach(function (element) {
XhmikosR's avatar
Dist    
XhmikosR committed
652
          var actualMargin = element.style.marginRight;
XhmikosR's avatar
XhmikosR committed
653
654
655
          var calculatedMargin = window.getComputedStyle(element)['margin-right'];
          Manipulator.setDataAttribute(element, 'margin-right', actualMargin);
          element.style.marginRight = parseFloat(calculatedMargin) - _this9._scrollbarWidth + "px";
XhmikosR's avatar
Dist    
XhmikosR committed
656
657
658
        }); // Adjust body padding

        var actualPadding = document.body.style.paddingRight;
XhmikosR's avatar
XhmikosR committed
659
660
661
        var calculatedPadding = window.getComputedStyle(document.body)['padding-right'];
        Manipulator.setDataAttribute(document.body, 'padding-right', actualPadding);
        document.body.style.paddingRight = parseFloat(calculatedPadding) + this._scrollbarWidth + "px";
XhmikosR's avatar
Dist    
XhmikosR committed
662
      }
XhmikosR's avatar
Dist    
XhmikosR committed
663

XhmikosR's avatar
XhmikosR committed
664
      document.body.classList.add(ClassName.OPEN);
XhmikosR's avatar
Dist    
XhmikosR committed
665
    };
Mark Otto's avatar
grunt    
Mark Otto committed
666

XhmikosR's avatar
Dist    
XhmikosR committed
667
668
    _proto._resetScrollbar = function _resetScrollbar() {
      // Restore fixed content padding
XhmikosR's avatar
XhmikosR committed
669
670
      makeArray(SelectorEngine.find(Selector.FIXED_CONTENT)).forEach(function (element) {
        var padding = Manipulator.getDataAttribute(element, 'padding-right');
XhmikosR's avatar
Dist    
XhmikosR committed
671

XhmikosR's avatar
XhmikosR committed
672
673
674
675
676
677
678
679
        if (typeof padding !== 'undefined') {
          Manipulator.removeDataAttribute(element, 'padding-right');
          element.style.paddingRight = padding;
        }
      }); // Restore sticky content and navbar-toggler margin

      makeArray(SelectorEngine.find("" + Selector.STICKY_CONTENT)).forEach(function (element) {
        var margin = Manipulator.getDataAttribute(element, 'margin-right');
XhmikosR's avatar
Dist    
XhmikosR committed
680
681

        if (typeof margin !== 'undefined') {
XhmikosR's avatar
XhmikosR committed
682
683
          Manipulator.removeDataAttribute(element, 'margin-right');
          element.style.marginRight = margin;
XhmikosR's avatar
Dist    
XhmikosR committed
684
685
        }
      }); // Restore body padding
Mark Otto's avatar
dist    
Mark Otto committed
686

XhmikosR's avatar
XhmikosR committed
687
688
      var padding = Manipulator.getDataAttribute(document.body, 'padding-right');

XhmikosR's avatar
Dist.    
XhmikosR committed
689
690
691
      if (typeof padding === 'undefined') {
        document.body.style.paddingRight = '';
      } else {
XhmikosR's avatar
XhmikosR committed
692
693
694
        Manipulator.removeDataAttribute(document.body, 'padding-right');
        document.body.style.paddingRight = padding;
      }
XhmikosR's avatar
Dist    
XhmikosR committed
695
    };
Mark Otto's avatar
grunt    
Mark Otto committed
696

XhmikosR's avatar
Dist    
XhmikosR committed
697
698
699
700
701
702
703
704
    _proto._getScrollbarWidth = function _getScrollbarWidth() {
      // thx d.walsh
      var scrollDiv = document.createElement('div');
      scrollDiv.className = ClassName.SCROLLBAR_MEASURER;
      document.body.appendChild(scrollDiv);
      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
      document.body.removeChild(scrollDiv);
      return scrollbarWidth;
Mark Otto's avatar
Mark Otto committed
705
706
    } // Static
    ;
Mark Otto's avatar
grunt    
Mark Otto committed
707

XhmikosR's avatar
XhmikosR committed
708
    Modal.jQueryInterface = function jQueryInterface(config, relatedTarget) {
XhmikosR's avatar
Dist    
XhmikosR committed
709
      return this.each(function () {
XhmikosR's avatar
XhmikosR committed
710
        var data = Data.getData(this, DATA_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
711

712
        var _config = _objectSpread2({}, Default, {}, Manipulator.getDataAttributes(this), {}, typeof config === 'object' && config ? config : {});
Mark Otto's avatar
dist    
Mark Otto committed
713

XhmikosR's avatar
Dist    
XhmikosR committed
714
715
716
        if (!data) {
          data = new Modal(this, _config);
        }
Mark Otto's avatar
dist    
Mark Otto committed
717

XhmikosR's avatar
Dist    
XhmikosR committed
718
719
720
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new TypeError("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
721
          }
Mark Otto's avatar
dist    
Mark Otto committed
722

XhmikosR's avatar
Dist    
XhmikosR committed
723
724
725
          data[config](relatedTarget);
        } else if (_config.show) {
          data.show(relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
726
        }
XhmikosR's avatar
Dist    
XhmikosR committed
727
728
      });
    };
729

XhmikosR's avatar
XhmikosR committed
730
    Modal.getInstance = function getInstance(element) {
XhmikosR's avatar
XhmikosR committed
731
732
733
      return Data.getData(element, DATA_KEY);
    };

XhmikosR's avatar
Dist    
XhmikosR committed
734
735
736
737
738
739
740
741
742
743
744
    _createClass(Modal, null, [{
      key: "VERSION",
      get: function get() {
        return VERSION;
      }
    }, {
      key: "Default",
      get: function get() {
        return Default;
      }
    }]);
Mark Otto's avatar
dist    
Mark Otto committed
745

XhmikosR's avatar
Dist    
XhmikosR committed
746
747
748
749
750
751
752
    return Modal;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
753
754


XhmikosR's avatar
XhmikosR committed
755
  EventHandler.on(document, Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
XhmikosR's avatar
Dist    
XhmikosR committed
756
    var _this10 = this;
757

XhmikosR's avatar
XhmikosR committed
758
    var target = getElementFromSelector(this);
XhmikosR's avatar
Dist    
XhmikosR committed
759
760
761
762
763

    if (this.tagName === 'A' || this.tagName === 'AREA') {
      event.preventDefault();
    }

XhmikosR's avatar
XhmikosR committed
764
    EventHandler.one(target, Event.SHOW, function (showEvent) {
XhmikosR's avatar
XhmikosR committed
765
766
      if (showEvent.defaultPrevented) {
        // only register focus restorer if modal will actually get shown
XhmikosR's avatar
Dist    
XhmikosR committed
767
        return;
768
769
      }

XhmikosR's avatar
XhmikosR committed
770
      EventHandler.one(target, Event.HIDDEN, function () {
XhmikosR's avatar
XhmikosR committed
771
        if (isVisible(_this10)) {
XhmikosR's avatar
Dist    
XhmikosR committed
772
          _this10.focus();
773
774
775
        }
      });
    });
XhmikosR's avatar
XhmikosR committed
776
777
778
    var data = Data.getData(target, DATA_KEY);

    if (!data) {
779
780
      var config = _objectSpread2({}, Manipulator.getDataAttributes(target), {}, Manipulator.getDataAttributes(this));

XhmikosR's avatar
XhmikosR committed
781
782
      data = new Modal(target, config);
    }
783

XhmikosR's avatar
XhmikosR committed
784
    data.show(this);
XhmikosR's avatar
Dist    
XhmikosR committed
785
  });
XhmikosR's avatar
XhmikosR committed
786
  var $ = getjQuery();
XhmikosR's avatar
Dist    
XhmikosR committed
787
788
789
790
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
791
   * add .modal to jQuery only if jQuery is present
XhmikosR's avatar
Dist    
XhmikosR committed
792
   */
793

794
795
  /* istanbul ignore if */

XhmikosR's avatar
XhmikosR committed
796
797
798
799
  if ($) {
    var JQUERY_NO_CONFLICT = $.fn[NAME];
    $.fn[NAME] = Modal.jQueryInterface;
    $.fn[NAME].Constructor = Modal;
Mark Otto's avatar
dist    
Mark Otto committed
800

XhmikosR's avatar
XhmikosR committed
801
802
803
    $.fn[NAME].noConflict = function () {
      $.fn[NAME] = JQUERY_NO_CONFLICT;
      return Modal.jQueryInterface;
XhmikosR's avatar
XhmikosR committed
804
805
    };
  }
806
807

  return Modal;
Mark Otto's avatar
dist    
Mark Otto committed
808

Mark Otto's avatar
Mark Otto committed
809
}));
Mark Otto's avatar
dist    
Mark Otto committed
810
//# sourceMappingURL=modal.js.map