diff --git a/lib/modules/bridge.js b/lib/modules/bridge.js index aff1e94..7087eb6 100644 --- a/lib/modules/bridge.js +++ b/lib/modules/bridge.js @@ -2,18 +2,20 @@ let loaded = false; const callbacks = []; export const loadBridge = (src) => { - // Way to make sure all event handlers are called after loading - window.storyblokRegisterEvent = (cb) => { - if (window.location === window.parent.location) { - console.warn("You are not in Draft Mode or in the Visual Editor."); - return; - } + return new Promise((resolve, reject) => { + if (typeof window === "undefined") return; - if (!loaded) callbacks.push(cb); - else cb(); - }; + // Way to make sure all event handlers are called after loading + window.storyblokRegisterEvent = (cb) => { + if (window.location === window.parent.location) { + console.warn("You are not in Draft Mode or in the Visual Editor."); + return; + } + + if (!loaded) callbacks.push(cb); + else cb(); + }; - return new Promise((resolve, reject) => { if (document.getElementById("storyblok-javascript-bridge")) return; const script = document.createElement("script"); diff --git a/package.json b/package.json index aa078b4..f415e13 100644 --- a/package.json +++ b/package.json @@ -43,7 +43,8 @@ "prettier" ], "env": { - "browser": true + "browser": true, + "es6": true }, "ignorePatterns": "dist/", "parserOptions": {