Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions demos/highlighter.html
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@


function highlightSelectedText() {
highlighter.highlightSelection("highlight");
highlighter.highlightSelection("highlight", { dataset: { mark: "note-id" } });
}

function noteSelectedText() {
Expand Down Expand Up @@ -149,4 +149,4 @@ <h2>Who plays football <span class="smaller">(this section is in pre-formatted t
Commons Attribution/Share-Alike License</a>.
</p>
</body>
</html>
</html>
15 changes: 15 additions & 0 deletions lib/rangy-classapplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions lib/rangy-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
15 changes: 15 additions & 0 deletions src/modules/rangy-classapplier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions src/modules/rangy-highlighter.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down