From 0e005f2ca6a3d9e572ed18b51c720d8bea907118 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 24 Feb 2024 23:30:58 -0500 Subject: Fix anki template field marker menu (#725) * Fix HTML collection * Expose templates * Fix menu setup * Warn --- ext/js/dom/html-template-collection.js | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) (limited to 'ext/js/dom') 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; } /** -- cgit v1.2.3