-
Notifications
You must be signed in to change notification settings - Fork 15
Expand file tree
/
Copy pathonContentSaved.ts
More file actions
37 lines (32 loc) · 901 Bytes
/
onContentSaved.ts
File metadata and controls
37 lines (32 loc) · 901 Bytes
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
interface PropertySaved {
name: string;
successful: boolean;
}
interface ContentSavedEventArgs {
contentLink: string;
previewUrl: string;
isIndexed: boolean;
properties: PropertySaved[];
parentId?: string;
sectionId?: string;
}
export function getPreviewToken() {
if (typeof window !== "undefined" && window.location !== undefined) {
const queryString = window?.location?.search;
const urlParams = new URLSearchParams(queryString);
return urlParams.get('preview_token');
} else {
return undefined;
}
}
function isInEditMode() {
return !!getPreviewToken();
}
export function onContentSaved(callback: ((message: ContentSavedEventArgs) => void )) {
if (!isInEditMode()) {
return;
}
window.addEventListener("optimizely:cms:contentSaved", (event: any) => {
callback(event.detail);
});
}