1 | /* |
2 | Copyright - 2017 2023 - wwwouaiebe - Contact: https://www.ouaie.be/ |
3 | |
4 | This program is free software; |
5 | you can redistribute it and/or modify it under the terms of the |
6 | GNU General Public License as published by the Free Software Foundation; |
7 | either version 3 of the License, or any later version. |
8 | |
9 | This program is distributed in the hope that it will be useful, |
10 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
12 | GNU General Public License for more details. |
13 | |
14 | You should have received a copy of the GNU General Public License |
15 | along with this program; if not, write to the Free Software |
16 | Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
17 | */ |
18 | /* |
19 | Changes: |
20 | - v4.0.0: |
21 | - created from v3.6.0 |
22 | Doc reviewed 202208 |
23 | */ |
24 | |
25 | import theConfig from '../data/Config.js'; |
26 | |
27 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
28 | /** |
29 | A simple container to store the font size |
30 | */ |
31 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
32 | |
33 | class FontSizeManager { |
34 | |
35 | /** |
36 | The font size |
37 | @type {Number} |
38 | */ |
39 | |
40 | #fontSize; |
41 | |
42 | /** |
43 | The constructor |
44 | */ |
45 | |
46 | constructor ( ) { |
47 | Object.freeze ( this ); |
48 | |
49 | // It's needed to initialize the fontSize in the increment or decrement functions because |
50 | // theFontSizeManager is a global object created before theConfig initialization |
51 | this.#fontSize = null; |
52 | } |
53 | |
54 | /** |
55 | Increment the font size |
56 | */ |
57 | |
58 | increment ( ) { |
59 | if ( ! this.#fontSize ) { |
60 | this.#fontSize = theConfig.fontSize.initialValue; |
61 | } |
62 | this.#fontSize += theConfig.fontSize.incrementValue; |
63 | document.body.style [ 'font-size' ] = String ( this.#fontSize ) + 'mm'; |
64 | } |
65 | |
66 | /** |
67 | Decrement the font size |
68 | */ |
69 | |
70 | decrement ( ) { |
71 | if ( ! this.#fontSize ) { |
72 | this.#fontSize = theConfig.fontSize.initialValue; |
73 | } |
74 | this.#fontSize -= theConfig.fontSize.incrementValue; |
75 | document.body.style [ 'font-size' ] = String ( this.#fontSize ) + 'mm'; |
76 | } |
77 | } |
78 | |
79 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
80 | /** |
81 | The one and only one instance of FontSizeManager class |
82 | @type {FontSizeManager} |
83 | */ |
84 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
85 | |
86 | const theFontSizeManager = new FontSizeManager ( ); |
87 | |
88 | export default theFontSizeManager; |
89 | |
90 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
91 |