Update PopupPreviewController to support settings v2 (#972)

This commit is contained in:
toasted-nutbread 2020-10-30 22:21:56 -04:00 committed by GitHub
parent f5d6573bec
commit 54768ca6e4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -26,10 +26,26 @@ class PopupPreviewController {
this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, ''); this._targetOrigin = chrome.runtime.getURL('/').replace(/\/$/, '');
this._frame = null; this._frame = null;
this._previewTextInput = null; this._previewTextInput = null;
this._customCss = null;
this._customOuterCss = null;
} }
prepare() { prepare() {
document.querySelector('#settings-popup-preview-button').addEventListener('click', this._onShowPopupPreviewButtonClick.bind(this), false); const button = document.querySelector('#settings-popup-preview-button');
if (button !== null) {
button.addEventListener('click', this._onShowPopupPreviewButtonClick.bind(this), false);
} else {
this._frame = document.querySelector('#popup-preview-frame');
this._customCss = document.querySelector('#custom-popup-css');
this._customOuterCss = document.querySelector('#custom-popup-outer-css');
this._customCss.addEventListener('input', this._onCustomCssChange.bind(this), false);
this._customCss.addEventListener('settingChanged', this._onCustomCssChange.bind(this), false);
this._customOuterCss.addEventListener('input', this._onCustomOuterCssChange.bind(this), false);
this._customOuterCss.addEventListener('settingChanged', this._onCustomOuterCssChange.bind(this), false);
this._frame.addEventListener('load', this._onFrameLoad2.bind(this), false);
this._settingsController.on('optionsContextChanged', this._onOptionsContextChange.bind(this));
}
} }
// Private // Private
@ -51,6 +67,8 @@ class PopupPreviewController {
this._previewTextInput = text; this._previewTextInput = text;
this._frame = frame; this._frame = frame;
this._customCss = customCss;
this._customOuterCss = customOuterCss;
wanakana.bind(text); wanakana.bind(text);
@ -75,16 +93,22 @@ class PopupPreviewController {
this._setText(this._previewTextInput.value); this._setText(this._previewTextInput.value);
} }
_onFrameLoad2() {
this._onOptionsContextChange();
this._onCustomCssChange();
this._onCustomOuterCssChange();
}
_onTextChange(e) { _onTextChange(e) {
this._setText(e.currentTarget.value); this._setText(e.currentTarget.value);
} }
_onCustomCssChange(e) { _onCustomCssChange() {
this._invoke('setCustomCss', {css: e.currentTarget.value}); this._invoke('setCustomCss', {css: this._customCss.value});
} }
_onCustomOuterCssChange(e) { _onCustomOuterCssChange() {
this._invoke('setCustomOuterCss', {css: e.currentTarget.value}); this._invoke('setCustomOuterCss', {css: this._customOuterCss.value});
} }
_onOptionsContextChange() { _onOptionsContextChange() {