aboutsummaryrefslogtreecommitdiff
path: root/ext/js/dom
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-18 08:10:09 -0500
committerGitHub <noreply@github.com>2024-02-18 13:10:09 +0000
commit6cf38229b54efbbc3ae7bc174c3999f9dfa7b1d2 (patch)
tree1d47e64bf80ef2f7fd082dde956d0b214946f189 /ext/js/dom
parentc48cd6ff6d8dcced7baf1b27ce3ac2449944f5d7 (diff)
Html templates update (#707)
* Simplify display template loading * Add helper * Rename file * Rename for simplicity * Create templates file * Load * Remove templates * Move permissions templates * Remove "templates" from comments * Fix prepare
Diffstat (limited to 'ext/js/dom')
-rw-r--r--ext/js/dom/html-template-collection.js24
1 files changed, 16 insertions, 8 deletions
diff --git a/ext/js/dom/html-template-collection.js b/ext/js/dom/html-template-collection.js
index 981d5528..a71d954f 100644
--- a/ext/js/dom/html-template-collection.js
+++ b/ext/js/dom/html-template-collection.js
@@ -16,6 +16,8 @@
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
+import {fetchText} from '../core/fetch-utilities.js';
+
export class HtmlTemplateCollection {
constructor() {
/** @type {Map<string, HTMLTemplateElement>} */
@@ -23,17 +25,23 @@ export class HtmlTemplateCollection {
}
/**
- * @param {string|Document} source
+ * @param {string[]} urls
*/
- load(source) {
- const sourceNode = (
- typeof source === 'string' ?
- new DOMParser().parseFromString(source, 'text/html') :
- source
- );
+ async loadFromFiles(urls) {
+ const htmlRawArray = await Promise.all(urls.map((url) => fetchText(url)));
+ const domParser = new DOMParser();
+ for (const htmlRaw of htmlRawArray) {
+ const templatesDocument = domParser.parseFromString(htmlRaw, 'text/html');
+ this.load(templatesDocument);
+ }
+ }
+ /**
+ * @param {Document} source
+ */
+ load(source) {
const pattern = /^([\w\W]+)-template$/;
- for (const template of sourceNode.querySelectorAll('template')) {
+ for (const template of source.querySelectorAll('template')) {
const match = pattern.exec(template.id);
if (match === null) { continue; }
this._prepareTemplate(template);