diff --git a/addons/website/static/src/js/website.editor.js b/addons/website/static/src/js/website.editor.js index aef390027c5..a1b8ffdb9ee 100644 --- a/addons/website/static/src/js/website.editor.js +++ b/addons/website/static/src/js/website.editor.js @@ -927,7 +927,7 @@ } - var Observer = window.MutationObserver || window.WebkitMutationObserver || window.JsMutationObserver; + website.Observer = window.MutationObserver || window.WebkitMutationObserver || window.JsMutationObserver; var OBSERVER_CONFIG = { childList: true, attributes: true, @@ -935,7 +935,7 @@ subtree: true, attributeOldValue: true, }; - var observer = new Observer(function (mutations) { + var observer = new website.Observer(function (mutations) { // NOTE: Webkit does not fire DOMAttrModified => webkit browsers // relying on JsMutationObserver shim (Chrome < 18, Safari < 6) // will not mark dirty on attribute changes (@class, img/@src, diff --git a/addons/website/static/src/js/website.snippets.js b/addons/website/static/src/js/website.snippets.js index 5f6d8b5073c..17dd829708f 100644 --- a/addons/website/static/src/js/website.snippets.js +++ b/addons/website/static/src/js/website.snippets.js @@ -45,7 +45,14 @@ /* ----- SNIPPET SELECTOR ---- */ website.snippet = {}; - + var observer = new website.Observer(function (mutations) { + if (!_(mutations).find(function (m) { + return m.type === 'childList' && m.addedNodes.length > 0; + })) { + return; + } + hack_to_add_snippet_id() + }); // puts $el at the same absolute position as $target function hack_to_add_snippet_id () { @@ -80,7 +87,11 @@ this.$active_snipped_id = false; hack_to_add_snippet_id(); this.snippets = []; - $("body").on('DOMNodeInserted', hack_to_add_snippet_id); + + observer.observe(document.body, { + childList: true, + subtree: true, + }); }, dom_filter: function (dom, sibling) { if (typeof dom === "string") {