import server from "../../services/server.js"; import utils from "../../services/utils.js"; import cssLoader from "../../services/css_loader.js"; import zoomService from "../../services/zoom.js"; import optionsService from "../../services/options.js"; const TPL = `

Settings on this options tab are saved automatically after each change.

Zooming can be controlled with CTRL-+ and CTRL-= shortcuts as well.

Font sizes

%
%
%

Note that tree and detail font sizing is relative to the main font size setting.

Left pane sizing

px
%

Left pane width is calculated from the percent of window size, if this is smaller than minimum width, then minimum width is used. If you want to have fixed width left pane, set minimum width to the desired width and set percent to 0.

`; export default class ApperanceOptions { constructor() { $("#options-appearance").html(TPL); this.$themeSelect = $("#theme-select"); this.$zoomFactorSelect = $("#zoom-factor-select"); this.$oneTabDisplaySelect = $("#one-tab-display-select"); this.$leftPaneMinWidth = $("#left-pane-min-width"); this.$leftPaneWidthPercent = $("#left-pane-width-percent"); this.$mainFontSize = $("#main-font-size"); this.$treeFontSize = $("#tree-font-size"); this.$detailFontSize = $("#detail-font-size"); this.$body = $("body"); this.$container = $("#container"); this.$themeSelect.on('change', () => { const newTheme = this.$themeSelect.val(); for (const clazz of Array.from(this.$body[0].classList)) { // create copy to safely iterate over while removing classes if (clazz.startsWith("theme-")) { this.$body.removeClass(clazz); } } const noteId = $(this).find(":selected").attr("data-note-id"); if (noteId) { // make sure the CSS is loaded // if the CSS has been loaded and then updated then the changes won't take effect though cssLoader.requireCss(`/api/notes/download/${noteId}`); } this.$body.addClass("theme-" + newTheme); server.put('options/theme/' + newTheme); }); this.$zoomFactorSelect.on('change', () => { zoomService.setZoomFactorAndSave(this.$zoomFactorSelect.val()); }); this.$oneTabDisplaySelect.on('change', () => { const hideTabRowForOneTab = this.$oneTabDisplaySelect.val() === 'hide' ? 'true' : 'false'; server.put('options/hideTabRowForOneTab/' + hideTabRowForOneTab) .then(optionsService.reloadOptions); }); this.$leftPaneMinWidth.on('change', async () => { await server.put('options/leftPaneMinWidth/' + this.$leftPaneMinWidth.val()); this.resizeLeftPanel(); }); this.$leftPaneWidthPercent.on('change', async () => { await server.put('options/leftPaneWidthPercent/' + this.$leftPaneWidthPercent.val()); this.resizeLeftPanel(); }); this.$mainFontSize.on('change', async () => { await server.put('options/mainFontSize/' + this.$mainFontSize.val()); this.applyFontSizes(); }); this.$treeFontSize.on('change', async () => { await server.put('options/treeFontSize/' + this.$treeFontSize.val()); this.applyFontSizes(); }); this.$detailFontSize.on('change', async () => { await server.put('options/detailFontSize/' + this.$detailFontSize.val()); this.applyFontSizes(); }); } async optionsLoaded(options) { const themes = [ { val: 'white', title: 'White' }, { val: 'dark', title: 'Dark' }, { val: 'black', title: 'Black' } ].concat(await server.get('options/user-themes')); this.$themeSelect.empty(); for (const theme of themes) { this.$themeSelect.append($("