source: imaps-frontend/node_modules/bootstrap/js/dist/modal.js@ d565449

main
Last change on this file since d565449 was d565449, checked in by stefan toskovski <stefantoska84@…>, 4 weeks ago

Update repo after prototype presentation

  • Property mode set to 100644
File size: 10.9 KB
RevLine 
[d565449]1/*!
2 * Bootstrap modal.js v5.3.3 (https://getbootstrap.com/)
3 * Copyright 2011-2024 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('./base-component.js'), require('./dom/event-handler.js'), require('./dom/selector-engine.js'), require('./util/backdrop.js'), require('./util/component-functions.js'), require('./util/focustrap.js'), require('./util/index.js'), require('./util/scrollbar.js')) :
8 typeof define === 'function' && define.amd ? define(['./base-component', './dom/event-handler', './dom/selector-engine', './util/backdrop', './util/component-functions', './util/focustrap', './util/index', './util/scrollbar'], factory) :
9 (global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.Modal = factory(global.BaseComponent, global.EventHandler, global.SelectorEngine, global.Backdrop, global.ComponentFunctions, global.Focustrap, global.Index, global.Scrollbar));
10})(this, (function (BaseComponent, EventHandler, SelectorEngine, Backdrop, componentFunctions_js, FocusTrap, index_js, ScrollBarHelper) { 'use strict';
11
12 /**
13 * --------------------------------------------------------------------------
14 * Bootstrap modal.js
15 * Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
16 * --------------------------------------------------------------------------
17 */
18
19
20 /**
21 * Constants
22 */
23
24 const NAME = 'modal';
25 const DATA_KEY = 'bs.modal';
26 const EVENT_KEY = `.${DATA_KEY}`;
27 const DATA_API_KEY = '.data-api';
28 const ESCAPE_KEY = 'Escape';
29 const EVENT_HIDE = `hide${EVENT_KEY}`;
30 const EVENT_HIDE_PREVENTED = `hidePrevented${EVENT_KEY}`;
31 const EVENT_HIDDEN = `hidden${EVENT_KEY}`;
32 const EVENT_SHOW = `show${EVENT_KEY}`;
33 const EVENT_SHOWN = `shown${EVENT_KEY}`;
34 const EVENT_RESIZE = `resize${EVENT_KEY}`;
35 const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`;
36 const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY}`;
37 const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`;
38 const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`;
39 const CLASS_NAME_OPEN = 'modal-open';
40 const CLASS_NAME_FADE = 'fade';
41 const CLASS_NAME_SHOW = 'show';
42 const CLASS_NAME_STATIC = 'modal-static';
43 const OPEN_SELECTOR = '.modal.show';
44 const SELECTOR_DIALOG = '.modal-dialog';
45 const SELECTOR_MODAL_BODY = '.modal-body';
46 const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="modal"]';
47 const Default = {
48 backdrop: true,
49 focus: true,
50 keyboard: true
51 };
52 const DefaultType = {
53 backdrop: '(boolean|string)',
54 focus: 'boolean',
55 keyboard: 'boolean'
56 };
57
58 /**
59 * Class definition
60 */
61
62 class Modal extends BaseComponent {
63 constructor(element, config) {
64 super(element, config);
65 this._dialog = SelectorEngine.findOne(SELECTOR_DIALOG, this._element);
66 this._backdrop = this._initializeBackDrop();
67 this._focustrap = this._initializeFocusTrap();
68 this._isShown = false;
69 this._isTransitioning = false;
70 this._scrollBar = new ScrollBarHelper();
71 this._addEventListeners();
72 }
73
74 // Getters
75 static get Default() {
76 return Default;
77 }
78 static get DefaultType() {
79 return DefaultType;
80 }
81 static get NAME() {
82 return NAME;
83 }
84
85 // Public
86 toggle(relatedTarget) {
87 return this._isShown ? this.hide() : this.show(relatedTarget);
88 }
89 show(relatedTarget) {
90 if (this._isShown || this._isTransitioning) {
91 return;
92 }
93 const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, {
94 relatedTarget
95 });
96 if (showEvent.defaultPrevented) {
97 return;
98 }
99 this._isShown = true;
100 this._isTransitioning = true;
101 this._scrollBar.hide();
102 document.body.classList.add(CLASS_NAME_OPEN);
103 this._adjustDialog();
104 this._backdrop.show(() => this._showElement(relatedTarget));
105 }
106 hide() {
107 if (!this._isShown || this._isTransitioning) {
108 return;
109 }
110 const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE);
111 if (hideEvent.defaultPrevented) {
112 return;
113 }
114 this._isShown = false;
115 this._isTransitioning = true;
116 this._focustrap.deactivate();
117 this._element.classList.remove(CLASS_NAME_SHOW);
118 this._queueCallback(() => this._hideModal(), this._element, this._isAnimated());
119 }
120 dispose() {
121 EventHandler.off(window, EVENT_KEY);
122 EventHandler.off(this._dialog, EVENT_KEY);
123 this._backdrop.dispose();
124 this._focustrap.deactivate();
125 super.dispose();
126 }
127 handleUpdate() {
128 this._adjustDialog();
129 }
130
131 // Private
132 _initializeBackDrop() {
133 return new Backdrop({
134 isVisible: Boolean(this._config.backdrop),
135 // 'static' option will be translated to true, and booleans will keep their value,
136 isAnimated: this._isAnimated()
137 });
138 }
139 _initializeFocusTrap() {
140 return new FocusTrap({
141 trapElement: this._element
142 });
143 }
144 _showElement(relatedTarget) {
145 // try to append dynamic modal
146 if (!document.body.contains(this._element)) {
147 document.body.append(this._element);
148 }
149 this._element.style.display = 'block';
150 this._element.removeAttribute('aria-hidden');
151 this._element.setAttribute('aria-modal', true);
152 this._element.setAttribute('role', 'dialog');
153 this._element.scrollTop = 0;
154 const modalBody = SelectorEngine.findOne(SELECTOR_MODAL_BODY, this._dialog);
155 if (modalBody) {
156 modalBody.scrollTop = 0;
157 }
158 index_js.reflow(this._element);
159 this._element.classList.add(CLASS_NAME_SHOW);
160 const transitionComplete = () => {
161 if (this._config.focus) {
162 this._focustrap.activate();
163 }
164 this._isTransitioning = false;
165 EventHandler.trigger(this._element, EVENT_SHOWN, {
166 relatedTarget
167 });
168 };
169 this._queueCallback(transitionComplete, this._dialog, this._isAnimated());
170 }
171 _addEventListeners() {
172 EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, event => {
173 if (event.key !== ESCAPE_KEY) {
174 return;
175 }
176 if (this._config.keyboard) {
177 this.hide();
178 return;
179 }
180 this._triggerBackdropTransition();
181 });
182 EventHandler.on(window, EVENT_RESIZE, () => {
183 if (this._isShown && !this._isTransitioning) {
184 this._adjustDialog();
185 }
186 });
187 EventHandler.on(this._element, EVENT_MOUSEDOWN_DISMISS, event => {
188 // a bad trick to segregate clicks that may start inside dialog but end outside, and avoid listen to scrollbar clicks
189 EventHandler.one(this._element, EVENT_CLICK_DISMISS, event2 => {
190 if (this._element !== event.target || this._element !== event2.target) {
191 return;
192 }
193 if (this._config.backdrop === 'static') {
194 this._triggerBackdropTransition();
195 return;
196 }
197 if (this._config.backdrop) {
198 this.hide();
199 }
200 });
201 });
202 }
203 _hideModal() {
204 this._element.style.display = 'none';
205 this._element.setAttribute('aria-hidden', true);
206 this._element.removeAttribute('aria-modal');
207 this._element.removeAttribute('role');
208 this._isTransitioning = false;
209 this._backdrop.hide(() => {
210 document.body.classList.remove(CLASS_NAME_OPEN);
211 this._resetAdjustments();
212 this._scrollBar.reset();
213 EventHandler.trigger(this._element, EVENT_HIDDEN);
214 });
215 }
216 _isAnimated() {
217 return this._element.classList.contains(CLASS_NAME_FADE);
218 }
219 _triggerBackdropTransition() {
220 const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED);
221 if (hideEvent.defaultPrevented) {
222 return;
223 }
224 const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
225 const initialOverflowY = this._element.style.overflowY;
226 // return if the following background transition hasn't yet completed
227 if (initialOverflowY === 'hidden' || this._element.classList.contains(CLASS_NAME_STATIC)) {
228 return;
229 }
230 if (!isModalOverflowing) {
231 this._element.style.overflowY = 'hidden';
232 }
233 this._element.classList.add(CLASS_NAME_STATIC);
234 this._queueCallback(() => {
235 this._element.classList.remove(CLASS_NAME_STATIC);
236 this._queueCallback(() => {
237 this._element.style.overflowY = initialOverflowY;
238 }, this._dialog);
239 }, this._dialog);
240 this._element.focus();
241 }
242
243 /**
244 * The following methods are used to handle overflowing modals
245 */
246
247 _adjustDialog() {
248 const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight;
249 const scrollbarWidth = this._scrollBar.getWidth();
250 const isBodyOverflowing = scrollbarWidth > 0;
251 if (isBodyOverflowing && !isModalOverflowing) {
252 const property = index_js.isRTL() ? 'paddingLeft' : 'paddingRight';
253 this._element.style[property] = `${scrollbarWidth}px`;
254 }
255 if (!isBodyOverflowing && isModalOverflowing) {
256 const property = index_js.isRTL() ? 'paddingRight' : 'paddingLeft';
257 this._element.style[property] = `${scrollbarWidth}px`;
258 }
259 }
260 _resetAdjustments() {
261 this._element.style.paddingLeft = '';
262 this._element.style.paddingRight = '';
263 }
264
265 // Static
266 static jQueryInterface(config, relatedTarget) {
267 return this.each(function () {
268 const data = Modal.getOrCreateInstance(this, config);
269 if (typeof config !== 'string') {
270 return;
271 }
272 if (typeof data[config] === 'undefined') {
273 throw new TypeError(`No method named "${config}"`);
274 }
275 data[config](relatedTarget);
276 });
277 }
278 }
279
280 /**
281 * Data API implementation
282 */
283
284 EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
285 const target = SelectorEngine.getElementFromSelector(this);
286 if (['A', 'AREA'].includes(this.tagName)) {
287 event.preventDefault();
288 }
289 EventHandler.one(target, EVENT_SHOW, showEvent => {
290 if (showEvent.defaultPrevented) {
291 // only register focus restorer if modal will actually get shown
292 return;
293 }
294 EventHandler.one(target, EVENT_HIDDEN, () => {
295 if (index_js.isVisible(this)) {
296 this.focus();
297 }
298 });
299 });
300
301 // avoid conflict when clicking modal toggler while another one is open
302 const alreadyOpen = SelectorEngine.findOne(OPEN_SELECTOR);
303 if (alreadyOpen) {
304 Modal.getInstance(alreadyOpen).hide();
305 }
306 const data = Modal.getOrCreateInstance(target);
307 data.toggle(this);
308 });
309 componentFunctions_js.enableDismissTrigger(Modal);
310
311 /**
312 * jQuery
313 */
314
315 index_js.defineJQueryPlugin(Modal);
316
317 return Modal;
318
319}));
320//# sourceMappingURL=modal.js.map
Note: See TracBrowser for help on using the repository browser.