aboutsummaryrefslogtreecommitdiff
path: root/ext/bg/js/settings
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2020-11-06 22:14:00 -0500
committerGitHub <noreply@github.com>2020-11-06 22:14:00 -0500
commit9c6ff387a0836a78b7a755cfc99828e09d6a6cf8 (patch)
tree5218136c06d9c01a25281934369e6f7d4386dfd8 /ext/bg/js/settings
parentb62c48822eeea948c0d78c5730f20793838d59da (diff)
Popup preview update (#994)
* Add options.global.showPopupPreview option * Add preview visibility control using a checkbox * Add attribute on page load * Disable animation until page is loaded
Diffstat (limited to 'ext/bg/js/settings')
-rw-r--r--ext/bg/js/settings/popup-preview-controller.js21
-rw-r--r--ext/bg/js/settings/popup-preview-frame-main.js2
2 files changed, 22 insertions, 1 deletions
diff --git a/ext/bg/js/settings/popup-preview-controller.js b/ext/bg/js/settings/popup-preview-controller.js
index 80a64156..9dc29524 100644
--- a/ext/bg/js/settings/popup-preview-controller.js
+++ b/ext/bg/js/settings/popup-preview-controller.js
@@ -28,9 +28,11 @@ class PopupPreviewController {
this._previewTextInput = null;
this._customCss = null;
this._customOuterCss = null;
+ this._previewFrameContainer = null;
+ this._showPopupPreviewCheckbox = null;
}
- prepare() {
+ async prepare() {
const button = document.querySelector('#settings-popup-preview-button');
if (button !== null) {
button.addEventListener('click', this._onShowPopupPreviewButtonClick.bind(this), false);
@@ -38,13 +40,20 @@ class PopupPreviewController {
this._frame = document.querySelector('#popup-preview-frame');
this._customCss = document.querySelector('#custom-popup-css');
this._customOuterCss = document.querySelector('#custom-popup-outer-css');
+ this._previewFrameContainer = document.querySelector('.preview-frame-container');
+ this._showPopupPreviewCheckbox = document.querySelector('#show-preview-checkbox');
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._showPopupPreviewCheckbox.addEventListener('change', this._onShowPreviewCheckboxChange.bind(this), false);
this._settingsController.on('optionsContextChanged', this._onOptionsContextChange.bind(this));
+
+ const {global: {showPopupPreview}} = await this._settingsController.getOptionsFull();
+ this._showPopupPreviewCheckbox.checked = showPopupPreview;
+ this._updatePopupPreviewVisibility();
}
}
@@ -56,6 +65,10 @@ class PopupPreviewController {
this._previewVisible = true;
}
+ _onShowPreviewCheckboxChange() {
+ this._updatePopupPreviewVisibility();
+ }
+
_showAppearancePreview() {
const container = document.querySelector('#settings-popup-preview-container');
const buttonContainer = document.querySelector('#settings-popup-preview-button-container');
@@ -124,4 +137,10 @@ class PopupPreviewController {
if (this._frame === null || this._frame.contentWindow === null) { return; }
this._frame.contentWindow.postMessage({action, params}, this._targetOrigin);
}
+
+ _updatePopupPreviewVisibility() {
+ const value = this._showPopupPreviewCheckbox.checked;
+ this._previewFrameContainer.classList.toggle('preview-frame-container-visible', value);
+ this._settingsController.setGlobalSetting('global.showPopupPreview', value);
+ }
}
diff --git a/ext/bg/js/settings/popup-preview-frame-main.js b/ext/bg/js/settings/popup-preview-frame-main.js
index 866b9f57..038327cd 100644
--- a/ext/bg/js/settings/popup-preview-frame-main.js
+++ b/ext/bg/js/settings/popup-preview-frame-main.js
@@ -32,6 +32,8 @@
const preview = new PopupPreviewFrame(frameId, popupFactory);
await preview.prepare();
+
+ document.documentElement.dataset.loaded = 'true';
} catch (e) {
yomichan.logError(e);
}