sweetalert2 11.3.3 → 11.3.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +2257 -0
- package/README.md +8 -10
- package/dist/sweetalert2.all.js +175 -78
- package/dist/sweetalert2.all.min.js +1 -1
- package/dist/sweetalert2.js +175 -78
- package/dist/sweetalert2.min.js +1 -1
- package/package.json +12 -8
- package/src/SweetAlert.js +12 -11
- package/src/buttons-handlers.js +32 -29
- package/src/globalState.js +1 -1
- package/src/instanceMethods/_destroy.js +2 -2
- package/src/instanceMethods/close.js +25 -23
- package/src/instanceMethods/enable-disable-elements.js +7 -7
- package/src/instanceMethods/getInput.js +1 -1
- package/src/instanceMethods/hideLoading.js +2 -5
- package/src/instanceMethods/progress-steps.js +1 -1
- package/src/instanceMethods/update.js +20 -13
- package/src/instanceMethods/validation-message.js +2 -2
- package/src/keydown-handler.js +22 -16
- package/src/popup-click-handler.js +3 -1
- package/src/privateMethods.js +1 -1
- package/src/privateProps.js +1 -1
- package/src/staticMethods/argsToParams.js +1 -1
- package/src/staticMethods/bindClickHandler.js +1 -1
- package/src/staticMethods/dom.js +1 -1
- package/src/staticMethods/fire.js +2 -2
- package/src/staticMethods/mixin.js +2 -2
- package/src/staticMethods/showLoading.js +1 -4
- package/src/staticMethods.js +1 -5
- package/src/utils/DismissReason.js +1 -1
- package/src/utils/Timer.js +6 -6
- package/src/utils/aria.js +2 -2
- package/src/utils/classes.js +1 -7
- package/src/utils/defaultInputValidators.js +1 -1
- package/src/utils/dom/animationEndEvent.js +2 -3
- package/src/utils/dom/domUtils.js +16 -9
- package/src/utils/dom/getters.js +11 -11
- package/src/utils/dom/init.js +3 -7
- package/src/utils/dom/inputUtils.js +26 -19
- package/src/utils/dom/parseHtmlToContainer.js +14 -3
- package/src/utils/dom/renderers/renderActions.js +3 -3
- package/src/utils/dom/renderers/renderContainer.js +3 -3
- package/src/utils/dom/renderers/renderContent.js +4 -2
- package/src/utils/dom/renderers/renderIcon.js +26 -17
- package/src/utils/dom/renderers/renderInput.js +30 -21
- package/src/utils/dom/renderers/renderPopup.js +2 -1
- package/src/utils/dom/renderers/renderProgressSteps.js +1 -1
- package/src/utils/getTemplateParams.js +43 -9
- package/src/utils/iosFix.js +33 -10
- package/src/utils/isNodeEnv.js +5 -1
- package/src/utils/openPopup.js +1 -1
- package/src/utils/params.js +2 -2
- package/src/utils/setParameters.js +5 -5
- package/src/utils/utils.js +14 -11
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import privateProps from '../privateProps.js'
|
|
2
2
|
|
|
3
|
-
function setButtonsDisabled
|
|
3
|
+
function setButtonsDisabled(instance, buttons, disabled) {
|
|
4
4
|
const domCache = privateProps.domCache.get(instance)
|
|
5
|
-
buttons.forEach(button => {
|
|
5
|
+
buttons.forEach((button) => {
|
|
6
6
|
domCache[button].disabled = disabled
|
|
7
7
|
})
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
function setInputDisabled
|
|
10
|
+
function setInputDisabled(input, disabled) {
|
|
11
11
|
if (!input) {
|
|
12
12
|
return false
|
|
13
13
|
}
|
|
@@ -22,18 +22,18 @@ function setInputDisabled (input, disabled) {
|
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
-
export function enableButtons
|
|
25
|
+
export function enableButtons() {
|
|
26
26
|
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], false)
|
|
27
27
|
}
|
|
28
28
|
|
|
29
|
-
export function disableButtons
|
|
29
|
+
export function disableButtons() {
|
|
30
30
|
setButtonsDisabled(this, ['confirmButton', 'denyButton', 'cancelButton'], true)
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
export function enableInput
|
|
33
|
+
export function enableInput() {
|
|
34
34
|
return setInputDisabled(this.getInput(), false)
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
export function disableInput
|
|
37
|
+
export function disableInput() {
|
|
38
38
|
return setInputDisabled(this.getInput(), true)
|
|
39
39
|
}
|
|
@@ -5,7 +5,7 @@ import privateProps from '../privateProps.js'
|
|
|
5
5
|
* Gets the input DOM node, this method works with input parameter.
|
|
6
6
|
* @returns {HTMLElement | null}
|
|
7
7
|
*/
|
|
8
|
-
export function getInput
|
|
8
|
+
export function getInput(instance) {
|
|
9
9
|
const innerParams = privateProps.innerParams.get(instance || this)
|
|
10
10
|
const domCache = privateProps.domCache.get(instance || this)
|
|
11
11
|
if (!domCache) {
|
|
@@ -5,7 +5,7 @@ import privateProps from '../privateProps.js'
|
|
|
5
5
|
/**
|
|
6
6
|
* Hides loader and shows back the button which was hidden by .showLoading()
|
|
7
7
|
*/
|
|
8
|
-
function hideLoading
|
|
8
|
+
function hideLoading() {
|
|
9
9
|
// do nothing if popup is closed
|
|
10
10
|
const innerParams = privateProps.innerParams.get(this)
|
|
11
11
|
if (!innerParams) {
|
|
@@ -37,7 +37,4 @@ const showRelatedButton = (domCache) => {
|
|
|
37
37
|
}
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
export {
|
|
41
|
-
hideLoading,
|
|
42
|
-
hideLoading as disableLoading
|
|
43
|
-
}
|
|
40
|
+
export { hideLoading, hideLoading as disableLoading }
|
|
@@ -6,24 +6,17 @@ import { isUpdatableParameter } from '../../src/utils/params.js'
|
|
|
6
6
|
/**
|
|
7
7
|
* Updates popup parameters.
|
|
8
8
|
*/
|
|
9
|
-
export function update
|
|
9
|
+
export function update(params) {
|
|
10
10
|
const popup = dom.getPopup()
|
|
11
11
|
const innerParams = privateProps.innerParams.get(this)
|
|
12
12
|
|
|
13
13
|
if (!popup || dom.hasClass(popup, innerParams.hideClass.popup)) {
|
|
14
|
-
return warn(
|
|
14
|
+
return warn(
|
|
15
|
+
`You're trying to update the closed or closing popup, that won't work. Use the update() method in preConfirm parameter or show a new popup.`
|
|
16
|
+
)
|
|
15
17
|
}
|
|
16
18
|
|
|
17
|
-
const validUpdatableParams =
|
|
18
|
-
|
|
19
|
-
// assign valid params from `params` to `defaults`
|
|
20
|
-
Object.keys(params).forEach(param => {
|
|
21
|
-
if (isUpdatableParameter(param)) {
|
|
22
|
-
validUpdatableParams[param] = params[param]
|
|
23
|
-
} else {
|
|
24
|
-
warn(`Invalid parameter to update: "${param}". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md`)
|
|
25
|
-
}
|
|
26
|
-
})
|
|
19
|
+
const validUpdatableParams = filterValidParams(params)
|
|
27
20
|
|
|
28
21
|
const updatedParams = Object.assign({}, innerParams, validUpdatableParams)
|
|
29
22
|
|
|
@@ -34,7 +27,21 @@ export function update (params) {
|
|
|
34
27
|
params: {
|
|
35
28
|
value: Object.assign({}, this.params, params),
|
|
36
29
|
writable: false,
|
|
37
|
-
enumerable: true
|
|
30
|
+
enumerable: true,
|
|
31
|
+
},
|
|
32
|
+
})
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const filterValidParams = (params) => {
|
|
36
|
+
const validUpdatableParams = {}
|
|
37
|
+
Object.keys(params).forEach((param) => {
|
|
38
|
+
if (isUpdatableParameter(param)) {
|
|
39
|
+
validUpdatableParams[param] = params[param]
|
|
40
|
+
} else {
|
|
41
|
+
warn(
|
|
42
|
+
`Invalid parameter to update: "${param}". Updatable params are listed here: https://github.com/sweetalert2/sweetalert2/blob/master/src/utils/params.js\n\nIf you think this parameter should be updatable, request it here: https://github.com/sweetalert2/sweetalert2/issues/new?template=02_feature_request.md`
|
|
43
|
+
)
|
|
38
44
|
}
|
|
39
45
|
})
|
|
46
|
+
return validUpdatableParams
|
|
40
47
|
}
|
|
@@ -3,7 +3,7 @@ import { swalClasses } from '../utils/classes.js'
|
|
|
3
3
|
import privateProps from '../privateProps.js'
|
|
4
4
|
|
|
5
5
|
// Show block with validation message
|
|
6
|
-
export function showValidationMessage
|
|
6
|
+
export function showValidationMessage(error) {
|
|
7
7
|
const domCache = privateProps.domCache.get(this)
|
|
8
8
|
const params = privateProps.innerParams.get(this)
|
|
9
9
|
dom.setInnerHtml(domCache.validationMessage, error)
|
|
@@ -23,7 +23,7 @@ export function showValidationMessage (error) {
|
|
|
23
23
|
}
|
|
24
24
|
|
|
25
25
|
// Hide block with validation message
|
|
26
|
-
export function resetValidationMessage
|
|
26
|
+
export function resetValidationMessage() {
|
|
27
27
|
const domCache = privateProps.domCache.get(this)
|
|
28
28
|
if (domCache.validationMessage) {
|
|
29
29
|
dom.hide(domCache.validationMessage)
|
package/src/keydown-handler.js
CHANGED
|
@@ -6,7 +6,9 @@ import privateProps from './privateProps.js'
|
|
|
6
6
|
|
|
7
7
|
export const addKeydownHandler = (instance, globalState, innerParams, dismissWith) => {
|
|
8
8
|
if (globalState.keydownTarget && globalState.keydownHandlerAdded) {
|
|
9
|
-
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
9
|
+
globalState.keydownTarget.removeEventListener('keydown', globalState.keydownHandler, {
|
|
10
|
+
capture: globalState.keydownListenerCapture,
|
|
11
|
+
})
|
|
10
12
|
globalState.keydownHandlerAdded = false
|
|
11
13
|
}
|
|
12
14
|
|
|
@@ -14,7 +16,9 @@ export const addKeydownHandler = (instance, globalState, innerParams, dismissWit
|
|
|
14
16
|
globalState.keydownHandler = (e) => keydownHandler(instance, e, dismissWith)
|
|
15
17
|
globalState.keydownTarget = innerParams.keydownListenerCapture ? window : dom.getPopup()
|
|
16
18
|
globalState.keydownListenerCapture = innerParams.keydownListenerCapture
|
|
17
|
-
globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
|
|
19
|
+
globalState.keydownTarget.addEventListener('keydown', globalState.keydownHandler, {
|
|
20
|
+
capture: globalState.keydownListenerCapture,
|
|
21
|
+
})
|
|
18
22
|
globalState.keydownHandlerAdded = true
|
|
19
23
|
}
|
|
20
24
|
}
|
|
@@ -41,13 +45,9 @@ export const setFocus = (innerParams, index, increment) => {
|
|
|
41
45
|
dom.getPopup().focus()
|
|
42
46
|
}
|
|
43
47
|
|
|
44
|
-
const arrowKeysNextButton = [
|
|
45
|
-
'ArrowRight', 'ArrowDown',
|
|
46
|
-
]
|
|
48
|
+
const arrowKeysNextButton = ['ArrowRight', 'ArrowDown']
|
|
47
49
|
|
|
48
|
-
const arrowKeysPreviousButton = [
|
|
49
|
-
'ArrowLeft', 'ArrowUp',
|
|
50
|
-
]
|
|
50
|
+
const arrowKeysPreviousButton = ['ArrowLeft', 'ArrowUp']
|
|
51
51
|
|
|
52
52
|
const keydownHandler = (instance, e, dismissWith) => {
|
|
53
53
|
const innerParams = privateProps.innerParams.get(instance)
|
|
@@ -63,24 +63,27 @@ const keydownHandler = (instance, e, dismissWith) => {
|
|
|
63
63
|
// ENTER
|
|
64
64
|
if (e.key === 'Enter') {
|
|
65
65
|
handleEnter(instance, e, innerParams)
|
|
66
|
+
}
|
|
66
67
|
|
|
67
68
|
// TAB
|
|
68
|
-
|
|
69
|
+
else if (e.key === 'Tab') {
|
|
69
70
|
handleTab(e, innerParams)
|
|
71
|
+
}
|
|
70
72
|
|
|
71
73
|
// ARROWS - switch focus between buttons
|
|
72
|
-
|
|
74
|
+
else if ([...arrowKeysNextButton, ...arrowKeysPreviousButton].includes(e.key)) {
|
|
73
75
|
handleArrows(e.key)
|
|
76
|
+
}
|
|
74
77
|
|
|
75
78
|
// ESC
|
|
76
|
-
|
|
79
|
+
else if (e.key === 'Escape') {
|
|
77
80
|
handleEsc(e, innerParams, dismissWith)
|
|
78
81
|
}
|
|
79
82
|
}
|
|
80
83
|
|
|
81
84
|
const handleEnter = (instance, e, innerParams) => {
|
|
82
|
-
// #720 #721
|
|
83
|
-
if (e.isComposing) {
|
|
85
|
+
// #2386 #720 #721
|
|
86
|
+
if (!callIfFunction(innerParams.allowEnterKey) || e.isComposing) {
|
|
84
87
|
return
|
|
85
88
|
}
|
|
86
89
|
|
|
@@ -106,13 +109,16 @@ const handleTab = (e, innerParams) => {
|
|
|
106
109
|
}
|
|
107
110
|
}
|
|
108
111
|
|
|
112
|
+
// Cycle to the next button
|
|
109
113
|
if (!e.shiftKey) {
|
|
110
|
-
// Cycle to the next button
|
|
111
114
|
setFocus(innerParams, btnIndex, 1)
|
|
112
|
-
}
|
|
113
|
-
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
// Cycle to the prev button
|
|
118
|
+
else {
|
|
114
119
|
setFocus(innerParams, btnIndex, -1)
|
|
115
120
|
}
|
|
121
|
+
|
|
116
122
|
e.stopPropagation()
|
|
117
123
|
e.preventDefault()
|
|
118
124
|
}
|
|
@@ -34,10 +34,12 @@ const handleToastClick = (instance, domCache, dismissWith) => {
|
|
|
34
34
|
* @returns {boolean}
|
|
35
35
|
*/
|
|
36
36
|
const isAnyButtonShown = (innerParams) => {
|
|
37
|
-
return
|
|
37
|
+
return (
|
|
38
|
+
innerParams.showConfirmButton ||
|
|
38
39
|
innerParams.showDenyButton ||
|
|
39
40
|
innerParams.showCancelButton ||
|
|
40
41
|
innerParams.showCloseButton
|
|
42
|
+
)
|
|
41
43
|
}
|
|
42
44
|
|
|
43
45
|
let ignoreOutsideClick = false
|
package/src/privateMethods.js
CHANGED
package/src/privateProps.js
CHANGED
|
@@ -8,7 +8,7 @@ export const argsToParams = (args) => {
|
|
|
8
8
|
if (typeof args[0] === 'object' && !isElement(args[0])) {
|
|
9
9
|
Object.assign(params, args[0])
|
|
10
10
|
} else {
|
|
11
|
-
['title', 'html', 'icon'].forEach((name, index) => {
|
|
11
|
+
;['title', 'html', 'icon'].forEach((name, index) => {
|
|
12
12
|
const arg = args[index]
|
|
13
13
|
if (typeof arg === 'string' || isElement(arg)) {
|
|
14
14
|
params[name] = arg
|
package/src/staticMethods/dom.js
CHANGED
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
*
|
|
17
17
|
* @param mixinParams
|
|
18
18
|
*/
|
|
19
|
-
export function mixin
|
|
19
|
+
export function mixin(mixinParams) {
|
|
20
20
|
class MixinSwal extends this {
|
|
21
|
-
_main
|
|
21
|
+
_main(params, priorityMixinParams) {
|
|
22
22
|
return super._main(params, Object.assign({}, mixinParams, priorityMixinParams))
|
|
23
23
|
}
|
|
24
24
|
}
|
package/src/staticMethods.js
CHANGED
|
@@ -5,8 +5,4 @@ export * from './staticMethods/mixin.js'
|
|
|
5
5
|
export * from './staticMethods/showLoading.js'
|
|
6
6
|
export * from './staticMethods/timer.js'
|
|
7
7
|
export * from './staticMethods/bindClickHandler.js'
|
|
8
|
-
export {
|
|
9
|
-
isValidParameter,
|
|
10
|
-
isUpdatableParameter,
|
|
11
|
-
isDeprecatedParameter
|
|
12
|
-
} from './utils/params.js'
|
|
8
|
+
export { isValidParameter, isUpdatableParameter, isDeprecatedParameter } from './utils/params.js'
|
package/src/utils/Timer.js
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export default class Timer {
|
|
2
|
-
constructor
|
|
2
|
+
constructor(callback, delay) {
|
|
3
3
|
this.callback = callback
|
|
4
4
|
this.remaining = delay
|
|
5
5
|
this.running = false
|
|
@@ -7,7 +7,7 @@ export default class Timer {
|
|
|
7
7
|
this.start()
|
|
8
8
|
}
|
|
9
9
|
|
|
10
|
-
start
|
|
10
|
+
start() {
|
|
11
11
|
if (!this.running) {
|
|
12
12
|
this.running = true
|
|
13
13
|
this.started = new Date()
|
|
@@ -16,7 +16,7 @@ export default class Timer {
|
|
|
16
16
|
return this.remaining
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
stop
|
|
19
|
+
stop() {
|
|
20
20
|
if (this.running) {
|
|
21
21
|
this.running = false
|
|
22
22
|
clearTimeout(this.id)
|
|
@@ -25,7 +25,7 @@ export default class Timer {
|
|
|
25
25
|
return this.remaining
|
|
26
26
|
}
|
|
27
27
|
|
|
28
|
-
increase
|
|
28
|
+
increase(n) {
|
|
29
29
|
const running = this.running
|
|
30
30
|
if (running) {
|
|
31
31
|
this.stop()
|
|
@@ -37,7 +37,7 @@ export default class Timer {
|
|
|
37
37
|
return this.remaining
|
|
38
38
|
}
|
|
39
39
|
|
|
40
|
-
getTimerLeft
|
|
40
|
+
getTimerLeft() {
|
|
41
41
|
if (this.running) {
|
|
42
42
|
this.stop()
|
|
43
43
|
this.start()
|
|
@@ -45,7 +45,7 @@ export default class Timer {
|
|
|
45
45
|
return this.remaining
|
|
46
46
|
}
|
|
47
47
|
|
|
48
|
-
isRunning
|
|
48
|
+
isRunning() {
|
|
49
49
|
return this.running
|
|
50
50
|
}
|
|
51
51
|
}
|
package/src/utils/aria.js
CHANGED
|
@@ -8,7 +8,7 @@ import { toArray } from './utils.js'
|
|
|
8
8
|
|
|
9
9
|
export const setAriaHidden = () => {
|
|
10
10
|
const bodyChildren = toArray(document.body.children)
|
|
11
|
-
bodyChildren.forEach(el => {
|
|
11
|
+
bodyChildren.forEach((el) => {
|
|
12
12
|
if (el === getContainer() || el.contains(getContainer())) {
|
|
13
13
|
return
|
|
14
14
|
}
|
|
@@ -22,7 +22,7 @@ export const setAriaHidden = () => {
|
|
|
22
22
|
|
|
23
23
|
export const unsetAriaHidden = () => {
|
|
24
24
|
const bodyChildren = toArray(document.body.children)
|
|
25
|
-
bodyChildren.forEach(el => {
|
|
25
|
+
bodyChildren.forEach((el) => {
|
|
26
26
|
if (el.hasAttribute('data-previous-aria-hidden')) {
|
|
27
27
|
el.setAttribute('aria-hidden', el.getAttribute('data-previous-aria-hidden'))
|
|
28
28
|
el.removeAttribute('data-previous-aria-hidden')
|
package/src/utils/classes.js
CHANGED
|
@@ -80,10 +80,4 @@ export const swalClasses = prefix([
|
|
|
80
80
|
'icon-error',
|
|
81
81
|
])
|
|
82
82
|
|
|
83
|
-
export const iconTypes = prefix([
|
|
84
|
-
'success',
|
|
85
|
-
'warning',
|
|
86
|
-
'info',
|
|
87
|
-
'question',
|
|
88
|
-
'error'
|
|
89
|
-
])
|
|
83
|
+
export const iconTypes = prefix(['success', 'warning', 'info', 'question', 'error'])
|
|
@@ -9,9 +9,8 @@ export const animationEndEvent = (() => {
|
|
|
9
9
|
|
|
10
10
|
const testEl = document.createElement('div')
|
|
11
11
|
const transEndEventNames = {
|
|
12
|
-
WebkitAnimation: 'webkitAnimationEnd',
|
|
13
|
-
|
|
14
|
-
animation: 'animationend'
|
|
12
|
+
WebkitAnimation: 'webkitAnimationEnd', // Chrome, Safari and Opera
|
|
13
|
+
animation: 'animationend', // Standard syntax
|
|
15
14
|
}
|
|
16
15
|
for (const i in transEndEventNames) {
|
|
17
16
|
if (Object.prototype.hasOwnProperty.call(transEndEventNames, i) && typeof testEl.style[i] !== 'undefined') {
|
|
@@ -1,10 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
1
|
+
import { getCancelButton, getConfirmButton, getDenyButton, getTimerProgressBar } from './getters.js'
|
|
2
|
+
import { iconTypes, swalClasses } from '../classes.js'
|
|
3
3
|
import { toArray, warn } from '../utils.js'
|
|
4
4
|
|
|
5
5
|
// Remember state in cases where opening and handling a modal will fiddle with it.
|
|
6
6
|
export const states = {
|
|
7
|
-
previousBodyPadding: null
|
|
7
|
+
previousBodyPadding: null,
|
|
8
8
|
}
|
|
9
9
|
|
|
10
10
|
/**
|
|
@@ -47,7 +47,7 @@ export const hasClass = (elem, className) => {
|
|
|
47
47
|
}
|
|
48
48
|
|
|
49
49
|
const removeCustomClasses = (elem, params) => {
|
|
50
|
-
toArray(elem.classList).forEach(className => {
|
|
50
|
+
toArray(elem.classList).forEach((className) => {
|
|
51
51
|
if (
|
|
52
52
|
!Object.values(swalClasses).includes(className) &&
|
|
53
53
|
!Object.values(iconTypes).includes(className) &&
|
|
@@ -63,7 +63,11 @@ export const applyCustomClass = (elem, params, className) => {
|
|
|
63
63
|
|
|
64
64
|
if (params.customClass && params.customClass[className]) {
|
|
65
65
|
if (typeof params.customClass[className] !== 'string' && !params.customClass[className].forEach) {
|
|
66
|
-
return warn(
|
|
66
|
+
return warn(
|
|
67
|
+
`Invalid type of customClass.${className}! Expected string or iterable object, got "${typeof params.customClass[
|
|
68
|
+
className
|
|
69
|
+
]}"`
|
|
70
|
+
)
|
|
67
71
|
}
|
|
68
72
|
|
|
69
73
|
addClass(elem, params.customClass[className])
|
|
@@ -87,8 +91,10 @@ export const getInput = (popup, inputType) => {
|
|
|
87
91
|
case 'checkbox':
|
|
88
92
|
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.checkbox} input`)
|
|
89
93
|
case 'radio':
|
|
90
|
-
return
|
|
94
|
+
return (
|
|
95
|
+
popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:checked`) ||
|
|
91
96
|
popup.querySelector(`.${swalClasses.popup} > .${swalClasses.radio} input:first-child`)
|
|
97
|
+
)
|
|
92
98
|
case 'range':
|
|
93
99
|
return popup.querySelector(`.${swalClasses.popup} > .${swalClasses.range} input`)
|
|
94
100
|
default:
|
|
@@ -176,7 +182,7 @@ export const applyNumericalStyle = (elem, property, value) => {
|
|
|
176
182
|
value = parseInt(value)
|
|
177
183
|
}
|
|
178
184
|
if (value || parseInt(value) === 0) {
|
|
179
|
-
elem.style[property] =
|
|
185
|
+
elem.style[property] = typeof value === 'number' ? `${value}px` : value
|
|
180
186
|
} else {
|
|
181
187
|
elem.style.removeProperty(property)
|
|
182
188
|
}
|
|
@@ -211,7 +217,8 @@ export const toggle = (elem, condition, display) => {
|
|
|
211
217
|
// borrowed from jquery $(elem).is(':visible') implementation
|
|
212
218
|
export const isVisible = (elem) => !!(elem && (elem.offsetWidth || elem.offsetHeight || elem.getClientRects().length))
|
|
213
219
|
|
|
214
|
-
export const allButtonsAreHidden = () =>
|
|
220
|
+
export const allButtonsAreHidden = () =>
|
|
221
|
+
!isVisible(getConfirmButton()) && !isVisible(getDenyButton()) && !isVisible(getCancelButton())
|
|
215
222
|
|
|
216
223
|
export const isScrollable = (elem) => !!(elem.scrollHeight > elem.clientHeight)
|
|
217
224
|
|
|
@@ -245,7 +252,7 @@ export const stopTimerProgressBar = () => {
|
|
|
245
252
|
timerProgressBar.style.removeProperty('transition')
|
|
246
253
|
timerProgressBar.style.width = '100%'
|
|
247
254
|
const timerProgressBarFullWidth = parseInt(window.getComputedStyle(timerProgressBar).width)
|
|
248
|
-
const timerProgressBarPercent = timerProgressBarWidth / timerProgressBarFullWidth * 100
|
|
255
|
+
const timerProgressBarPercent = (timerProgressBarWidth / timerProgressBarFullWidth) * 100
|
|
249
256
|
timerProgressBar.style.removeProperty('transition')
|
|
250
257
|
timerProgressBar.style.width = `${timerProgressBarPercent}%`
|
|
251
258
|
}
|
package/src/utils/dom/getters.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { swalClasses } from '../classes.js'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { toArray, uniqueArray } from '../utils.js'
|
|
3
|
+
import { hasClass, isVisible } from './domUtils.js'
|
|
4
4
|
|
|
5
5
|
/**
|
|
6
6
|
* Gets the popup container which contains the backdrop and the popup itself.
|
|
@@ -72,23 +72,23 @@ export const getFocusableElements = () => {
|
|
|
72
72
|
const focusableElementsWithTabindex = toArray(
|
|
73
73
|
getPopup().querySelectorAll('[tabindex]:not([tabindex="-1"]):not([tabindex="0"])')
|
|
74
74
|
)
|
|
75
|
-
|
|
75
|
+
// sort according to tabindex
|
|
76
76
|
.sort((a, b) => {
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
if (
|
|
77
|
+
const tabindexA = parseInt(a.getAttribute('tabindex'))
|
|
78
|
+
const tabindexB = parseInt(b.getAttribute('tabindex'))
|
|
79
|
+
if (tabindexA > tabindexB) {
|
|
80
80
|
return 1
|
|
81
|
-
} else if (
|
|
81
|
+
} else if (tabindexA < tabindexB) {
|
|
82
82
|
return -1
|
|
83
83
|
}
|
|
84
84
|
return 0
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
-
const otherFocusableElements = toArray(
|
|
88
|
-
|
|
89
|
-
)
|
|
87
|
+
const otherFocusableElements = toArray(getPopup().querySelectorAll(focusable)).filter(
|
|
88
|
+
(el) => el.getAttribute('tabindex') !== '-1'
|
|
89
|
+
)
|
|
90
90
|
|
|
91
|
-
return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter(el => isVisible(el))
|
|
91
|
+
return uniqueArray(focusableElementsWithTabindex.concat(otherFocusableElements)).filter((el) => isVisible(el))
|
|
92
92
|
}
|
|
93
93
|
|
|
94
94
|
export const isModal = () => {
|
package/src/utils/dom/init.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { swalClasses } from '../classes.js'
|
|
2
2
|
import { getContainer, getPopup } from './getters.js'
|
|
3
|
-
import { addClass,
|
|
3
|
+
import { addClass, getDirectChildByClass, removeClass, setInnerHtml } from './domUtils.js'
|
|
4
4
|
import { isNodeEnv } from '../isNodeEnv.js'
|
|
5
5
|
import { error } from '../utils.js'
|
|
6
6
|
import globalState from '../../globalState.js'
|
|
@@ -49,11 +49,7 @@ const resetOldContainer = () => {
|
|
|
49
49
|
oldContainer.remove()
|
|
50
50
|
removeClass(
|
|
51
51
|
[document.documentElement, document.body],
|
|
52
|
-
[
|
|
53
|
-
swalClasses['no-backdrop'],
|
|
54
|
-
swalClasses['toast-shown'],
|
|
55
|
-
swalClasses['has-column']
|
|
56
|
-
]
|
|
52
|
+
[swalClasses['no-backdrop'], swalClasses['toast-shown'], swalClasses['has-column']]
|
|
57
53
|
)
|
|
58
54
|
|
|
59
55
|
return true
|
|
@@ -91,7 +87,7 @@ const addInputChangeListeners = () => {
|
|
|
91
87
|
}
|
|
92
88
|
}
|
|
93
89
|
|
|
94
|
-
const getTarget = (target) => typeof target === 'string' ? document.querySelector(target) : target
|
|
90
|
+
const getTarget = (target) => (typeof target === 'string' ? document.querySelector(target) : target)
|
|
95
91
|
|
|
96
92
|
const setupAccessibility = (params) => {
|
|
97
93
|
const popup = getPopup()
|