mirror of
https://github.com/srid/ema.git
synced 2024-11-25 20:12:20 +03:00
js: Add ema.switchRoute
This commit is contained in:
parent
28eb12ff07
commit
674005845b
@ -1,5 +1,9 @@
|
||||
# Revision history for ema
|
||||
|
||||
## Unreleased
|
||||
|
||||
- Websocket API: Add `ema.switchRoute` to switch to other routes in live server.
|
||||
|
||||
## 0.4.0.0 -- 2022-01-19
|
||||
|
||||
- Pin TailwindCSS to 2.x, because the 3.x broke our CDN url
|
||||
|
@ -1,6 +1,6 @@
|
||||
cabal-version: 2.4
|
||||
name: ema
|
||||
version: 0.4.0.0
|
||||
version: 0.5.0.0
|
||||
license: AGPL-3.0-only
|
||||
copyright: 2021 Sridhar Ratnakumar
|
||||
maintainer: srid@srid.ca
|
||||
|
@ -1,6 +1,4 @@
|
||||
{-# LANGUAGE DeriveFunctor #-}
|
||||
{-# LANGUAGE TypeApplications #-}
|
||||
|
||||
-- | TODO: Deprecate this module!
|
||||
module Ema.Helper.FileSystem
|
||||
( module X,
|
||||
)
|
||||
|
@ -2,6 +2,8 @@
|
||||
{-# LANGUAGE TypeFamilies #-}
|
||||
|
||||
-- | Helper to deal with slug trees
|
||||
--
|
||||
-- TODO: Move to a separate package
|
||||
module Ema.Helper.PathTree where
|
||||
|
||||
import qualified Data.List as List
|
||||
|
@ -302,6 +302,7 @@ wsClientShim =
|
||||
|
||||
function switchRoute(path) {
|
||||
console.log(`ema: → Switching to $${path}`);
|
||||
window.history.pushState({}, "", path);
|
||||
sendObservePath(path);
|
||||
}
|
||||
|
||||
@ -309,7 +310,6 @@ wsClientShim =
|
||||
const origin = e.target.closest("a");
|
||||
if (origin) {
|
||||
if (window.location.host === origin.host && origin.getAttribute("target") != "_blank") {
|
||||
window.history.pushState({}, "", origin.pathname);
|
||||
switchRoute(origin.pathname);
|
||||
e.preventDefault();
|
||||
};
|
||||
@ -372,6 +372,11 @@ wsClientShim =
|
||||
window.onpopstate = function(e) {
|
||||
watchCurrentRoute();
|
||||
};
|
||||
|
||||
// API for user invocations
|
||||
window.ema = {
|
||||
switchRoute: switchRoute
|
||||
};
|
||||
};
|
||||
|
||||
window.onpageshow = function () { init(false) };
|
||||
|
Loading…
Reference in New Issue
Block a user