Passed
Pull Request — master (#45)
by
unknown
02:56
created

modal.js ➔ _interopDefaultLegacy   B

Complexity

Conditions 7

Size

Total Lines 1
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 7
eloc 1
dl 0
loc 1
rs 8
c 0
b 0
f 0
1
/*!
2
  * Bootstrap modal.js v4.5.3 (https://getbootstrap.com/)
3
  * Copyright 2011-2020 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.js'], 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 _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
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 17 as a function. While this will work, it can be very confusing.
Loading history...
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...
18
19
  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); } }
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...
20
21
  function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
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...
22
  /**
23
   * ------------------------------------------------------------------------
24
   * Constants
25
   * ------------------------------------------------------------------------
26
   */
27
28
  var NAME = 'modal';
29
  var VERSION = '4.5.3';
30
  var DATA_KEY = 'bs.modal';
31
  var EVENT_KEY = "." + DATA_KEY;
32
  var DATA_API_KEY = '.data-api';
33
  var JQUERY_NO_CONFLICT = $__default['default'].fn[NAME];
34
  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
35
36
  var Default = {
37
    backdrop: true,
38
    keyboard: true,
39
    focus: true,
40
    show: true
41
  };
42
  var DefaultType = {
43
    backdrop: '(boolean|string)',
44
    keyboard: 'boolean',
45
    focus: 'boolean',
46
    show: 'boolean'
47
  };
48
  var EVENT_HIDE = "hide" + EVENT_KEY;
49
  var EVENT_HIDE_PREVENTED = "hidePrevented" + EVENT_KEY;
50
  var EVENT_HIDDEN = "hidden" + EVENT_KEY;
51
  var EVENT_SHOW = "show" + EVENT_KEY;
52
  var EVENT_SHOWN = "shown" + EVENT_KEY;
53
  var EVENT_FOCUSIN = "focusin" + EVENT_KEY;
54
  var EVENT_RESIZE = "resize" + EVENT_KEY;
55
  var EVENT_CLICK_DISMISS = "click.dismiss" + EVENT_KEY;
56
  var EVENT_KEYDOWN_DISMISS = "keydown.dismiss" + EVENT_KEY;
57
  var EVENT_MOUSEUP_DISMISS = "mouseup.dismiss" + EVENT_KEY;
58
  var EVENT_MOUSEDOWN_DISMISS = "mousedown.dismiss" + EVENT_KEY;
59
  var EVENT_CLICK_DATA_API = "click" + EVENT_KEY + DATA_API_KEY;
60
  var CLASS_NAME_SCROLLABLE = 'modal-dialog-scrollable';
61
  var CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure';
62
  var CLASS_NAME_BACKDROP = 'modal-backdrop';
63
  var CLASS_NAME_OPEN = 'modal-open';
64
  var CLASS_NAME_FADE = 'fade';
65
  var CLASS_NAME_SHOW = 'show';
66
  var CLASS_NAME_STATIC = 'modal-static';
67
  var SELECTOR_DIALOG = '.modal-dialog';
68
  var SELECTOR_MODAL_BODY = '.modal-body';
69
  var SELECTOR_DATA_TOGGLE = '[data-toggle="modal"]';
70
  var SELECTOR_DATA_DISMISS = '[data-dismiss="modal"]';
71
  var SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top';
72
  var SELECTOR_STICKY_CONTENT = '.sticky-top';
73
  /**
74
   * ------------------------------------------------------------------------
75
   * Class Definition
76
   * ------------------------------------------------------------------------
77
   */
78
79
  var Modal = /*#__PURE__*/function () {
80
    function Modal(element, config) {
81
      this._config = this._getConfig(config);
82
      this._element = element;
83
      this._dialog = element.querySelector(SELECTOR_DIALOG);
84
      this._backdrop = null;
85
      this._isShown = false;
86
      this._isBodyOverflowing = false;
87
      this._ignoreBackdropClick = false;
88
      this._isTransitioning = false;
89
      this._scrollbarWidth = 0;
90
    } // Getters
91
92
93
    var _proto = Modal.prototype;
94
95
    // Public
96
    _proto.toggle = function toggle(relatedTarget) {
97
      return this._isShown ? this.hide() : this.show(relatedTarget);
98
    };
99
100
    _proto.show = function show(relatedTarget) {
101
      var _this = this;
102
103
      if (this._isShown || this._isTransitioning) {
104
        return;
105
      }
106
107
      if ($__default['default'](this._element).hasClass(CLASS_NAME_FADE)) {
108
        this._isTransitioning = true;
109
      }
110
111
      var showEvent = $__default['default'].Event(EVENT_SHOW, {
112
        relatedTarget: relatedTarget
113
      });
114
      $__default['default'](this._element).trigger(showEvent);
115
116
      if (this._isShown || showEvent.isDefaultPrevented()) {
117
        return;
118
      }
119
120
      this._isShown = true;
121
122
      this._checkScrollbar();
123
124
      this._setScrollbar();
125
126
      this._adjustDialog();
127
128
      this._setEscapeEvent();
129
130
      this._setResizeEvent();
131
132
      $__default['default'](this._element).on(EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, function (event) {
133
        return _this.hide(event);
134
      });
135
      $__default['default'](this._dialog).on(EVENT_MOUSEDOWN_DISMISS, function () {
136
        $__default['default'](_this._element).one(EVENT_MOUSEUP_DISMISS, function (event) {
137
          if ($__default['default'](event.target).is(_this._element)) {
138
            _this._ignoreBackdropClick = true;
139
          }
140
        });
141
      });
142
143
      this._showBackdrop(function () {
144
        return _this._showElement(relatedTarget);
145
      });
146
    };
147
148
    _proto.hide = function hide(event) {
149
      var _this2 = this;
150
151
      if (event) {
152
        event.preventDefault();
153
      }
154
155
      if (!this._isShown || this._isTransitioning) {
156
        return;
157
      }
158
159
      var hideEvent = $__default['default'].Event(EVENT_HIDE);
160
      $__default['default'](this._element).trigger(hideEvent);
161
162
      if (!this._isShown || hideEvent.isDefaultPrevented()) {
163
        return;
164
      }
165
166
      this._isShown = false;
167
      var transition = $__default['default'](this._element).hasClass(CLASS_NAME_FADE);
168
169
      if (transition) {
170
        this._isTransitioning = true;
171
      }
172
173
      this._setEscapeEvent();
174
175
      this._setResizeEvent();
176
177
      $__default['default'](document).off(EVENT_FOCUSIN);
178
      $__default['default'](this._element).removeClass(CLASS_NAME_SHOW);
179
      $__default['default'](this._element).off(EVENT_CLICK_DISMISS);
180
      $__default['default'](this._dialog).off(EVENT_MOUSEDOWN_DISMISS);
181
182
      if (transition) {
183
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this._element);
184
        $__default['default'](this._element).one(Util__default['default'].TRANSITION_END, function (event) {
185
          return _this2._hideModal(event);
186
        }).emulateTransitionEnd(transitionDuration);
187
      } else {
188
        this._hideModal();
189
      }
190
    };
191
192
    _proto.dispose = function dispose() {
193
      [window, this._element, this._dialog].forEach(function (htmlElement) {
194
        return $__default['default'](htmlElement).off(EVENT_KEY);
195
      });
196
      /**
197
       * `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
198
       * Do not move `document` in `htmlElements` array
199
       * It will remove `EVENT_CLICK_DATA_API` event that should remain
200
       */
201
202
      $__default['default'](document).off(EVENT_FOCUSIN);
203
      $__default['default'].removeData(this._element, DATA_KEY);
204
      this._config = null;
205
      this._element = null;
206
      this._dialog = null;
207
      this._backdrop = null;
208
      this._isShown = null;
209
      this._isBodyOverflowing = null;
210
      this._ignoreBackdropClick = null;
211
      this._isTransitioning = null;
212
      this._scrollbarWidth = null;
213
    };
214
215
    _proto.handleUpdate = function handleUpdate() {
216
      this._adjustDialog();
217
    } // Private
218
    ;
219
220
    _proto._getConfig = function _getConfig(config) {
221
      config = _extends({}, Default, config);
222
      Util__default['default'].typeCheckConfig(NAME, config, DefaultType);
223
      return config;
224
    };
225
226
    _proto._triggerBackdropTransition = function _triggerBackdropTransition() {
227
      var _this3 = this;
228
229
      if (this._config.backdrop === 'static') {
230
        var hideEventPrevented = $__default['default'].Event(EVENT_HIDE_PREVENTED);
231
        $__default['default'](this._element).trigger(hideEventPrevented);
232
233
        if (hideEventPrevented.isDefaultPrevented()) {
234
          return;
235
        }
236
237
        var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
238
239
        if (!isModalOverflowing) {
240
          this._element.style.overflowY = 'hidden';
241
        }
242
243
        this._element.classList.add(CLASS_NAME_STATIC);
244
245
        var modalTransitionDuration = Util__default['default'].getTransitionDurationFromElement(this._dialog);
246
        $__default['default'](this._element).off(Util__default['default'].TRANSITION_END);
247
        $__default['default'](this._element).one(Util__default['default'].TRANSITION_END, function () {
248
          _this3._element.classList.remove(CLASS_NAME_STATIC);
249
250
          if (!isModalOverflowing) {
251
            $__default['default'](_this3._element).one(Util__default['default'].TRANSITION_END, function () {
252
              _this3._element.style.overflowY = '';
253
            }).emulateTransitionEnd(_this3._element, modalTransitionDuration);
254
          }
255
        }).emulateTransitionEnd(modalTransitionDuration);
256
257
        this._element.focus();
258
      } else {
259
        this.hide();
260
      }
261
    };
262
263
    _proto._showElement = function _showElement(relatedTarget) {
264
      var _this4 = this;
265
266
      var transition = $__default['default'](this._element).hasClass(CLASS_NAME_FADE);
267
      var modalBody = this._dialog ? this._dialog.querySelector(SELECTOR_MODAL_BODY) : null;
268
269
      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
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...
270
        // Don't move modal's DOM position
271
        document.body.appendChild(this._element);
272
      }
273
274
      this._element.style.display = 'block';
275
276
      this._element.removeAttribute('aria-hidden');
277
278
      this._element.setAttribute('aria-modal', true);
279
280
      this._element.setAttribute('role', 'dialog');
281
282
      if ($__default['default'](this._dialog).hasClass(CLASS_NAME_SCROLLABLE) && modalBody) {
283
        modalBody.scrollTop = 0;
284
      } else {
285
        this._element.scrollTop = 0;
286
      }
287
288
      if (transition) {
289
        Util__default['default'].reflow(this._element);
290
      }
291
292
      $__default['default'](this._element).addClass(CLASS_NAME_SHOW);
293
294
      if (this._config.focus) {
295
        this._enforceFocus();
296
      }
297
298
      var shownEvent = $__default['default'].Event(EVENT_SHOWN, {
299
        relatedTarget: relatedTarget
300
      });
301
302
      var transitionComplete = function transitionComplete() {
303
        if (_this4._config.focus) {
304
          _this4._element.focus();
305
        }
306
307
        _this4._isTransitioning = false;
308
        $__default['default'](_this4._element).trigger(shownEvent);
309
      };
310
311
      if (transition) {
312
        var transitionDuration = Util__default['default'].getTransitionDurationFromElement(this._dialog);
313
        $__default['default'](this._dialog).one(Util__default['default'].TRANSITION_END, transitionComplete).emulateTransitionEnd(transitionDuration);
314
      } else {
315
        transitionComplete();
316
      }
317
    };
