From e66257a6f66bf905d82c8df6e4e4d1a1509e0810 Mon Sep 17 00:00:00 2001
From: navewindre <boneyaard@gmail.com>
Date: Wed, 11 Feb 2026 06:12:26 +0100
Subject: click callback for auto navigation, rendering fixes

---
 web/src/jsx.tsx | 32 ++++++++++++++++++++++++++++++++
 1 file changed, 32 insertions(+)

(limited to 'web/src/jsx.tsx')

diff --git a/web/src/jsx.tsx b/web/src/jsx.tsx
index 749e93f..1243398 100644
--- a/web/src/jsx.tsx
+++ b/web/src/jsx.tsx
@@ -78,6 +78,7 @@ export function onPostNavigate( callback: Function ) {
   onpostnavigate = callback;
 }
 
+
 /**
  * replaces the root element with the route component
  **/
@@ -126,6 +127,17 @@ export function navigateParams( route: string, params: any ) {
   onpostnavigate();
 }
 
+/**
+ * convenience function to pass to href elements
+ **/
+export function href( e: Event ) {
+  const el = $( e.target );
+  if( el.is( 'a' ) ) {
+    e.preventDefault();
+    navigate( el.attr( 'href' ) );
+  }
+}
+
 /**
  * wrapper for history.pushState
  **/
@@ -302,3 +314,23 @@ export function createFragment( props: any ) {
 function setTitle() {
   document.title = defaultTitle;
 }
+
+document.addEventListener( "click", e => {
+  let a = ( e.target ) as HTMLAnchorElement;
+  if( !a )
+    return;
+  if( a.origin !== location.origin )
+    return;
+
+  e.preventDefault();
+  if( !a.onclick ) {
+    if( routeForPath( a.pathname ) )
+      return navigate( a.pathname );
+
+    const hasExt = /\.[a-zA-Z0-9]{1,8}$/.test( a.href );
+    if( hasExt )
+      location.href = a.href;
+    else
+      navigate( err404page );
+  }
+} );
-- 
cgit v1.2.3

