administrate-bootstrap-theme 0.1.0 → 0.1.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +25 -11
- data/Rakefile +10 -14
- data/app/assets/config/administrate-bootstrap-theme_manifest.js +1 -0
- data/app/assets/javascripts/administrate-bootstrap-theme/theme.js +2 -0
- data/app/assets/stylesheets/administrate-bootstrap-theme/_base.scss +17 -1
- data/app/assets/stylesheets/administrate-bootstrap-theme/components/_content_body.scss +17 -3
- data/app/assets/stylesheets/administrate-bootstrap-theme/components/_form.scss +52 -16
- data/app/assets/stylesheets/administrate-bootstrap-theme/theme.scss +12 -0
- data/lib/administrate-bootstrap-theme/engine.rb +2 -0
- data/lib/administrate-bootstrap-theme/version.rb +1 -1
- data/node_modules/bootstrap/js/src/alert.js +141 -0
- data/node_modules/bootstrap/js/src/base-component.js +46 -0
- data/node_modules/bootstrap/js/src/button.js +95 -0
- data/node_modules/bootstrap/js/src/carousel.js +624 -0
- data/node_modules/bootstrap/js/src/collapse.js +410 -0
- data/node_modules/bootstrap/js/src/dom/data.js +57 -0
- data/node_modules/bootstrap/js/src/dom/event-handler.js +331 -0
- data/node_modules/bootstrap/js/src/dom/manipulator.js +80 -0
- data/node_modules/bootstrap/js/src/dom/selector-engine.js +75 -0
- data/node_modules/bootstrap/js/src/dropdown.js +543 -0
- data/node_modules/bootstrap/js/src/modal.js +582 -0
- data/node_modules/bootstrap/js/src/offcanvas.js +279 -0
- data/node_modules/bootstrap/js/src/popover.js +171 -0
- data/node_modules/bootstrap/js/src/scrollspy.js +319 -0
- data/node_modules/bootstrap/js/src/tab.js +220 -0
- data/node_modules/bootstrap/js/src/toast.js +219 -0
- data/node_modules/bootstrap/js/src/tooltip.js +802 -0
- data/node_modules/bootstrap/js/src/util/index.js +253 -0
- data/node_modules/bootstrap/js/src/util/sanitizer.js +127 -0
- data/node_modules/bootstrap/js/src/util/scrollbar.js +70 -0
- data/node_modules/bootstrap/scss/_accordion.scss +116 -0
- data/node_modules/bootstrap/scss/_alert.scss +57 -0
- data/node_modules/bootstrap/scss/_badge.scss +29 -0
- data/node_modules/bootstrap/scss/_breadcrumb.scss +28 -0
- data/node_modules/bootstrap/scss/_button-group.scss +139 -0
- data/node_modules/bootstrap/scss/_buttons.scss +111 -0
- data/node_modules/bootstrap/scss/_card.scss +215 -0
- data/node_modules/bootstrap/scss/_carousel.scss +229 -0
- data/node_modules/bootstrap/scss/_close.scss +40 -0
- data/node_modules/bootstrap/scss/_containers.scss +41 -0
- data/node_modules/bootstrap/scss/_dropdown.scss +246 -0
- data/node_modules/bootstrap/scss/_forms.scss +9 -0
- data/node_modules/bootstrap/scss/_functions.scss +205 -0
- data/node_modules/bootstrap/scss/_grid.scss +22 -0
- data/node_modules/bootstrap/scss/_helpers.scss +7 -0
- data/node_modules/bootstrap/scss/_images.scss +42 -0
- data/node_modules/bootstrap/scss/_list-group.scss +174 -0
- data/node_modules/bootstrap/scss/_mixins.scss +41 -0
- data/node_modules/bootstrap/scss/_modal.scss +237 -0
- data/node_modules/bootstrap/scss/_nav.scss +139 -0
- data/node_modules/bootstrap/scss/_navbar.scss +306 -0
- data/node_modules/bootstrap/scss/_offcanvas.scss +77 -0
- data/node_modules/bootstrap/scss/_pagination.scss +64 -0
- data/node_modules/bootstrap/scss/_popover.scss +158 -0
- data/node_modules/bootstrap/scss/_progress.scss +48 -0
- data/node_modules/bootstrap/scss/_reboot.scss +621 -0
- data/node_modules/bootstrap/scss/_root.scss +16 -0
- data/node_modules/bootstrap/scss/_spinners.scss +69 -0
- data/node_modules/bootstrap/scss/_tables.scss +150 -0
- data/node_modules/bootstrap/scss/_toasts.scss +51 -0
- data/node_modules/bootstrap/scss/_tooltip.scss +115 -0
- data/node_modules/bootstrap/scss/_transitions.scss +21 -0
- data/node_modules/bootstrap/scss/_type.scss +104 -0
- data/node_modules/bootstrap/scss/_utilities.scss +594 -0
- data/node_modules/bootstrap/scss/_variables.scss +1464 -0
- data/node_modules/bootstrap/scss/bootstrap-grid.scss +65 -0
- data/node_modules/bootstrap/scss/bootstrap-reboot.scss +15 -0
- data/node_modules/bootstrap/scss/bootstrap-utilities.scss +18 -0
- data/node_modules/bootstrap/scss/bootstrap.scss +52 -0
- data/node_modules/bootstrap/scss/forms/_floating-labels.scss +61 -0
- data/node_modules/bootstrap/scss/forms/_form-check.scss +152 -0
- data/node_modules/bootstrap/scss/forms/_form-control.scss +219 -0
- data/node_modules/bootstrap/scss/forms/_form-range.scss +91 -0
- data/node_modules/bootstrap/scss/forms/_form-select.scss +67 -0
- data/node_modules/bootstrap/scss/forms/_form-text.scss +11 -0
- data/node_modules/bootstrap/scss/forms/_input-group.scss +121 -0
- data/node_modules/bootstrap/scss/forms/_labels.scss +36 -0
- data/node_modules/bootstrap/scss/forms/_validation.scss +12 -0
- data/node_modules/bootstrap/scss/helpers/_clearfix.scss +3 -0
- data/node_modules/bootstrap/scss/helpers/_colored-links.scss +12 -0
- data/node_modules/bootstrap/scss/helpers/_position.scss +30 -0
- data/node_modules/bootstrap/scss/helpers/_ratio.scss +26 -0
- data/node_modules/bootstrap/scss/helpers/_stretched-link.scss +15 -0
- data/node_modules/bootstrap/scss/helpers/_text-truncation.scss +7 -0
- data/node_modules/bootstrap/scss/helpers/_visually-hidden.scss +8 -0
- data/node_modules/bootstrap/scss/mixins/_alert.scss +11 -0
- data/node_modules/bootstrap/scss/mixins/_border-radius.scss +78 -0
- data/node_modules/bootstrap/scss/mixins/_box-shadow.scss +18 -0
- data/node_modules/bootstrap/scss/mixins/_breakpoints.scss +127 -0
- data/node_modules/bootstrap/scss/mixins/_buttons.scss +133 -0
- data/node_modules/bootstrap/scss/mixins/_caret.scss +64 -0
- data/node_modules/bootstrap/scss/mixins/_clearfix.scss +9 -0
- data/node_modules/bootstrap/scss/mixins/_container.scss +9 -0
- data/node_modules/bootstrap/scss/mixins/_deprecate.scss +10 -0
- data/node_modules/bootstrap/scss/mixins/_forms.scss +134 -0
- data/node_modules/bootstrap/scss/mixins/_gradients.scss +47 -0
- data/node_modules/bootstrap/scss/mixins/_grid.scss +120 -0
- data/node_modules/bootstrap/scss/mixins/_image.scss +16 -0
- data/node_modules/bootstrap/scss/mixins/_list-group.scss +24 -0
- data/node_modules/bootstrap/scss/mixins/_lists.scss +7 -0
- data/node_modules/bootstrap/scss/mixins/_pagination.scss +31 -0
- data/node_modules/bootstrap/scss/mixins/_reset-text.scss +17 -0
- data/node_modules/bootstrap/scss/mixins/_resize.scss +6 -0
- data/node_modules/bootstrap/scss/mixins/_table-variants.scss +21 -0
- data/node_modules/bootstrap/scss/mixins/_text-truncate.scss +8 -0
- data/node_modules/bootstrap/scss/mixins/_transition.scss +26 -0
- data/node_modules/bootstrap/scss/mixins/_utilities.scss +68 -0
- data/node_modules/bootstrap/scss/mixins/_visually-hidden.scss +29 -0
- data/node_modules/bootstrap/scss/utilities/_api.scss +47 -0
- data/node_modules/bootstrap/scss/vendor/_rfs.scss +312 -0
- metadata +106 -19
@@ -0,0 +1,582 @@
|
|
1
|
+
/**
|
2
|
+
* --------------------------------------------------------------------------
|
3
|
+
* Bootstrap (v5.0.0-beta3): modal.js
|
4
|
+
* Licensed under MIT (https://github.com/twbs/bootstrap/blob/main/LICENSE)
|
5
|
+
* --------------------------------------------------------------------------
|
6
|
+
*/
|
7
|
+
|
8
|
+
import {
|
9
|
+
defineJQueryPlugin,
|
10
|
+
emulateTransitionEnd,
|
11
|
+
getElementFromSelector,
|
12
|
+
getTransitionDurationFromElement,
|
13
|
+
isVisible,
|
14
|
+
isRTL,
|
15
|
+
reflow,
|
16
|
+
typeCheckConfig
|
17
|
+
} from './util/index'
|
18
|
+
import Data from './dom/data'
|
19
|
+
import EventHandler from './dom/event-handler'
|
20
|
+
import Manipulator from './dom/manipulator'
|
21
|
+
import SelectorEngine from './dom/selector-engine'
|
22
|
+
import BaseComponent from './base-component'
|
23
|
+
|
24
|
+
/**
|
25
|
+
* ------------------------------------------------------------------------
|
26
|
+
* Constants
|
27
|
+
* ------------------------------------------------------------------------
|
28
|
+
*/
|
29
|
+
|
30
|
+
const NAME = 'modal'
|
31
|
+
const DATA_KEY = 'bs.modal'
|
32
|
+
const EVENT_KEY = `.${DATA_KEY}`
|
33
|
+
const DATA_API_KEY = '.data-api'
|
34
|
+
const ESCAPE_KEY = 'Escape'
|
35
|
+
|
36
|
+
const Default = {
|
37
|
+
backdrop: true,
|
38
|
+
keyboard: true,
|
39
|
+
focus: true
|
40
|
+
}
|
41
|
+
|
42
|
+
const DefaultType = {
|
43
|
+
backdrop: '(boolean|string)',
|
44
|
+
keyboard: 'boolean',
|
45
|
+
focus: 'boolean'
|
46
|
+
}
|
47
|
+
|
48
|
+
const EVENT_HIDE = `hide${EVENT_KEY}`
|
49
|
+
const EVENT_HIDE_PREVENTED = `hidePrevented${EVENT_KEY}`
|
50
|
+
const EVENT_HIDDEN = `hidden${EVENT_KEY}`
|
51
|
+
const EVENT_SHOW = `show${EVENT_KEY}`
|
52
|
+
const EVENT_SHOWN = `shown${EVENT_KEY}`
|
53
|
+
const EVENT_FOCUSIN = `focusin${EVENT_KEY}`
|
54
|
+
const EVENT_RESIZE = `resize${EVENT_KEY}`
|
55
|
+
const EVENT_CLICK_DISMISS = `click.dismiss${EVENT_KEY}`
|
56
|
+
const EVENT_KEYDOWN_DISMISS = `keydown.dismiss${EVENT_KEY}`
|
57
|
+
const EVENT_MOUSEUP_DISMISS = `mouseup.dismiss${EVENT_KEY}`
|
58
|
+
const EVENT_MOUSEDOWN_DISMISS = `mousedown.dismiss${EVENT_KEY}`
|
59
|
+
const EVENT_CLICK_DATA_API = `click${EVENT_KEY}${DATA_API_KEY}`
|
60
|
+
|
61
|
+
const CLASS_NAME_SCROLLBAR_MEASURER = 'modal-scrollbar-measure'
|
62
|
+
const CLASS_NAME_BACKDROP = 'modal-backdrop'
|
63
|
+
const CLASS_NAME_OPEN = 'modal-open'
|
64
|
+
const CLASS_NAME_FADE = 'fade'
|
65
|
+
const CLASS_NAME_SHOW = 'show'
|
66
|
+
const CLASS_NAME_STATIC = 'modal-static'
|
67
|
+
|
68
|
+
const SELECTOR_DIALOG = '.modal-dialog'
|
69
|
+
const SELECTOR_MODAL_BODY = '.modal-body'
|
70
|
+
const SELECTOR_DATA_TOGGLE = '[data-bs-toggle="modal"]'
|
71
|
+
const SELECTOR_DATA_DISMISS = '[data-bs-dismiss="modal"]'
|
72
|
+
const SELECTOR_FIXED_CONTENT = '.fixed-top, .fixed-bottom, .is-fixed, .sticky-top'
|
73
|
+
const SELECTOR_STICKY_CONTENT = '.sticky-top'
|
74
|
+
|
75
|
+
/**
|
76
|
+
* ------------------------------------------------------------------------
|
77
|
+
* Class Definition
|
78
|
+
* ------------------------------------------------------------------------
|
79
|
+
*/
|
80
|
+
|
81
|
+
class Modal extends BaseComponent {
|
82
|
+
constructor(element, config) {
|
83
|
+
super(element)
|
84
|
+
|
85
|
+
this._config = this._getConfig(config)
|
86
|
+
this._dialog = SelectorEngine.findOne(SELECTOR_DIALOG, this._element)
|
87
|
+
this._backdrop = null
|
88
|
+
this._isShown = false
|
89
|
+
this._isBodyOverflowing = false
|
90
|
+
this._ignoreBackdropClick = false
|
91
|
+
this._isTransitioning = false
|
92
|
+
this._scrollbarWidth = 0
|
93
|
+
}
|
94
|
+
|
95
|
+
// Getters
|
96
|
+
|
97
|
+
static get Default() {
|
98
|
+
return Default
|
99
|
+
}
|
100
|
+
|
101
|
+
static get DATA_KEY() {
|
102
|
+
return DATA_KEY
|
103
|
+
}
|
104
|
+
|
105
|
+
// Public
|
106
|
+
|
107
|
+
toggle(relatedTarget) {
|
108
|
+
return this._isShown ? this.hide() : this.show(relatedTarget)
|
109
|
+
}
|
110
|
+
|
111
|
+
show(relatedTarget) {
|
112
|
+
if (this._isShown || this._isTransitioning) {
|
113
|
+
return
|
114
|
+
}
|
115
|
+
|
116
|
+
if (this._isAnimated()) {
|
117
|
+
this._isTransitioning = true
|
118
|
+
}
|
119
|
+
|
120
|
+
const showEvent = EventHandler.trigger(this._element, EVENT_SHOW, {
|
121
|
+
relatedTarget
|
122
|
+
})
|
123
|
+
|
124
|
+
if (this._isShown || showEvent.defaultPrevented) {
|
125
|
+
return
|
126
|
+
}
|
127
|
+
|
128
|
+
this._isShown = true
|
129
|
+
|
130
|
+
this._checkScrollbar()
|
131
|
+
this._setScrollbar()
|
132
|
+
|
133
|
+
this._adjustDialog()
|
134
|
+
|
135
|
+
this._setEscapeEvent()
|
136
|
+
this._setResizeEvent()
|
137
|
+
|
138
|
+
EventHandler.on(this._element, EVENT_CLICK_DISMISS, SELECTOR_DATA_DISMISS, event => this.hide(event))
|
139
|
+
|
140
|
+
EventHandler.on(this._dialog, EVENT_MOUSEDOWN_DISMISS, () => {
|
141
|
+
EventHandler.one(this._element, EVENT_MOUSEUP_DISMISS, event => {
|
142
|
+
if (event.target === this._element) {
|
143
|
+
this._ignoreBackdropClick = true
|
144
|
+
}
|
145
|
+
})
|
146
|
+
})
|
147
|
+
|
148
|
+
this._showBackdrop(() => this._showElement(relatedTarget))
|
149
|
+
}
|
150
|
+
|
151
|
+
hide(event) {
|
152
|
+
if (event) {
|
153
|
+
event.preventDefault()
|
154
|
+
}
|
155
|
+
|
156
|
+
if (!this._isShown || this._isTransitioning) {
|
157
|
+
return
|
158
|
+
}
|
159
|
+
|
160
|
+
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE)
|
161
|
+
|
162
|
+
if (hideEvent.defaultPrevented) {
|
163
|
+
return
|
164
|
+
}
|
165
|
+
|
166
|
+
this._isShown = false
|
167
|
+
const isAnimated = this._isAnimated()
|
168
|
+
|
169
|
+
if (isAnimated) {
|
170
|
+
this._isTransitioning = true
|
171
|
+
}
|
172
|
+
|
173
|
+
this._setEscapeEvent()
|
174
|
+
this._setResizeEvent()
|
175
|
+
|
176
|
+
EventHandler.off(document, EVENT_FOCUSIN)
|
177
|
+
|
178
|
+
this._element.classList.remove(CLASS_NAME_SHOW)
|
179
|
+
|
180
|
+
EventHandler.off(this._element, EVENT_CLICK_DISMISS)
|
181
|
+
EventHandler.off(this._dialog, EVENT_MOUSEDOWN_DISMISS)
|
182
|
+
|
183
|
+
if (isAnimated) {
|
184
|
+
const transitionDuration = getTransitionDurationFromElement(this._element)
|
185
|
+
|
186
|
+
EventHandler.one(this._element, 'transitionend', event => this._hideModal(event))
|
187
|
+
emulateTransitionEnd(this._element, transitionDuration)
|
188
|
+
} else {
|
189
|
+
this._hideModal()
|
190
|
+
}
|
191
|
+
}
|
192
|
+
|
193
|
+
dispose() {
|
194
|
+
[window, this._element, this._dialog]
|
195
|
+
.forEach(htmlElement => EventHandler.off(htmlElement, EVENT_KEY))
|
196
|
+
|
197
|
+
super.dispose()
|
198
|
+
|
199
|
+
/**
|
200
|
+
* `document` has 2 events `EVENT_FOCUSIN` and `EVENT_CLICK_DATA_API`
|
201
|
+
* Do not move `document` in `htmlElements` array
|
202
|
+
* It will remove `EVENT_CLICK_DATA_API` event that should remain
|
203
|
+
*/
|
204
|
+
EventHandler.off(document, EVENT_FOCUSIN)
|
205
|
+
|
206
|
+
this._config = null
|
207
|
+
this._dialog = null
|
208
|
+
this._backdrop = null
|
209
|
+
this._isShown = null
|
210
|
+
this._isBodyOverflowing = null
|
211
|
+
this._ignoreBackdropClick = null
|
212
|
+
this._isTransitioning = null
|
213
|
+
this._scrollbarWidth = null
|
214
|
+
}
|
215
|
+
|
216
|
+
handleUpdate() {
|
217
|
+
this._adjustDialog()
|
218
|
+
}
|
219
|
+
|
220
|
+
// Private
|
221
|
+
|
222
|
+
_getConfig(config) {
|
223
|
+
config = {
|
224
|
+
...Default,
|
225
|
+
...config
|
226
|
+
}
|
227
|
+
typeCheckConfig(NAME, config, DefaultType)
|
228
|
+
return config
|
229
|
+
}
|
230
|
+
|
231
|
+
_showElement(relatedTarget) {
|
232
|
+
const isAnimated = this._isAnimated()
|
233
|
+
const modalBody = SelectorEngine.findOne(SELECTOR_MODAL_BODY, this._dialog)
|
234
|
+
|
235
|
+
if (!this._element.parentNode || this._element.parentNode.nodeType !== Node.ELEMENT_NODE) {
|
236
|
+
// Don't move modal's DOM position
|
237
|
+
document.body.appendChild(this._element)
|
238
|
+
}
|
239
|
+
|
240
|
+
this._element.style.display = 'block'
|
241
|
+
this._element.removeAttribute('aria-hidden')
|
242
|
+
this._element.setAttribute('aria-modal', true)
|
243
|
+
this._element.setAttribute('role', 'dialog')
|
244
|
+
this._element.scrollTop = 0
|
245
|
+
|
246
|
+
if (modalBody) {
|
247
|
+
modalBody.scrollTop = 0
|
248
|
+
}
|
249
|
+
|
250
|
+
if (isAnimated) {
|
251
|
+
reflow(this._element)
|
252
|
+
}
|
253
|
+
|
254
|
+
this._element.classList.add(CLASS_NAME_SHOW)
|
255
|
+
|
256
|
+
if (this._config.focus) {
|
257
|
+
this._enforceFocus()
|
258
|
+
}
|
259
|
+
|
260
|
+
const transitionComplete = () => {
|
261
|
+
if (this._config.focus) {
|
262
|
+
this._element.focus()
|
263
|
+
}
|
264
|
+
|
265
|
+
this._isTransitioning = false
|
266
|
+
EventHandler.trigger(this._element, EVENT_SHOWN, {
|
267
|
+
relatedTarget
|
268
|
+
})
|
269
|
+
}
|
270
|
+
|
271
|
+
if (isAnimated) {
|
272
|
+
const transitionDuration = getTransitionDurationFromElement(this._dialog)
|
273
|
+
|
274
|
+
EventHandler.one(this._dialog, 'transitionend', transitionComplete)
|
275
|
+
emulateTransitionEnd(this._dialog, transitionDuration)
|
276
|
+
} else {
|
277
|
+
transitionComplete()
|
278
|
+
}
|
279
|
+
}
|
280
|
+
|
281
|
+
_enforceFocus() {
|
282
|
+
EventHandler.off(document, EVENT_FOCUSIN) // guard against infinite focus loop
|
283
|
+
EventHandler.on(document, EVENT_FOCUSIN, event => {
|
284
|
+
if (document !== event.target &&
|
285
|
+
this._element !== event.target &&
|
286
|
+
!this._element.contains(event.target)) {
|
287
|
+
this._element.focus()
|
288
|
+
}
|
289
|
+
})
|
290
|
+
}
|
291
|
+
|
292
|
+
_setEscapeEvent() {
|
293
|
+
if (this._isShown) {
|
294
|
+
EventHandler.on(this._element, EVENT_KEYDOWN_DISMISS, event => {
|
295
|
+
if (this._config.keyboard && event.key === ESCAPE_KEY) {
|
296
|
+
event.preventDefault()
|
297
|
+
this.hide()
|
298
|
+
} else if (!this._config.keyboard && event.key === ESCAPE_KEY) {
|
299
|
+
this._triggerBackdropTransition()
|
300
|
+
}
|
301
|
+
})
|
302
|
+
} else {
|
303
|
+
EventHandler.off(this._element, EVENT_KEYDOWN_DISMISS)
|
304
|
+
}
|
305
|
+
}
|
306
|
+
|
307
|
+
_setResizeEvent() {
|
308
|
+
if (this._isShown) {
|
309
|
+
EventHandler.on(window, EVENT_RESIZE, () => this._adjustDialog())
|
310
|
+
} else {
|
311
|
+
EventHandler.off(window, EVENT_RESIZE)
|
312
|
+
}
|
313
|
+
}
|
314
|
+
|
315
|
+
_hideModal() {
|
316
|
+
this._element.style.display = 'none'
|
317
|
+
this._element.setAttribute('aria-hidden', true)
|
318
|
+
this._element.removeAttribute('aria-modal')
|
319
|
+
this._element.removeAttribute('role')
|
320
|
+
this._isTransitioning = false
|
321
|
+
this._showBackdrop(() => {
|
322
|
+
document.body.classList.remove(CLASS_NAME_OPEN)
|
323
|
+
this._resetAdjustments()
|
324
|
+
this._resetScrollbar()
|
325
|
+
EventHandler.trigger(this._element, EVENT_HIDDEN)
|
326
|
+
})
|
327
|
+
}
|
328
|
+
|
329
|
+
_removeBackdrop() {
|
330
|
+
this._backdrop.parentNode.removeChild(this._backdrop)
|
331
|
+
this._backdrop = null
|
332
|
+
}
|
333
|
+
|
334
|
+
_showBackdrop(callback) {
|
335
|
+
const isAnimated = this._isAnimated()
|
336
|
+
if (this._isShown && this._config.backdrop) {
|
337
|
+
this._backdrop = document.createElement('div')
|
338
|
+
this._backdrop.className = CLASS_NAME_BACKDROP
|
339
|
+
|
340
|
+
if (isAnimated) {
|
341
|
+
this._backdrop.classList.add(CLASS_NAME_FADE)
|
342
|
+
}
|
343
|
+
|
344
|
+
document.body.appendChild(this._backdrop)
|
345
|
+
|
346
|
+
EventHandler.on(this._element, EVENT_CLICK_DISMISS, event => {
|
347
|
+
if (this._ignoreBackdropClick) {
|
348
|
+
this._ignoreBackdropClick = false
|
349
|
+
return
|
350
|
+
}
|
351
|
+
|
352
|
+
if (event.target !== event.currentTarget) {
|
353
|
+
return
|
354
|
+
}
|
355
|
+
|
356
|
+
if (this._config.backdrop === 'static') {
|
357
|
+
this._triggerBackdropTransition()
|
358
|
+
} else {
|
359
|
+
this.hide()
|
360
|
+
}
|
361
|
+
})
|
362
|
+
|
363
|
+
if (isAnimated) {
|
364
|
+
reflow(this._backdrop)
|
365
|
+
}
|
366
|
+
|
367
|
+
this._backdrop.classList.add(CLASS_NAME_SHOW)
|
368
|
+
|
369
|
+
if (!isAnimated) {
|
370
|
+
callback()
|
371
|
+
return
|
372
|
+
}
|
373
|
+
|
374
|
+
const backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop)
|
375
|
+
|
376
|
+
EventHandler.one(this._backdrop, 'transitionend', callback)
|
377
|
+
emulateTransitionEnd(this._backdrop, backdropTransitionDuration)
|
378
|
+
} else if (!this._isShown && this._backdrop) {
|
379
|
+
this._backdrop.classList.remove(CLASS_NAME_SHOW)
|
380
|
+
|
381
|
+
const callbackRemove = () => {
|
382
|
+
this._removeBackdrop()
|
383
|
+
callback()
|
384
|
+
}
|
385
|
+
|
386
|
+
if (isAnimated) {
|
387
|
+
const backdropTransitionDuration = getTransitionDurationFromElement(this._backdrop)
|
388
|
+
EventHandler.one(this._backdrop, 'transitionend', callbackRemove)
|
389
|
+
emulateTransitionEnd(this._backdrop, backdropTransitionDuration)
|
390
|
+
} else {
|
391
|
+
callbackRemove()
|
392
|
+
}
|
393
|
+
} else {
|
394
|
+
callback()
|
395
|
+
}
|
396
|
+
}
|
397
|
+
|
398
|
+
_isAnimated() {
|
399
|
+
return this._element.classList.contains(CLASS_NAME_FADE)
|
400
|
+
}
|
401
|
+
|
402
|
+
_triggerBackdropTransition() {
|
403
|
+
const hideEvent = EventHandler.trigger(this._element, EVENT_HIDE_PREVENTED)
|
404
|
+
if (hideEvent.defaultPrevented) {
|
405
|
+
return
|
406
|
+
}
|
407
|
+
|
408
|
+
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
|
409
|
+
|
410
|
+
if (!isModalOverflowing) {
|
411
|
+
this._element.style.overflowY = 'hidden'
|
412
|
+
}
|
413
|
+
|
414
|
+
this._element.classList.add(CLASS_NAME_STATIC)
|
415
|
+
const modalTransitionDuration = getTransitionDurationFromElement(this._dialog)
|
416
|
+
EventHandler.off(this._element, 'transitionend')
|
417
|
+
EventHandler.one(this._element, 'transitionend', () => {
|
418
|
+
this._element.classList.remove(CLASS_NAME_STATIC)
|
419
|
+
if (!isModalOverflowing) {
|
420
|
+
EventHandler.one(this._element, 'transitionend', () => {
|
421
|
+
this._element.style.overflowY = ''
|
422
|
+
})
|
423
|
+
emulateTransitionEnd(this._element, modalTransitionDuration)
|
424
|
+
}
|
425
|
+
})
|
426
|
+
emulateTransitionEnd(this._element, modalTransitionDuration)
|
427
|
+
this._element.focus()
|
428
|
+
}
|
429
|
+
|
430
|
+
// ----------------------------------------------------------------------
|
431
|
+
// the following methods are used to handle overflowing modals
|
432
|
+
// ----------------------------------------------------------------------
|
433
|
+
|
434
|
+
_adjustDialog() {
|
435
|
+
const isModalOverflowing = this._element.scrollHeight > document.documentElement.clientHeight
|
436
|
+
|
437
|
+
if ((!this._isBodyOverflowing && isModalOverflowing && !isRTL()) || (this._isBodyOverflowing && !isModalOverflowing && isRTL())) {
|
438
|
+
this._element.style.paddingLeft = `${this._scrollbarWidth}px`
|
439
|
+
}
|
440
|
+
|
441
|
+
if ((this._isBodyOverflowing && !isModalOverflowing && !isRTL()) || (!this._isBodyOverflowing && isModalOverflowing && isRTL())) {
|
442
|
+
this._element.style.paddingRight = `${this._scrollbarWidth}px`
|
443
|
+
}
|
444
|
+
}
|
445
|
+
|
446
|
+
_resetAdjustments() {
|
447
|
+
this._element.style.paddingLeft = ''
|
448
|
+
this._element.style.paddingRight = ''
|
449
|
+
}
|
450
|
+
|
451
|
+
_checkScrollbar() {
|
452
|
+
const rect = document.body.getBoundingClientRect()
|
453
|
+
this._isBodyOverflowing = Math.round(rect.left + rect.right) < window.innerWidth
|
454
|
+
this._scrollbarWidth = this._getScrollbarWidth()
|
455
|
+
}
|
456
|
+
|
457
|
+
_setScrollbar() {
|
458
|
+
if (this._isBodyOverflowing) {
|
459
|
+
this._setElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight', calculatedValue => calculatedValue + this._scrollbarWidth)
|
460
|
+
this._setElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight', calculatedValue => calculatedValue - this._scrollbarWidth)
|
461
|
+
this._setElementAttributes('body', 'paddingRight', calculatedValue => calculatedValue + this._scrollbarWidth)
|
462
|
+
}
|
463
|
+
|
464
|
+
document.body.classList.add(CLASS_NAME_OPEN)
|
465
|
+
}
|
466
|
+
|
467
|
+
_setElementAttributes(selector, styleProp, callback) {
|
468
|
+
SelectorEngine.find(selector)
|
469
|
+
.forEach(element => {
|
470
|
+
if (element !== document.body && window.innerWidth > element.clientWidth + this._scrollbarWidth) {
|
471
|
+
return
|
472
|
+
}
|
473
|
+
|
474
|
+
const actualValue = element.style[styleProp]
|
475
|
+
const calculatedValue = window.getComputedStyle(element)[styleProp]
|
476
|
+
Manipulator.setDataAttribute(element, styleProp, actualValue)
|
477
|
+
element.style[styleProp] = callback(Number.parseFloat(calculatedValue)) + 'px'
|
478
|
+
})
|
479
|
+
}
|
480
|
+
|
481
|
+
_resetScrollbar() {
|
482
|
+
this._resetElementAttributes(SELECTOR_FIXED_CONTENT, 'paddingRight')
|
483
|
+
this._resetElementAttributes(SELECTOR_STICKY_CONTENT, 'marginRight')
|
484
|
+
this._resetElementAttributes('body', 'paddingRight')
|
485
|
+
}
|
486
|
+
|
487
|
+
_resetElementAttributes(selector, styleProp) {
|
488
|
+
SelectorEngine.find(selector).forEach(element => {
|
489
|
+
const value = Manipulator.getDataAttribute(element, styleProp)
|
490
|
+
if (typeof value === 'undefined' && element === document.body) {
|
491
|
+
element.style[styleProp] = ''
|
492
|
+
} else {
|
493
|
+
Manipulator.removeDataAttribute(element, styleProp)
|
494
|
+
element.style[styleProp] = value
|
495
|
+
}
|
496
|
+
})
|
497
|
+
}
|
498
|
+
|
499
|
+
_getScrollbarWidth() { // thx d.walsh
|
500
|
+
const scrollDiv = document.createElement('div')
|
501
|
+
scrollDiv.className = CLASS_NAME_SCROLLBAR_MEASURER
|
502
|
+
document.body.appendChild(scrollDiv)
|
503
|
+
const scrollbarWidth = scrollDiv.getBoundingClientRect().width - scrollDiv.clientWidth
|
504
|
+
document.body.removeChild(scrollDiv)
|
505
|
+
return scrollbarWidth
|
506
|
+
}
|
507
|
+
|
508
|
+
// Static
|
509
|
+
|
510
|
+
static jQueryInterface(config, relatedTarget) {
|
511
|
+
return this.each(function () {
|
512
|
+
let data = Data.get(this, DATA_KEY)
|
513
|
+
const _config = {
|
514
|
+
...Default,
|
515
|
+
...Manipulator.getDataAttributes(this),
|
516
|
+
...(typeof config === 'object' && config ? config : {})
|
517
|
+
}
|
518
|
+
|
519
|
+
if (!data) {
|
520
|
+
data = new Modal(this, _config)
|
521
|
+
}
|
522
|
+
|
523
|
+
if (typeof config === 'string') {
|
524
|
+
if (typeof data[config] === 'undefined') {
|
525
|
+
throw new TypeError(`No method named "${config}"`)
|
526
|
+
}
|
527
|
+
|
528
|
+
data[config](relatedTarget)
|
529
|
+
}
|
530
|
+
})
|
531
|
+
}
|
532
|
+
}
|
533
|
+
|
534
|
+
/**
|
535
|
+
* ------------------------------------------------------------------------
|
536
|
+
* Data Api implementation
|
537
|
+
* ------------------------------------------------------------------------
|
538
|
+
*/
|
539
|
+
|
540
|
+
EventHandler.on(document, EVENT_CLICK_DATA_API, SELECTOR_DATA_TOGGLE, function (event) {
|
541
|
+
const target = getElementFromSelector(this)
|
542
|
+
|
543
|
+
if (this.tagName === 'A' || this.tagName === 'AREA') {
|
544
|
+
event.preventDefault()
|
545
|
+
}
|
546
|
+
|
547
|
+
EventHandler.one(target, EVENT_SHOW, showEvent => {
|
548
|
+
if (showEvent.defaultPrevented) {
|
549
|
+
// only register focus restorer if modal will actually get shown
|
550
|
+
return
|
551
|
+
}
|
552
|
+
|
553
|
+
EventHandler.one(target, EVENT_HIDDEN, () => {
|
554
|
+
if (isVisible(this)) {
|
555
|
+
this.focus()
|
556
|
+
}
|
557
|
+
})
|
558
|
+
})
|
559
|
+
|
560
|
+
let data = Data.get(target, DATA_KEY)
|
561
|
+
if (!data) {
|
562
|
+
const config = {
|
563
|
+
...Manipulator.getDataAttributes(target),
|
564
|
+
...Manipulator.getDataAttributes(this)
|
565
|
+
}
|
566
|
+
|
567
|
+
data = new Modal(target, config)
|
568
|
+
}
|
569
|
+
|
570
|
+
data.toggle(this)
|
571
|
+
})
|
572
|
+
|
573
|
+
/**
|
574
|
+
* ------------------------------------------------------------------------
|
575
|
+
* jQuery
|
576
|
+
* ------------------------------------------------------------------------
|
577
|
+
* add .Modal to jQuery only if jQuery is present
|
578
|
+
*/
|
579
|
+
|
580
|
+
defineJQueryPlugin(NAME, Modal)
|
581
|
+
|
582
|
+
export default Modal
|