From afb893c1574d341e955571b96e3a2d981061b6bf Mon Sep 17 00:00:00 2001 From: SiriusXT <1160925501@qq.com> Date: Thu, 22 Jun 2023 15:38:36 +0800 Subject: [PATCH] Fix bugs in toc and improve related codes --- src/public/app/widgets/highlights_list.js | 86 ++++++++++--------- src/public/app/widgets/toc.js | 4 +- .../widgets/type_widgets/content_widget.js | 4 +- .../options/text_notes/highlighted_text.js | 40 --------- .../options/text_notes/highlights_list.js | 40 +++++++++ src/routes/api/options.js | 2 +- src/services/options_init.js | 2 +- 7 files changed, 90 insertions(+), 88 deletions(-) delete mode 100644 src/public/app/widgets/type_widgets/options/text_notes/highlighted_text.js create mode 100644 src/public/app/widgets/type_widgets/options/text_notes/highlights_list.js diff --git a/src/public/app/widgets/highlights_list.js b/src/public/app/widgets/highlights_list.js index 4e88e9e45..8d32e7b36 100644 --- a/src/public/app/widgets/highlights_list.js +++ b/src/public/app/widgets/highlights_list.js @@ -10,20 +10,20 @@ import RightPanelWidget from "./right_panel_widget.js"; import options from "../services/options.js"; import OnClickButtonWidget from "./buttons/onclick_button.js"; -const TPL = `
-`; - -export default class HighlightedTextOptions extends OptionsWidget { - doRender() { - this.$widget = $(TPL); - this.$hlt = this.$widget.find("input.highlighted-text-check"); - this.$hlt.on('change', () => { - const hltVals = this.$widget.find('input.highlighted-text-check[type="checkbox"]:checked').map(function () { - return this.value; - }).get(); - this.updateOption('highlightedText', JSON.stringify(hltVals)); - }); - } - - async optionsLoaded(options) { - const hltVals = JSON.parse(options.highlightedText); - this.$widget.find('input.highlighted-text-check[type="checkbox"]').each(function () { - if ($.inArray($(this).val(), hltVals) !== -1) { - $(this).prop("checked", true); - } else { - $(this).prop("checked", false); - } - }); - } -} diff --git a/src/public/app/widgets/type_widgets/options/text_notes/highlights_list.js b/src/public/app/widgets/type_widgets/options/text_notes/highlights_list.js new file mode 100644 index 000000000..5e2a2595d --- /dev/null +++ b/src/public/app/widgets/type_widgets/options/text_notes/highlights_list.js @@ -0,0 +1,40 @@ +import OptionsWidget from "../options_widget.js"; + +const TPL = ` + + + + + + + +`; + +export default class HighlightsListOptions extends OptionsWidget { + doRender() { + this.$widget = $(TPL); + this.$hlt = this.$widget.find("input.highlights-list-check"); + this.$hlt.on('change', () => { + const hltVals = this.$widget.find('input.highlights-list-check[type="checkbox"]:checked').map(function () { + return this.value; + }).get(); + this.updateOption('highlightsList', JSON.stringify(hltVals)); + }); + } + + async optionsLoaded(options) { + const hltVals = JSON.parse(options.highlightsList); + this.$widget.find('input.highlights-list-check[type="checkbox"]').each(function () { + if ($.inArray($(this).val(), hltVals) !== -1) { + $(this).prop("checked", true); + } else { + $(this).prop("checked", false); + } + }); + } +} diff --git a/src/routes/api/options.js b/src/routes/api/options.js index 4d9ee77a2..ba8bc7943 100644 --- a/src/routes/api/options.js +++ b/src/routes/api/options.js @@ -60,7 +60,7 @@ const ALLOWED_OPTIONS = new Set([ 'compressImages', 'downloadImagesAutomatically', 'minTocHeadings', - 'highlightedText', + 'highlightsList', 'checkForUpdates', 'disableTray', 'customSearchEngineName', diff --git a/src/services/options_init.js b/src/services/options_init.js index 358403214..b8026d371 100644 --- a/src/services/options_init.js +++ b/src/services/options_init.js @@ -87,7 +87,7 @@ const defaultOptions = [ { name: 'compressImages', value: 'true', isSynced: true }, { name: 'downloadImagesAutomatically', value: 'true', isSynced: true }, { name: 'minTocHeadings', value: '5', isSynced: true }, - { name: 'highlightedText', value: '["bold","italic","underline","color","bgColor"]', isSynced: true }, + { name: 'highlightsList', value: '["bold","italic","underline","color","bgColor"]', isSynced: true }, { name: 'checkForUpdates', value: 'true', isSynced: true }, { name: 'disableTray', value: 'false', isSynced: false }, { name: 'customSearchEngineName', value: 'Duckduckgo', isSynced: false },