Completed
Push — master ( 36261e...adbdec )
by
unknown
14s queued 12s
created

modal.js ➔ _extends   B

Complexity

Conditions 6

Size

Total Lines 16
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 6
eloc 9
dl 0
loc 16
rs 8.6666
c 0
b 0
f 0
1
/*!
2
  * Bootstrap modal.js v4.6.1 (https://getbootstrap.com/)
3
  * Copyright 2011-2021 The Bootstrap Authors (https://github.com/twbs/bootstrap/graphs/contributors)
4
  * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
5
  */
6
(function (global, factory) {
7
  typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('jquery'), require('./util.js')) :
8
  typeof define === 'function' && define.amd ? define(['jquery', './util'], factory) :
0 ignored issues
show
Bug introduced by
The variable define seems to be never declared. If this is a global, consider adding a /** global: define */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
9
  (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Modal = factory(global.jQuery, global.Util));
0 ignored issues
show
Bug introduced by
The variable globalThis seems to be never declared. If this is a global, consider adding a /** global: globalThis */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
Best Practice introduced by
If you intend to check if the variable self is declared in the current environment, consider using typeof self === "undefined" instead. This is safe if the variable is not actually declared.
Loading history...
Comprehensibility introduced by
Usage of the sequence operator is discouraged, since it may lead to obfuscated code.

The sequence or comma operator allows the inclusion of multiple expressions where only is permitted. The result of the sequence is the value of the last expression.

This operator is most often used in for statements.

Used in another places it can make code hard to read, especially when people do not realize it even exists as a seperate operator.

This check looks for usage of the sequence operator in locations where it is not necessary and could be replaced by a series of expressions or statements.

var a,b,c;

a = 1, b = 1,  c= 3;

could just as well be written as:

var a,b,c;

a = 1;
b = 1;
c = 3;

To learn more about the sequence operator, please refer to the MDN.

Loading history...
10
})(this, (function ($, Util) { 'use strict';
11
12
  function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
13
14
  var $__default = /*#__PURE__*/_interopDefaultLegacy($);
15
  var Util__default = /*#__PURE__*/_interopDefaultLegacy(Util);
16
17
  function _defineProperties(target, props) {
18
    for (var i = 0; i < props.length; i++) {
19
      var descriptor = props[i];
20
      descriptor.enumerable = descriptor.enumerable || false;
21
      descriptor.configurable = true;
22
      if ("value" in descriptor) descriptor.writable = true;
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
23
      Object.defineProperty(target, descriptor.key, descriptor);
24
    }
25
  }
26
27
  function _createClass(Constructor, protoProps, staticProps) {
28
    if (protoProps) _defineProperties(Constructor.prototype, protoProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
29
    if (staticProps) _defineProperties(Constructor, staticProps);
0 ignored issues
show
Coding Style Best Practice introduced by
Curly braces around statements make for more readable code and help prevent bugs when you add further statements.

Consider adding curly braces around all statements when they are executed conditionally. This is optional if there is only one statement, but leaving them out can lead to unexpected behaviour if another statement is added later.

Consider:

if (a > 0)
    b = 42;

If you or someone else later decides to put another statement in, only the first statement will be executed.

if (a > 0)
    console.log("a > 0");
    b = 42;

In this case the statement b = 42 will always be executed, while the logging statement will be executed conditionally.

if (a > 0) {
    console.log("a > 0");
    b = 42;
}

ensures that the proper code will be executed conditionally no matter how many statements are added or removed.

Loading history...
30
    return Constructor;
31
  }
32
33
  function _extends() {
34
    _extends = Object.assign || function (target) {
35
      for (var i = 1; i < arguments.length; i++) {
36
        var source = arguments[i];
37
0 ignored issues
show
Comprehensibility introduced by
It seems like you are trying to overwrite a function name here. _extends is already defined in line 36 as a function. While this will work, it can be very confusing.
Loading history...
38
        for (var key in source) {
39
          if (Object.prototype.hasOwnProperty.call(source, key)) {
40
            target[key] = source[key];
41
          }
0 ignored issues
show
Complexity introduced by
A for in loop automatically includes the property of any prototype object, consider checking the key using hasOwnProperty.

When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically:

var someObject;
for (var key in someObject) {
    if ( ! someObject.hasOwnProperty(key)) {
        continue; // Skip keys from the prototype.
    }

    doSomethingWith(key);
}
Loading history...
42
        }
43
      }
44
45
      return target;
46
    };
47
48
    return _extends.apply(this, arguments);
49
  }
50
51
  /**
52
   * Constants
53
   */
54
55
  var NAME = 'modal';
56
  var VERSION = '4.6.1';
57
  var DATA_KEY = 'bs.modal';
58
  var EVENT_KEY = "." + DATA_KEY;
59
  var DATA_API_KEY = '.data-api';
60
  var JQUERY_NO_CONFLICT = $__default["default"].fn[NAME];
61
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
62
63
  var CLASS_NAME_SCROLLABLE = 'modal-dialog-scrollable';
64
  var CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure';
65
  var CLASS_NAME_BACKDROP = 'modal-backdrop';
66
  var CLASS_NAME_OPEN = 'modal-open';
67
  var CLASS_NAME_FADE = 'fade';
68
  var CLASS_NAME_SHOW = 'show';
69
  var CLASS_NAME_STATIC = 'modal-static';
70
  var EVENT_HIDE = "hide" + EVENT_KEY;
71
  var EVENT_HIDE_PREVENTED = "hidePrevented" + EVENT_KEY;
72
  var EVENT_HIDDEN = "hidden" + EVENT_KEY;
73
  var EVENT_SHOW = "show" + EVENT_KEY;
74
  var EVENT_SHOWN = "shown" + EVENT_KEY;
75
  var EVENT_FOCUSIN = "focusin" + EVENT_KEY;
76
  var EVENT_RESIZE = "resize" + EVENT_KEY;
77
  var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY;
78
  var EVENT_KEYDOWN_DISMISS = "keydown.dismiss" + EVENT_KEY;
79
  var EVENT_MOUSEUP_DISMISS = "mouseup.dismiss" + EVENT_KEY;
80
  var EVENT_MOUSEDOWN_DISMISS = "mousedown.dismiss" + EVENT_KEY;
81
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
82
  var SELECTOR_DIALOG = '.modal-dialog';
83
  var SELECTOR_MODAL_BODY = '.modal-body';
84
  var SELECTOR_DATA_TOGGLE = '[data-toggle="modal"]';
85
  var SELECTOR_DATA_DISMISS = '[data-dismiss="modal"]';
86
  var SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
87
  var SELECTOR_STICKY_CONTENT = '.sticky-top';
88
  var Default = {
89
    backdrop: true,
90
    keyboard: true,
91
    focus: true,
92
    show: true
93
  };
94
  var DefaultType = {
95
    backdrop: '(boolean|string)',
96
    keyboard: 'boolean',
97
    focus: 'boolean',
98
    show: 'boolean'
99
  };
100
  /**
101
   * Class definition
102
   */
103
104
  var Modal = /*#__PURE__*/function () {
105
    function Modal(element, config) {
106
      this._config = this._getConfig(config);
107
      this._element = element;
108
      this._dialog = element.querySelector(SELECTOR_DIALOG);
109
      this._backdrop = null;
110
      this._isShown = false;
111
      this._isBodyOverflowing = false;
112
      this._ignoreBackdropClick = false;
113
      this._isTransitioning = false;
114
      this._scrollbarWidth = 0;
115
    } // Getters
116
117
118
    var _proto = Modal.prototype;
119
120
    // Public
121
    _proto.toggle = function toggle(relatedTarget) {
122
      return this._isShown ? this.hide() : this.show(relatedTarget);
123
    };
124
125
    _proto.show = function show(relatedTarget) {
126
      var _this = this;
127
128
      if (this._isShown || this._isTransitioning) {
129
        return;
130
      }
131
132
      var showEvent = $__default["default"].Event(EVENT_SHOW, {
133
        relatedTarget: relatedTarget
134
      });
135
      $__default["default"](this._element).trigger(showEvent);
136
137
      if (showEvent.isDefaultPrevented()) {
138
        return;
139
      }
140
141
      this._isShown = true;
142
143
      if ($__default["default"](this._element).hasClass(CLASS_NAME_FADE)) {
144
        this._isTransitioning = true;
145
      }
146
147
      this._checkScrollbar();
148
149
      this._setScrollbar();
150
151
      this._adjustDialog();
152
153
      this._setEscapeEvent();
154
155
      this._setResizeEvent();
156
157
      $__default["default"](this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) {
158
        return _this.hide(event);
159
      });
160
      $__default["default"](this._dialog).on(EVENT_MOUSEDOWN_DISMISS, function () {
161
        $__default["default"](_this._element).one(EVENT_MOUSEUP_DISMISS, function (event) {
162
          if ($__default["default"](event.target).is(_this._element)) {
163
            _this._ignoreBackdropClick = true;
164
          }
165
        });
166
      });
167
168
      this._showBackdrop(function () {
169
        return _this._showElement(relatedTarget);
170
      });
171
    };
172
173
    _proto.hide = function hide(event) {
174
      var _this2 = this;
175
176
      if (event) {
177
        event.preventDefault();
178
      }
179
180
      if (!this._isShown || this._isTransitioning) {
181
        return;
182
      }
183
184
      var hideEvent = $__default["default"].Event(EVENT_HIDE);
185
      $__default["default"](this._element).trigger(hideEvent);
186
187
      if (!this._isShown || hideEvent.isDefaultPrevented()) {
188
        return;
189
      }
190
191
      this._isShown = false;
192
      var transition = $__default["default"](this._element).hasClass(CLASS_NAME_FADE);
193
194
      if (transition) {
195
        this._isTransitioning = true;
196
      }
197
198
      this._setEscapeEvent();
199
200
      this._setResizeEvent();
201
202
      $__default["default"](document).off(EVENT_FOCUSIN);
203
      $__default["default"](this._element).removeClass(CLASS_NAME_SHOW);
204
      $__default["default"](this._element).off(EVENT_CLICK_DISMISS);
205
      $__default["default"](this._dialog).off(EVENT_MOUSEDOWN_DISMISS);
206
207
      if (transition) {
208
        var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this._element);
209
        $__default["default"](this._element).one(Util__default["default"].TRANSITION_END, function (event) {
210
          return _this2._hideModal(event);
211
        }).emulateTransitionEnd(transitionDuration);
212
      } else {
213
        this._hideModal();
214
      }
215
    };
216
217
    _proto.dispose = function dispose() {
218
      [window, this._element, this._dialog].forEach(function (htmlElement) {
219
        return $__default["default"](htmlElement).off(EVENT_KEY);
220
      });
221
      /**
222
       * `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
223
       * Do not move `document` in `htmlElements` array
224
       * It will remove `EVENT_CLICK_DATA_API` event that should remain
225
       */
226
227
      $__default["default"](document).off(EVENT_FOCUSIN);
228
      $__default["default"].removeData(this._element, DATA_KEY);
229
      this._config = null;
230
      this._element = null;
231
      this._dialog = null;
232
      this._backdrop = null;
233
      this._isShown = null;
234
      this._isBodyOverflowing = null;
235
      this._ignoreBackdropClick = null;
236
      this._isTransitioning = null;
237
      this._scrollbarWidth = null;
238
    };
239
240
    _proto.handleUpdate = function handleUpdate() {
241
      this._adjustDialog();
242
    } // Private
243
    ;
244
245
    _proto._getConfig = function _getConfig(config) {
246
      config = _extends({}, Default, config);
247
      Util__default["default"].typeCheckConfig(NAME, config, DefaultType);
248
      return config;
249
    };
250
251
    _proto._triggerBackdropTransition = function _triggerBackdropTransition() {
252
      var _this3 = this;
253
254
      var hideEventPrevented = $__default["default"].Event(EVENT_HIDE_PREVENTED);
255
      $__default["default"](this._element).trigger(hideEventPrevented);
256
257
      if (hideEventPrevented.isDefaultPrevented()) {
258
        return;
259
      }
260
261
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
262
263
      if (!isModalOverflowing) {
264
        this._element.style.overflowY = 'hidden';
265
      }
266
267
      this._element.classList.add(CLASS_NAME_STATIC);
268
269
      var modalTransitionDuration = Util__default["default"].getTransitionDurationFromElement(this._dialog);
270
      $__default["default"](this._element).off(Util__default["default"].TRANSITION_END);
271
      $__default["default"](this._element).one(Util__default["default"].TRANSITION_END, function () {
272
        _this3._element.classList.remove(CLASS_NAME_STATIC);
273
274
        if (!isModalOverflowing) {
275
          $__default["default"](_this3._element).one(Util__default["default"].TRANSITION_END, function () {
276
            _this3._element.style.overflowY = '';
277
          }).emulateTransitionEnd(_this3._element, modalTransitionDuration);
278
        }
279
      }).emulateTransitionEnd(modalTransitionDuration);
280
281
      this._element.focus();
282
    };
283
284
    _proto._showElement = function _showElement(relatedTarget) {
285
      var _this4 = this;
286
287
      var transition = $__default["default"](this._element).hasClass(CLASS_NAME_FADE);
288
      var modalBody = this._dialog ? this._dialog.querySelector(SELECTOR_MODAL_BODY) : null;
289
290
      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
291
        // Don't move modal's DOM position
292
        document.body.appendChild(this._element);
0 ignored issues
show
Bug introduced by
The variable Node seems to be never declared. If this is a global, consider adding a /** global: Node */ comment.

This checks looks for references to variables that have not been declared. This is most likey a typographical error or a variable has been renamed.

To learn more about declaring variables in Javascript, see the MDN.

Loading history...
293
      }
294
295
      this._element.style.display = 'block';
296
297
      this._element.removeAttribute('aria-hidden');
298
299
      this._element.setAttribute('aria-modal', true);
300
301
      this._element.setAttribute('role', 'dialog');
302
303
      if ($__default["default"](this._dialog).hasClass(CLASS_NAME_SCROLLABLE) && modalBody) {
304
        modalBody.scrollTop = 0;
305
      } else {
306
        this._element.scrollTop = 0;
307
      }
308
309
      if (transition) {
310
        Util__default["default"].reflow(this._element);
311
      }
312
313
      $__default["default"](this._element).addClass(CLASS_NAME_SHOW);
314
315
      if (this._config.focus) {
316
        this._enforceFocus();
317
      }
318
319
      var shownEvent = $__default["default"].Event(EVENT_SHOWN, {
320
        relatedTarget: relatedTarget
321
      });
322
323
      var transitionComplete = function transitionComplete() {
324
        if (_this4._config.focus) {
325
          _this4._element.focus();
326
        }
327
328
        _this4._isTransitioning = false;
329
        $__default["default"](_this4._element).trigger(shownEvent);
330
      };
331
332
      if (transition) {
333
        var transitionDuration = Util__default["default"].getTransitionDurationFromElement(this._dialog);
334
        $__default["default"](this._dialog).one(Util__default["default"].TRANSITION_END, transitionComplete).emulateTransitionEnd(transitionDuration);
335
      } else {
336
        transitionComplete();
337
      }
338
    };
339
340
    _proto._enforceFocus = function _enforceFocus() {
341
      var _this5 = this;
342
343
      $__default["default"](document).off(EVENT_FOCUSIN) // Guard against infinite focus loop
344
      .on(EVENT_FOCUSIN, function (event) {
345
        if (document !== event.target && _this5._element !== event.target && $__default["default"](_this5._element).has(event.target).length === 0) {
346
          _this5._element.focus();
347
        }
348
      });
349
    };
350
351
    _proto._setEscapeEvent = function _setEscapeEvent() {
352
      var _this6 = this;
353
354
      if (this._isShown) {
355
        $__default["default"](this._element).on(EVENT_KEYDOWN_DISMISS, function (event) {
356
          if (_this6._config.keyboard && event.which === ESCAPE_KEYCODE) {
357
            event.preventDefault();
358
359
            _this6.hide();
360
          } else if (!_this6._config.keyboard && event.which === ESCAPE_KEYCODE) {
361
            _this6._triggerBackdropTransition();
362
          }
363
        });
364
      } else if (!this._isShown) {
365
        $__default["default"](this._element).off(EVENT_KEYDOWN_DISMISS);
366
      }
367
    };
368
369
    _proto._setResizeEvent = function _setResizeEvent() {
370
      var _this7 = this;
371
372
      if (this._isShown) {
373
        $__default["default"](window).on(EVENT_RESIZE, function (event) {
374
          return _this7.handleUpdate(event);
375
        });
376
      } else {
377
        $__default["default"](window).off(EVENT_RESIZE);
378
      }
379
    };
380
381
    _proto._hideModal = function _hideModal() {
382
      var _this8 = this;
383
384
      this._element.style.display = 'none';
385
386
      this._element.setAttribute('aria-hidden', true);
387
388
      this._element.removeAttribute('aria-modal');
389
390
      this._element.removeAttribute('role');
391
392
      this._isTransitioning = false;
393
394
      this._showBackdrop(function () {
395
        $__default["default"](document.body).removeClass(CLASS_NAME_OPEN);
396
397
        _this8._resetAdjustments();
398
399
        _this8._resetScrollbar();
400
401
        $__default["default"](_this8._element).trigger(EVENT_HIDDEN);
402
      });
403
    };
404
405
    _proto._removeBackdrop = function _removeBackdrop() {
406
      if (this._backdrop) {
407
        $__default["default"](this._backdrop).remove();
408
        this._backdrop = null;
409
      }
410
    };
411
412
    _proto._showBackdrop = function _showBackdrop(callback) {
413
      var _this9 = this;
414
415
      var animate = $__default["default"](this._element).hasClass(CLASS_NAME_FADE) ? CLASS_NAME_FADE : '';
416
417
      if (this._isShown && this._config.backdrop) {
418
        this._backdrop = document.createElement('div');
419
        this._backdrop.className = CLASS_NAME_BACKDROP;
420
421
        if (animate) {
422
          this._backdrop.classList.add(animate);
423
        }
424
425
        $__default["default"](this._backdrop).appendTo(document.body);
426
        $__default["default"](this._element).on(EVENT_CLICK_DISMISS, function (event) {
427
          if (_this9._ignoreBackdropClick) {
428
            _this9._ignoreBackdropClick = false;
429
            return;
430
          }
431
432
          if (event.target !== event.currentTarget) {
433
            return;
434
          }
435
436
          if (_this9._config.backdrop === 'static') {
437
            _this9._triggerBackdropTransition();
438
          } else {
439
            _this9.hide();
440
          }
441
        });
442
443
        if (animate) {
444
          Util__default["default"].reflow(this._backdrop);
445
        }
446
447
        $__default["default"](this._backdrop).addClass(CLASS_NAME_SHOW);
448
449
        if (!callback) {
450
          return;
451
        }
452
453
        if (!animate) {
454
          callback();
455
          return;
456
        }
457
458
        var backdropTransitionDuration = Util__default["default"].getTransitionDurationFromElement(this._backdrop);
459
        $__default["default"](this._backdrop).one(Util__default["default"].TRANSITION_END, callback).emulateTransitionEnd(backdropTransitionDuration);
460
      } else if (!this._isShown && this._backdrop) {
461
        $__default["default"](this._backdrop).removeClass(CLASS_NAME_SHOW);
462
463
        var callbackRemove = function callbackRemove() {
464
          _this9._removeBackdrop();
465
466
          if (callback) {
467
            callback();
468
          }
469
        };
470
471
        if ($__default["default"](this._element).hasClass(CLASS_NAME_FADE)) {
472
          var _backdropTransitionDuration = Util__default["default"].getTransitionDurationFromElement(this._backdrop);
473
474
          $__default["default"](this._backdrop).one(Util__default["default"].TRANSITION_END, callbackRemove).emulateTransitionEnd(_backdropTransitionDuration);
475
        } else {
476
          callbackRemove();
477
        }
478
      } else if (callback) {
479
        callback();
480
      }
481
    } // ----------------------------------------------------------------------
482
    // the following methods are used to handle overflowing modals
483
    // todo (fat): these should probably be refactored out of modal.js
484
    // ----------------------------------------------------------------------
485
    ;
486
487
    _proto._adjustDialog = function _adjustDialog() {
488
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
489
490
      if (!this._isBodyOverflowing && isModalOverflowing) {
491
        this._element.style.paddingLeft = this._scrollbarWidth + "px";
492
      }
493
494
      if (this._isBodyOverflowing && !isModalOverflowing) {
495
        this._element.style.paddingRight = this._scrollbarWidth + "px";
496
      }
497
    };
498
499
    _proto._resetAdjustments = function _resetAdjustments() {
500
      this._element.style.paddingLeft = '';
501
      this._element.style.paddingRight = '';
502
    };
503
504
    _proto._checkScrollbar = function _checkScrollbar() {
505
      var rect = document.body.getBoundingClientRect();
506
      this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth;
507
      this._scrollbarWidth = this._getScrollbarWidth();
508
    };
509
510
    _proto._setScrollbar = function _setScrollbar() {
511
      var _this10 = this;
512
513
      if (this._isBodyOverflowing) {
514
        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
515
        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
516
        var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT));
517
        var stickyContent = [].slice.call(document.querySelectorAll(SELECTOR_STICKY_CONTENT)); // Adjust fixed content padding
518
519
        $__default["default"](fixedContent).each(function (index, element) {
520
          var actualPadding = element.style.paddingRight;
521
          var calculatedPadding = $__default["default"](element).css('padding-right');
522
          $__default["default"](element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px");
523
        }); // Adjust sticky content margin
524
525
        $__default["default"](stickyContent).each(function (index, element) {
526
          var actualMargin = element.style.marginRight;
527
          var calculatedMargin = $__default["default"](element).css('margin-right');
528
          $__default["default"](element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this10._scrollbarWidth + "px");
529
        }); // Adjust body padding
530
531
        var actualPadding = document.body.style.paddingRight;
532
        var calculatedPadding = $__default["default"](document.body).css('padding-right');
533
        $__default["default"](document.body).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + "px");
534
      }
535
536
      $__default["default"](document.body).addClass(CLASS_NAME_OPEN);
537
    };
