aboutsummaryrefslogtreecommitdiff
path: root/ext/js/dom/html-template-collection.js
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2024-02-24 23:30:58 -0500
committerGitHub <noreply@github.com>2024-02-25 04:30:58 +0000
commit0e005f2ca6a3d9e572ed18b51c720d8bea907118 (patch)
tree697931975a5caf68e848f63f4a18cc4a4fe75372 /ext/js/dom/html-template-collection.js
parent9b5de0d2d4cb224751c57bdae6558a046351c2f4 (diff)
Fix anki template field marker menu (#725)
* Fix HTML collection * Expose templates * Fix menu setup * Warn
Diffstat (limited to 'ext/js/dom/html-template-collection.js')
-rw-r--r--ext/js/dom/html-template-collection.js17
1 files changed, 11 insertions, 6 deletions
diff --git a/ext/js/dom/html-template-collection.js b/ext/js/dom/html-template-collection.js
index a71d954f..57b54e59 100644
--- a/ext/js/dom/html-template-collection.js
+++ b/ext/js/dom/html-template-collection.js
@@ -56,9 +56,7 @@ export class HtmlTemplateCollection {
* @throws {Error}
*/
instantiate(name) {
- const template = this._templates.get(name);
- if (typeof template === 'undefined') { throw new Error(`Failed to find template: ${name}`); }
- const {firstElementChild} = template.content;
+ const {firstElementChild} = this.getTemplateContent(name);
if (firstElementChild === null) { throw new Error(`Failed to find template content element: ${name}`); }
return /** @type {T} */ (document.importNode(firstElementChild, true));
}
@@ -66,13 +64,20 @@ export class HtmlTemplateCollection {
/**
* @param {string} name
* @returns {DocumentFragment}
- * @throws {Error}
*/
instantiateFragment(name) {
+ return document.importNode(this.getTemplateContent(name), true);
+ }
+
+ /**
+ * @param {string} name
+ * @returns {DocumentFragment}
+ * @throws {Error}
+ */
+ getTemplateContent(name) {
const template = this._templates.get(name);
if (typeof template === 'undefined') { throw new Error(`Failed to find template: ${name}`); }
- const {content} = template;
- return document.importNode(content, true);
+ return template.content;
}
/**