mirror of
https://github.com/TriliumNext/Notes.git
synced 2025-08-02 05:02:27 +08:00
chore(client/ts): port fonts
This commit is contained in:
parent
428ffa7826
commit
639d118f41
@ -1,6 +1,7 @@
|
|||||||
import OptionsWidget from "../options_widget.js";
|
import OptionsWidget from "../options_widget.js";
|
||||||
import utils from "../../../../services/utils.js";
|
import utils from "../../../../services/utils.js";
|
||||||
import { t } from "../../../../services/i18n.js";
|
import { t } from "../../../../services/i18n.js";
|
||||||
|
import { OptionMap, OptionNames } from "../../../../../../services/options_interface.js";
|
||||||
|
|
||||||
const FONT_FAMILIES = [
|
const FONT_FAMILIES = [
|
||||||
{ value: "theme", label: t("fonts.theme_defined") },
|
{ value: "theme", label: t("fonts.theme_defined") },
|
||||||
@ -115,6 +116,18 @@ const TPL = `
|
|||||||
</div>`;
|
</div>`;
|
||||||
|
|
||||||
export default class FontsOptions extends OptionsWidget {
|
export default class FontsOptions extends OptionsWidget {
|
||||||
|
|
||||||
|
private $mainFontSize!: JQuery<HTMLElement>;
|
||||||
|
private $mainFontFamily!: JQuery<HTMLElement>;
|
||||||
|
private $treeFontSize!: JQuery<HTMLElement>;
|
||||||
|
private $treeFontFamily!: JQuery<HTMLElement>;
|
||||||
|
private $detailFontSize!: JQuery<HTMLElement>;
|
||||||
|
private $detailFontFamily!: JQuery<HTMLElement>;
|
||||||
|
private $monospaceFontSize!: JQuery<HTMLElement>;
|
||||||
|
private $monospaceFontFamily!: JQuery<HTMLElement>;
|
||||||
|
|
||||||
|
private _isEnabled?: boolean;
|
||||||
|
|
||||||
doRender() {
|
doRender() {
|
||||||
this.$widget = $(TPL);
|
this.$widget = $(TPL);
|
||||||
|
|
||||||
@ -134,10 +147,10 @@ export default class FontsOptions extends OptionsWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isEnabled() {
|
isEnabled() {
|
||||||
return this._isEnabled;
|
return !!this._isEnabled;
|
||||||
}
|
}
|
||||||
|
|
||||||
async optionsLoaded(options) {
|
async optionsLoaded(options: OptionMap) {
|
||||||
this._isEnabled = (options.overrideThemeFonts === 'true');
|
this._isEnabled = (options.overrideThemeFonts === 'true');
|
||||||
this.toggleInt(this._isEnabled);
|
this.toggleInt(this._isEnabled);
|
||||||
if (!this._isEnabled) {
|
if (!this._isEnabled) {
|
||||||
@ -156,7 +169,7 @@ export default class FontsOptions extends OptionsWidget {
|
|||||||
this.$monospaceFontSize.val(options.monospaceFontSize);
|
this.$monospaceFontSize.val(options.monospaceFontSize);
|
||||||
this.fillFontFamilyOptions(this.$monospaceFontFamily, options.monospaceFontFamily);
|
this.fillFontFamilyOptions(this.$monospaceFontFamily, options.monospaceFontFamily);
|
||||||
|
|
||||||
const optionsToSave = [
|
const optionsToSave: OptionNames[] = [
|
||||||
'mainFontFamily', 'mainFontSize',
|
'mainFontFamily', 'mainFontSize',
|
||||||
'treeFontFamily', 'treeFontSize',
|
'treeFontFamily', 'treeFontSize',
|
||||||
'detailFontFamily', 'detailFontSize',
|
'detailFontFamily', 'detailFontSize',
|
||||||
@ -164,12 +177,13 @@ export default class FontsOptions extends OptionsWidget {
|
|||||||
];
|
];
|
||||||
|
|
||||||
for (const optionName of optionsToSave) {
|
for (const optionName of optionsToSave) {
|
||||||
this[`$${optionName}`].on('change', () =>
|
const $el = (this as any)[`$${optionName}`];
|
||||||
this.updateOption(optionName, this[`$${optionName}`].val()));
|
$el.on('change', () =>
|
||||||
|
this.updateOption(optionName, $el.val()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fillFontFamilyOptions($select, currentValue) {
|
fillFontFamilyOptions($select: JQuery<HTMLElement>, currentValue: string) {
|
||||||
$select.empty();
|
$select.empty();
|
||||||
|
|
||||||
for (const {value, label} of FONT_FAMILIES) {
|
for (const {value, label} of FONT_FAMILIES) {
|
Loading…
x
Reference in New Issue
Block a user