| 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 |
|