@@ -1347,6 +1347,16 @@ var htmx = (function() {
13471347 return [ findThisElement ( elt , attrName ) ]
13481348 } else {
13491349 const result = querySelectorAllExt ( elt , attrTarget )
1350+ // find `inherit` whole word in value, make sure it's surrounded by commas or is at the start/end of string
1351+ const shouldInherit = / ( ^ | , ) ( \s * ) i n h e r i t ( \s * ) ( $ | , ) / . test ( attrTarget )
1352+ if ( shouldInherit ) {
1353+ const eltToInheritFrom = asElement ( getClosestMatch ( elt , function ( parent ) {
1354+ return parent !== elt && hasAttribute ( asElement ( parent ) , attrName )
1355+ } ) )
1356+ if ( eltToInheritFrom ) {
1357+ result . push ( ...findAttributeTargets ( eltToInheritFrom , attrName ) )
1358+ }
1359+ }
13501360 if ( result . length === 0 ) {
13511361 logError ( 'The selector "' + attrTarget + '" on ' + attrName + ' returned no matches!' )
13521362 return [ DUMMY_ELT ]
@@ -1850,6 +1860,30 @@ var htmx = (function() {
18501860 return oobElts . length > 0
18511861 }
18521862
1863+ /**
1864+ * Apply swapping class and then execute the swap with optional delay
1865+ * @param {string|Element } target
1866+ * @param {string } content
1867+ * @param {HtmxSwapSpecification } swapSpec
1868+ * @param {SwapOptions } [swapOptions]
1869+ */
1870+ function swap ( target , content , swapSpec , swapOptions ) {
1871+ if ( ! swapOptions ) {
1872+ swapOptions = { }
1873+ }
1874+
1875+ target = resolveTarget ( target )
1876+ target . classList . add ( htmx . config . swappingClass )
1877+ const localSwap = function ( ) {
1878+ runSwap ( target , content , swapSpec , swapOptions )
1879+ }
1880+ if ( swapSpec ?. swapDelay && swapSpec . swapDelay > 0 ) {
1881+ getWindow ( ) . setTimeout ( localSwap , swapSpec . swapDelay )
1882+ } else {
1883+ localSwap ( )
1884+ }
1885+ }
1886+
18531887 /**
18541888 * Implements complete swapping pipeline, including: focus and selection preservation,
18551889 * title updates, scroll, OOB swapping, normal swapping and settling
@@ -1858,7 +1892,7 @@ var htmx = (function() {
18581892 * @param {HtmxSwapSpecification } swapSpec
18591893 * @param {SwapOptions } [swapOptions]
18601894 */
1861- function swap ( target , content , swapSpec , swapOptions ) {
1895+ function runSwap ( target , content , swapSpec , swapOptions ) {
18621896 if ( ! swapOptions ) {
18631897 swapOptions = { }
18641898 }
@@ -4168,7 +4202,7 @@ var htmx = (function() {
41684202 }
41694203 const target = etc . targetOverride || asElement ( getTarget ( elt ) )
41704204 if ( target == null || target == DUMMY_ELT ) {
4171- triggerErrorEvent ( elt , 'htmx:targetError' , { target : getAttributeValue ( elt , 'hx-target' ) } )
4205+ triggerErrorEvent ( elt , 'htmx:targetError' , { target : getClosestAttributeValue ( elt , 'hx-target' ) } )
41724206 maybeCall ( reject )
41734207 return promise
41744208 }
@@ -4790,8 +4824,6 @@ var htmx = (function() {
47904824 swapSpec . ignoreTitle = ignoreTitle
47914825 }
47924826
4793- target . classList . add ( htmx . config . swappingClass )
4794-
47954827 // optional transition API promise callbacks
47964828 let settleResolve = null
47974829 let settleReject = null
@@ -4822,7 +4854,7 @@ var htmx = (function() {
48224854 }
48234855
48244856 swap ( target , serverResponse , swapSpec , {
4825- select : selectOverride || select ,
4857+ select : selectOverride === 'unset' ? null : selectOverride || select ,
48264858 selectOOB,
48274859 eventInfo : responseInfo ,
48284860 anchor : responseInfo . pathInfo . anchor ,
@@ -4878,12 +4910,7 @@ var htmx = (function() {
48784910 } )
48794911 }
48804912 }
4881-
4882- if ( swapSpec . swapDelay > 0 ) {
4883- getWindow ( ) . setTimeout ( doSwap , swapSpec . swapDelay )
4884- } else {
4885- doSwap ( )
4886- }
4913+ doSwap ( )
48874914 }
48884915 if ( isError ) {
48894916 triggerErrorEvent ( elt , 'htmx:responseError' , mergeObjects ( { error : 'Response Status Error Code ' + xhr . status + ' from ' + responseInfo . pathInfo . requestPath } , responseInfo ) )
0 commit comments