@@ -5,48 +5,40 @@ function createRipple(event) {
55 const diameter = Math . max ( button . clientWidth , button . clientHeight ) ;
66 const radius = diameter / 2 ;
77
8- circle . style . width = circle . style . height = `${ diameter } px` ;
9- circle . style . left = `${ event . offsetX - radius } px` ;
10- circle . style . top = `${ event . offsetY - radius } px` ;
8+ Object . assign ( circle . style , {
9+ width : `${ diameter } px` ,
10+ height : `${ diameter } px` ,
11+ left : `${ event . offsetX - radius } px` ,
12+ top : `${ event . offsetY - radius } px` ,
13+ } ) ;
14+
1115 circle . classList . add ( "ripple" ) ;
1216
13- const ripple = button . querySelector ( ".ripple" ) ;
14- if ( ripple ) ripple . remove ( ) ;
17+ button . querySelector ( ".ripple" ) ?. remove ( ) ;
1518
1619 button . appendChild ( circle ) ;
1720}
1821
19- const buttons = document . querySelectorAll ( "button[data-ripple]" ) ;
20- for ( const button of buttons ) {
21- if ( ! button . classList . contains ( "tooltip" ) ) button . addEventListener ( "click" , createRipple ) ;
22+ for ( const button of document . querySelectorAll ( "button[data-ripple]" ) ) {
23+ if ( ! button . classList . contains ( "tooltip" ) ) {
24+ button . addEventListener ( "click" , createRipple ) ;
25+ }
2226}
2327
24- const openModalButtons = document . querySelectorAll ( "button[data-modal]" )
25- for ( const button of openModalButtons ) {
28+ for ( const button of document . querySelectorAll ( "button[data-modal]" ) ) {
2629 button . addEventListener ( "click" , ( ) => {
27- const id = button . getAttribute ( "data-modal" ) ;
28- openModal ( id ) ;
29-
30- document . addEventListener ( "keydown" , ( event ) => event . key === "Escape" ? closeModal ( id ) : null ) ;
30+ document . getElementById ( button . dataset . modal ) ?. showModal ( ) ;
3131 } ) ;
3232}
3333
34- const closeButtons = document . querySelectorAll ( ".close-btn" ) ;
35- for ( const button of closeButtons ) {
34+ for ( const button of document . querySelectorAll ( ".close-btn" ) ) {
3635 button . addEventListener ( "click" , ( ) => {
37- const id = button . getAttribute ( "data-modal" ) ;
38- closeModal ( id ) ;
39-
40- document . addEventListener ( "keydown" , ( event ) => event . key === "Escape" ? closeModal ( id ) : null ) ;
36+ button . closest ( "dialog" ) ?. close ( ) ;
4137 } ) ;
4238}
4339
44- function closeModal ( id ) {
45- const modal = document . getElementById ( id ) ;
46- modal . style . display = "none" ;
47- }
48-
49- function openModal ( id ) {
50- const modal = document . getElementById ( id ) ;
51- modal . style . display = "block" ;
40+ for ( const dialog of document . querySelectorAll ( "dialog.modal" ) ) {
41+ dialog . addEventListener ( "click" , ( event ) => {
42+ if ( event . target === dialog ) dialog . close ( ) ;
43+ } ) ;
5244}
0 commit comments