Skip to content

Commit

Permalink
Trim whitespace in html matching (#64)
Browse files Browse the repository at this point in the history
  • Loading branch information
econti authored Apr 23, 2021
1 parent 099ebea commit acaeeca
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 16 deletions.
34 changes: 19 additions & 15 deletions static/js/refinery.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,31 +63,35 @@ refinery.RefineryAPI.prototype.getLiveRefinement = function() {
});
};

refinery.RefineryAPI.prototype.applyChange = function(change) {
if (window.location.href === change.href) {
let elem = document.querySelector(change.domPath);
if (elem.innerHTML.trim() !== change.beforeHtml.trim()) {
console.warn(`Can't apply change on '${change.beforeHtml}' because copy doesn't match.\
'${change.beforeHtml.trim()}' vs. '${elem.innerHTML.trim()}'.`);
} else {
console.log(change.afterHtml);
elem.innerHTML = change.afterHtml;
}
} else {
console.warn(`
Can't apply change on '${change.beforeHtml}' because href's don't match.\
'${change.href}' vs. '${window.location.href}'.`);
}
};

refinery.RefineryAPI.prototype.applyChanges = function() {
const self = this;
self.getLiveRefinement().then(response => {
// right now we assume 1 changeset only, so grab the first i.e. [0]
let changeset = response[0];
let changes;
(changeset.publish) ? changes = changeset.changes : changes = [];

changes.filter(change => !change.deleted).forEach(change => {
if (window.location.href === change.href) {
let elem = document.querySelector(change.domPath);
if (elem.innerHTML !== change.beforeHtml) {
console.warn(`Can't apply change on '${change.beforeHtml}' because copy doesn't match.\
'${change.beforeHtml}' vs. '${elem.innerHTML}'.`);
} else {
elem.innerHTML = change.afterHtml;
}
} else {
console.warn(`
Can't apply change on '${change.beforeHtml}' because href's don't match.\
'${change.href}' vs. '${window.location.href}'.`);
}
self.applyChange(change);

});
});

}

let refineryAPI = new refinery.RefineryAPI();
Expand Down
2 changes: 1 addition & 1 deletion static/minified/refinery.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit acaeeca

Please sign in to comment.