-
Notifications
You must be signed in to change notification settings - Fork 9
/
fontSize.js
76 lines (59 loc) · 1.76 KB
/
fontSize.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
(function fontSizeBtn() {
'use strict';
// requires menuButton.js
/* globals scUtils, l10nStrings, storage */
const $passages = document.querySelector('#passages');
function saveFontSize(value) {
storage.set('fontSize', value);
}
function loadFontSize() {
const loaded = storage.get('fontSize') || '100';
let value = parseInt(loaded);
if (isNaN(value)) {
return 100;
} else {
return value;
}
}
function applyFontSize(value) {
$passages.style.fontSize = `${value}%`;
}
function createFontSizeBtn(interval = 10, min = 60, max = 200) {
let fs = loadFontSize();
if (fs !== 100) {
applyFontSize(fs);
saveFontSize(fs);
}
const ops = {
inc() {
fs += interval;
fs = Math.min(fs, max);
},
dec() {
fs -= interval;
fs = Math.max(fs, min);
},
};
function updateUI(button) {
button.find('a').removeAttr('disabled');
if (fs === min) {
button.find('a:eq(0)').attr('disabled', true);
} else if (fs === max) {
button.find('a:eq(1)').attr('disabled', true);
}
}
const {button} = scUtils.createMultiButton('fontSize', l10nStrings.uiFontSize || 'Font size', ['-', '+'], (event, index) => {
ops[index === 0 ? 'dec' : 'inc']();
updateUI(button);
applyFontSize(fs);
saveFontSize(fs);
});
updateUI(button);
}
window.scUtils = Object.assign(
window.scUtils || {},
{
createFontSizeBtn,
}
);
}());