From f68ad1f843607d4ba1ad216fe16305c420cee8d6 Mon Sep 17 00:00:00 2001 From: toasted-nutbread Date: Sat, 4 Sep 2021 12:43:56 -0400 Subject: 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 --- ext/js/display/sandbox/structured-content-generator.js | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'ext/js/display/sandbox') 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': { -- cgit v1.2.3