modal.js 19.5 KB
Newer Older
XhmikosR's avatar
Dist    
XhmikosR committed
1
2
3
4
5
/*!
  * Bootstrap modal.js v4.1.3 (https://getbootstrap.com/)
  * Copyright 2011-2018 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
  */
Mark Otto's avatar
dist    
Mark Otto committed
6
7
8
9
10
11
12
13
14
15
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
(function (global, factory) {
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
  typeof define === 'function' && define.amd ? define(['jquery', './util.js'], factory) :
  (global.Modal = factory(global.jQuery,global.Util));
}(this, (function ($,Util) { 'use strict';

  $ = $ && $.hasOwnProperty('default') ? $['default'] : $;
  Util = Util && Util.hasOwnProperty('default') ? Util['default'] : Util;

  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
42

Mark Otto's avatar
dist    
Mark Otto committed
43
44
    return obj;
  }
Mark Otto's avatar
dist    
Mark Otto committed
45

Mark Otto's avatar
dist    
Mark Otto committed
46
47
48
49
  function _objectSpread(target) {
    for (var i = 1; i < arguments.length; i++) {
      var source = arguments[i] != null ? arguments[i] : {};
      var ownKeys = Object.keys(source);
Mark Otto's avatar
dist    
Mark Otto committed
50

Mark Otto's avatar
dist    
Mark Otto committed
51
52
53
54
55
56
57
58
59
60
61
62
63
      if (typeof Object.getOwnPropertySymbols === 'function') {
        ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function (sym) {
          return Object.getOwnPropertyDescriptor(source, sym).enumerable;
        }));
      }

      ownKeys.forEach(function (key) {
        _defineProperty(target, key, source[key]);
      });
    }

    return target;
  }
64
65

  /**
Mark Otto's avatar
dist    
Mark Otto committed
66
   * --------------------------------------------------------------------------
Mark Otto's avatar
Mark Otto committed
67
   * Bootstrap (v4.1.3): modal.js
Mark Otto's avatar
dist    
Mark Otto committed
68
69
   * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
   * --------------------------------------------------------------------------
70
   */
Mark Otto's avatar
dist    
Mark Otto committed
71

XhmikosR's avatar
Dist    
XhmikosR committed
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
  /**
   * ------------------------------------------------------------------------
   * Constants
   * ------------------------------------------------------------------------
   */

  var NAME = 'modal';
  var VERSION = '4.1.3';
  var DATA_KEY = 'bs.modal';
  var EVENT_KEY = "." + DATA_KEY;
  var DATA_API_KEY = '.data-api';
  var JQUERY_NO_CONFLICT = $.fn[NAME];
  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'
  };
  var Event = {
    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 = {
    SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
    BACKDROP: 'modal-backdrop',
    OPEN: 'modal-open',
    FADE: 'fade',
    SHOW: 'show'
  };
  var Selector = {
    DIALOG: '.modal-dialog',
    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
124
125
    /**
     * ------------------------------------------------------------------------
XhmikosR's avatar
Dist    
XhmikosR committed
126
     * Class Definition
Mark Otto's avatar
dist    
Mark Otto committed
127
128
     * ------------------------------------------------------------------------
     */
129

XhmikosR's avatar
Dist    
XhmikosR committed
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
  };

  var Modal =
  /*#__PURE__*/
  function () {
    function Modal(element, config) {
      this._config = this._getConfig(config);
      this._element = element;
      this._dialog = element.querySelector(Selector.DIALOG);
      this._backdrop = null;
      this._isShown = false;
      this._isBodyOverflowing = false;
      this._ignoreBackdropClick = false;
      this._isTransitioning = false;
      this._scrollbarWidth = 0;
    } // 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
153
    };
154

XhmikosR's avatar
Dist    
XhmikosR committed
155
156
    _proto.show = function show(relatedTarget) {
      var _this = this;
Jacob Thornton's avatar
Jacob Thornton committed
157

XhmikosR's avatar
Dist    
XhmikosR committed
158
159
160
      if (this._isShown || this._isTransitioning) {
        return;
      }
161

XhmikosR's avatar
Dist    
XhmikosR committed
162
163
164
      if ($(this._element).hasClass(ClassName.FADE)) {
        this._isTransitioning = true;
      }
165

XhmikosR's avatar
Dist    
XhmikosR committed
166
167
168
169
      var showEvent = $.Event(Event.SHOW, {
        relatedTarget: relatedTarget
      });
      $(this._element).trigger(showEvent);
Mark Otto's avatar
grunt    
Mark Otto committed
170

XhmikosR's avatar
Dist    
XhmikosR committed
171
172
173
      if (this._isShown || showEvent.isDefaultPrevented()) {
        return;
      }
174

XhmikosR's avatar
Dist    
XhmikosR committed
175
      this._isShown = true;
Mark Otto's avatar
grunt    
Mark Otto committed
176

XhmikosR's avatar
Dist    
XhmikosR committed
177
      this._checkScrollbar();
178

XhmikosR's avatar
Dist    
XhmikosR committed
179
      this._setScrollbar();
Mark Otto's avatar
grunt    
Mark Otto committed
180

XhmikosR's avatar
Dist    
XhmikosR committed
181
      this._adjustDialog();
Mark Otto's avatar
grunt    
Mark Otto committed
182

XhmikosR's avatar
Dist    
XhmikosR committed
183
      $(document.body).addClass(ClassName.OPEN);
Mark Otto's avatar
dist    
Mark Otto committed
184

XhmikosR's avatar
Dist    
XhmikosR committed
185
      this._setEscapeEvent();
186

XhmikosR's avatar
Dist    
XhmikosR committed
187
      this._setResizeEvent();
Mark Otto's avatar
grunt    
Mark Otto committed
188

XhmikosR's avatar
Dist    
XhmikosR committed
189
190
191
192
193
194
195
196
      $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) {
        return _this.hide(event);
      });
      $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () {
        $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) {
          if ($(event.target).is(_this._element)) {
            _this._ignoreBackdropClick = true;
          }
Mark Otto's avatar
dist    
Mark Otto committed
197
        });
