@@ -1796,6 +1796,30 @@ var htmx = (function() {
1796
1796
return oobElts . length > 0
1797
1797
}
1798
1798
1799
+ /**
1800
+ * Apply swapping class and then execute the swap with optional delay
1801
+ * @param {string|Element } target
1802
+ * @param {string } content
1803
+ * @param {HtmxSwapSpecification } swapSpec
1804
+ * @param {SwapOptions } [swapOptions]
1805
+ */
1806
+ function swap ( target , content , swapSpec , swapOptions ) {
1807
+ if ( ! swapOptions ) {
1808
+ swapOptions = { }
1809
+ }
1810
+
1811
+ target = resolveTarget ( target )
1812
+ target . classList . add ( htmx . config . swappingClass )
1813
+ const localSwap = function ( ) {
1814
+ runSwap ( target , content , swapSpec , swapOptions )
1815
+ }
1816
+ if ( swapSpec ?. swapDelay && swapSpec . swapDelay > 0 ) {
1817
+ getWindow ( ) . setTimeout ( localSwap , swapSpec . swapDelay )
1818
+ } else {
1819
+ localSwap ( )
1820
+ }
1821
+ }
1822
+
1799
1823
/**
1800
1824
* Implements complete swapping pipeline, including: focus and selection preservation,
1801
1825
* title updates, scroll, OOB swapping, normal swapping and settling
@@ -1804,7 +1828,7 @@ var htmx = (function() {
1804
1828
* @param {HtmxSwapSpecification } swapSpec
1805
1829
* @param {SwapOptions } [swapOptions]
1806
1830
*/
1807
- function swap ( target , content , swapSpec , swapOptions ) {
1831
+ function runSwap ( target , content , swapSpec , swapOptions ) {
1808
1832
if ( ! swapOptions ) {
1809
1833
swapOptions = { }
1810
1834
}
@@ -4695,8 +4719,6 @@ var htmx = (function() {
4695
4719
swapSpec . ignoreTitle = ignoreTitle
4696
4720
}
4697
4721
4698
- target . classList . add ( htmx . config . swappingClass )
4699
-
4700
4722
// optional transition API promise callbacks
4701
4723
let settleResolve = null
4702
4724
let settleReject = null
@@ -4783,12 +4805,7 @@ var htmx = (function() {
4783
4805
} )
4784
4806
}
4785
4807
}
4786
-
4787
- if ( swapSpec . swapDelay > 0 ) {
4788
- getWindow ( ) . setTimeout ( doSwap , swapSpec . swapDelay )
4789
- } else {
4790
- doSwap ( )
4791
- }
4808
+ doSwap ( )
4792
4809
}
4793
4810
if ( isError ) {
4794
4811
triggerErrorEvent ( elt , 'htmx:responseError' , mergeObjects ( { error : 'Response Status Error Code ' + xhr . status + ' from ' + responseInfo . pathInfo . requestPath } , responseInfo ) )
0 commit comments