Skip to content

Commit

Permalink
fix(h5p-webcomponents): corrected external dispatcher check
Browse files Browse the repository at this point in the history
  • Loading branch information
sr258 committed Dec 13, 2021
1 parent 9a045ce commit 1faf2de
Showing 1 changed file with 14 additions and 10 deletions.
24 changes: 14 additions & 10 deletions packages/h5p-webcomponents/src/h5p-editor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ export class H5PEditorComponent extends HTMLElement {
}

// Unregister our event listener from the global H5P dispatcher.
if (window.H5P.externalDispatcher) {
if (window.H5P?.externalDispatcher) {
window.H5P.externalDispatcher.off(
'editorloaded',
this.onEditorLoaded
Expand Down Expand Up @@ -314,10 +314,12 @@ export class H5PEditorComponent extends HTMLElement {
);
// After our editor has been initialized, it will never fire the
// global event again, so we can unsubscribe from it.
window.H5P.externalDispatcher.off(
'editorloaded',
this.onEditorLoaded
);
if (window.H5P?.externalDispatcher) {
window.H5P.externalDispatcher.off(
'editorloaded',
this.onEditorLoaded
);
}
}
};

Expand Down Expand Up @@ -416,11 +418,13 @@ export class H5PEditorComponent extends HTMLElement {
}

// Register our global editorloaded event handler.
window.H5P.externalDispatcher.on(
'editorloaded',
this.onEditorLoaded,
this
);
if (window.H5P.externalDispatcher) {
window.H5P.externalDispatcher.on(
'editorloaded',
this.onEditorLoaded,
this
);
}

// Configure the H5P core editor.
H5PEditor.$ = window.H5P.jQuery;
Expand Down

0 comments on commit 1faf2de

Please sign in to comment.