PageSourceSearch

https://www.lsu.lt/wp-content/themes/salient-child/js/modal.js

js lsu.lt collected 2026-10-02 11:07:11 UTC 18,708 bytes, 577 lines download raw bytes

1var _typeof = typeof Symbol === "function" && typeof Symbol.iterator === "symbol" ? function (obj) { return typeof obj; } : function (obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; };
2
3var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }();
4
5function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
6
7/**
8 * --------------------------------------------------------------------------
9 * Bootstrap (v4.0.0-beta): modal.js
10 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/master/LICENSE)
11 * --------------------------------------------------------------------------
12 */
13
14var Modal = function ($) {
15
16  /**
17   * ------------------------------------------------------------------------
18   * Constants
19   * ------------------------------------------------------------------------
20   */
21
22  var NAME = 'modal';
23  var VERSION = '4.0.0-beta';
24  var DATA_KEY = 'bs.modal';
25  var EVENT_KEY = '.' + DATA_KEY;
26  var DATA_API_KEY = '.data-api';
27  var JQUERY_NO_CONFLICT = $.fn[NAME];
28  var TRANSITION_DURATION = 300;
29  var BACKDROP_TRANSITION_DURATION = 150;
30  var ESCAPE_KEYCODE = 27; // KeyboardEvent.which value for Escape (Esc) key
31
32  var Default = {
33    backdrop: true,
34    keyboard: true,
35    focus: true,
36    show: true
37  };
38
39  var DefaultType = {
40    backdrop: '(boolean|string)',
41    keyboard: 'boolean',
42    focus: 'boolean',
43    show: 'boolean'
44  };
45
46  var Event = {
47    HIDE: 'hide' + EVENT_KEY,
48    HIDDEN: 'hidden' + EVENT_KEY,
49    SHOW: 'show' + EVENT_KEY,
50    SHOWN: 'shown' + EVENT_KEY,
51    FOCUSIN: 'focusin' + EVENT_KEY,
52    RESIZE: 'resize' + EVENT_KEY,
53    CLICK_DISMISS: 'click.dismiss' + EVENT_KEY,
54    KEYDOWN_DISMISS: 'keydown.dismiss' + EVENT_KEY,
55    MOUSEUP_DISMISS: 'mouseup.dismiss' + EVENT_KEY,
56    MOUSEDOWN_DISMISS: 'mousedown.dismiss' + EVENT_KEY,
57    CLICK_DATA_API: 'click' + EVENT_KEY + DATA_API_KEY
58  };
59
60  var ClassName = {
61    SCROLLBAR_MEASURER: 'modal-scrollbar-measure',
62    BACKDROP: 'modal-backdrop',
63    OPEN: 'modal-open',
64    FADE: 'fade',
65    SHOW: 'show'
66  };
67
68  var Selector = {
69    DIALOG: '.modal-dialog',
70    DATA_TOGGLE: '[data-toggle="modal"]',
71    DATA_DISMISS: '[data-dismiss="modal"]',
72    FIXED_CONTENT: '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top',
73    NAVBAR_TOGGLER: '.navbar-toggler'
74
75    /**
76     * ------------------------------------------------------------------------
77     * Class Definition
78     * ------------------------------------------------------------------------
79     */
80
81  };
82  var Modal = function () {
83    function Modal(element, config) {
84      _classCallCheck(this, Modal);
85
86      this._config = this._getConfig(config);
87      this._element = element;
88      this._dialog = $(element).find(Selector.DIALOG)[0];
89      this._backdrop = null;
90      this._isShown = false;
91      this._isBodyOverflowing = false;
92      this._ignoreBackdropClick = false;
93      this._originalBodyPadding = 0;
94      this._scrollbarWidth = 0;
95    }
96
97    // getters
98
99    // public
100
101    Modal.prototype.toggle = function toggle(relatedTarget) {
102      return this._isShown ? this.hide() : this.show(relatedTarget);
103    };
104
105    Modal.prototype.show = function show(relatedTarget) {
106      var _this = this;
107
108      if (this._isTransitioning) {
109        return;
110      }
111
112      if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
113        this._isTransitioning = true;
114      }
115
116      var showEvent = $.Event(Event.SHOW, {
117        relatedTarget: relatedTarget
118      });
119
120      $(this._element).trigger(showEvent);
121
122      if (this._isShown || showEvent.isDefaultPrevented()) {
123        return;
124      }
125
126      this._isShown = true;
127
128      this._checkScrollbar();
129      this._setScrollbar();
130
131      $(document.body).addClass(ClassName.OPEN);
132
133      this._setEscapeEvent();
134      this._setResizeEvent();
135
136      $(this._element).on(Event.CLICK_DISMISS, Selector.DATA_DISMISS, function (event) {
137        return _this.hide(event);
138      });
139
140      $(this._dialog).on(Event.MOUSEDOWN_DISMISS, function () {
141        $(_this._element).one(Event.MOUSEUP_DISMISS, function (event) {
142          if ($(event.target).is(_this._element)) {
143            _this._ignoreBackdropClick = true;
144          }
145        });
146      });
147
148      this._showBackdrop(function () {
149        return _this._showElement(relatedTarget);
150      });
151    };
152
153    Modal.prototype.hide = function hide(event) {
154      var _this2 = this;
155
156      if (event) {
157        event.preventDefault();
158      }
159
160      if (this._isTransitioning || !this._isShown) {
161        return;
162      }
163
164      var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE);
165
166      if (transition) {
167        this._isTransitioning = true;
168      }
169
170      var hideEvent = $.Event(Event.HIDE);
171
172      $(this._element).trigger(hideEvent);
173
174      if (!this._isShown || hideEvent.isDefaultPrevented()) {
175        return;
176      }
177
178      this._isShown = false;
179
180      this._setEscapeEvent();
181      this._setResizeEvent();
182
183      $(document).off(Event.FOCUSIN);
184
185      $(this._element).removeClass(ClassName.SHOW);
186
187      $(this._element).off(Event.CLICK_DISMISS);
188      $(this._dialog).off(Event.MOUSEDOWN_DISMISS);
189
190      if (transition) {
191
192        $(this._element).one(Util.TRANSITION_END, function (event) {
193          return _this2._hideModal(event);
194        }).emulateTransitionEnd(TRANSITION_DURATION);
195      } else {
196        this._hideModal();
197      }
198    };
199
200    Modal.prototype.dispose = function dispose() {
201      $.removeData(this._element, DATA_KEY);
202
203      $(window, document, this._element, this._backdrop).off(EVENT_KEY);
204
205      this._config = null;
206      this._element = null;
207      this._dialog = null;
208      this._backdrop = null;
209      this._isShown = null;
210      this._isBodyOverflowing = null;
211      this._ignoreBackdropClick = null;
212      this._scrollbarWidth = null;
213    };
214
215    Modal.prototype.handleUpdate = function handleUpdate() {
216      this._adjustDialog();
217    };
218
219    // private
220
221    Modal.prototype._getConfig = function _getConfig(config) {
222      config = $.extend({}, Default, config);
223      Util.typeCheckConfig(NAME, config, DefaultType);
224      return config;
225    };
226
227    Modal.prototype._showElement = function _showElement(relatedTarget) {
228      var _this3 = this;
229
230      var transition = Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE);
231
232      if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
233        // don't move modals dom position
234        document.body.appendChild(this._element);
235      }
236
237      this._element.style.display = 'block';
238      this._element.removeAttribute('aria-hidden');
239      this._element.scrollTop = 0;
240
241      if (transition) {
242        Util.reflow(this._element);
243      }
244
245      $(this._element).addClass(ClassName.SHOW);
246
247      if (this._config.focus) {
248        this._enforceFocus();
249      }
250
251      var shownEvent = $.Event(Event.SHOWN, {
252        relatedTarget: relatedTarget
253      });
254
255      var transitionComplete = function transitionComplete() {
256        if (_this3._config.focus) {
257          _this3._element.focus();
258        }
259        _this3._isTransitioning = false;
260        $(_this3._element).trigger(shownEvent);
261      };
262
263      if (transition) {
264        $(this._dialog).one(Util.TRANSITION_END, transitionComplete).emulateTransitionEnd(TRANSITION_DURATION);
265      } else {
266        transitionComplete();
267      }
268    };
269
270    Modal.prototype._enforceFocus = function _enforceFocus() {
271      var _this4 = this;
272
273      $(document).off(Event.FOCUSIN) // guard against infinite focus loop
274      .on(Event.FOCUSIN, function (event) {
275        if (document !== event.target && _this4._element !== event.target && !$(_this4._element).has(event.target).length) {
276          _this4._element.focus();
277        }
278      });
279    };
280
281    Modal.prototype._setEscapeEvent = function _setEscapeEvent() {
282      var _this5 = this;
283
284      if (this._isShown && this._config.keyboard) {
285        $(this._element).on(Event.KEYDOWN_DISMISS, function (event) {
286          if (event.which === ESCAPE_KEYCODE) {
287            event.preventDefault();
288            _this5.hide();
289          }
290        });
291      } else if (!this._isShown) {
292        $(this._element).off(Event.KEYDOWN_DISMISS);
293      }
294    };
295
296    Modal.prototype._setResizeEvent = function _setResizeEvent() {
297      var _this6 = this;
298
299      if (this._isShown) {
300        $(window).on(Event.RESIZE, function (event) {
301          return _this6.handleUpdate(event);
302        });
303      } else {
304        $(window).off(Event.RESIZE);
305      }
306    };
307
308    Modal.prototype._hideModal = function _hideModal() {
309      var _this7 = this;
310
311      this._element.style.display = 'none';
312      this._element.setAttribute('aria-hidden', true);
313      this._isTransitioning = false;
314      this._showBackdrop(function () {
315        $(document.body).removeClass(ClassName.OPEN);
316        _this7._resetAdjustments();
317        _this7._resetScrollbar();
318        $(_this7._element).trigger(Event.HIDDEN);
319      });
320    };
321
322    Modal.prototype._removeBackdrop = function _removeBackdrop() {
323      if (this._backdrop) {
324        $(this._backdrop).remove();
325        this._backdrop = null;
326      }
327    };
328
329    Modal.prototype._showBackdrop = function _showBackdrop(callback) {
330      var _this8 = this;
331
332      var animate = $(this._element).hasClass(ClassName.FADE) ? ClassName.FADE : '';
333
334      if (this._isShown && this._config.backdrop) {
335        var doAnimate = Util.supportsTransitionEnd() && animate;
336
337        this._backdrop = document.createElement('div');
338        this._backdrop.className = ClassName.BACKDROP;
339
340        if (animate) {
341          $(this._backdrop).addClass(animate);
342        }
343
344        $(this._backdrop).appendTo(document.body);
345
346        $(this._element).on(Event.CLICK_DISMISS, function (event) {
347          if (_this8._ignoreBackdropClick) {
348            _this8._ignoreBackdropClick = false;
349            return;
350          }
351          if (event.target !== event.currentTarget) {
352            return;
353          }
354          if (_this8._config.backdrop === 'static') {
355            _this8._element.focus();
356          } else {
357            _this8.hide();
358          }
359        });
360
361        if (doAnimate) {
362          Util.reflow(this._backdrop);
363        }
364
365        $(this._backdrop).addClass(ClassName.SHOW);
366
367        if (!callback) {
368          return;
369        }
370
371        if (!doAnimate) {
372          callback();
373          return;
374        }
375
376        $(this._backdrop).one(Util.TRANSITION_END, callback).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION);
377      } else if (!this._isShown && this._backdrop) {
378        $(this._backdrop).removeClass(ClassName.SHOW);
379
380        var callbackRemove = function callbackRemove() {
381          _this8._removeBackdrop();
382          if (callback) {
383            callback();
384          }
385        };
386
387        if (Util.supportsTransitionEnd() && $(this._element).hasClass(ClassName.FADE)) {
388          $(this._backdrop).one(Util.TRANSITION_END, callbackRemove).emulateTransitionEnd(BACKDROP_TRANSITION_DURATION);
389        } else {
390          callbackRemove();
391        }
392      } else if (callback) {
393        callback();
394      }
395    };
396
397    // ----------------------------------------------------------------------
398    // the following methods are used to handle overflowing modals
399    // todo (fat): these should probably be refactored out of modal.js
400    // ----------------------------------------------------------------------
401
402    Modal.prototype._adjustDialog = function _adjustDialog() {
403      var isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
404
405      if (!this._isBodyOverflowing && isModalOverflowing) {
406        this._element.style.paddingLeft = this._scrollbarWidth + 'px';
407      }
408
409      if (this._isBodyOverflowing && !isModalOverflowing) {
410        this._element.style.paddingRight = this._scrollbarWidth + 'px';
411      }
412    };
413
414    Modal.prototype._resetAdjustments = function _resetAdjustments() {
415      this._element.style.paddingLeft = '';
416      this._element.style.paddingRight = '';
417    };
418
419    Modal.prototype._checkScrollbar = function _checkScrollbar() {
420      this._isBodyOverflowing = document.body.clientWidth < window.innerWidth;
421      this._scrollbarWidth = this._getScrollbarWidth();
422    };
423
424    Modal.prototype._setScrollbar = function _setScrollbar() {
425      var _this9 = this;
426
427      if (this._isBodyOverflowing) {
428        // Note: DOMNode.style.paddingRight returns the actual value or '' if not set
429        //   while $(DOMNode).css('padding-right') returns the calculated value or 0 if not set
430
431        // Adjust fixed content padding
432        $(Selector.FIXED_CONTENT).each(function (index, element) {
433          var actualPadding = $(element)[0].style.paddingRight;
434          var calculatedPadding = $(element).css('padding-right');
435          $(element).data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + _this9._scrollbarWidth + 'px');
436        });
437
438        // Adjust navbar-toggler margin
439        $(Selector.NAVBAR_TOGGLER).each(function (index, element) {
440          var actualMargin = $(element)[0].style.marginRight;
441          var calculatedMargin = $(element).css('margin-right');
442          $(element).data('margin-right', actualMargin).css('margin-right', parseFloat(calculatedMargin) + _this9._scrollbarWidth + 'px');
443        });
444
445        // Adjust body padding
446        var actualPadding = document.body.style.paddingRight;
447        var calculatedPadding = $('body').css('padding-right');
448        $('body').data('padding-right', actualPadding).css('padding-right', parseFloat(calculatedPadding) + this._scrollbarWidth + 'px');
449      }
450    };
451
452    Modal.prototype._resetScrollbar = function _resetScrollbar() {
453      // Restore fixed content padding
454      $(Selector.FIXED_CONTENT).each(function (index, element) {
455        var padding = $(element).data('padding-right');
456        if (typeof padding !== 'undefined') {
457          $(element).css('padding-right', padding).removeData('padding-right');
458        }
459      });
460
461      // Restore navbar-toggler margin
462      $(Selector.NAVBAR_TOGGLER).each(function (index, element) {
463        var margin = $(element).data('margin-right');
464        if (typeof margin !== 'undefined') {
465          $(element).css('margin-right', margin).removeData('margin-right');
466        }
467      });
468
469      // Restore body padding
470      var padding = $('body').data('padding-right');
471      if (typeof padding !== 'undefined') {
472        $('body').css('padding-right', padding).removeData('padding-right');
473      }
474    };
475
476    Modal.prototype._getScrollbarWidth = function _getScrollbarWidth() {
477      // thx d.walsh
478      var scrollDiv = document.createElement('div');
479      scrollDiv.className = ClassName.SCROLLBAR_MEASURER;
480      document.body.appendChild(scrollDiv);
481      var scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth;
482      document.body.removeChild(scrollDiv);
483      return scrollbarWidth;
484    };
485
486    // static
487
488    Modal._jQueryInterface = function _jQueryInterface(config, relatedTarget) {
489      return this.each(function () {
490        var data = $(this).data(DATA_KEY);
491        var _config = $.extend({}, Modal.Default, $(this).data(), (t
491ypeof config === 'undefined' ? 'undefined' : _typeof(config)) === 'object' && config);
492
493        if (!data) {
494          data = new Modal(this, _config);
495          $(this).data(DATA_KEY, data);
496        }
497
498        if (typeof config === 'string') {
499          if (data[config] === undefined) {
500            throw new Error('No method named "' + config + '"');
501          }
502          data[config](relatedTarget);
503        } else if (_config.show) {
504          data.show(relatedTarget);
505        }
506      });
507    };
508
509    _createClass(Modal, null, [{
510      key: 'VERSION',
511      get: function get() {
512        return VERSION;
513      }
514    }, {
515      key: 'Default',
516      get: function get() {
517        return Default;
518      }
519    }]);
520
521    return Modal;
522  }();
523
524  /**
525   * ------------------------------------------------------------------------
526   * Data Api implementation
527   * ------------------------------------------------------------------------
528   */
529
530  $(document).on(Event.CLICK_DATA_API, Selector.DATA_TOGGLE, function (event) {
531    var _this10 = this;
532
533    var target = void 0;
534    var selector = Util.getSelectorFromElement(this);
535
536    if (selector) {
537      target = $(selector)[0];
538    }
539
540    var config = $(target).data(DATA_KEY) ? 'toggle' : $.extend({}, $(target).data(), $(this).data());
541
542    if (this.tagName === 'A' || this.tagName === 'AREA') {
543      event.preventDefault();
544    }
545
546    var $target = $(target).one(Event.SHOW, function (showEvent) {
547      if (showEvent.isDefaultPrevented()) {
548        // only register focus restorer if modal will actually get shown
549        return;
550      }
551
552      $target.one(Event.HIDDEN, function () {
553        if ($(_this10).is(':visible')) {
554          _this10.focus();
555        }
556      });
557    });
558
559    Modal._jQueryInterface.call($(target), config, this);
560  });
561
562  /**
563   * ------------------------------------------------------------------------
564   * jQuery
565   * ------------------------------------------------------------------------
566   */
567
568  $.fn[NAME] = Modal._jQueryInterface;
569  $.fn[NAME].Constructor = Modal;
570  $.fn[NAME].noConflict = function () {
571    $.fn[NAME] = JQUERY_NO_CONFLICT;
572    return Modal._jQueryInterface;
573  };
574
575  return Modal;
576}(jQuery);
577//# sourceMappingURL=modal.js.map

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.