summaryrefslogtreecommitdiff
path: root/web/src/jsx.tsx
diff options
context:
space:
mode:
Diffstat (limited to 'web/src/jsx.tsx')
-rw-r--r--web/src/jsx.tsx32
1 files changed, 32 insertions, 0 deletions
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
**/
@@ -127,6 +128,17 @@ export function navigateParams( route: string, params: any ) {
}
/**
+ * 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
**/
export function pushParams( params: any ) {
@@ -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 );
+ }
+} );