diff options
author | toasted-nutbread <toasted-nutbread@users.noreply.github.com> | 2022-03-17 19:01:59 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-17 19:01:59 -0400 |
commit | 7a2ab866099edffaba471ad808593f67ee796b21 (patch) | |
tree | ddfe746ed76e16d80e0ac6e3029e2bc1049544d2 /ext/js/display/sandbox | |
parent | 8aa060337cea2bb8fce7864d509d07df4688f1c2 (diff) |
Structured content links (#2089)
* Update CSS to JSON converter to generalize the remove-property comment
* Fix navigation not being updated when _clearContent is run
* Add structured content schema for link tags
* Add test links
* Add external-link icon
* Pass Display instance to DisplayContentManager
* Update structured content generation
* Update link styles
Diffstat (limited to 'ext/js/display/sandbox')
-rw-r--r-- | ext/js/display/sandbox/structured-content-generator.js | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/ext/js/display/sandbox/structured-content-generator.js b/ext/js/display/sandbox/structured-content-generator.js index 799da586..eb847d07 100644 --- a/ext/js/display/sandbox/structured-content-generator.js +++ b/ext/js/display/sandbox/structured-content-generator.js @@ -59,6 +59,8 @@ class StructuredContentGenerator { return this._createStructuredContentElement(tag, content, dictionary, 'simple', true, true); case 'img': return this.createDefinitionImage(content, dictionary); + case 'a': + return this._createLinkElement(content, dictionary); } return null; } @@ -253,4 +255,30 @@ class StructuredContentGenerator { if (typeof marginRight === 'number') { style.marginRight = `${marginRight}em`; } if (typeof marginBottom === 'number') { style.marginBottom = `${marginBottom}em`; } } + + _createLinkElement(content, dictionary) { + let {href} = content; + const internal = href.startsWith('?'); + if (internal) { + href = `${location.protocol}//${location.host}/search.html${href.length > 1 ? href : ''}`; + } + + const node = this._createElement('a', 'gloss-link'); + node.dataset.external = `${!internal}`; + + const text = this._createElement('span', 'gloss-link-text'); + node.appendChild(text); + + const child = this.createStructuredContent(content.content, dictionary); + if (child !== null) { text.appendChild(child); } + + if (!internal) { + const icon = this._createElement('span', 'gloss-link-external-icon icon'); + icon.dataset.icon = 'external-link'; + node.appendChild(icon); + } + + this._contentManager.prepareLink(node, href, internal); + return node; + } } |