From 250a465263232d89ac540bf3e68b62196ee5e5ae Mon Sep 17 00:00:00 2001 From: Jack Lukic Date: Tue, 17 May 2016 19:09:06 -0700 Subject: [PATCH] Removal observer always should use document to teardown --- src/definitions/modules/popup.js | 14 +++++++------- src/definitions/modules/sticky.js | 19 ++++++++----------- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/src/definitions/modules/popup.js b/src/definitions/modules/popup.js index a3139ce1c..cce8f97bd 100644 --- a/src/definitions/modules/popup.js +++ b/src/definitions/modules/popup.js @@ -73,7 +73,7 @@ $.fn.popup = function(parameters) { element = this, instance = $module.data(moduleNamespace), - contextObserver, + documentObserver, elementNamespace, id, module @@ -103,12 +103,12 @@ $.fn.popup = function(parameters) { observeChanges: function() { 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, 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() { module.debug('Destroying previous module'); - if(contextObserver) { - contextObserver.disconnect(); + if(documentObserver) { + documentObserver.disconnect(); } // remove element only if was created dynamically if($popup && !settings.preserve) { @@ -206,7 +206,7 @@ $.fn.popup = function(parameters) { module.set.position(); } }, - contextChanged: function(mutations) { + documentChanged: function(mutations) { [].forEach.call(mutations, function(mutation) { if(mutation.removedNodes) { [].forEach.call(mutation.removedNodes, function(node) { diff --git a/src/definitions/modules/sticky.js b/src/definitions/modules/sticky.js index a764299f9..761df1339 100644 --- a/src/definitions/modules/sticky.js +++ b/src/definitions/modules/sticky.js @@ -65,7 +65,7 @@ $.fn.sticky = function(parameters) { element = this, - contextObserver, + documentObserver, observer, module ; @@ -99,8 +99,8 @@ $.fn.sticky = function(parameters) { destroy: function() { module.verbose('Destroying previous instance'); module.reset(); - if(contextObserver) { - contextObserver.disconnect(); + if(documentObserver) { + documentObserver.disconnect(); } if(observer) { observer.disconnect(); @@ -116,13 +116,10 @@ $.fn.sticky = function(parameters) { }, observeChanges: function() { - var - context = $context[0] - ; 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, subtree : true }); @@ -130,7 +127,7 @@ $.fn.sticky = function(parameters) { childList : true, subtree : true }); - observer.observe(context, { + observer.observe($context[0], { childList : true, subtree : true }); @@ -189,7 +186,7 @@ $.fn.sticky = function(parameters) { module.refresh(); }, 100); }, - contextChanged: function(mutations) { + documentChanged: function(mutations) { [].forEach.call(mutations, function(mutation) { if(mutation.removedNodes) { [].forEach.call(mutation.removedNodes, function(node) {