318
319
    _proto._enforceFocus = function _enforceFocus() {
320
      var _this5 = this;
321
322
      $__default['default'](document).off(EVENT_FOCUSIN) // Guard against infinite focus loop
323
      .on(EVENT_FOCUSIN, function (event) {
324
        if (document !== event.target && _this5._element !== event.target && $__default['default'](_this5._element).has(event.target).length === 0) {
325
          _this5._element.focus();
326
        }
327
      });
328
    };
329
330
    _proto._setEscapeEvent = function _setEscapeEvent() {
331
      var _this6 = this;
332
333
      if (this._isShown) {
334
        $__default['default'](this._element).on(EVENT_KEYDOWN_DISMISS, function (event) {
335
          if (_this6._config.keyboard && event.which === ESCAPE_KEYCODE) {
336
            event.preventDefault();
337
338
            _this6.hide();
339
          } else if (!_this6._config.keyboard && event.which === ESCAPE_KEYCODE) {
340
            _this6._triggerBackdropTransition();
341
          }
342
        });
343
      } else if (!this._isShown) {
344
        $__default['default'](this._element).off(EVENT_KEYDOWN_DISMISS);
345
      }
346
    };
347
348
    _proto._setResizeEvent = function _setResizeEvent() {
349
      var _this7 = this;
350
351
      if (this._isShown) {
352
        $__default['default'](window).on(EVENT_RESIZE, function (event) {
353
          return _this7.handleUpdate(event);
354
        });
355
      } else {
356
        $__default['default'](window).off(EVENT_RESIZE);
357
      }
358
    };