538
539
    _proto._resetScrollbar = function _resetScrollbar() {
540
      // Restore fixed content padding
541
      var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT));
542
      $__default["default"](fixedContent).each(function (index, element) {
543
        var padding = $__default["default"](element).data('padding-right');
544
        $__default["default"](element).removeData('padding-right');
545
        element.style.paddingRight = padding ? padding : '';
546
      }); // Restore sticky content
547
548
      var elements = [].slice.call(document.querySelectorAll("" + SELECTOR_STICKY_CONTENT));
549
      $__default["default"](elements).each(function (index, element) {
550
        var margin = $__default["default"](element).data('margin-right');
551
552
        if (typeof margin !== 'undefined') {
553
          $__default["default"](element).css('margin-right', margin).removeData('margin-right');
554
        }
555
      }); // Restore body padding
556
557
      var padding = $__default["default"](document.body).data('padding-right');
558
      $__default["default"](document.body).removeData('padding-right');
559
      document.body.style.paddingRight = padding ? padding : '';
560
    };
561
562
    _proto._getScrollbarWidth = function _getScrollbarWidth() {
563
      // thx d.walsh
564
      var scrollDiv = document.createElement('div');
565
      scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER;
566
      document.body.appendChild(scrollDiv);
567
      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
568
      document.body.removeChild(scrollDiv);
569
      return scrollbarWidth;
570
    } // Static
