-
Notifications
You must be signed in to change notification settings - Fork 0
/
dialogicPolyfill.mjs
54 lines (52 loc) · 1.49 KB
/
dialogicPolyfill.mjs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
/**
* @name DialogicPolyfill
* @description
* Polyfill for dialog element (Q4 2019 is native support only in Chrome and Opera)
* @author ic < [email protected] >
* @see https://iiic.dev/dialogic-polyfill
* @license https://creativecommons.org/licenses/by-sa/4.0/legalcode.cs CC BY-SA 4.0
* @since Q4 2019
* @version 0.2
*/
( () =>
{
/** @type {HTMLDialogElement|HTMLUnknownElement} */
const dialog = ( document.createElement( 'DIALOG' ) );
const OPEN_STATUS = 'open';
const SHOW_FUNCTION = 'show';
const CLOSE_FUNCTION = 'close';
if (
dialog instanceof HTMLUnknownElement &&
!( OPEN_STATUS in dialog && SHOW_FUNCTION in dialog && CLOSE_FUNCTION in dialog )
) {
Object.defineProperty( HTMLUnknownElement.prototype, OPEN_STATUS, {
value: false,
writable: true,
configurable: false,
enumerable: false,
} );
Object.defineProperty( HTMLUnknownElement.prototype, SHOW_FUNCTION, {
value: function ()
{
this.style.display = 'block';
this[ OPEN_STATUS ] = true;
this.setAttribute( OPEN_STATUS, '' );
this.querySelector( 'button,[href],input,select,textarea,[tabindex]:not([tabindex="-1"])' ).focus();
},
writable: false,
configurable: false,
enumerable: false,
} );
Object.defineProperty( HTMLUnknownElement.prototype, CLOSE_FUNCTION, {
value: function ()
{
this.style.display = 'none';
this[ OPEN_STATUS ] = false;
this.removeAttribute( OPEN_STATUS );
},
writable: false,
configurable: false,
enumerable: false,
} );
}
} )();