359
360
    _proto._hideModal = function _hideModal() {
361
      var _this8 = this;
362
363
      this._element.style.display = 'none';
364
365
      this._element.setAttribute('aria-hidden', true);
366
367
      this._element.removeAttribute('aria-modal');
368
369
      this._element.removeAttribute('role');
370
371
      this._isTransitioning = false;
372
373
      this._showBackdrop(function () {
374
        $__default['default'](document.body).removeClass(CLASS_NAME_OPEN);
375
376
        _this8._resetAdjustments();
377
378
        _this8._resetScrollbar();
379
380
        $__default['default'](_this8._element).trigger(EVENT_HIDDEN);
381
      });
382
    };
383
384
    _proto._removeBackdrop = function _removeBackdrop() {
385
      if (this._backdrop) {
386
        $__default['default'](this._backdrop).remove();
387
        this._backdrop = null;
388
      }
389
    };
390
391
    _proto._showBackdrop = function _showBackdrop(callback) {
392
      var _this9 = this;
393
394
      var animate = $__default['default'](this._element).hasClass(CLASS_NAME_FADE) ? CLASS_NAME_FADE : '';
395
396
      if (this._isShown && this._config.backdrop) {
397
        this._backdrop = document.createElement('div');
398
        this._backdrop.className = CLASS_NAME_BACKDROP;
399
400
        if (animate) {
401
          this._backdrop.classList.add(animate);
402
        }
403
404
        $__default['default'](this._backdrop).appendTo(document.body);
405
        $__default['default'](this._element).on(EVENT_CLICK_DISMISS, function (event) {
406
          if (_this9._ignoreBackdropClick) {
407
            _this9._ignoreBackdropClick = false;
408
            return;
409
          }
410
411
          if (event.target !== event.currentTarget) {
412
            return;
413
          }
414
415
          _this9._triggerBackdropTransition();
416
        });
417
418
        if (animate) {
419
          Util__default['default'].reflow(this._backdrop);
420
        }
421
422
        $__default['default'](this._backdrop).addClass(CLASS_NAME_SHOW);
423
424
        if (!callback) {
425
          return;
426
        }
427
428
        if (!animate) {
429
          callback();
430
          return;
431
        }
432
433
        var backdropTransitionDuration = Util__default['default'].getTransitionDurationFromElement(this._backdrop);
434
        $__default['default'](this._backdrop).one(Util__default['default'].TRANSITION_END, callback).emulateTransitionEnd(backdropTransitionDuration);
435
      } else if (!this._isShown && this._backdrop) {
436
        $__default['default'](this._backdrop).removeClass(CLASS_NAME_SHOW);
437
438
        var callbackRemove = function callbackRemove() {
439
          _this9._removeBackdrop();
440
441
          if (callback) {
442
            callback();
443
          }
444
        };
445
446
        if ($__default['default'](this._element).hasClass(CLASS_NAME_FADE)) {
447
          var _backdropTransitionDuration = Util__default['default'].getTransitionDurationFromElement(this._backdrop);
448
449
          $__default['default'](this._backdrop).one(Util__default['default'].TRANSITION_END, callbackRemove).emulateTransitionEnd(_backdropTransitionDuration);
450
        } else {
451
          callbackRemove();
452
        }
453
      } else if (callback) {
454
        callback();
455
      }
456
    } // ----------------------------------------------------------------------
