Created
October 30, 2015 10:33
-
-
Save steoo/6aa45e6c6d99974fbd2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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