summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2013-12-02 12:33:04 +0100
committerXavier Morel <xmo@openerp.com>2013-12-02 12:33:04 +0100
commitfdfa7362ac00bbf47344643191ecbe56fdbf61e2 (patch)
tree4b15ad7b5b43f1b98e2a63abb7208f94c6dd1469 /addons
parent52b1ac6a3e451e4cb2f123bff07d52355ca7c464 (diff)
[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
Diffstat (limited to 'addons')
-rw-r--r--addons/website/static/src/js/website.editor.js32
1 files 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':
- // <br type="_moz"> 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<nodes.length; ++i) {
+ var node = nodes[i];
+ if (node.nodeName === 'BR' && node.getAttribute('type') === '_moz') {
+ // <br type="_moz"> 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;
+ }
})();