Browse Source

Removal observer always should use document to teardown

pull/4046/head
Jack Lukic 9 years ago
parent
commit
250a465263
2 changed files with 15 additions and 18 deletions
  1. 14
      src/definitions/modules/popup.js
  2. 19
      src/definitions/modules/sticky.js

14
src/definitions/modules/popup.js

@ -73,7 +73,7 @@ $.fn.popup = function(parameters) {
element = this, element = this,
instance = $module.data(moduleNamespace), instance = $module.data(moduleNamespace),
contextObserver,
documentObserver,
elementNamespace, elementNamespace,
id, id,
module module
@ -103,12 +103,12 @@ $.fn.popup = function(parameters) {
observeChanges: function() { observeChanges: function() {
if('MutationObserver' in window) { if('MutationObserver' in window) {
contextObserver = new MutationObserver(module.event.contextChanged);
contextObserver.observe($context[0], {
documentObserver = new MutationObserver(module.event.documentChanged);
documentObserver.observe(document, {
childList : true, childList : true,
subtree : true subtree : true
}); });
module.debug('Setting up mutation observer', contextObserver);
module.debug('Setting up mutation observer', documentObserver);
} }
}, },
@ -158,8 +158,8 @@ $.fn.popup = function(parameters) {
destroy: function() { destroy: function() {
module.debug('Destroying previous module'); module.debug('Destroying previous module');
if(contextObserver) {
contextObserver.disconnect();
if(documentObserver) {
documentObserver.disconnect();
} }
// remove element only if was created dynamically // remove element only if was created dynamically
if($popup && !settings.preserve) { if($popup && !settings.preserve) {
@ -206,7 +206,7 @@ $.fn.popup = function(parameters) {
module.set.position(); module.set.position();
} }
}, },
contextChanged: function(mutations) {
documentChanged: function(mutations) {
[].forEach.call(mutations, function(mutation) { [].forEach.call(mutations, function(mutation) {
if(mutation.removedNodes) { if(mutation.removedNodes) {
[].forEach.call(mutation.removedNodes, function(node) { [].forEach.call(mutation.removedNodes, function(node) {

19
src/definitions/modules/sticky.js

@ -65,7 +65,7 @@ $.fn.sticky = function(parameters) {
element = this, element = this,
contextObserver,
documentObserver,
observer, observer,
module module
; ;
@ -99,8 +99,8 @@ $.fn.sticky = function(parameters) {
destroy: function() { destroy: function() {
module.verbose('Destroying previous instance'); module.verbose('Destroying previous instance');
module.reset(); module.reset();
if(contextObserver) {
contextObserver.disconnect();
if(documentObserver) {
documentObserver.disconnect();
} }
if(observer) { if(observer) {
observer.disconnect(); observer.disconnect();
@ -116,13 +116,10 @@ $.fn.sticky = function(parameters) {
}, },
observeChanges: function() { observeChanges: function() {
var
context = $context[0]
;
if('MutationObserver' in window) { if('MutationObserver' in window) {
contextObserver = new MutationObserver(module.event.contextChanged);
observer = new MutationObserver(module.event.changed);
contextObserver.observe($context[0], {
documentObserver = new MutationObserver(module.event.documentChanged);
observer = new MutationObserver(module.event.changed);
documentObserver.observe(document, {
childList : true, childList : true,
subtree : true subtree : true
}); });
@ -130,7 +127,7 @@ $.fn.sticky = function(parameters) {
childList : true, childList : true,
subtree : true subtree : true
}); });
observer.observe(context, {
observer.observe($context[0], {
childList : true, childList : true,
subtree : true subtree : true
}); });
@ -189,7 +186,7 @@ $.fn.sticky = function(parameters) {
module.refresh(); module.refresh();
}, 100); }, 100);
}, },
contextChanged: function(mutations) {
documentChanged: function(mutations) {
[].forEach.call(mutations, function(mutation) { [].forEach.call(mutations, function(mutation) {
if(mutation.removedNodes) { if(mutation.removedNodes) {
[].forEach.call(mutation.removedNodes, function(node) { [].forEach.call(mutation.removedNodes, function(node) {

Loading…
Cancel
Save