@@ -1850,6 +1850,30 @@ var htmx = (function() {
18501850 return oobElts . length > 0
18511851 }
18521852
1853+ /**
1854+ * Apply swapping class and then execute the swap with optional delay
1855+ * @param {string|Element } target
1856+ * @param {string } content
1857+ * @param {HtmxSwapSpecification } swapSpec
1858+ * @param {SwapOptions } [swapOptions]
1859+ */
1860+ function swap ( target , content , swapSpec , swapOptions ) {
1861+ if ( ! swapOptions ) {
1862+ swapOptions = { }
1863+ }
1864+
1865+ target = resolveTarget ( target )
1866+ target . classList . add ( htmx . config . swappingClass )
1867+ const localSwap = function ( ) {
1868+ runSwap ( target , content , swapSpec , swapOptions )
1869+ }
1870+ if ( swapSpec ?. swapDelay && swapSpec . swapDelay > 0 ) {
1871+ getWindow ( ) . setTimeout ( localSwap , swapSpec . swapDelay )
1872+ } else {
1873+ localSwap ( )
1874+ }
1875+ }
1876+
18531877 /**
18541878 * Implements complete swapping pipeline, including: focus and selection preservation,
18551879 * title updates, scroll, OOB swapping, normal swapping and settling
@@ -1858,7 +1882,7 @@ var htmx = (function() {
18581882 * @param {HtmxSwapSpecification } swapSpec
18591883 * @param {SwapOptions } [swapOptions]
18601884 */
1861- function swap ( target , content , swapSpec , swapOptions ) {
1885+ function runSwap ( target , content , swapSpec , swapOptions ) {
18621886 if ( ! swapOptions ) {
18631887 swapOptions = { }
18641888 }
@@ -4790,8 +4814,6 @@ var htmx = (function() {
47904814 swapSpec . ignoreTitle = ignoreTitle
47914815 }
47924816
4793- target . classList . add ( htmx . config . swappingClass )
4794-
47954817 // optional transition API promise callbacks
47964818 let settleResolve = null
47974819 let settleReject = null
@@ -4878,12 +4900,7 @@ var htmx = (function() {
48784900 } )
48794901 }
48804902 }
4881-
4882- if ( swapSpec . swapDelay > 0 ) {
4883- getWindow ( ) . setTimeout ( doSwap , swapSpec . swapDelay )
4884- } else {
4885- doSwap ( )
4886- }
4903+ doSwap ( )
48874904 }
48884905 if ( isError ) {
48894906 triggerErrorEvent ( elt , 'htmx:responseError' , mergeObjects ( { error : 'Response Status Error Code ' + xhr . status + ' from ' + responseInfo . pathInfo . requestPath } , responseInfo ) )
0 commit comments