summaryrefslogtreecommitdiff
path: root/ext/js/pages/settings
diff options
context:
space:
mode:
Diffstat (limited to 'ext/js/pages/settings')
-rw-r--r--ext/js/pages/settings/popup-preview-frame.js28
-rw-r--r--ext/js/pages/settings/settings-display-controller.js19
-rw-r--r--ext/js/pages/settings/settings-main.js6
3 files changed, 30 insertions, 23 deletions
diff --git a/ext/js/pages/settings/popup-preview-frame.js b/ext/js/pages/settings/popup-preview-frame.js
index 37aca898..7abcfe2a 100644
--- a/ext/js/pages/settings/popup-preview-frame.js
+++ b/ext/js/pages/settings/popup-preview-frame.js
@@ -18,6 +18,7 @@
import * as wanakana from '../../../lib/wanakana.js';
import {Frontend} from '../../app/frontend.js';
+import {ThemeController} from '../../app/theme-controller.js';
import {createApiMap, invokeApiMapHandler} from '../../core/api-map.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
import {TextSourceRange} from '../../dom/text-source-range.js';
@@ -57,6 +58,8 @@ export class PopupPreviewFrame {
this._languageSummaries = [];
/** @type {boolean} */
this._wanakanaBound = false;
+ /** @type {ThemeController} */
+ this._themeController = new ThemeController(document.documentElement);
/* eslint-disable @stylistic/no-multi-spaces */
/** @type {import('popup-preview-frame').ApiMap} */
@@ -74,10 +77,10 @@ export class PopupPreviewFrame {
async prepare() {
window.addEventListener('message', this._onMessage.bind(this), false);
+ this._themeController.siteTheme = 'light';
+ this._themeController.prepare();
+
// Setup events
- /** @type {HTMLInputElement} */
- const darkThemeCheckbox = querySelectorNotNull(document, '#theme-dark-checkbox');
- darkThemeCheckbox.addEventListener('change', this._onThemeDarkCheckboxChanged.bind(this), false);
this._exampleText.addEventListener('click', this._onExampleTextClick.bind(this), false);
this._exampleTextInput.addEventListener('blur', this._onExampleTextInputBlur.bind(this), false);
this._exampleTextInput.addEventListener('input', this._onExampleTextInputInput.bind(this), false);
@@ -137,6 +140,8 @@ export class PopupPreviewFrame {
options.general.popupHorizontalTextPosition = 'below';
options.general.popupVerticalTextPosition = 'before';
options.scanning.selectText = false;
+ this._themeController.theme = options.general.popupTheme;
+ this._themeController.updateTheme();
return options;
}
@@ -165,23 +170,6 @@ export class PopupPreviewFrame {
invokeApiMapHandler(this._windowMessageHandlers, action, params, [], callback);
}
- /**
- * @param {Event} e
- */
- _onThemeDarkCheckboxChanged(e) {
- const element = /** @type {HTMLInputElement} */ (e.currentTarget);
- document.documentElement.classList.toggle('dark', element.checked);
- if (this._themeChangeTimeout !== null) {
- clearTimeout(this._themeChangeTimeout);
- }
- this._themeChangeTimeout = setTimeout(() => {
- this._themeChangeTimeout = null;
- const popup = /** @type {Frontend} */ (this._frontend).popup;
- if (popup === null) { return; }
- void popup.updateTheme();
- }, 300);
- }
-
/** */
_onExampleTextClick() {
if (this._exampleTextInput === null) { return; }
diff --git a/ext/js/pages/settings/settings-display-controller.js b/ext/js/pages/settings/settings-display-controller.js
index f732f1ef..49f7192c 100644
--- a/ext/js/pages/settings/settings-display-controller.js
+++ b/ext/js/pages/settings/settings-display-controller.js
@@ -16,6 +16,7 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {ThemeController} from '../../app/theme-controller.js';
import {isInputElementFocused} from '../../dom/document-util.js';
import {PopupMenu} from '../../dom/popup-menu.js';
import {querySelectorNotNull} from '../../dom/query-selector.js';
@@ -39,10 +40,16 @@ export class SettingsDisplayController {
this._onMoreToggleClickBind = this._onMoreToggleClick.bind(this);
/** @type {(event: MouseEvent) => void} */
this._onMenuButtonClickBind = this._onMenuButtonClick.bind(this);
+ /** @type {ThemeController} */
+ this._themeController = new ThemeController(document.documentElement);
}
/** */
prepare() {
+ this._themeController.siteTheme = 'light';
+ this._themeController.prepare();
+ void this._updateTheme();
+
const onFabButtonClick = this._onFabButtonClick.bind(this);
for (const fabButton of /** @type {NodeListOf<HTMLElement>} */ (document.querySelectorAll('.fab-button'))) {
fabButton.addEventListener('click', onFabButtonClick, false);
@@ -84,6 +91,18 @@ export class SettingsDisplayController {
window.addEventListener('keydown', this._onKeyDown.bind(this), false);
window.addEventListener('popstate', this._onPopState.bind(this), false);
this._updateScrollTarget();
+
+ const themeDropdown = document.querySelector('[data-setting="general.popupTheme"]');
+ if (themeDropdown) {
+ themeDropdown.addEventListener('change', this._updateTheme.bind(this), false);
+ }
+ }
+
+ /** */
+ async _updateTheme() {
+ const options = await this._settingsController.getOptions();
+ this._themeController.theme = options.general.popupTheme;
+ this._themeController.updateTheme();
}
// Private
diff --git a/ext/js/pages/settings/settings-main.js b/ext/js/pages/settings/settings-main.js
index 3ff818ac..a315eac4 100644
--- a/ext/js/pages/settings/settings-main.js
+++ b/ext/js/pages/settings/settings-main.js
@@ -169,10 +169,10 @@ await Application.main(true, async (application) => {
const sortFrequencyDictionaryController = new SortFrequencyDictionaryController(settingsController);
preparePromises.push(sortFrequencyDictionaryController.prepare());
+ const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
+ settingsDisplayController.prepare();
+
await Promise.all(preparePromises);
document.documentElement.dataset.loaded = 'true';
-
- const settingsDisplayController = new SettingsDisplayController(settingsController, modalController);
- settingsDisplayController.prepare();
});