11import {
2+ $ ,
23 args ,
34 generateDbKey ,
45 hasValue ,
@@ -86,15 +87,18 @@ export function addActionEventListener(component, eventType) {
8687 if ( eventArg . startsWith ( "$event" ) ) {
8788 // Remove any extra whitespace, everything before and including "$event", and the ending paren
8889 // let eventArg = action.name.trim();
89- eventArg = eventArg . trim ( ) . slice ( eventArg . indexOf ( "$event" ) + 6 ) . trim ( ) ;
90-
90+ eventArg = eventArg
91+ . trim ( )
92+ . slice ( eventArg . indexOf ( "$event" ) + 6 )
93+ . trim ( ) ;
94+
9195 const originalSpecialVariable = `$event${ eventArg } ` ;
9296 let data = event ;
9397 let invalidPiece = false ;
94-
98+
9599 eventArg . split ( "." ) . forEach ( ( piece ) => {
96100 piece = piece . trim ( ) ;
97-
101+
98102 if ( piece ) {
99103 // TODO: Handle method calls with args
100104 if ( piece . endsWith ( "()" ) ) {
@@ -108,34 +112,67 @@ export function addActionEventListener(component, eventType) {
108112 }
109113 }
110114 } ) ;
111-
115+
112116 if ( invalidPiece ) {
113- console . error ( `${ originalSpecialVariable } could not be retrieved` )
117+ console . error (
118+ `'${ originalSpecialVariable } ' could not be retrieved`
119+ ) ;
114120 action . name = action . name . replace ( originalSpecialVariable , "" ) ;
115121 } else if ( data ) {
116122 if ( typeof data === "string" ) {
117123 // Wrap strings in quotes
118124 data = `"${ data } "` ;
119125 }
120-
121- action . name = action . name . replace ( originalSpecialVariable , data ) ;
126+
127+ action . name = action . name . replace (
128+ originalSpecialVariable ,
129+ data
130+ ) ;
122131 }
123132 }
124133 } ) ;
125134
126135 if ( targetElement . loading ) {
127136 if ( targetElement . loading . attr ) {
128- targetElement . el [ targetElement . loading . attr ] = targetElement . loading . attr ;
129- }
130-
131- if ( targetElement . loading . class ) {
137+ targetElement . el [ targetElement . loading . attr ] =
138+ targetElement . loading . attr ;
139+ } else if ( targetElement . loading . class ) {
132140 targetElement . el . classList . add ( targetElement . loading . class ) ;
141+ } else if ( targetElement . loading . removeClass ) {
142+ targetElement . el . classList . remove (
143+ targetElement . loading . removeClass
144+ ) ;
133145 }
146+ }
147+
148+ // Look at all elements with a loading attribute
149+ component . loadingEls . forEach ( ( loadingElement ) => {
150+ if ( loadingElement . target ) {
151+ let targetedEl = $ ( `#${ loadingElement . target } ` , component . root ) ;
134152
135- if ( targetElement . loading . removeClass ) {
136- targetElement . el . classList . remove ( targetElement . loading . removeClass ) ;
153+ if ( ! targetedEl ) {
154+ component . keyEls . forEach ( ( keyElement ) => {
155+ if ( ! targetedEl && keyElement . key === loadingElement . target ) {
156+ targetedEl = keyElement . el ;
157+ }
158+ } ) ;
159+ }
160+
161+ if ( targetedEl ) {
162+ if ( targetElement . el . isSameNode ( targetedEl ) ) {
163+ if ( loadingElement . loading . hide ) {
164+ loadingElement . hide ( ) ;
165+ } else if ( loadingElement . loading . show ) {
166+ loadingElement . show ( ) ;
167+ }
168+ }
169+ }
170+ } else if ( loadingElement . loading . hide ) {
171+ loadingElement . hide ( ) ;
172+ } else if ( loadingElement . loading . show ) {
173+ loadingElement . show ( ) ;
137174 }
138- }
175+ } ) ;
139176
140177 if ( action . key ) {
141178 if ( action . key === toKebabCase ( event . key ) ) {
0 commit comments