[FIX] don't use mutation events if unnecessary
Mutation events are synchronous and one is triggered per observed alteration (they're not batched). When doing lots of modifications to the DOM tree, they will add a lot of overhead as (in this case) the event handler will run for *each* added node and it will run during (and slow down) node insertion rather than afterwards. bzr revid: xmo@openerp.com-20131016123708-lx389x0g6xs6zu10
This commit is contained in:
parent
2c58996d57
commit
57c5f11aae
|
@ -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,
|
||||
|
|
|
@ -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") {
|
||||
|
|
Loading…
Reference in New Issue