571
    ;
572
573
    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
574
      return this.each(function () {
575
        var data = $__default["default"](this).data(DATA_KEY);
576
577
        var _config = _extends({}, Default, $__default["default"](this).data(), typeof config === 'object' && config ? config : {});
578
579
        if (!data) {
580
          data = new Modal(this, _config);
581
          $__default["default"](this).data(DATA_KEY, data);
582
        }
583
584
        if (typeof config === 'string') {
585
          if (typeof data[config] === 'undefined') {
586
            throw new TypeError("No method named \"" + config + "\"");
587
          }
588
589
          data[config](relatedTarget);
590
        } else if (_config.show) {
591
          data.show(relatedTarget);
592
        }
593
      });
594
    };
595
596
    _createClass(Modal, null, [{
597
      key: "VERSION",
598
      get: function get() {
599
        return VERSION;
600
      }
601
    }, {
602
      key: "Default",
603
      get: function get() {
604
        return Default;
605
      }
606
    }]);
607
608
    return Modal;
609
  }();
610
  /**
611
   * Data API implementation
612
   */
613
614
615
  $__default["default"](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
616
    var _this11 = this;
617
618
    var target;
619
    var selector = Util__default["default"].getSelectorFromElement(this);
620
621
    if (selector) {
622
      target = document.querySelector(selector);
623
    }
624
625
    var config = $__default["default"](target).data(DATA_KEY) ? 'toggle' : _extends({}, $__default["default"](target).data(), $__default["default"](this).data());
626
627
    if (this.tagName === 'A' || this.tagName === 'AREA') {
0 ignored issues
show
Bug introduced by
The variable target does not seem to be initialized in case selector on line 623 is false. Are you sure this can never be the case?
Loading history...
628
      event.preventDefault();
629
    }
630
631
    var $target = $__default["default"](target).one(EVENT_SHOW, function (showEvent) {
632
      if (showEvent.isDefaultPrevented()) {
633
        // Only register focus restorer if modal will actually get shown
634
        return;
635
      }
636
637
      $target.one(EVENT_HIDDEN, function () {
638
        if ($__default["default"](_this11).is(':visible')) {
639
          _this11.focus();
640
        }
641
      });
642
    });
643
644
    Modal._jQueryInterface.call($__default["default"](target), config, this);
645
  });
646
  /**
647
   * jQuery
648
   */
649
650
  $__default["default"].fn[NAME] = Modal._jQueryInterface;
651
  $__default["default"].fn[NAME].Constructor = Modal;
652
653
  $__default["default"].fn[NAME].noConflict = function () {
654
    $__default["default"].fn[NAME] = JQUERY_NO_CONFLICT;
655
    return Modal._jQueryInterface;
656
  };
657
658
  return Modal;
659
660
}));
661
//# sourceMappingURL=modal.js.map
662