diff options
author | Feuerfuchs <git@feuerfuchs.dev> | 2019-06-26 09:37:39 +0200 |
---|---|---|
committer | Feuerfuchs <git@feuerfuchs.dev> | 2019-06-26 09:37:39 +0200 |
commit | a21a402d9aaaf4c2c7720da0f76b7311d3d64830 (patch) | |
tree | 932ec831065f9ce80b7d7e9182bca438e0c6d81a /js | |
parent | Improved wrapping behavior (diff) | |
download | gopherproxy-a21a402d9aaaf4c2c7720da0f76b7311d3d64830.tar.gz gopherproxy-a21a402d9aaaf4c2c7720da0f76b7311d3d64830.tar.bz2 gopherproxy-a21a402d9aaaf4c2c7720da0f76b7311d3d64830.zip |
Make word wrap optional, better mobile design
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 | (() => { |