457
    // the following methods are used to handle overflowing modals
458
    // todo (fat): these should probably be refactored out of modal.js
459
    // ----------------------------------------------------------------------
460
    ;
461
462
    _proto._adjustDialog = function _adjustDialog() {
463
      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
464
465
      if (!this._isBodyOverflowing && isModalOverflowing) {
466
        this._element.style.paddingLeft = this._scrollbarWidth + "px";
467
      }
468
469
      if (this._isBodyOverflowing && !isModalOverflowing) {
470
        this._element.style.paddingRight = this._scrollbarWidth + "px";
471
      }
472
    };
473
474
    _proto._resetAdjustments = function _resetAdjustments() {
475
      this._element.style.paddingLeft = '';
476
      this._element.style.paddingRight = '';
477
    };
478
479
    _proto._checkScrollbar = function _checkScrollbar() {
480
      var rect = document.body.getBoundingClientRect();
481
      this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth;
482
      this._scrollbarWidth = this._getScrollbarWidth();
483
    };
484
485
    _proto._setScrollbar = function _setScrollbar() {
486
      var _this10 = this;
487
488
      if (this._isBodyOverflowing) {
489
        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
490
        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
491
        var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT));
492
        var stickyContent = [].slice.call(document.querySelectorAll(SELECTOR_STICKY_CONTENT)); // Adjust fixed content padding
