@@ -2902,44 +2902,32 @@ var htmx = (function() {
2902
2902
* @param {Element|HTMLInputElement } elt
2903
2903
*/
2904
2904
function initNode ( elt ) {
2905
- if ( closest ( elt , htmx . config . disableSelector ) ) {
2906
- cleanUpElement ( elt )
2907
- return
2908
- }
2905
+ triggerEvent ( elt , 'htmx:beforeProcessNode' )
2906
+
2909
2907
const nodeData = getInternalData ( elt )
2910
- const attrHash = attributeHash ( elt )
2911
- if ( nodeData . initHash !== attrHash ) {
2912
- // clean up any previously processed info
2913
- deInitNode ( elt )
2914
-
2915
- nodeData . initHash = attrHash
2916
-
2917
- triggerEvent ( elt , 'htmx:beforeProcessNode' )
2918
-
2919
- const triggerSpecs = getTriggerSpecs ( elt )
2920
- const hasExplicitHttpAction = processVerbs ( elt , nodeData , triggerSpecs )
2921
-
2922
- if ( ! hasExplicitHttpAction ) {
2923
- if ( getClosestAttributeValue ( elt , 'hx-boost' ) === 'true' ) {
2924
- boostElement ( elt , nodeData , triggerSpecs )
2925
- } else if ( hasAttribute ( elt , 'hx-trigger' ) ) {
2926
- triggerSpecs . forEach ( function ( triggerSpec ) {
2927
- // For "naked" triggers, don't do anything at all
2928
- addTriggerHandler ( elt , triggerSpec , nodeData , function ( ) {
2929
- } )
2930
- } )
2931
- }
2932
- }
2908
+ const triggerSpecs = getTriggerSpecs ( elt )
2909
+ const hasExplicitHttpAction = processVerbs ( elt , nodeData , triggerSpecs )
2933
2910
2934
- // Handle submit buttons/inputs that have the form attribute set
2935
- // see https://developer.mozilla.org/docs/Web/HTML/Element/button
2936
- if ( elt . tagName === 'FORM' || ( getRawAttribute ( elt , 'type' ) === 'submit' && hasAttribute ( elt , 'form' ) ) ) {
2937
- initButtonTracking ( elt )
2911
+ if ( ! hasExplicitHttpAction ) {
2912
+ if ( getClosestAttributeValue ( elt , 'hx-boost' ) === 'true' ) {
2913
+ boostElement ( elt , nodeData , triggerSpecs )
2914
+ } else if ( hasAttribute ( elt , 'hx-trigger' ) ) {
2915
+ triggerSpecs . forEach ( function ( triggerSpec ) {
2916
+ // For "naked" triggers, don't do anything at all
2917
+ addTriggerHandler ( elt , triggerSpec , nodeData , function ( ) {
2918
+ } )
2919
+ } )
2938
2920
}
2921
+ }
2939
2922
2940
- nodeData . firstInitCompleted = true
2941
- triggerEvent ( elt , 'htmx:afterProcessNode' )
2923
+ // Handle submit buttons/inputs that have the form attribute set
2924
+ // see https://developer.mozilla.org/docs/Web/HTML/Element/button
2925
+ if ( elt . tagName === 'FORM' || ( getRawAttribute ( elt , 'type' ) === 'submit' && hasAttribute ( elt , 'form' ) ) ) {
2926
+ initButtonTracking ( elt )
2942
2927
}
2928
+
2929
+ nodeData . firstInitCompleted = true
2930
+ triggerEvent ( elt , 'htmx:afterProcessNode' )
2943
2931
}
2944
2932
2945
2933
/**
@@ -2955,9 +2943,29 @@ var htmx = (function() {
2955
2943
cleanUpElement ( elt )
2956
2944
return
2957
2945
}
2958
- initNode ( elt )
2959
- forEach ( findElementsToProcess ( elt ) , function ( child ) { initNode ( child ) } )
2946
+
2947
+ const elementsToInit = [ ]
2948
+
2949
+ function maybeDeInit ( e ) {
2950
+ if ( closest ( e , htmx . config . disableSelector ) ) {
2951
+ cleanUpElement ( e )
2952
+ return
2953
+ }
2954
+ const nodeData = getInternalData ( e )
2955
+ const hash = attributeHash ( e )
2956
+ if ( nodeData . initHash !== hash ) {
2957
+ deInitNode ( e )
2958
+ nodeData . initHash = hash
2959
+ elementsToInit . push ( e )
2960
+ }
2961
+ }
2962
+
2963
+ maybeDeInit ( elt )
2964
+ forEach ( findElementsToProcess ( elt ) , maybeDeInit )
2965
+
2960
2966
forEach ( findHxOnWildcardElements ( elt ) , processHxOnWildcard )
2967
+ initNode ( elt )
2968
+ forEach ( elementsToInit , initNode )
2961
2969
}
2962
2970
2963
2971
//= ===================================================================
0 commit comments