Skip to content

Commit

Permalink
add scriptUrl prop to load editor via on-premise js file
Browse files Browse the repository at this point in the history
  • Loading branch information
jtsui committed Nov 18, 2021
1 parent 458b539 commit 2fa2133
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
2 changes: 1 addition & 1 deletion src/index.js
Expand Up @@ -12,7 +12,7 @@ export default class extends Component {
}

componentDidMount() {
loadScript(this.loadEditor);
loadScript(this.loadEditor, this.props.scriptUrl);
}

render() {
Expand Down
8 changes: 4 additions & 4 deletions src/loadScript.js
@@ -1,8 +1,8 @@
const scriptUrl = '//editor.unlayer.com/embed.js?2';
const defaultScriptUrl = '//editor.unlayer.com/embed.js?2';
const callbacks = [];
let loaded = false;

const isScriptInjected = () => {
const isScriptInjected = (scriptUrl) => {
const scripts = document.querySelectorAll('script');
let injected = false;

Expand All @@ -29,10 +29,10 @@ const runCallbacks = () => {
}
};

export const loadScript = (callback) => {
export const loadScript = (callback, scriptUrl = defaultScriptUrl) => {
addCallback(callback);

if (!isScriptInjected()) {
if (!isScriptInjected(scriptUrl)) {
const embedScript = document.createElement('script');
embedScript.setAttribute('src', scriptUrl);
embedScript.onload = () => {
Expand Down

0 comments on commit 2fa2133

Please sign in to comment.