493
494
        $__default['default'](fixedContent).each(function (index, element) {
495
          var actualPadding = element.style.paddingRight;
496
          var calculatedPadding = $__default['default'](element).css('padding-right');
497
          $__default['default'](element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this10._scrollbarWidth + "px");
498
        }); // Adjust sticky content margin
499
500
        $__default['default'](stickyContent).each(function (index, element) {
501
          var actualMargin = element.style.marginRight;
502
          var calculatedMargin = $__default['default'](element).css('margin-right');
503
          $__default['default'](element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) - _this10._scrollbarWidth + "px");
504
        }); // Adjust body padding
505
506
        var actualPadding = document.body.style.paddingRight;
507
        var calculatedPadding = $__default['default'](document.body).css('padding-right');
508
        $__default['default'](document.body).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + "px");
509
      }
510
511
      $__default['default'](document.body).addClass(CLASS_NAME_OPEN);
512
    };
513
514
    _proto._resetScrollbar = function _resetScrollbar() {
515
      // Restore fixed content padding
516
      var fixedContent = [].slice.call(document.querySelectorAll(SELECTOR_FIXED_CONTENT));
517
      $__default['default'](fixedContent).each(function (index, element) {
518
        var padding = $__default['default'](element).data('padding-right');
519
        $__default['default'](element).removeData('padding-right');
520
        element.style.paddingRight = padding ? padding : '';
521
      }); // Restore sticky content
522
523
      var elements = [].slice.call(document.querySelectorAll("" + SELECTOR_STICKY_CONTENT));
524
      $__default['default'](elements).each(function (index, element) {
525
        var margin = $__default['default'](element).data('margin-right');
526
527
        if (typeof margin !== 'undefined') {
528
          $__default['default'](element).css('margin-right', margin).removeData('margin-right');
529
        }
530
      }); // Restore body padding
531
532
      var padding = $__default['default'](document.body).data('padding-right');
533
      $__default['default'](document.body).removeData('padding-right');
534
      document.body.style.paddingRight = padding ? padding : '';
535
    };
