PluginProbe
seQura / 3.2.2
seQura v3.2.2
4.3.4 4.3.3 4.3.2 4.3.1 trunk 2.0.0 2.0.10 2.0.11 2.0.12 2.0.5 2.0.6 2.0.7 2.0.8 2.0.9 3.0.0 3.0.2 3.0.5 3.0.6 3.0.7 3.1.0 3.1.1 3.2.0 3.2.1 3.2.2 4.0.0 All 30 releases
sequra / assets / js / src / core / TemplateService.js

TemplateService.js in seQura 3.2.2, at assets/js/src/core/TemplateService.js

79 lines 2.0 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 if (!window.SequraFE) {
2 window.SequraFE = {};
3 }
4
5 (function () {
6 function TemplateService() {
7 /**
8 * The configuration object for all templates.
9 */
10 let templates = {};
11 let mainPlaceholder = '#sq-page-wrapper';
12 let contentWrapper = '.sq-page-content-wrapper';
13
14 /**
15 * Gets the main page DOM element.
16 *
17 * @returns {HTMLElement}
18 */
19 this.getMainPage = () => document.querySelector(mainPlaceholder);
20
21 /**
22 * Gets the main page DOM element.
23 *
24 * @returns {HTMLElement}
25 */
26 this.getContentWrapper = () => document.querySelector(contentWrapper);
27
28 /**
29 * Clears the main page.
30 *
31 * @return {HTMLElement}
32 */
33 this.clearMainPage = () => {
34 this.clearComponent(this.getMainPage());
35 };
36
37 /**
38 * Sets the content templates.
39 *
40 * @param {{}} configuration
41 */
42 this.setTemplates = (configuration) => {
43 templates = configuration;
44 };
45
46 /**
47 * Gets the template with translated text.
48 *
49 * @param {string} templateId
50 *
51 * @return {string} HTML as string.
52 */
53 this.getTemplate = (templateId) => translate(templates[templateId]);
54
55 /**
56 * Replaces all translation keys in the provided HTML.
57 *
58 * @param {string} html
59 * @return {string}
60 */
61 const translate = (html) => {
62 return html ? SequraFE.translationService.translateHtml(html) : '';
63 };
64
65 /**
66 * Removes component's children.
67 *
68 * @param {Element} component
69 */
70 this.clearComponent = (component) => {
71 while (component.firstChild) {
72 component.removeChild(component.firstChild);
73 }
74 };
75 }
76
77 SequraFE.templateService = new TemplateService();
78 })();
79