11import { POST } from '../modules/fetch.ts' ;
22import { addDelegatedEventListener , hideElem , showElem , toggleElem } from '../utils/dom.ts' ;
33import { fomanticQuery } from '../modules/fomantic/base.ts' ;
4- import { registerGlobalSelectorFunc } from '../modules/observer.ts' ;
54import { camelize } from 'vue' ;
65
76export function initGlobalButtonClickOnEnter ( ) : void {
@@ -75,10 +74,9 @@ export function initGlobalDeleteButton(): void {
7574 }
7675}
7776
78- function onShowPanelClick ( e : MouseEvent ) {
77+ function onShowPanelClick ( el : HTMLElement , e : MouseEvent ) {
7978 // a '.show-panel' element can show a panel, by `data-panel="selector"`
8079 // if it has "toggle" class, it toggles the panel
81- const el = e . currentTarget as HTMLElement ;
8280 e . preventDefault ( ) ;
8381 const sel = el . getAttribute ( 'data-panel' ) ;
8482 if ( el . classList . contains ( 'toggle' ) ) {
@@ -88,9 +86,8 @@ function onShowPanelClick(e: MouseEvent) {
8886 }
8987}
9088
91- function onHidePanelClick ( e : MouseEvent ) {
89+ function onHidePanelClick ( el : HTMLElement , e : MouseEvent ) {
9290 // a `.hide-panel` element can hide a panel, by `data-panel="selector"` or `data-panel-closest="selector"`
93- const el = e . currentTarget as HTMLElement ;
9491 e . preventDefault ( ) ;
9592 let sel = el . getAttribute ( 'data-panel' ) ;
9693 if ( sel ) {
@@ -105,15 +102,14 @@ function onHidePanelClick(e: MouseEvent) {
105102 throw new Error ( 'no panel to hide' ) ; // should never happen, otherwise there is a bug in code
106103}
107104
108- function onShowModalClick ( e : MouseEvent ) {
105+ function onShowModalClick ( el : HTMLElement , e : MouseEvent ) {
109106 // A ".show-modal" button will show a modal dialog defined by its "data-modal" attribute.
110107 // Each "data-modal-{target}" attribute will be filled to target element's value or text-content.
111108 // * First, try to query '#target'
112109 // * Then, try to query '[name=target]'
113110 // * Then, try to query '.target'
114111 // * Then, try to query 'target' as HTML tag
115112 // If there is a ".{attr}" part like "data-modal-form.action", then the form's "action" attribute will be set.
116- const el = e . currentTarget as HTMLElement ;
117113 e . preventDefault ( ) ;
118114 const modalSelector = el . getAttribute ( 'data-modal' ) ;
119115 const elModal = document . querySelector ( modalSelector ) ;
@@ -161,7 +157,15 @@ export function initGlobalButtons(): void {
161157 // There are a few cancel buttons in non-modal forms, and there are some dynamically created forms (eg: the "Edit Issue Content")
162158 addDelegatedEventListener ( document , 'click' , 'form button.ui.cancel.button' , ( _ /* el */ , e ) => e . preventDefault ( ) ) ;
163159
164- registerGlobalSelectorFunc ( '.show-panel' , ( el ) => el . addEventListener ( 'click' , onShowPanelClick ) ) ;
165- registerGlobalSelectorFunc ( '.hide-panel' , ( el ) => el . addEventListener ( 'click' , onHidePanelClick ) ) ;
166- registerGlobalSelectorFunc ( '.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+ } ) ;
167171}
0 commit comments