11import { POST } from '../modules/fetch.ts' ;
2- import { addDelegatedEventListener , hideElem , queryElems , showElem , toggleElem } from '../utils/dom.ts' ;
2+ import { addDelegatedEventListener , hideElem , showElem , toggleElem } from '../utils/dom.ts' ;
33import { fomanticQuery } from '../modules/fomantic/base.ts' ;
44import { camelize } from 'vue' ;
55
@@ -74,10 +74,9 @@ export function initGlobalDeleteButton(): void {
7474 }
7575}
7676
77- function onShowPanelClick ( e : MouseEvent ) {
77+ function onShowPanelClick ( el : HTMLElement , e : MouseEvent ) {
7878 // a '.show-panel' element can show a panel, by `data-panel="selector"`
7979 // if it has "toggle" class, it toggles the panel
80- const el = e . currentTarget as HTMLElement ;
8180 e . preventDefault ( ) ;
8281 const sel = el . getAttribute ( 'data-panel' ) ;
8382 if ( el . classList . contains ( 'toggle' ) ) {
@@ -87,9 +86,8 @@ function onShowPanelClick(e: MouseEvent) {
8786 }
8887}
8988
90- function onHidePanelClick ( e : MouseEvent ) {
89+ function onHidePanelClick ( el : HTMLElement , e : MouseEvent ) {
9190 // a `.hide-panel` element can hide a panel, by `data-panel="selector"` or `data-panel-closest="selector"`
92- const el = e . currentTarget as HTMLElement ;
9391 e . preventDefault ( ) ;
9492 let sel = el . getAttribute ( 'data-panel' ) ;
9593 if ( sel ) {
@@ -104,15 +102,14 @@ function onHidePanelClick(e: MouseEvent) {
104102 throw new Error ( 'no panel to hide' ) ; // should never happen, otherwise there is a bug in code
105103}
106104
107- function onShowModalClick ( e : MouseEvent ) {
105+ function onShowModalClick ( el : HTMLElement , e : MouseEvent ) {
108106 // A ".show-modal" button will show a modal dialog defined by its "data-modal" attribute.
109107 // Each "data-modal-{target}" attribute will be filled to target element's value or text-content.
110108 // * First, try to query '#target'
111109 // * Then, try to query '[name=target]'
112110 // * Then, try to query '.target'
113111 // * Then, try to query 'target' as HTML tag
114112 // If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" attribute will be set.
115- const el = e . currentTarget as HTMLElement ;
116113 e . preventDefault ( ) ;
117114 const modalSelector = el . getAttribute ( 'data-modal' ) ;
118115 const elModal = document . querySelector ( modalSelector ) ;
@@ -160,7 +157,15 @@ export function initGlobalButtons(): void {
160157 // There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content")
161158 addDelegatedEventListener ( document , 'click' , 'form button.ui.cancel.button' , ( _ /* el */ , e ) => e . preventDefault ( ) ) ;
162159
163- queryElems ( document , '.show-panel' , ( el ) => el . addEventListener ( 'click' , onShowPanelClick ) ) ;
164- queryElems ( document , '.hide-panel' , ( el ) => el . addEventListener ( 'click' , onHidePanelClick ) ) ;
165- queryElems ( document , '.show-modal' , ( el ) => el . addEventListener ( 'click' , onShowModalClick ) ) ;
160+ // Ideally these "button" events should be handled by registerGlobalEventFunc
161+ // Refactoring would involve too many changes, so at the moment, just use the global event listener.
162+ addDelegatedEventListener ( document , 'click' , '.show-panel, .hide-panel, .show-modal' , ( el , e : MouseEvent ) => {
163+ if ( el . classList . contains ( 'show-panel' ) ) {
164+ onShowPanelClick ( el , e ) ;
165+ } else if ( el . classList . contains ( 'hide-panel' ) ) {
166+ onHidePanelClick ( el , e ) ;
167+ } else if ( el . classList . contains ( 'show-modal' ) ) {
168+ onShowModalClick ( el , e ) ;
169+ }
170+ } ) ;
166171}
0 commit comments