diff options
Diffstat (limited to 'js')
-rw-r--r-- | js/main.ts | 34 |
1 files changed, 33 insertions, 1 deletions
@@ -12,10 +12,14 @@ function ensureSetting(key: string, defaultValue: string): string { | |||
12 | } | 12 | } |
13 | 13 | ||
14 | const settings = new KeyValueStore({ | 14 | const settings = new KeyValueStore({ |
15 | wordWrap: { | ||
16 | value: ensureSetting('word-wrap', '1') === '1', | ||
17 | valueRange: [false, true] | ||
18 | }, | ||
15 | imagePreviews: { | 19 | imagePreviews: { |
16 | value: ensureSetting('image-previews', '1') === '1', | 20 | value: ensureSetting('image-previews', '1') === '1', |
17 | valueRange: [false, true] | 21 | valueRange: [false, true] |
18 | } | 22 | }, |
19 | }); | 23 | }); |
20 | 24 | ||
21 | // | 25 | // |
@@ -52,6 +56,10 @@ const settings = new KeyValueStore({ | |||
52 | })(); | 56 | })(); |
53 | 57 | ||
54 | (() => { | 58 | (() => { |
59 | const contentEl = document.getElementsByClassName('content')[0]; | ||
60 | |||
61 | // | ||
62 | |||
55 | const settingImagePreviewEl = document.getElementsByClassName('setting--image-previews')[0]; | 63 | const settingImagePreviewEl = document.getElementsByClassName('setting--image-previews')[0]; |
56 | const settingImagePreviewValueEl = settingImagePreviewEl.getElementsByClassName('setting__value')[0]; | 64 | const settingImagePreviewValueEl = settingImagePreviewEl.getElementsByClassName('setting__value')[0]; |
57 | const settingImagePreviewCallback = (value: boolean, init = false) => { | 65 | const settingImagePreviewCallback = (value: boolean, init = false) => { |
@@ -73,6 +81,30 @@ const settings = new KeyValueStore({ | |||
73 | 81 | ||
74 | settingImagePreviewCallback(settings.getValue('imagePreviews'), true); | 82 | settingImagePreviewCallback(settings.getValue('imagePreviews'), true); |
75 | settings.addCallback('imagePreviews', settingImagePreviewCallback); | 83 | settings.addCallback('imagePreviews', settingImagePreviewCallback); |
84 | |||
85 | // | ||
86 | |||
87 | const settingWordWrapEl = document.getElementsByClassName('setting--word-wrap')[0]; | ||
88 | const settingWordWrapValueEl = settingWordWrapEl.getElementsByClassName('setting__value')[0]; | ||
89 | const settingWordWrapCallback = (value: boolean) => { | ||
90 | if (value) { | ||
91 | contentEl.classList.add("content--wrap"); | ||
92 | } else { | ||
93 | contentEl.classList.remove("content--wrap"); | ||
94 | } | ||
95 | |||
96 | localStorage.setItem('image-previews', value ? '1' : '0'); | ||
97 | settingWordWrapValueEl.textContent = value ? '[yes]' : '[no]'; | ||
98 | } | ||
99 | |||
100 | settingWordWrapValueEl.addEventListener('click', e => { | ||
101 | e.preventDefault(); | ||
102 | settings.cycleValue('wordWrap'); | ||
103 | return false; | ||
104 | }); | ||
105 | |||
106 | settingWordWrapCallback(settings.getValue('wordWrap')); | ||
107 | settings.addCallback('wordWrap', settingWordWrapCallback); | ||
76 | })(); | 108 | })(); |
77 | 109 | ||
78 | (() => { | 110 | (() => { |