diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2020-10-07 20:47:44 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-10-07 20:47:44 -0400 |
commit | cb1902eaddeb092bf1e3d78f9e601109bd32202c (patch) | |
tree | d1852c0153184e4998ca9841a1af3d43a4c79ab7 /ext/bg | |
parent | 2d765d2c4e44e83eb0e4f6e5fb771e4ae4abe7a0 (diff) |
Template handler update (#896)
* Rename TemplateHandler to HtmlTemplateCollection
* Rename _templateHandler to _templates
* Allow creation from both string and element
* Simplify setup of templates, don't throw errors on invalid ID
Diffstat (limited to 'ext/bg')
-rw-r--r-- | ext/bg/js/query-parser-generator.js | 16 | ||||
-rw-r--r-- | ext/bg/search.html | 2 |
2 files changed, 9 insertions, 9 deletions
diff --git a/ext/bg/js/query-parser-generator.js b/ext/bg/js/query-parser-generator.js index 6989e157..3f49184b 100644 --- a/ext/bg/js/query-parser-generator.js +++ b/ext/bg/js/query-parser-generator.js @@ -16,24 +16,24 @@ */ /* global - * TemplateHandler + * HtmlTemplateCollection * api */ class QueryParserGenerator { constructor() { - this._templateHandler = null; + this._templates = null; } async prepare() { const html = await api.getQueryParserTemplatesHtml(); - this._templateHandler = new TemplateHandler(html); + this._templates = new HtmlTemplateCollection(html); } createParseResult(terms, preview=false) { const fragment = document.createDocumentFragment(); for (const term of terms) { - const termContainer = this._templateHandler.instantiate(preview ? 'term-preview' : 'term'); + const termContainer = this._templates.instantiate(preview ? 'term-preview' : 'term'); for (const segment of term) { if (!segment.text.trim()) { continue; } if (!segment.reading.trim()) { @@ -48,7 +48,7 @@ class QueryParserGenerator { } createSegment(segment) { - const segmentContainer = this._templateHandler.instantiate('segment'); + const segmentContainer = this._templates.instantiate('segment'); const segmentTextContainer = segmentContainer.querySelector('.query-parser-segment-text'); const segmentReadingContainer = segmentContainer.querySelector('.query-parser-segment-reading'); segmentTextContainer.appendChild(this.createSegmentText(segment.text)); @@ -59,7 +59,7 @@ class QueryParserGenerator { createSegmentText(text) { const fragment = document.createDocumentFragment(); for (const chr of text) { - const charContainer = this._templateHandler.instantiate('char'); + const charContainer = this._templates.instantiate('char'); charContainer.textContent = chr; fragment.appendChild(charContainer); } @@ -67,9 +67,9 @@ class QueryParserGenerator { } createParserSelect(parseResults, selectedParser) { - const selectContainer = this._templateHandler.instantiate('select'); + const selectContainer = this._templates.instantiate('select'); for (const parseResult of parseResults) { - const optionContainer = this._templateHandler.instantiate('select-option'); + const optionContainer = this._templates.instantiate('select-option'); optionContainer.value = parseResult.id; switch (parseResult.source) { case 'scanning-parser': diff --git a/ext/bg/search.html b/ext/bg/search.html index b1fb7663..8df20581 100644 --- a/ext/bg/search.html +++ b/ext/bg/search.html @@ -89,7 +89,7 @@ <script src="/mixed/js/media-loader.js"></script> <script src="/mixed/js/scroll.js"></script> <script src="/mixed/js/text-scanner.js"></script> - <script src="/mixed/js/template-handler.js"></script> + <script src="/mixed/js/html-template-collection.js"></script> <script src="/mixed/js/text-to-speech-audio.js"></script> <script src="/bg/js/anki-note-builder.js"></script> |