-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathindex.ts
More file actions
39 lines (38 loc) · 1.33 KB
/
index.ts
File metadata and controls
39 lines (38 loc) · 1.33 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
import { PublicLogger } from "../logger/logger";
import { addLivePreviewQueryTags } from "./addLivePreviewQueryTags";
export function hasWindow(): boolean {
return typeof window !== "undefined";
}
export { addLivePreviewQueryTags };
export function addParamsToUrl() {
// Setting the query params to all the click events related to current domain
window.addEventListener("click", (event: any) => {
const target: any = event.target;
const targetHref: string | any = target.href;
const docOrigin: string = document.location.origin;
if (
targetHref &&
targetHref.includes(docOrigin) &&
!targetHref.includes("live_preview")
) {
const newUrl = addLivePreviewQueryTags(target.href);
event.target.href = newUrl || target.href;
}
});
}
export function isOpeningInTimeline(): boolean {
if (hasWindow()) {
const urlParams = new URLSearchParams(window.location.search);
const previewTimestamp = urlParams.get("preview_timestamp");
return !!previewTimestamp;
}
return false;
}
export function isOpenInBuilder(): boolean {
if (hasWindow()) {
const urlParams = new URLSearchParams(window.location.search);
const builder = urlParams.get("builder");
return !!builder;
}
return false;
}