Created
March 23, 2023 12:55
-
-
Save bennadel/8561a0b85d0d72b2141c547a27297d74 to your computer and use it in GitHub Desktop.
Disabling Turbo Drive In A Subdirectory Of Your ColdFusion Application
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<cfmodule template="./tags/page.cfm" section="about"> | |
<cfoutput> | |
<h2> | |
About This Site | |
</h2> | |
<p> | |
Copy copy copy.... | |
</p> | |
<p> | |
Check out this really old demo: | |
</p> | |
<ul> | |
<li> | |
<a href="resources/old-demo/index.htm?force=true">Old Demo (force)</a> | |
</li> | |
<li> | |
<a href="resources/old-demo/index.htm">Old Demo</a> | |
</li> | |
</ul> | |
</cfoutput> | |
</cfmodule> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// Import core modules. | |
import * as Turbo from "@hotwired/turbo"; | |
// ----------------------------------------------------------------------------------- // | |
// ----------------------------------------------------------------------------------- // | |
document.documentElement.addEventListener( | |
"turbo:click", | |
function handleClick( event ) { | |
// For the demo, we're going to allow any URL with [force=true] to be consumed by | |
// Turbo Drive, regardless of where it is pointing to. | |
if ( event.detail.url.includes( "force=true" ) ) { | |
return; | |
} | |
// As we migrate an old site over to use Hotwire Turbo Drive, there may be a whole | |
// host of links that point to old pages that are NOT NOW and WILL NEVER BE | |
// compatible with the Turbo Drive requirements. We can hook into the Turbo Drive | |
// events and prevent Hotwire from managing these archaic links. | |
if ( event.detail.url.includes( "/resources/" ) ) { | |
console.group( "Detected 'Resources' Subdirectory" ); | |
console.log( "URL:", event.detail.url ); | |
console.log( "Preventing default." ); | |
console.groupEnd(); | |
// Cancel this event to let the click fall through to the browser as normal | |
// link navigation. | |
event.preventDefault(); | |
} | |
} | |
); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<!--- | |
CAUTION: Turbo Drive merges the contents of the HEAD on page navigation. If we're | |
not careful, this WILL clobber the styles of the root site when the user navigates | |
back to the root of the site. | |
---> | |
<style type="text/css"> | |
body { | |
background-color: #212121 ; | |
color: #f0f0f0 ; | |
} | |
a { | |
color: inherit ; | |
} | |
</style> | |
</head> | |
<body> | |
<h1> | |
Really Old Demo | |
</h1> | |
<p> | |
Copy copy copy.... | |
</p> | |
<p> | |
<a href="../../index.htm">Back to root</a> | |
</p> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment