From fdfa7362ac00bbf47344643191ecbe56fdbf61e2 Mon Sep 17 00:00:00 2001 From: Xavier Morel Date: Mon, 2 Dec 2013 12:33:04 +0100 Subject: [PATCH] [FIX] image fields getting overly dirty the addition and removal of the [edit] button on hover would be caught by the mutation observer and mark the image field as dirty, even when it had not actually been altered, leaving to spurious save events for said field. bzr revid: xmo@openerp.com-20131202113304-xpgu43se5er1ho7y --- .../website/static/src/js/website.editor.js | 32 +++++++++++++++++-- 1 file changed, 30 insertions(+), 2 deletions(-) diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index c1d31bcd7cc..78e452ef76c 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -1371,6 +1371,11 @@ // a/@href, ...) _(mutations).chain() .filter(function (m) { + // ignore any change related to mundane image-edit-button + if (m.target && m.target.className + && m.target.className.indexOf('image-edit-button') !== -1) { + return false; + } switch(m.type) { case 'attributes': // ignore .cke_focus being added or removed // if attribute is not a class, can't be .cke_focus change @@ -1384,8 +1389,11 @@ // ignore mutation if the *only* change is .cke_focus return change.length !== 1 || change[0] === 'cke_focus'; case 'childList': - //
appears when focusing RTE in FF, ignore - return m.addedNodes.length !== 1 || m.addedNodes[0].nodeName !== 'BR'; + // 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. + return !!remove_mundane_nodes(m.addedNodes).length || + !!remove_mundane_nodes(m.removedNodes).length; default: return true; } @@ -1402,4 +1410,24 @@ .uniq() .each(function (node) { $(node).trigger('content_changed'); }) }); + function remove_mundane_nodes(nodes) { + if (!nodes || !nodes.length) { return []; } + + var output = []; + for(var i=0; i appears when focusing RTE in FF, ignore + continue; + } + if (node.className.indexOf('image-edit-button') !== -1) { + // [Edit] button added and removed on image hover, don't count + // as making parent node dirty + continue; + } + + output.push(node); + } + return output; + } })();