536
537
    _proto._getScrollbarWidth = function _getScrollbarWidth() {
538
      // thx d.walsh
539
      var scrollDiv = document.createElement('div');
540
      scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER;
541
      document.body.appendChild(scrollDiv);
542
      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
543
      document.body.removeChild(scrollDiv);
544
      return scrollbarWidth;
545
    } // Static
546
    ;
547
548
    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
549
      return this.each(function () {
550
        var data = $__default['default'](this).data(DATA_KEY);
551
552
        var _config = _extends({}, Default, $__default['default'](this).data(), typeof config === 'object' && config ? config : {});
553
554
        if (!data) {
555
          data = new Modal(this, _config);
556
          $__default['default'](this).data(DATA_KEY, data);
557
        }
558
559
        if (typeof config === 'string') {
560
          if (typeof data[config] === 'undefined') {
561
            throw new TypeError("No method named \"" + config + "\"");
562
          }
563
564
          data[config](relatedTarget);
565
        } else if (_config.show) {
566
          data.show(relatedTarget);
567
        }
568
      });
569
    };
570
571
    _createClass(Modal, null, [{
572
      key: "VERSION",
573
      get: function get() {
574
        return VERSION;
575
      }
576
    }, {
577
      key: "Default",
578
      get: function get() {
579
        return Default;
580
      }
581
    }]);
582
583
    return Modal;
584
  }();
585
  /**
586
   * ------------------------------------------------------------------------
587
   * Data Api implementation
588
   * ------------------------------------------------------------------------
589
   */
590
591
592
  $__default['default'](document).on(EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
593
    var _this11 = this;
594
595
    var target;
596
    var selector = Util__default['default'].getSelectorFromElement(this);
597
598
    if (selector) {
599
      target = document.querySelector(selector);
600
    }
601
602
    var config = $__default['default'](target).data(DATA_KEY) ? 'toggle' : _extends({}, $__default['default'](target).data(), $__default['default'](this).data());
0 ignored issues
show
Bug introduced by
The variable target does not seem to be initialized in case selector on line 598 is false. Are you sure this can never be the case?
Loading history...
603
604
    if (this.tagName === 'A' || this.tagName === 'AREA') {
605
      event.preventDefault();
606
    }
607
608
    var $target = $__default['default'](target).one(EVENT_SHOW, function (showEvent) {
609
      if (showEvent.isDefaultPrevented()) {
610
        // Only register focus restorer if modal will actually get shown
611
        return;
612
      }
613
614
      $target.one(EVENT_HIDDEN, function () {
615
        if ($__default['default'](_this11).is(':visible')) {
616
          _this11.focus();
617
        }
618
      });
619
    });
620
621
    Modal._jQueryInterface.call($__default['default'](target), config, this);
622
  });
623
  /**
624
   * ------------------------------------------------------------------------
625
   * jQuery
626
   * ------------------------------------------------------------------------
627
   */
628
629
  $__default['default'].fn[NAME] = Modal._jQueryInterface;
630
  $__default['default'].fn[NAME].Constructor = Modal;
631
632
  $__default['default'].fn[NAME].noConflict = function () {
633
    $__default['default'].fn[NAME] = JQUERY_NO_CONFLICT;
634
    return Modal._jQueryInterface;
635
  };
636
637
  return Modal;
638
639
})));
640
//# sourceMappingURL=modal.js.map
641