Skip to content

Instantly share code, notes, and snippets.

@steoo
Created October 30, 2015 10:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save steoo/6aa45e6c6d99974fbd2d to your computer and use it in GitHub Desktop.
Save steoo/6aa45e6c6d99974fbd2d to your computer and use it in GitHub Desktop.
var target = this.$el[0],
test = new RegExp("(font-(.*))+|line-(.*)+"),
that = this,
observer = new MutationObserver(function (mutations) {
mutations.forEach(function (mutation) {
//console.log(mutation);
/* Rimuove gli styling che applica il browser */
var length = mutation.addedNodes.length;
if (mutation.type === "attributes" && test.test(mutation.oldValue)) {
console.log("You shall not pass");
var target = mutation.target;
/* Vado a rimuovere solo gli attributi di style
* TODO: controllare se sputtana l'align */
for (var i = 0; i < target.attributes.length; i++) {
if(target.attributes[i].name === "style"){
target.removeAttributeNode(target.attributes[i]);
}
}
} else if (mutation.type.toLowerCase() === "childlist" && length > 0) {
for (var j = 0; j < length; j++) {
if (mutation.addedNodes[j].nodeName.toLowerCase() === "span") {
that.unwrap(mutation.addedNodes[j]);
}
}
}
});
}), config = {
attributes: true,
childList: true,
characterData: false,
subtree: true,
attributeOldValue: true
};
observer.observe(target, config);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment