UNPKG

@expofp/floorplan

Version:

Interactive floor plan library for expos and events

2 lines (1 loc) • 1.06 kB
import{splitPlatformParams as s}from"@expofp/config";import{createBrowserHistory as g}from"history";import w from"../tools/logger";const t=g();let a=window.location.pathname;const o=[];let c="",r=!1,l=!1,u=0,h=()=>{},m;export function getLocationHistory(){return o}function d(e){if(!c)return a+e;const n=s(e).search,i=n==="?"?"":n;return a+(i?`${i}&${c}`:`?${c}`)}export function currentSearch(){return s(t.location.search).search}export function pushQuery(e){!r&&!l&&t.push(d(e))}export function replaceQuery(e){return r||l?!1:(t.replace(d(e)),!0)}export function disableUrlWrites(){r=!0}export function initUrlSync(e){r||=e.offHistory,h=e.onNavigate,a=window.location.pathname,c=s(t.location.search).platform,r||o.push(a+t.location.search),m=t.listen((n,i)=>{if(f(),r)return;const p=a+n.search;o[o.length-1]!==p&&o.push(p),w.log("history",i,n),i==="POP"&&h()})}export function destroyUrlSync(){r=!1,c="",o.length=0,f(),m?.()}function f(){l=!1,window.clearTimeout(u)}export function goBack(){l=!0,window.clearTimeout(u),u=window.setTimeout(f,1e3),t.goBack()}