mirror of
https://github.com/TryGhost/Ghost.git
synced 2025-02-24 23:48:13 -05:00
Fixed error when closing branding modal
no issue - clean up event listeners when component is destroyed - add guard for iframe existing when attempting to replace preview contents
This commit is contained in:
parent
c9dc56841b
commit
734674d299
1 changed files with 18 additions and 10 deletions
|
@ -8,6 +8,7 @@ import {
|
||||||
} from 'ghost-admin/components/gh-image-uploader';
|
} from 'ghost-admin/components/gh-image-uploader';
|
||||||
import {computed} from '@ember/object';
|
import {computed} from '@ember/object';
|
||||||
import {htmlSafe} from '@ember/string';
|
import {htmlSafe} from '@ember/string';
|
||||||
|
import {run} from '@ember/runloop';
|
||||||
import {inject as service} from '@ember/service';
|
import {inject as service} from '@ember/service';
|
||||||
import {task} from 'ember-concurrency';
|
import {task} from 'ember-concurrency';
|
||||||
import {timeout} from 'ember-concurrency';
|
import {timeout} from 'ember-concurrency';
|
||||||
|
@ -69,11 +70,12 @@ export default ModalComponent.extend({
|
||||||
},
|
},
|
||||||
|
|
||||||
didInsertElement() {
|
didInsertElement() {
|
||||||
window.addEventListener('message', (event) => {
|
this._previewListener = run.bind(this, this.handlePreviewIframeMessage);
|
||||||
if (event && event.data && event.data === 'loaded') {
|
window.addEventListener('message', this._previewListener);
|
||||||
this.replacePreview();
|
},
|
||||||
}
|
|
||||||
});
|
willDestroyElement() {
|
||||||
|
window.removeEventListener('message', this._previewListener);
|
||||||
},
|
},
|
||||||
|
|
||||||
actions: {
|
actions: {
|
||||||
|
@ -177,10 +179,10 @@ export default ModalComponent.extend({
|
||||||
this.ajax
|
this.ajax
|
||||||
.post(ghostFrontendUrl, options)
|
.post(ghostFrontendUrl, options)
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
this.getPreviewIframe().contentWindow.postMessage(response, '*');
|
const iframe = this.getPreviewIframe();
|
||||||
})
|
if (iframe) {
|
||||||
.catch(() => {
|
iframe.contentWindow.postMessage(response, '*');
|
||||||
this.notifications.showAlert('Sorry, there was an error with preview. Please let the Ghost team know what happened.', {type: 'error'});
|
}
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -189,10 +191,17 @@ export default ModalComponent.extend({
|
||||||
// REset the src and trigger a reload
|
// REset the src and trigger a reload
|
||||||
this.getPreviewIframe().src = this.themePreviewUrl;
|
this.getPreviewIframe().src = this.themePreviewUrl;
|
||||||
},
|
},
|
||||||
|
|
||||||
getPreviewIframe() {
|
getPreviewIframe() {
|
||||||
return document.getElementById('site-frame');
|
return document.getElementById('site-frame');
|
||||||
},
|
},
|
||||||
|
|
||||||
|
handlePreviewIframeMessage(event) {
|
||||||
|
if (event && event.data && event.data === 'loaded') {
|
||||||
|
this.replacePreview();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
|
||||||
debounceUpdateAccentColor: task(function* (event) {
|
debounceUpdateAccentColor: task(function* (event) {
|
||||||
yield timeout(500);
|
yield timeout(500);
|
||||||
this._updateAccentColor(event);
|
this._updateAccentColor(event);
|
||||||
|
@ -254,5 +263,4 @@ export default ModalComponent.extend({
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue