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 theHTMLElementsFactory from '../../core/uiLib/HTMLElementsFactory.js'; |
26 | import theHTMLSanitizer from '../../core/htmlSanitizer/HTMLSanitizer.js'; |
27 | |
28 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
29 | /** |
30 | Show the attributons of the current map, OpenStreetMap, leaflet and TravelNotes. |
31 | See theAttributionsUI for the one and only one instance of this class |
32 | */ |
33 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
34 | |
35 | class AttributionsUI { |
36 | |
37 | /** |
38 | The root HTMLElement of the UI |
39 | @type {HTMLElement} |
40 | */ |
41 | |
42 | #mainHTMLElement = null; |
43 | |
44 | /** |
45 | The constructor |
46 | */ |
47 | |
48 | constructor ( ) { |
49 | Object.freeze ( this ); |
50 | } |
51 | |
52 | /** |
53 | creates the Attributions UI. |
54 | */ |
55 | |
56 | createUI ( ) { |
57 | this.#mainHTMLElement = theHTMLElementsFactory.create ( 'div', { id : 'TravelNotes-AttributionsUI' }, document.body ); |
58 | } |
59 | |
60 | /** |
61 | Add/replace the given map attributions to the UI. Leaflet, OpenStreetMap and TravelNotes are always credited. |
62 | */ |
63 | |
64 | set attributions ( attributions ) { |
65 | const attributionsString = |
66 | '© <a href="https://leafletjs.com/" target="_blank" title="Leaflet">Leaflet</a> ' + |
67 | '| © <a href="https://www.openstreetmap.org/copyright" target="_blank" ' + |
68 | 'title="OpenStreetMap contributors">OpenStreetMap contributors</a> ' + |
69 | attributions + |
70 | '| © <a href="https://github.com/wwwouaiebe" target="_blank" ' + |
71 | 'title="https://github.com/wwwouaiebe">Travel & Notes</a>'; |
72 | |
73 | while ( this.#mainHTMLElement.firstChild ) { |
74 | this.#mainHTMLElement.removeChild ( this.#mainHTMLElement.firstChild ); |
75 | } |
76 | theHTMLSanitizer.sanitizeToHtmlElement ( attributionsString, this.#mainHTMLElement ); |
77 | } |
78 | } |
79 | |
80 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
81 | /** |
82 | The one and only one instance of AttributionsUI class |
83 | @type {AttributionsUI} |
84 | */ |
85 | /* ------------------------------------------------------------------------------------------------------------------------- */ |
86 | |
87 | const theAttributionsUI = new AttributionsUI ( ); |
88 | |
89 | export default theAttributionsUI; |
90 | |
91 | /* --- End of file --------------------------------------------------------------------------------------------------------- */ |
92 |