diff --git a/demos/highlighter.html b/demos/highlighter.html index ef5d3d48..da823ee6 100644 --- a/demos/highlighter.html +++ b/demos/highlighter.html @@ -58,7 +58,7 @@ function highlightSelectedText() { - highlighter.highlightSelection("highlight"); + highlighter.highlightSelection("highlight", { dataset: { mark: "note-id" } }); } function noteSelectedText() { @@ -149,4 +149,4 @@

Who plays football (this section is in pre-formatted t Commons Attribution/Share-Alike License.

- \ No newline at end of file + diff --git a/lib/rangy-classapplier.js b/lib/rangy-classapplier.js index 9fe90d85..7cab1d05 100644 --- a/lib/rangy-classapplier.js +++ b/lib/rangy-classapplier.js @@ -631,6 +631,21 @@ } } this.attrExceptions.push(p); + } + + // Special case for dataset + else if (p == "dataset") { + for (s in props[p]) { + if (props[p].hasOwnProperty(s)) { + el[p][s] = propValue[s]; + if (createCopy) { + if(!elProps[p]){ + elProps[p] = {}; + } + elProps[p][s] = propValue[s]; + } + } + } } else { el[p] = propValue; // Copy the property back from the dummy element so that later comparisons to check whether diff --git a/lib/rangy-highlighter.js b/lib/rangy-highlighter.js index bde6ba43..ba47b2f8 100644 --- a/lib/rangy-highlighter.js +++ b/lib/rangy-highlighter.js @@ -473,6 +473,10 @@ throw new Error("No class applier found for class '" + className + "'"); } + if(options.dataset && typeof options.dataset == 'object'){ + classApplier.elementProperties.dataset = {...classApplier.elementProperties.dataset, ...options.dataset} + } + // Store the existing selection as character ranges var serializedSelection = converter.serializeSelection(selection, containerElement); diff --git a/src/modules/rangy-classapplier.js b/src/modules/rangy-classapplier.js index 4f066ed6..e8762f3d 100644 --- a/src/modules/rangy-classapplier.js +++ b/src/modules/rangy-classapplier.js @@ -628,6 +628,21 @@ rangy.createModule("ClassApplier", ["WrappedSelection"], function(api, module) { } } this.attrExceptions.push(p); + } + + // Special case for dataset + else if (p == "dataset") { + for (s in props[p]) { + if (props[p].hasOwnProperty(s)) { + el[p][s] = propValue[s]; + if (createCopy) { + if(!elProps[p]){ + elProps[p] = {}; + } + elProps[p][s] = propValue[s]; + } + } + } } else { el[p] = propValue; // Copy the property back from the dummy element so that later comparisons to check whether diff --git a/src/modules/rangy-highlighter.js b/src/modules/rangy-highlighter.js index 4527d5d6..b4c0e972 100644 --- a/src/modules/rangy-highlighter.js +++ b/src/modules/rangy-highlighter.js @@ -462,6 +462,10 @@ rangy.createModule("Highlighter", ["ClassApplier"], function(api, module) { throw new Error("No class applier found for class '" + className + "'"); } + if(options.dataset && typeof options.dataset == 'object'){ + classApplier.elementProperties.dataset = {...classApplier.elementProperties.dataset, ...options.dataset} + } + // Store the existing selection as character ranges var serializedSelection = converter.serializeSelection(selection, containerElement);