[FIX] website: copy paste from website

Pasting from the website to the website could for example copy
t-field="..." which then would easily add an error if e.g a field
is copied to an area where it is not available.

This fix strip the data-oe-... attributes of nodes added to the DOM
when pasting.

closes #7653
opw-644968
This commit is contained in:
Nicolas Lempereur 2015-07-17 08:42:00 +02:00
parent c838a27dea
commit e7e9eb987b
1 changed files with 16 additions and 0 deletions

View File

@ -1924,6 +1924,11 @@
subtree: true,
attributeOldValue: true,
};
var pasting = false;
$(document).on('paste', '[contenteditable]', function() {
pasting = true;
setTimeout(function(){ pasting = false; }, 0);
});
var observer = new website.Observer(function (mutations) {
// NOTE: Webkit does not fire DOMAttrModified => webkit browsers
// relying on JsMutationObserver shim (Chrome < 18, Safari < 6)
@ -1960,6 +1965,7 @@
setTimeout(function () {
fixup_browser_crap(m.addedNodes);
}, 0);
if (pasting) { remove_oe_attributes(m.addedNodes); }
// Remove ignorable nodes from addedNodes or removedNodes,
// if either set remains non-empty it's considered to be an
// impactful change. Otherwise it's ignored.
@ -1980,6 +1986,16 @@
.uniq()
.each(function (node) { $(node).trigger('content_changed'); })
});
function remove_oe_attributes(nodes) {
_.chain(nodes).filter(function(node){ return node.nodeType === 1 }).each(function(node){
_.each(_.toArray(node.attributes), function(attr){
if(attr.nodeName.indexOf('data-oe-') === 0) {
node.removeAttribute(attr.nodeName)
}
});
remove_oe_attributes(node.childNodes);
});
};
function remove_mundane_nodes(nodes) {
if (!nodes || !nodes.length) { return []; }