@shortfuse/materialdesignweb 0.0.9 → 0.4.0
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/.browserslistrc +3 -0
- package/.eslintrc.json +146 -27
- package/.stylelintrc.json +598 -2
- package/.vscode/launch.json +20 -5
- package/.vscode/settings.json +3 -0
- package/.vscode/tasks.json +19 -10
- package/CHANGELOG.md +24 -0
- package/README.md +84 -2
- package/adapters/datatable/column.js +203 -0
- package/adapters/datatable/index.js +972 -0
- package/adapters/dom/index.js +601 -0
- package/adapters/list/index.js +69 -0
- package/adapters/search/index.js +521 -0
- package/components/appbar/_spec.scss +225 -0
- package/components/appbar/_theme.scss +0 -0
- package/components/appbar/index.scss +2 -0
- package/components/banner/_spec.scss +118 -0
- package/components/banner/_theme.scss +0 -0
- package/components/banner/index.scss +2 -0
- package/components/bottomnav/README.md +85 -0
- package/components/bottomnav/_spec.scss +157 -0
- package/components/bottomnav/_theme.scss +0 -0
- package/components/bottomnav/index.js +122 -0
- package/components/bottomnav/index.scss +2 -0
- package/components/bottomnav/item.js +89 -0
- package/components/{core/button → button}/README.md +16 -22
- package/components/button/_spec.scss +161 -0
- package/components/button/_theme.scss +65 -0
- package/components/button/index.eta +32 -0
- package/components/button/index.js +43 -0
- package/components/button/index.pug +18 -0
- package/components/button/index.scss +2 -0
- package/components/card/_spec.scss +249 -0
- package/components/card/_theme.scss +0 -0
- package/components/card/index.scss +2 -0
- package/components/chip/_spec.scss +134 -0
- package/components/chip/_theme.scss +177 -0
- package/components/chip/index.js +21 -0
- package/components/chip/index.scss +2 -0
- package/components/chip/item.js +20 -0
- package/components/datatable/_spec.scss +288 -0
- package/components/datatable/_theme.scss +154 -0
- package/components/datatable/cell.js +45 -0
- package/components/datatable/columnheader.js +47 -0
- package/components/datatable/index.js +388 -0
- package/components/datatable/index.scss +2 -0
- package/components/datatable/row.js +49 -0
- package/components/datatable/rowheader.js +18 -0
- package/components/dialog/_spec.scss +213 -0
- package/components/dialog/_theme.scss +0 -0
- package/components/dialog/index.js +627 -0
- package/components/dialog/index.scss +2 -0
- package/components/divider/_spec.scss +13 -0
- package/components/divider/_theme.scss +0 -0
- package/components/divider/index.scss +2 -0
- package/components/elevation/_spec.scss +9 -0
- package/components/elevation/_theme.scss +0 -0
- package/components/elevation/index.scss +2 -0
- package/components/fab/_spec.scss +222 -0
- package/components/fab/_theme.scss +0 -0
- package/components/fab/index.js +103 -0
- package/components/fab/index.scss +2 -0
- package/components/grid/_spec.scss +312 -0
- package/components/grid/_theme.scss +0 -0
- package/components/grid/index.scss +2 -0
- package/components/layout/_mixins.scss +33 -0
- package/components/layout/_spec.scss +1012 -0
- package/components/layout/_theme.scss +44 -0
- package/components/layout/index.js +464 -0
- package/components/layout/index.scss +2 -0
- package/components/list/_spec.scss +397 -0
- package/components/list/_theme.scss +111 -0
- package/components/list/content.js +110 -0
- package/components/list/index.js +260 -0
- package/components/list/index.scss +2 -0
- package/components/list/item.js +170 -0
- package/components/list/secondary.js +46 -0
- package/components/menu/_spec.scss +362 -0
- package/components/menu/_theme.scss +0 -0
- package/components/menu/index.js +721 -0
- package/components/menu/index.scss +2 -0
- package/components/menu/item.js +239 -0
- package/components/{core/progress/style.scss → progress/_spec.scss} +36 -25
- package/components/progress/_theme.scss +0 -0
- package/components/progress/index.js +36 -0
- package/components/progress/index.scss +2 -0
- package/components/selection/_spec.scss +386 -0
- package/components/selection/_theme.scss +166 -0
- package/components/selection/index.eta +60 -0
- package/components/selection/index.js +76 -0
- package/components/selection/index.pug +30 -0
- package/components/selection/index.scss +2 -0
- package/components/selection/input.js +56 -0
- package/components/selection/radiogroup.js +47 -0
- package/components/slider/_spec.scss +64 -0
- package/components/slider/_theme.scss +0 -0
- package/components/slider/index.scss +2 -0
- package/components/snackbar/_spec.scss +195 -0
- package/components/snackbar/_theme.scss +0 -0
- package/components/snackbar/index.js +344 -0
- package/components/snackbar/index.scss +2 -0
- package/components/tab/_spec.scss +235 -0
- package/components/tab/_theme.scss +0 -0
- package/components/tab/content.js +205 -0
- package/components/tab/index.js +260 -0
- package/components/tab/index.scss +2 -0
- package/components/tab/item.js +89 -0
- package/components/tab/list.js +210 -0
- package/components/tab/panel.js +54 -0
- package/components/template/_theme.scss +27 -0
- package/components/{core/textfield → textfield}/README.md +70 -50
- package/components/textfield/_mixins.scss +52 -0
- package/components/textfield/_spec.scss +809 -0
- package/components/textfield/_theme.scss +299 -0
- package/components/textfield/index.eta +74 -0
- package/components/textfield/index.js +168 -0
- package/components/textfield/index.pug +30 -0
- package/components/textfield/index.scss +2 -0
- package/components/tooltip/_spec.scss +188 -0
- package/components/tooltip/_theme.scss +0 -0
- package/components/tooltip/index.scss +2 -0
- package/components/type/_spec.scss +224 -0
- package/components/type/_theme.scss +0 -0
- package/components/type/index.scss +2 -0
- package/core/_breakpoint.scss +189 -0
- package/core/_elevation.scss +38 -0
- package/core/_length.scss +9 -0
- package/core/_motion.scss +31 -0
- package/core/_platform.scss +34 -0
- package/core/_type.scss +127 -0
- package/core/aria/attributes.js +141 -0
- package/core/aria/button.js +50 -0
- package/core/aria/keyboard.js +93 -0
- package/core/aria/rovingtabindex.js +178 -0
- package/core/aria/tab.js +60 -0
- package/core/color/_spec.scss +0 -0
- package/core/color/_theme.scss +390 -0
- package/core/color/index.scss +2 -0
- package/core/document/index.js +39 -0
- package/core/dom.js +271 -0
- package/core/overlay/_spec.scss +31 -0
- package/core/overlay/_theme.scss +171 -0
- package/core/overlay/index.js +108 -0
- package/core/overlay/index.scss +2 -0
- package/core/ripple/_spec.scss +197 -0
- package/core/ripple/_theme.scss +40 -0
- package/core/ripple/index.js +294 -0
- package/core/ripple/index.scss +2 -0
- package/core/theme/_config.scss +2 -0
- package/core/theme/_mixins.scss +172 -0
- package/{components/theming/palettes.scss → core/theme/_palettes.scss} +173 -150
- package/core/theme/_variables.scss +24 -0
- package/core/theme/index.js +50 -0
- package/core/throttler.js +42 -0
- package/core/transition/index.js +468 -0
- package/docs/_flex.scss +22 -0
- package/docs/_menuoptions.js +183 -0
- package/docs/_mixins.pug +155 -0
- package/docs/_partials/_androidnavbar.eta +5 -0
- package/docs/_partials/_androidstatusbar.eta +13 -0
- package/docs/_partials/_appbar.eta +29 -0
- package/docs/_partials/_buttontest.eta +31 -0
- package/docs/_partials/_header.eta +149 -0
- package/docs/_partials/_navlistitem.eta +16 -0
- package/docs/_partials/_target.eta +1 -0
- package/docs/_sample-utils.js +93 -0
- package/docs/_storage.js +33 -0
- package/docs/docs.scss +295 -0
- package/docs/index.eta +16 -0
- package/docs/index.js +0 -0
- package/docs/pages/appbar.eta +114 -0
- package/docs/pages/appbar.js +0 -0
- package/docs/pages/appbar.pug +78 -0
- package/docs/pages/bottomnav.eta +188 -0
- package/docs/pages/bottomnav.js +115 -0
- package/docs/pages/bottomnav.pug +137 -0
- package/docs/pages/button.eta +124 -0
- package/docs/pages/button.js +224 -0
- package/docs/pages/button.pug +121 -0
- package/docs/pages/card.eta +90 -0
- package/docs/pages/card.js +177 -0
- package/docs/pages/card.pug +74 -0
- package/docs/pages/chip.eta +122 -0
- package/docs/pages/chip.js +82 -0
- package/docs/pages/chip.pug +91 -0
- package/docs/pages/color.eta +143 -0
- package/docs/pages/color.js +262 -0
- package/docs/pages/color.pug +121 -0
- package/docs/pages/datatable.eta +323 -0
- package/docs/pages/datatable.js +164 -0
- package/docs/pages/datatable.pug +283 -0
- package/docs/pages/dialog.eta +186 -0
- package/docs/pages/dialog.js +177 -0
- package/docs/pages/dialog.pug +132 -0
- package/docs/pages/dom.eta +26 -0
- package/docs/pages/dom.js +143 -0
- package/docs/pages/dom.pug +22 -0
- package/docs/pages/elevation.eta +35 -0
- package/docs/pages/elevation.js +0 -0
- package/docs/pages/elevation.pug +25 -0
- package/docs/pages/fab.eta +99 -0
- package/docs/pages/fab.js +44 -0
- package/docs/pages/fab.pug +66 -0
- package/docs/pages/grid.eta +135 -0
- package/docs/pages/grid.js +128 -0
- package/docs/pages/grid.pug +95 -0
- package/docs/pages/layout.eta +8 -0
- package/docs/pages/layout.js +0 -0
- package/docs/pages/layout.pug +7 -0
- package/docs/pages/list.eta +465 -0
- package/docs/pages/list.js +9 -0
- package/docs/pages/list.pug +326 -0
- package/docs/pages/menu.eta +276 -0
- package/docs/pages/menu.js +217 -0
- package/docs/pages/menu.pug +205 -0
- package/docs/pages/overlay.eta +69 -0
- package/docs/pages/overlay.js +4 -0
- package/docs/pages/overlay.pug +55 -0
- package/docs/pages/progress.eta +23 -0
- package/docs/pages/progress.js +12 -0
- package/docs/pages/progress.pug +16 -0
- package/docs/pages/ripple.eta +27 -0
- package/docs/pages/ripple.js +4 -0
- package/docs/pages/ripple.pug +21 -0
- package/docs/pages/search.eta +246 -0
- package/docs/pages/search.js +243 -0
- package/docs/pages/search.pug +165 -0
- package/docs/pages/selection.eta +111 -0
- package/docs/pages/selection.js +13 -0
- package/docs/pages/selection.pug +74 -0
- package/docs/pages/slider.eta +23 -0
- package/docs/pages/slider.js +0 -0
- package/docs/pages/slider.pug +17 -0
- package/docs/pages/snackbar.eta +83 -0
- package/docs/pages/snackbar.js +158 -0
- package/docs/pages/snackbar.pug +60 -0
- package/docs/pages/tab.eta +421 -0
- package/docs/pages/tab.js +151 -0
- package/docs/pages/tab.pug +304 -0
- package/docs/pages/textfield.eta +486 -0
- package/docs/pages/textfield.js +254 -0
- package/docs/pages/textfield.pug +360 -0
- package/docs/pages/tooltip.eta +94 -0
- package/docs/pages/tooltip.js +0 -0
- package/docs/pages/tooltip.pug +78 -0
- package/docs/pages/transition.eta +117 -0
- package/docs/pages/transition.js +54 -0
- package/docs/pages/transition.pug +76 -0
- package/docs/pages/type.eta +31 -0
- package/docs/pages/type.js +0 -0
- package/docs/pages/type.pug +29 -0
- package/docs/postrender.js +39 -0
- package/docs/prerender.js +16 -0
- package/docs/pwa/_dialogs.eta +143 -0
- package/docs/pwa/_dialogs.pug +96 -0
- package/docs/pwa/_menus.eta +16 -0
- package/docs/pwa/_menus.pug +11 -0
- package/docs/pwa/pwa-prerender.js +3 -0
- package/docs/pwa/pwa.eta +480 -0
- package/docs/pwa/pwa.js +306 -0
- package/docs/pwa/pwa.pug +325 -0
- package/docs/pwa/pwa.scss +26 -0
- package/docs/spec.scss +26 -0
- package/docs/themes/_component-themes.scss +26 -0
- package/docs/themes/theme-colored-fallbacks.scss +17 -0
- package/docs/themes/theme-colored.scss +17 -0
- package/docs/themes/theme-default-fallbacks.scss +17 -0
- package/docs/themes/theme-default.scss +17 -0
- package/jsconfig.json +4 -2
- package/package.json +43 -28
- package/scripts/deploy-docs.sh +9 -0
- package/templates/index.eta +2 -0
- package/templates/index.pug +3 -0
- package/utils/function.js +3 -0
- package/webpack.config.cjs +257 -0
- package/components/_index.scss +0 -4
- package/components/all-components.scss +0 -14
- package/components/common/functions.scss +0 -173
- package/components/common/mixins.scss +0 -107
- package/components/common/motion.scss +0 -36
- package/components/common/ripple.scss +0 -92
- package/components/common/variables.scss +0 -48
- package/components/complex/dialog/style.scss +0 -159
- package/components/complex/dialog/theming.scss +0 -29
- package/components/complex/navdrawer/style.scss +0 -477
- package/components/complex/navdrawer/theming.scss +0 -58
- package/components/complex/search/index.js +0 -492
- package/components/core/bottomnav/README.md +0 -85
- package/components/core/bottomnav/index.js +0 -140
- package/components/core/bottomnav/style.scss +0 -173
- package/components/core/bottomnav/theming.scss +0 -42
- package/components/core/button/index.js +0 -52
- package/components/core/button/style.scss +0 -283
- package/components/core/button/theming.scss +0 -131
- package/components/core/list/index.js +0 -94
- package/components/core/list/style.scss +0 -269
- package/components/core/list/theming.scss +0 -74
- package/components/core/menu/index.js +0 -127
- package/components/core/menu/style.scss +0 -239
- package/components/core/menu/theming.scss +0 -55
- package/components/core/progress/index.js +0 -33
- package/components/core/selection/style.scss +0 -249
- package/components/core/selection/theming.scss +0 -49
- package/components/core/switch/style.scss +0 -3
- package/components/core/tab/index.js +0 -174
- package/components/core/tab/style.scss +0 -202
- package/components/core/tab/theming.scss +0 -43
- package/components/core/textfield/index.js +0 -169
- package/components/core/textfield/style.scss +0 -672
- package/components/core/textfield/theming.scss +0 -262
- package/components/core/toolbar/style.scss +0 -109
- package/components/core/toolbar/theming.scss +0 -28
- package/components/core/tooltip/style.scss +0 -127
- package/components/core/type/style.scss +0 -133
- package/components/core/type/theming.scss +0 -25
- package/components/index.js +0 -24
- package/components/template/theming.scss +0 -31
- package/components/theming/theming.scss +0 -504
- package/docs/bottomnav.html +0 -171
- package/docs/bottomnav.min.js +0 -383
- package/docs/button.html +0 -322
- package/docs/button.min.js +0 -251
- package/docs/components.min.css +0 -1
- package/docs/components.min.js +0 -83
- package/docs/dialog.html +0 -103
- package/docs/dialog.min.js +0 -160
- package/docs/docs.min.css +0 -1
- package/docs/docs.min.js +0 -83
- package/docs/index.html +0 -55
- package/docs/index.min.js +0 -83
- package/docs/list.html +0 -442
- package/docs/list.min.js +0 -312
- package/docs/menu.html +0 -185
- package/docs/menu.min.js +0 -370
- package/docs/navdrawer.html +0 -199
- package/docs/navdrawer.min.js +0 -244
- package/docs/progress.html +0 -75
- package/docs/progress.min.js +0 -162
- package/docs/search.html +0 -230
- package/docs/search.min.js +0 -1202
- package/docs/selection.html +0 -188
- package/docs/selection.min.js +0 -160
- package/docs/src/complex/dialog.js +0 -3
- package/docs/src/complex/dialog.pug +0 -44
- package/docs/src/complex/navdrawer.js +0 -82
- package/docs/src/complex/navdrawer.pug +0 -109
- package/docs/src/complex/search.js +0 -207
- package/docs/src/complex/search.pug +0 -143
- package/docs/src/components.scss +0 -1
- package/docs/src/core/bottomnav.js +0 -22
- package/docs/src/core/bottomnav.pug +0 -93
- package/docs/src/core/button.js +0 -16
- package/docs/src/core/button.pug +0 -73
- package/docs/src/core/list.js +0 -21
- package/docs/src/core/list.pug +0 -246
- package/docs/src/core/menu.js +0 -33
- package/docs/src/core/menu.pug +0 -108
- package/docs/src/core/progress.js +0 -11
- package/docs/src/core/progress.pug +0 -17
- package/docs/src/core/selection.js +0 -4
- package/docs/src/core/selection.pug +0 -92
- package/docs/src/core/tab.js +0 -21
- package/docs/src/core/tab.pug +0 -180
- package/docs/src/core/textfield.js +0 -15
- package/docs/src/core/textfield.pug +0 -274
- package/docs/src/core/toolbar.js +0 -4
- package/docs/src/core/toolbar.pug +0 -79
- package/docs/src/core/tooltip.js +0 -4
- package/docs/src/core/tooltip.pug +0 -76
- package/docs/src/core/type.js +0 -4
- package/docs/src/core/type.pug +0 -36
- package/docs/src/docs.scss +0 -200
- package/docs/src/index.pug +0 -5
- package/docs/src/mixins.pug +0 -72
- package/docs/src/targetHandler.js +0 -50
- package/docs/src/theming.ie11.scss +0 -35
- package/docs/src/theming.scss +0 -36
- package/docs/tab.html +0 -301
- package/docs/tab.min.js +0 -397
- package/docs/textfield.html +0 -476
- package/docs/textfield.min.js +0 -381
- package/docs/theming.ie11.min.css +0 -1
- package/docs/theming.ie11.min.js +0 -83
- package/docs/theming.min.css +0 -1
- package/docs/theming.min.js +0 -83
- package/docs/toolbar.html +0 -213
- package/docs/toolbar.min.js +0 -160
- package/docs/tooltip.html +0 -138
- package/docs/tooltip.min.js +0 -160
- package/docs/type.html +0 -94
- package/docs/type.min.js +0 -160
- package/webpack.config.js +0 -176
|
@@ -0,0 +1,627 @@
|
|
|
1
|
+
// https://www.w3.org/TR/wai-aria-practices/#dialog_modal
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
dispatchDomEvent,
|
|
5
|
+
findElementParentByClassName,
|
|
6
|
+
getChildElementByClass,
|
|
7
|
+
iterateArrayLike,
|
|
8
|
+
iterateSomeOfArrayLike,
|
|
9
|
+
setTextNode,
|
|
10
|
+
} from '../../core/dom.js';
|
|
11
|
+
import * as Button from '../button/index.js';
|
|
12
|
+
|
|
13
|
+
class DialogStack {
|
|
14
|
+
/**
|
|
15
|
+
* @param {Element} element
|
|
16
|
+
* @param {Element} previousFocus
|
|
17
|
+
* @param {Object} [state]
|
|
18
|
+
* @param {Object} [previousState]
|
|
19
|
+
*/
|
|
20
|
+
constructor(element, previousFocus, state, previousState) {
|
|
21
|
+
this.element = (element);
|
|
22
|
+
this.previousFocus = (previousFocus);
|
|
23
|
+
this.state = state;
|
|
24
|
+
this.previousState = previousState;
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/** @type {DialogStack[]} */
|
|
29
|
+
const OPEN_DIALOGS = [];
|
|
30
|
+
|
|
31
|
+
export const CANCEL_EVENT = 'mdw:dialog-cancel';
|
|
32
|
+
export const CONFIRM_EVENT = 'mdw:dialog-confirm';
|
|
33
|
+
export const CUSTOM_EVENT = 'mdw:dialog-custom';
|
|
34
|
+
export const DISMISS_EVENT = 'mdw:dialog-dismiss';
|
|
35
|
+
|
|
36
|
+
/**
|
|
37
|
+
* @param {TransitionEvent} event
|
|
38
|
+
* @return {void}
|
|
39
|
+
*/
|
|
40
|
+
export function onTransitionEnd(event) {
|
|
41
|
+
if (event.propertyName !== 'opacity') {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
/** @type {HTMLElement} */
|
|
45
|
+
const dialogElement = (event.currentTarget);
|
|
46
|
+
if (dialogElement.getAttribute('aria-hidden') !== 'true') {
|
|
47
|
+
return;
|
|
48
|
+
}
|
|
49
|
+
/** @type {HTMLElement} */
|
|
50
|
+
const popupElement = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
51
|
+
if (!popupElement) {
|
|
52
|
+
return;
|
|
53
|
+
}
|
|
54
|
+
popupElement.style.removeProperty('display');
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* @param {Element} dialogElement
|
|
59
|
+
* @return {void}
|
|
60
|
+
*/
|
|
61
|
+
export function setupARIA(dialogElement) {
|
|
62
|
+
if (dialogElement.hasAttribute('mdw-no-aria')) {
|
|
63
|
+
return;
|
|
64
|
+
}
|
|
65
|
+
dialogElement.setAttribute('role', 'dialog');
|
|
66
|
+
dialogElement.setAttribute('aria-modal', 'true');
|
|
67
|
+
if (!dialogElement.hasAttribute('aria-hidden')) {
|
|
68
|
+
dialogElement.setAttribute('aria-hidden', 'true');
|
|
69
|
+
}
|
|
70
|
+
const popupElement = dialogElement.getElementsByClassName('mdw-dialog__popup')[0];
|
|
71
|
+
if (!popupElement) {
|
|
72
|
+
return;
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
if (!popupElement.hasAttribute('aria-label') && !popupElement.hasAttribute('aria-labelledby')) {
|
|
76
|
+
const titleElement = dialogElement.getElementsByClassName('mdw-dialog__title')[0];
|
|
77
|
+
if (titleElement) {
|
|
78
|
+
// titleElement
|
|
79
|
+
}
|
|
80
|
+
}
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
/**
|
|
84
|
+
* @param {Element} dialogElement
|
|
85
|
+
* @return {boolean} handled
|
|
86
|
+
*/
|
|
87
|
+
export function hide(dialogElement) {
|
|
88
|
+
if (dialogElement.getAttribute('aria-hidden') === 'true') {
|
|
89
|
+
return false;
|
|
90
|
+
}
|
|
91
|
+
if (!dispatchDomEvent(dialogElement, DISMISS_EVENT)) {
|
|
92
|
+
return false;
|
|
93
|
+
}
|
|
94
|
+
dialogElement.setAttribute('aria-hidden', 'true');
|
|
95
|
+
// .mdw-dialog__popup hidden by transitionEnd event
|
|
96
|
+
let stackIndex = -1;
|
|
97
|
+
OPEN_DIALOGS.some((stack, index) => {
|
|
98
|
+
if (stack.element === dialogElement) {
|
|
99
|
+
stackIndex = index;
|
|
100
|
+
return true;
|
|
101
|
+
}
|
|
102
|
+
return false;
|
|
103
|
+
});
|
|
104
|
+
if (stackIndex !== -1) {
|
|
105
|
+
const stack = OPEN_DIALOGS[stackIndex];
|
|
106
|
+
if (stack.previousFocus && stack.previousFocus instanceof HTMLElement) {
|
|
107
|
+
if (findElementParentByClassName(document.activeElement, 'mdw-dialog') === dialogElement) {
|
|
108
|
+
// Only pop focus back when hiding a dialog with focus within itself.
|
|
109
|
+
try {
|
|
110
|
+
stack.previousFocus.focus();
|
|
111
|
+
} catch (e) {
|
|
112
|
+
// Failed to focus
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
OPEN_DIALOGS.splice(stackIndex, 1);
|
|
117
|
+
if (stack.state && window.history && window.history.state) {
|
|
118
|
+
// IE11 returns a cloned state object, not the original
|
|
119
|
+
if (stack.state.hash === window.history.state.hash) {
|
|
120
|
+
window.history.back();
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
if (!OPEN_DIALOGS.length) {
|
|
125
|
+
// eslint-disable-next-line no-use-before-define
|
|
126
|
+
window.removeEventListener('popstate', onPopState);
|
|
127
|
+
}
|
|
128
|
+
return true;
|
|
129
|
+
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* @param {Element} dialogElement
|
|
133
|
+
* @return {void}
|
|
134
|
+
*/
|
|
135
|
+
export function cancel(dialogElement) {
|
|
136
|
+
if (dispatchDomEvent(dialogElement, CANCEL_EVENT)) {
|
|
137
|
+
hide(dialogElement);
|
|
138
|
+
}
|
|
139
|
+
}
|
|
140
|
+
|
|
141
|
+
/**
|
|
142
|
+
* @param {Element} dialogElement
|
|
143
|
+
* @return {void}
|
|
144
|
+
*/
|
|
145
|
+
export function confirm(dialogElement) {
|
|
146
|
+
if (dispatchDomEvent(dialogElement, CONFIRM_EVENT)) {
|
|
147
|
+
hide(dialogElement);
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* @param {MouseEvent} event
|
|
153
|
+
* @return {void}
|
|
154
|
+
*/
|
|
155
|
+
export function onCancelClick(event) {
|
|
156
|
+
if (event && event.currentTarget instanceof HTMLAnchorElement) {
|
|
157
|
+
event.preventDefault();
|
|
158
|
+
}
|
|
159
|
+
/** @type {HTMLElement} */
|
|
160
|
+
const cancelElement = (event.currentTarget);
|
|
161
|
+
const dialogElement = findElementParentByClassName(cancelElement, 'mdw-dialog');
|
|
162
|
+
cancel(dialogElement);
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
/**
|
|
166
|
+
* @param {MouseEvent} event
|
|
167
|
+
* @return {void}
|
|
168
|
+
*/
|
|
169
|
+
export function onConfirmClick(event) {
|
|
170
|
+
if (event && event.currentTarget instanceof HTMLAnchorElement) {
|
|
171
|
+
event.preventDefault();
|
|
172
|
+
}
|
|
173
|
+
/** @type {HTMLElement} */
|
|
174
|
+
const button = (event.currentTarget);
|
|
175
|
+
const dialogElement = findElementParentByClassName(button, 'mdw-dialog');
|
|
176
|
+
confirm(dialogElement);
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
/**
|
|
180
|
+
* @param {MouseEvent} event
|
|
181
|
+
* @return {void}
|
|
182
|
+
*/
|
|
183
|
+
export function onCustomButtonClick(event) {
|
|
184
|
+
if (event && event.currentTarget instanceof HTMLAnchorElement) {
|
|
185
|
+
event.preventDefault();
|
|
186
|
+
}
|
|
187
|
+
/** @type {HTMLElement} */
|
|
188
|
+
const button = (event.currentTarget);
|
|
189
|
+
if (dispatchDomEvent(button, CUSTOM_EVENT)) {
|
|
190
|
+
const dialogElement = findElementParentByClassName(button, 'mdw-dialog');
|
|
191
|
+
hide(dialogElement);
|
|
192
|
+
}
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
/**
|
|
196
|
+
* @param {KeyboardEvent} event
|
|
197
|
+
* @return {void}
|
|
198
|
+
*/
|
|
199
|
+
export function handleTabKeyPress(event) {
|
|
200
|
+
/** @type {Element} */
|
|
201
|
+
const popupElement = (event.currentTarget);
|
|
202
|
+
const focusableElements = popupElement.querySelectorAll([
|
|
203
|
+
'button:not(:disabled):not([tabindex="-1"])',
|
|
204
|
+
'[href]:not(:disabled):not([tabindex="-1"])',
|
|
205
|
+
'input:not(:disabled):not([tabindex="-1"])',
|
|
206
|
+
'select:not(:disabled):not([tabindex="-1"])',
|
|
207
|
+
'textarea:not(:disabled):not([tabindex="-1"])',
|
|
208
|
+
'[tabindex]:not([tabindex="-1"])'].join(', '));
|
|
209
|
+
let foundTarget = false;
|
|
210
|
+
let candidate = null;
|
|
211
|
+
iterateSomeOfArrayLike(focusableElements, (el) => {
|
|
212
|
+
if (el === event.target) {
|
|
213
|
+
foundTarget = true;
|
|
214
|
+
if (event.shiftKey) {
|
|
215
|
+
return true;
|
|
216
|
+
}
|
|
217
|
+
} else if (event.shiftKey) {
|
|
218
|
+
candidate = el;
|
|
219
|
+
} else if (foundTarget) {
|
|
220
|
+
candidate = el;
|
|
221
|
+
return true;
|
|
222
|
+
}
|
|
223
|
+
return false;
|
|
224
|
+
});
|
|
225
|
+
if (!candidate) {
|
|
226
|
+
if (event.shiftKey) {
|
|
227
|
+
// Select last item
|
|
228
|
+
candidate = focusableElements[focusableElements.length - 1];
|
|
229
|
+
} else {
|
|
230
|
+
// Select first item
|
|
231
|
+
candidate = focusableElements[0];
|
|
232
|
+
}
|
|
233
|
+
}
|
|
234
|
+
event.stopPropagation();
|
|
235
|
+
event.preventDefault();
|
|
236
|
+
if (candidate && candidate instanceof HTMLElement) {
|
|
237
|
+
try {
|
|
238
|
+
candidate.focus();
|
|
239
|
+
} catch (e) {
|
|
240
|
+
// Failed to focus
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
}
|
|
244
|
+
|
|
245
|
+
/**
|
|
246
|
+
* @param {KeyboardEvent} event
|
|
247
|
+
* @return {void}
|
|
248
|
+
*/
|
|
249
|
+
export function onEscapeKeyDown(event) {
|
|
250
|
+
event.stopPropagation();
|
|
251
|
+
event.preventDefault();
|
|
252
|
+
/** @type {HTMLElement} */
|
|
253
|
+
const popupElement = (event.currentTarget);
|
|
254
|
+
const dialogElement = findElementParentByClassName(popupElement, 'mdw-dialog');
|
|
255
|
+
cancel(dialogElement);
|
|
256
|
+
}
|
|
257
|
+
|
|
258
|
+
/**
|
|
259
|
+
* @param {KeyboardEvent} event
|
|
260
|
+
* @return {void}
|
|
261
|
+
*/
|
|
262
|
+
export function onKeyDown(event) {
|
|
263
|
+
if (event.key === 'Tab') {
|
|
264
|
+
handleTabKeyPress(event);
|
|
265
|
+
return;
|
|
266
|
+
}
|
|
267
|
+
if (event.key === 'Escape' || event.key === 'Esc') {
|
|
268
|
+
onEscapeKeyDown(event);
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
|
|
272
|
+
/**
|
|
273
|
+
* @param {Element} dialogElement
|
|
274
|
+
* @return {string}
|
|
275
|
+
*/
|
|
276
|
+
export function getTitleText(dialogElement) {
|
|
277
|
+
let title = 'Dialog';
|
|
278
|
+
const titleElement = dialogElement.getElementsByClassName('mdw-dialog__title')[0];
|
|
279
|
+
if (titleElement) {
|
|
280
|
+
title = titleElement.textContent;
|
|
281
|
+
} else {
|
|
282
|
+
const bodyElement = dialogElement.getElementsByClassName('mdw-dialog__body')[0];
|
|
283
|
+
if (bodyElement) {
|
|
284
|
+
title = bodyElement.textContent;
|
|
285
|
+
}
|
|
286
|
+
}
|
|
287
|
+
return title;
|
|
288
|
+
}
|
|
289
|
+
|
|
290
|
+
/**
|
|
291
|
+
* @param {PopStateEvent} event
|
|
292
|
+
* @return {void}
|
|
293
|
+
*/
|
|
294
|
+
export function onPopState(event) {
|
|
295
|
+
if (!event.state) {
|
|
296
|
+
return;
|
|
297
|
+
}
|
|
298
|
+
const lastOpenDialog = OPEN_DIALOGS[OPEN_DIALOGS.length - 1];
|
|
299
|
+
if (!lastOpenDialog || !lastOpenDialog.previousState) {
|
|
300
|
+
return;
|
|
301
|
+
}
|
|
302
|
+
if ((lastOpenDialog.previousState === event.state) || Object.keys(event.state)
|
|
303
|
+
.every((key) => event.state[key] === lastOpenDialog.previousState[key])) {
|
|
304
|
+
if (dispatchDomEvent(lastOpenDialog.element, CANCEL_EVENT)) {
|
|
305
|
+
hide(lastOpenDialog.element);
|
|
306
|
+
} else {
|
|
307
|
+
// Revert pop state by pushing state again
|
|
308
|
+
const title = getTitleText(lastOpenDialog.element);
|
|
309
|
+
window.history.pushState(lastOpenDialog.state, title);
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
}
|
|
313
|
+
|
|
314
|
+
/**
|
|
315
|
+
* @param {Element} dialogElement
|
|
316
|
+
* @param {(DocumentFragment|string)} [content]
|
|
317
|
+
* @return {void}
|
|
318
|
+
*/
|
|
319
|
+
export function updateTitle(dialogElement, content) {
|
|
320
|
+
let title = dialogElement.getElementsByClassName('mdw-dialog__title')[0];
|
|
321
|
+
if (!content) {
|
|
322
|
+
if (!title) {
|
|
323
|
+
// Nothing to be done
|
|
324
|
+
return;
|
|
325
|
+
}
|
|
326
|
+
title.parentElement.removeChild(title);
|
|
327
|
+
return;
|
|
328
|
+
}
|
|
329
|
+
if (!title) {
|
|
330
|
+
title = document.createElement('div');
|
|
331
|
+
title.className = 'mdw-dialog__title';
|
|
332
|
+
const popup = dialogElement.getElementsByClassName('mdw-dialog__popup')[0];
|
|
333
|
+
popup.insertBefore(title, popup.firstChild);
|
|
334
|
+
}
|
|
335
|
+
if (content instanceof DocumentFragment) {
|
|
336
|
+
while (title.lastChild) {
|
|
337
|
+
title.removeChild(title.lastChild);
|
|
338
|
+
}
|
|
339
|
+
title.appendChild(content);
|
|
340
|
+
} else {
|
|
341
|
+
title.textContent = content;
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
|
|
345
|
+
/**
|
|
346
|
+
* @param {Element} dialogElement
|
|
347
|
+
* @param {string[]} texts
|
|
348
|
+
* @return {void}
|
|
349
|
+
*/
|
|
350
|
+
export function updateButtonText(dialogElement, texts) {
|
|
351
|
+
const buttons = dialogElement.querySelectorAll('.mdw-dialog__button-area .mdw-button');
|
|
352
|
+
iterateArrayLike(buttons, (button, index) => {
|
|
353
|
+
setTextNode(button, texts[index]);
|
|
354
|
+
});
|
|
355
|
+
}
|
|
356
|
+
|
|
357
|
+
/**
|
|
358
|
+
* @param {Element} dialogElement
|
|
359
|
+
* @param {(DocumentFragment|string)} [content]
|
|
360
|
+
* @return {void}
|
|
361
|
+
*/
|
|
362
|
+
export function updateBody(dialogElement, content) {
|
|
363
|
+
let body = dialogElement.getElementsByClassName('mdw-dialog__body')[0];
|
|
364
|
+
if (!content) {
|
|
365
|
+
if (!body) {
|
|
366
|
+
// Nothing to be done
|
|
367
|
+
return;
|
|
368
|
+
}
|
|
369
|
+
body.parentElement.removeChild(body);
|
|
370
|
+
return;
|
|
371
|
+
}
|
|
372
|
+
if (!body) {
|
|
373
|
+
body = document.createElement('div');
|
|
374
|
+
body.className = 'mdw-dialog__body mdw-theme';
|
|
375
|
+
body.setAttribute('mdw-ink', 'medium');
|
|
376
|
+
const title = dialogElement.getElementsByClassName('mdw-dialog__title')[0];
|
|
377
|
+
if (title) {
|
|
378
|
+
title.insertAdjacentElement('afterend', body);
|
|
379
|
+
} else {
|
|
380
|
+
const popup = dialogElement.getElementsByClassName('mdw-dialog__popup')[0];
|
|
381
|
+
popup.insertBefore(body, popup.firstChild);
|
|
382
|
+
}
|
|
383
|
+
}
|
|
384
|
+
if (content instanceof DocumentFragment) {
|
|
385
|
+
while (body.lastChild) {
|
|
386
|
+
body.removeChild(body.lastChild);
|
|
387
|
+
}
|
|
388
|
+
body.appendChild(content);
|
|
389
|
+
} else {
|
|
390
|
+
body.textContent = content;
|
|
391
|
+
}
|
|
392
|
+
}
|
|
393
|
+
|
|
394
|
+
/**
|
|
395
|
+
* @param {Element} dialogElement
|
|
396
|
+
* @param {Event} [event]
|
|
397
|
+
* @return {void}
|
|
398
|
+
*/
|
|
399
|
+
export function updateTransformOrigin(dialogElement, event) {
|
|
400
|
+
/** @type {HTMLElement} */
|
|
401
|
+
const popup = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
402
|
+
popup.style.removeProperty('transform-origin');
|
|
403
|
+
if (!event) {
|
|
404
|
+
return;
|
|
405
|
+
}
|
|
406
|
+
const hadLayer = popup.style.getPropertyValue('display') != null;
|
|
407
|
+
if (!hadLayer) {
|
|
408
|
+
popup.style.setProperty('display', 'flex');
|
|
409
|
+
}
|
|
410
|
+
let pageX;
|
|
411
|
+
let pageY;
|
|
412
|
+
const dialogRect = dialogElement.getBoundingClientRect();
|
|
413
|
+
if ('pageX' in event && 'pageY' in event) {
|
|
414
|
+
({ pageX, pageY } = event);
|
|
415
|
+
pageX -= window.pageXOffset;
|
|
416
|
+
pageY -= window.pageYOffset;
|
|
417
|
+
} else {
|
|
418
|
+
/** @type {Element} */
|
|
419
|
+
const target = (event.target || event.currentTarget);
|
|
420
|
+
if (target instanceof Element === false) {
|
|
421
|
+
return;
|
|
422
|
+
}
|
|
423
|
+
const rect = target.getBoundingClientRect();
|
|
424
|
+
if (!rect.width && !rect.width && !rect.left && !rect.top) {
|
|
425
|
+
return;
|
|
426
|
+
}
|
|
427
|
+
pageX = rect.left + (rect.width / 2);
|
|
428
|
+
pageY = rect.top + (rect.height / 2);
|
|
429
|
+
}
|
|
430
|
+
const transformOriginX = pageX - dialogRect.left - popup.offsetLeft;
|
|
431
|
+
const transformOriginY = pageY - dialogRect.top - popup.offsetTop;
|
|
432
|
+
popup.style.setProperty('transform-origin', `${transformOriginX}px ${transformOriginY}px`);
|
|
433
|
+
if (!hadLayer) {
|
|
434
|
+
popup.style.removeProperty('display');
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
/**
|
|
439
|
+
* @param {Element} element
|
|
440
|
+
* @return {void}
|
|
441
|
+
*/
|
|
442
|
+
export function attach(element) {
|
|
443
|
+
element.setAttribute('mdw-dialog-js', '');
|
|
444
|
+
element.addEventListener('transitionend', onTransitionEnd);
|
|
445
|
+
|
|
446
|
+
let dialogCloser = getChildElementByClass(element, 'mdw-dialog__close');
|
|
447
|
+
if (!dialogCloser) {
|
|
448
|
+
dialogCloser = document.createElement('div');
|
|
449
|
+
dialogCloser.className = 'mdw-dialog__close';
|
|
450
|
+
if (element.firstChild) {
|
|
451
|
+
element.insertBefore(dialogCloser, element.firstChild);
|
|
452
|
+
} else {
|
|
453
|
+
element.appendChild(dialogCloser);
|
|
454
|
+
}
|
|
455
|
+
}
|
|
456
|
+
dialogCloser.addEventListener('click', onCancelClick);
|
|
457
|
+
const popup = getChildElementByClass(element, 'mdw-dialog__popup');
|
|
458
|
+
popup.addEventListener('keydown', onKeyDown);
|
|
459
|
+
const buttons = popup.querySelectorAll('.mdw-dialog__button-area .mdw-button');
|
|
460
|
+
let foundConfirmButton = false;
|
|
461
|
+
let foundCancelButton = false;
|
|
462
|
+
iterateArrayLike(buttons, (button) => {
|
|
463
|
+
Button.attach(button);
|
|
464
|
+
if (button.hasAttribute('mdw-custom')) {
|
|
465
|
+
button.addEventListener('click', onCustomButtonClick);
|
|
466
|
+
return;
|
|
467
|
+
}
|
|
468
|
+
if (!foundConfirmButton) {
|
|
469
|
+
button.addEventListener('click', onConfirmClick);
|
|
470
|
+
foundConfirmButton = true;
|
|
471
|
+
return;
|
|
472
|
+
}
|
|
473
|
+
if (!foundCancelButton) {
|
|
474
|
+
button.addEventListener('click', onCancelClick);
|
|
475
|
+
foundCancelButton = true;
|
|
476
|
+
return;
|
|
477
|
+
}
|
|
478
|
+
button.addEventListener('click', onCustomButtonClick);
|
|
479
|
+
});
|
|
480
|
+
setupARIA(element);
|
|
481
|
+
}
|
|
482
|
+
|
|
483
|
+
/**
|
|
484
|
+
* @param {Object} options
|
|
485
|
+
* @param {(DocumentFragment|string)} [options.title]
|
|
486
|
+
* @param {(DocumentFragment|string)} [options.body]
|
|
487
|
+
* @param {string[]} [options.buttons]
|
|
488
|
+
* @param {boolean} [options.stacked=false]
|
|
489
|
+
* @param {Element} [options.parent]
|
|
490
|
+
* @param {boolean} [options.custom=false] Use custom button events
|
|
491
|
+
* @param {(string|number)} [options.autofocus=0] Autofocus button by index or text
|
|
492
|
+
* @return {Element}
|
|
493
|
+
*/
|
|
494
|
+
export function create(options) {
|
|
495
|
+
const element = document.createElement('div');
|
|
496
|
+
element.className = 'mdw-dialog';
|
|
497
|
+
|
|
498
|
+
const popup = document.createElement('div');
|
|
499
|
+
popup.className = 'mdw-dialog__popup mdw-theme';
|
|
500
|
+
popup.setAttribute('mdw-surface', 'card');
|
|
501
|
+
element.appendChild(popup);
|
|
502
|
+
|
|
503
|
+
updateTitle(element, options.title);
|
|
504
|
+
updateBody(element, options.body);
|
|
505
|
+
|
|
506
|
+
if (options.buttons) {
|
|
507
|
+
const buttonArea = document.createElement('div');
|
|
508
|
+
buttonArea.className = 'mdw-dialog__button-area';
|
|
509
|
+
let index = 0;
|
|
510
|
+
options.buttons.forEach((buttonText) => {
|
|
511
|
+
const button = document.createElement('div');
|
|
512
|
+
button.className = 'mdw-button mdw-theme';
|
|
513
|
+
button.setAttribute('tabindex', '0');
|
|
514
|
+
button.setAttribute('mdw-ink', 'secondary');
|
|
515
|
+
if (options.custom) {
|
|
516
|
+
button.setAttribute('mdw-custom', '');
|
|
517
|
+
}
|
|
518
|
+
button.textContent = buttonText;
|
|
519
|
+
buttonArea.appendChild(button);
|
|
520
|
+
if ((options.autofocus == null && index === 0)
|
|
521
|
+
|| options.autofocus === index || options.autofocus === buttonText) {
|
|
522
|
+
button.setAttribute('mdw-autofocus', '');
|
|
523
|
+
}
|
|
524
|
+
index += 1;
|
|
525
|
+
});
|
|
526
|
+
if (options.stacked) {
|
|
527
|
+
buttonArea.setAttribute('mdw-stacked', '');
|
|
528
|
+
}
|
|
529
|
+
popup.appendChild(buttonArea);
|
|
530
|
+
}
|
|
531
|
+
if (options.parent) {
|
|
532
|
+
options.parent.appendChild(element);
|
|
533
|
+
}
|
|
534
|
+
attach(element);
|
|
535
|
+
return element;
|
|
536
|
+
}
|
|
537
|
+
|
|
538
|
+
/**
|
|
539
|
+
* @param {Element} dialogElement
|
|
540
|
+
* @param {Event} [event]
|
|
541
|
+
* @return {boolean} handled
|
|
542
|
+
*/
|
|
543
|
+
export function show(dialogElement, event) {
|
|
544
|
+
if (event && event.type === 'click' && event.currentTarget instanceof HTMLAnchorElement) {
|
|
545
|
+
// Prevent anchor link
|
|
546
|
+
event.preventDefault();
|
|
547
|
+
}
|
|
548
|
+
let changed = false;
|
|
549
|
+
|
|
550
|
+
if (dialogElement.getAttribute('aria-hidden') !== 'false') {
|
|
551
|
+
dialogElement.setAttribute('aria-hidden', 'false');
|
|
552
|
+
/** @type {HTMLElement} */
|
|
553
|
+
const popupElement = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
554
|
+
popupElement.style.setProperty('display', 'flex');
|
|
555
|
+
changed = true;
|
|
556
|
+
}
|
|
557
|
+
|
|
558
|
+
updateTransformOrigin(dialogElement, event);
|
|
559
|
+
|
|
560
|
+
if (!changed) {
|
|
561
|
+
return false;
|
|
562
|
+
}
|
|
563
|
+
attach(dialogElement);
|
|
564
|
+
const previousFocus = document.activeElement;
|
|
565
|
+
const newState = { hash: Math.random().toString(36).substr(2, 16) };
|
|
566
|
+
let previousState = null;
|
|
567
|
+
if (window.history && window.history.pushState) {
|
|
568
|
+
if (!window.history.state) {
|
|
569
|
+
// Create new previous state
|
|
570
|
+
window.history.replaceState({
|
|
571
|
+
hash: Math.random().toString(36).substr(2, 16),
|
|
572
|
+
}, document.title);
|
|
573
|
+
}
|
|
574
|
+
previousState = window.history.state;
|
|
575
|
+
const title = getTitleText(dialogElement);
|
|
576
|
+
window.history.pushState(newState, title);
|
|
577
|
+
window.addEventListener('popstate', onPopState);
|
|
578
|
+
}
|
|
579
|
+
const dialogStack = new DialogStack(dialogElement, previousFocus, newState, previousState);
|
|
580
|
+
OPEN_DIALOGS.push(dialogStack);
|
|
581
|
+
const focusElement = dialogElement.querySelector('[mdw-autofocus]');
|
|
582
|
+
try {
|
|
583
|
+
if (focusElement && focusElement instanceof HTMLElement) {
|
|
584
|
+
if (focusElement.scrollIntoView) {
|
|
585
|
+
focusElement.scrollIntoView();
|
|
586
|
+
}
|
|
587
|
+
focusElement.focus();
|
|
588
|
+
} else if (dialogElement instanceof HTMLElement) {
|
|
589
|
+
dialogElement.focus();
|
|
590
|
+
}
|
|
591
|
+
} catch (e) {
|
|
592
|
+
// Failed to focus
|
|
593
|
+
}
|
|
594
|
+
return true;
|
|
595
|
+
}
|
|
596
|
+
|
|
597
|
+
/**
|
|
598
|
+
* @param {Element} dialogElement
|
|
599
|
+
* @return {void}
|
|
600
|
+
*/
|
|
601
|
+
export function detach(dialogElement) {
|
|
602
|
+
dialogElement.removeEventListener('transitionend', onTransitionEnd);
|
|
603
|
+
dialogElement.removeAttribute('mdw-dialog-js');
|
|
604
|
+
const dialogCloser = getChildElementByClass(dialogElement, 'mdw-dialog__close');
|
|
605
|
+
if (dialogCloser) {
|
|
606
|
+
dialogCloser.removeEventListener('click', onCancelClick);
|
|
607
|
+
}
|
|
608
|
+
/** @type {HTMLElement} */
|
|
609
|
+
const popupElement = (dialogElement.getElementsByClassName('mdw-dialog__popup')[0]);
|
|
610
|
+
if (popupElement) {
|
|
611
|
+
popupElement.removeEventListener('keydown', onKeyDown);
|
|
612
|
+
popupElement.style.removeProperty('transform-origin');
|
|
613
|
+
if (popupElement.hasAttribute('style') && !popupElement.getAttribute('style')) {
|
|
614
|
+
popupElement.removeAttribute('style');
|
|
615
|
+
}
|
|
616
|
+
}
|
|
617
|
+
const buttons = popupElement.querySelectorAll('.mdw-dialog__button-area .mdw-button');
|
|
618
|
+
iterateArrayLike(buttons, (button) => {
|
|
619
|
+
Button.detach(button);
|
|
620
|
+
button.removeEventListener('click', onConfirmClick);
|
|
621
|
+
button.removeEventListener('click', onCancelClick);
|
|
622
|
+
button.removeEventListener('click', onCustomButtonClick);
|
|
623
|
+
});
|
|
624
|
+
}
|
|
625
|
+
|
|
626
|
+
// Aliases
|
|
627
|
+
export const dismiss = hide;
|
|
File without changes
|
|
File without changes
|