XhmikosR's avatar
Dist    
XhmikosR committed
198
      });
199

XhmikosR's avatar
Dist    
XhmikosR committed
200
201
202
203
      this._showBackdrop(function () {
        return _this._showElement(relatedTarget);
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
204

XhmikosR's avatar
Dist    
XhmikosR committed
205
206
    _proto.hide = function hide(event) {
      var _this2 = this;
207

XhmikosR's avatar
Dist    
XhmikosR committed
208
209
210
      if (event) {
        event.preventDefault();
      }
211

XhmikosR's avatar
Dist    
XhmikosR committed
212
213
214
      if (!this._isShown || this._isTransitioning) {
        return;
      }
215

XhmikosR's avatar
Dist    
XhmikosR committed
216
217
      var hideEvent = $.Event(Event.HIDE);
      $(this._element).trigger(hideEvent);
218

XhmikosR's avatar
Dist    
XhmikosR committed
219
220
221
      if (!this._isShown || hideEvent.isDefaultPrevented()) {
        return;
      }
Mark Otto's avatar
dist    
Mark Otto committed
222

XhmikosR's avatar
Dist    
XhmikosR committed
223
224
      this._isShown = false;
      var transition = $(this._element).hasClass(ClassName.FADE);
Mark Otto's avatar
grunt    
Mark Otto committed
225

XhmikosR's avatar
Dist    
XhmikosR committed
226
227
228
      if (transition) {
        this._isTransitioning = true;
      }
229

XhmikosR's avatar
Dist    
XhmikosR committed
230
      this._setEscapeEvent();
231

XhmikosR's avatar
Dist    
XhmikosR committed
232
      this._setResizeEvent();
Mark Otto's avatar
grunt    
Mark Otto committed
233

XhmikosR's avatar
Dist    
XhmikosR committed
234
235
236
237
      $(document).off(Event.FOCUSIN);
      $(this._element).removeClass(ClassName.SHOW);
      $(this._element).off(Event.CLICK_DISMISS);
      $(this._dialog).off(Event.MOUSEDOWN_DISMISS);
Mark Otto's avatar
dist    
Mark Otto committed
238

XhmikosR's avatar
Dist    
XhmikosR committed
239
240
241
242
243
244
245
246
247
      if (transition) {
        var transitionDuration = Util.getTransitionDurationFromElement(this._element);
        $(this._element).one(Util.TRANSITION_END, function (event) {
          return _this2._hideModal(event);
        }).emulateTransitionEnd(transitionDuration);
      } else {
        this._hideModal();
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
248

XhmikosR's avatar
Dist    
XhmikosR committed
249
250
251
252
253
254
255
256
257
    _proto.dispose = function dispose() {
      [window, this._element, this._dialog].forEach(function (htmlElement) {
        return $(htmlElement).off(EVENT_KEY);
      });
      /**
       * `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
258

XhmikosR's avatar
Dist    
XhmikosR committed
259
260
261
262
263
264
265
266
267
268
269
270
      $(document).off(Event.FOCUSIN);
      $.removeData(this._element, DATA_KEY);
      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
271

XhmikosR's avatar
Dist    
XhmikosR committed
272
273
274
    _proto.handleUpdate = function handleUpdate() {
      this._adjustDialog();
    }; // Private
Mark Otto's avatar
grunt    
Mark Otto committed
275
276


XhmikosR's avatar
Dist    
XhmikosR committed
277
278
279
280
281
    _proto._getConfig = function _getConfig(config) {
      config = _objectSpread({}, Default, config);
      Util.typeCheckConfig(NAME, config, DefaultType);
      return config;
    };
Mark Otto's avatar
grunt    
Mark Otto committed
282

XhmikosR's avatar
Dist    
XhmikosR committed
283
284
    _proto._showElement = function _showElement(relatedTarget) {
      var _this3 = this;
Mark Otto's avatar
dist    
Mark Otto committed
285

XhmikosR's avatar
Dist    
XhmikosR committed
286
      var transition = $(this._element).hasClass(ClassName.FADE);
Mark Otto's avatar
dist    
Mark Otto committed
287

XhmikosR's avatar
Dist    
XhmikosR committed
288
289
290
291
      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
292

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

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

XhmikosR's avatar
Dist    
XhmikosR committed
297
      this._element.scrollTop = 0;
298

XhmikosR's avatar
Dist    
XhmikosR committed
299
300
301
      if (transition) {
        Util.reflow(this._element);
      }
302

XhmikosR's avatar
Dist    
XhmikosR committed
303
      $(this._element).addClass(ClassName.SHOW);
Mark Otto's avatar
dist    
Mark Otto committed
304

XhmikosR's avatar
Dist    
XhmikosR committed
305
306
307
      if (this._config.focus) {
        this._enforceFocus();
      }
308

XhmikosR's avatar
Dist    
XhmikosR committed
309
310
311
      var shownEvent = $.Event(Event.SHOWN, {
        relatedTarget: relatedTarget
      });
Mark Otto's avatar
dist    
Mark Otto committed
312

XhmikosR's avatar
Dist    
XhmikosR committed
313
314
315
      var transitionComplete = function transitionComplete() {
        if (_this3._config.focus) {
          _this3._element.focus();
Mark Otto's avatar
dist    
Mark Otto committed
316
        }
317

XhmikosR's avatar
Dist    
XhmikosR committed
318
319
        _this3._isTransitioning = false;
        $(_this3._element).trigger(shownEvent);
Mark Otto's avatar
dist    
Mark Otto committed
320
      };
321

XhmikosR's avatar
Dist    
XhmikosR committed
322
323
324
325
326
327
328
      if (transition) {
        var transitionDuration = Util.getTransitionDurationFromElement(this._dialog);
        $(this._dialog).one(Util.TRANSITION_END, transitionComplete).emulateTransitionEnd(transitionDuration);
      } else {
        transitionComplete();
      }
    };
329

XhmikosR's avatar
Dist    
XhmikosR committed
330
331
    _proto._enforceFocus = function _enforceFocus() {
      var _this4 = this;
332

XhmikosR's avatar
Dist    
XhmikosR committed
333
334
335
336
      $(document).off(Event.FOCUSIN) // Guard against infinite focus loop
      .on(Event.FOCUSIN, function (event) {
        if (document !== event.target && _this4._element !== event.target && $(_this4._element).has(event.target).length === 0) {
          _this4._element.focus();
337
        }
XhmikosR's avatar
Dist    
XhmikosR committed
338
339
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
340

XhmikosR's avatar
Dist    
XhmikosR committed
341
342
    _proto._setEscapeEvent = function _setEscapeEvent() {
      var _this5 = this;
Mark Otto's avatar
grunt    
Mark Otto committed
343

XhmikosR's avatar
Dist    
XhmikosR committed
344
345
346
347
      if (this._isShown && this._config.keyboard) {
        $(this._element).on(Event.KEYDOWN_DISMISS, function (event) {
          if (event.which === ESCAPE_KEYCODE) {
            event.preventDefault();
Mark Otto's avatar
dist    
Mark Otto committed
348

XhmikosR's avatar
Dist    
XhmikosR committed
349
350
351
352
353
354
355
            _this5.hide();
          }
        });
      } else if (!this._isShown) {
        $(this._element).off(Event.KEYDOWN_DISMISS);
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
356

XhmikosR's avatar
Dist    
XhmikosR committed
357
358
    _proto._setResizeEvent = function _setResizeEvent() {
      var _this6 = this;
359

XhmikosR's avatar
Dist    
XhmikosR committed
360
361
362
363
364
365
366
367
      if (this._isShown) {
        $(window).on(Event.RESIZE, function (event) {
          return _this6.handleUpdate(event);
        });
      } else {
        $(window).off(Event.RESIZE);
      }
    };
368

XhmikosR's avatar
Dist    
XhmikosR committed
369
370
    _proto._hideModal = function _hideModal() {
      var _this7 = this;
371

XhmikosR's avatar
Dist    
XhmikosR committed
372
      this._element.style.display = 'none';
373

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

XhmikosR's avatar
Dist    
XhmikosR committed
376
      this._isTransitioning = false;
Mark Otto's avatar
dist    
Mark Otto committed
377

XhmikosR's avatar
Dist    
XhmikosR committed
378
379
      this._showBackdrop(function () {
        $(document.body).removeClass(ClassName.OPEN);
380

XhmikosR's avatar
Dist    
XhmikosR committed
381
        _this7._resetAdjustments();
Mark Otto's avatar
dist    
Mark Otto committed
382

XhmikosR's avatar
Dist    
XhmikosR committed
383
        _this7._resetScrollbar();
Mark Otto's avatar
dist    
Mark Otto committed
384

XhmikosR's avatar
Dist    
XhmikosR committed
385
386
387
        $(_this7._element).trigger(Event.HIDDEN);
      });
    };
Mark Otto's avatar
dist    
Mark Otto committed
388

XhmikosR's avatar
Dist    
XhmikosR committed
389
390
391
392
393
394
    _proto._removeBackdrop = function _removeBackdrop() {
      if (this._backdrop) {
        $(this._backdrop).remove();
        this._backdrop = null;
      }
    };
Mark Otto's avatar
dist    
Mark Otto committed
395

XhmikosR's avatar
Dist    
XhmikosR committed
396
397
    _proto._showBackdrop = function _showBackdrop(callback) {
      var _this8 = this;
Mark Otto's avatar
dist    
Mark Otto committed
398

XhmikosR's avatar
Dist    
XhmikosR committed
399
400
401
402
403
      var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : '';

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

XhmikosR's avatar
Dist    
XhmikosR committed
405
406
407
        if (animate) {
          this._backdrop.classList.add(animate);
        }
408

XhmikosR's avatar
Dist    
XhmikosR committed
409
410
411
412
        $(this._backdrop).appendTo(document.body);
        $(this._element).on(Event.CLICK_DISMISS, function (event) {
          if (_this8._ignoreBackdropClick) {
            _this8._ignoreBackdropClick = false;
413
414
            return;
          }
Mark Otto's avatar
dist    
Mark Otto committed
415

XhmikosR's avatar
Dist    
XhmikosR committed
416
          if (event.target !== event.currentTarget) {
417
418
419
            return;
          }

XhmikosR's avatar
Dist    
XhmikosR committed
420
421
422
423
424
425
          if (_this8._config.backdrop === 'static') {
            _this8._element.focus();
          } else {
            _this8.hide();
          }
        });
Mark Otto's avatar
dist    
Mark Otto committed
426

XhmikosR's avatar
Dist    
XhmikosR committed
427
428
429
        if (animate) {
          Util.reflow(this._backdrop);
        }
430

XhmikosR's avatar
Dist    
XhmikosR committed
431
        $(this._backdrop).addClass(ClassName.SHOW);
432

XhmikosR's avatar
Dist    
XhmikosR committed
433
434
435
        if (!callback) {
          return;
        }
Mark Otto's avatar
grunt    
Mark Otto committed
436

XhmikosR's avatar
Dist    
XhmikosR committed
437
        if (!animate) {
Mark Otto's avatar
dist    
Mark Otto committed
438
          callback();
XhmikosR's avatar
Dist    
XhmikosR committed
439
          return;
440
        }
Mark Otto's avatar
grunt    
Mark Otto committed
441

XhmikosR's avatar
Dist    
XhmikosR committed
442
443
444
445
        var backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop);
        $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(backdropTransitionDuration);
      } else if (!this._isShown && this._backdrop) {
        $(this._backdrop).removeClass(ClassName.SHOW);
Mark Otto's avatar
dist    
Mark Otto committed
446

XhmikosR's avatar
Dist    
XhmikosR committed
447
448
        var callbackRemove = function callbackRemove() {
          _this8._removeBackdrop();
Mark Otto's avatar
dist    
Mark Otto committed
449

XhmikosR's avatar
Dist    
XhmikosR committed
450
451
452
453
          if (callback) {
            callback();
          }
        };
Mark Otto's avatar
dist    
Mark Otto committed
454

XhmikosR's avatar
Dist    
XhmikosR committed
455
456
457
458
459
460
        if ($(this._element).hasClass(ClassName.FADE)) {
          var _backdropTransitionDuration = Util.getTransitionDurationFromElement(this._backdrop);

          $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(_backdropTransitionDuration);
        } else {
          callbackRemove();
Mark Otto's avatar
dist    
Mark Otto committed
461
        }
XhmikosR's avatar
Dist    
XhmikosR committed
462
463
464
465
466
467
468
      } else if (callback) {
        callback();
      }
    }; // ----------------------------------------------------------------------
    // the following methods are used to handle overflowing modals
    // todo (fat): these should probably be refactored out of modal.js
    // ----------------------------------------------------------------------
Mark Otto's avatar
dist    
Mark Otto committed
469
470


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

XhmikosR's avatar
Dist    
XhmikosR committed
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
      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
496

XhmikosR's avatar
Dist    
XhmikosR committed
497
498
499
      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
Mark Otto's avatar
dist    
Mark Otto committed
500
        var fixedContent = [].slice.call(document.querySelectorAll(Selector.FIXED_CONTENT));
XhmikosR's avatar
Dist    
XhmikosR committed
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
        var stickyContent = [].slice.call(document.querySelectorAll(Selector.STICKY_CONTENT)); // Adjust fixed content padding

        $(fixedContent).each(function (index, element) {
          var actualPadding = element.style.paddingRight;
          var calculatedPadding = $(element).css('padding-right');
          $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this9._scrollbarWidth + "px");
        }); // Adjust sticky content margin

        $(stickyContent).each(function (index, element) {
          var actualMargin = element.style.marginRight;
          var calculatedMargin = $(element).css('margin-right');
          $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this9._scrollbarWidth + "px");
        }); // Adjust body padding

        var actualPadding = document.body.style.paddingRight;
        var calculatedPadding = $(document.body).css('padding-right');
        $(document.body).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + "px");
      }
    };
Mark Otto's avatar
grunt    
Mark Otto committed
520

XhmikosR's avatar
Dist    
XhmikosR committed
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
    _proto._resetScrollbar = function _resetScrollbar() {
      // Restore fixed content padding
      var fixedContent = [].slice.call(document.querySelectorAll(Selector.FIXED_CONTENT));
      $(fixedContent).each(function (index, element) {
        var padding = $(element).data('padding-right');
        $(element).removeData('padding-right');
        element.style.paddingRight = padding ? padding : '';
      }); // Restore sticky content

      var elements = [].slice.call(document.querySelectorAll("" + Selector.STICKY_CONTENT));
      $(elements).each(function (index, element) {
        var margin = $(element).data('margin-right');

        if (typeof margin !== 'undefined') {
          $(element).css('margin-right', margin).removeData('margin-right');
        }
      }); // Restore body padding
Mark Otto's avatar
dist    
Mark Otto committed
538

XhmikosR's avatar
Dist    
XhmikosR committed
539
540
541
542
      var padding = $(document.body).data('padding-right');
      $(document.body).removeData('padding-right');
      document.body.style.paddingRight = padding ? padding : '';
    };
Mark Otto's avatar
grunt    
Mark Otto committed
543

XhmikosR's avatar
Dist    
XhmikosR committed
544
545
546
547
548
549
550
551
552
    _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;
    }; // Static
Mark Otto's avatar
grunt    
Mark Otto committed
553

Mark Otto's avatar
grunt    
Mark Otto committed
554

XhmikosR's avatar
Dist    
XhmikosR committed
555
556
557
    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
      return this.each(function () {
        var data = $(this).data(DATA_KEY);
Mark Otto's avatar
grunt    
Mark Otto committed
558

XhmikosR's avatar
Dist    
XhmikosR committed
559
        var _config = _objectSpread({}, Default, $(this).data(), typeof config === 'object' && config ? config : {});
Mark Otto's avatar
dist    
Mark Otto committed
560

XhmikosR's avatar
Dist    
XhmikosR committed
561
562
563
564
        if (!data) {
          data = new Modal(this, _config);
          $(this).data(DATA_KEY, data);
        }
Mark Otto's avatar
dist    
Mark Otto committed
565

XhmikosR's avatar
Dist    
XhmikosR committed
566
567
568
        if (typeof config === 'string') {
          if (typeof data[config] === 'undefined') {
            throw new TypeError("No method named \"" + config + "\"");
Mark Otto's avatar
dist    
Mark Otto committed
569
          }
Mark Otto's avatar
dist    
Mark Otto committed
570

XhmikosR's avatar
Dist    
XhmikosR committed
571
572
573
          data[config](relatedTarget);
        } else if (_config.show) {
          data.show(relatedTarget);
Mark Otto's avatar
dist    
Mark Otto committed
574
        }
XhmikosR's avatar
Dist    
XhmikosR committed
575
576
      });
    };
577

XhmikosR's avatar
Dist    
XhmikosR committed
578
579
580
581
582
583
584
585
586
587
588
    _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
589

XhmikosR's avatar
Dist    
XhmikosR committed
590
591
592
593
594
595
596
    return Modal;
  }();
  /**
   * ------------------------------------------------------------------------
   * Data Api implementation
   * ------------------------------------------------------------------------
   */
597
598


XhmikosR's avatar
Dist    
XhmikosR committed
599
600
  $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
    var _this10 = this;
601

XhmikosR's avatar
Dist    
XhmikosR committed
602
603
    var target;
    var selector = Util.getSelectorFromElement(this);
604

XhmikosR's avatar
Dist    
XhmikosR committed
605
606
607
    if (selector) {
      target = document.querySelector(selector);
    }
608

XhmikosR's avatar
Dist    
XhmikosR committed
609
610
611
612
613
614
615
616
617
618
    var config = $(target).data(DATA_KEY) ? 'toggle' : _objectSpread({}, $(target).data(), $(this).data());

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

    var $target = $(target).one(Event.SHOW, function (showEvent) {
      if (showEvent.isDefaultPrevented()) {
        // Only register focus restorer if modal will actually get shown
        return;
619
620
      }

XhmikosR's avatar
Dist    
XhmikosR committed
621
622
623
      $target.one(Event.HIDDEN, function () {
        if ($(_this10).is(':visible')) {
          _this10.focus();
624
625
626
627
        }
      });
    });

XhmikosR's avatar
Dist    
XhmikosR committed
628
629
630
631
632
633
634
    Modal._jQueryInterface.call($(target), config, this);
  });
  /**
   * ------------------------------------------------------------------------
   * jQuery
   * ------------------------------------------------------------------------
   */
635

XhmikosR's avatar
Dist    
XhmikosR committed
636
637
  $.fn[NAME] = Modal._jQueryInterface;
  $.fn[NAME].Constructor = Modal;
Mark Otto's avatar
dist    
Mark Otto committed
638

XhmikosR's avatar
Dist    
XhmikosR committed
639
640
641
642
  $.fn[NAME].noConflict = function () {
    $.fn[NAME] = JQUERY_NO_CONFLICT;
    return Modal._jQueryInterface;
  };
643
644

  return Modal;
Mark Otto's avatar
dist    
Mark Otto committed
645
646
647

})));
//# sourceMappingURL=modal.js.map