aboutsummaryrefslogtreecommitdiff
path: root/ext/js/display
diff options
context:
space:
mode:
authortoasted-nutbread <toasted-nutbread@users.noreply.github.com>2021-09-04 12:43:56 -0400
committerGitHub <noreply@github.com>2021-09-04 12:43:56 -0400
commitf68ad1f843607d4ba1ad216fe16305c420cee8d6 (patch)
tree0a1dc9a3d78df62fee501f467dce3277fb5b4f1e /ext/js/display
parenteb457caea9b3e5484355ffce80edb371d3bf232d (diff)
Structured content data (#1930)
* Add support for structured-content data attributes * Assign dataset properties * Don't remove data-sc attributes * Use helper functions * Update test data
Diffstat (limited to 'ext/js/display')
-rw-r--r--ext/js/display/sandbox/structured-content-generator.js12
1 files changed, 12 insertions, 0 deletions
diff --git a/ext/js/display/sandbox/structured-content-generator.js b/ext/js/display/sandbox/structured-content-generator.js
index 82bf0421..8aa34bb2 100644
--- a/ext/js/display/sandbox/structured-content-generator.js
+++ b/ext/js/display/sandbox/structured-content-generator.js
@@ -169,6 +169,16 @@ class StructuredContentGenerator {
return this._document.createDocumentFragment();
}
+ _setElementDataset(element, data) {
+ for (let [key, value] of Object.entries(data)) {
+ if (key.length > 0) {
+ key = `${key[0].toUpperCase()}${key.substring(1)}`;
+ }
+ key = `sc${key}`;
+ element.dataset[key] = value;
+ }
+ }
+
_setImageData(node, image, imageBackground, url, unloaded) {
if (url !== null) {
image.src = url;
@@ -192,6 +202,8 @@ class StructuredContentGenerator {
_createStructuredContentElement(tag, content, dictionary, type, hasChildren, hasStyle) {
const node = this._createElement(tag, `gloss-sc-${tag}`);
+ const {data} = content;
+ if (typeof data === 'object' && data !== null) { this._setElementDataset(node, data); }
switch (type) {
case 'table-cell':
{