Created
June 28, 2016 02:44
-
-
Save sourcepirate/f1cba44998be9ae37ceff4cdc7b66e7d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var observeDOM = (function(){ | |
var MutationObserver = window.MutationObserver || window.WebKitMutationObserver, | |
eventListenerSupported = window.addEventListener; | |
return function(obj, callback){ | |
if( MutationObserver ){ | |
// define a new observer | |
var obs = new MutationObserver(function(mutations, observer){ | |
if( mutations[0].addedNodes.length || mutations[0].removedNodes.length ) | |
callback(); | |
}); | |
// have the observer observe foo for changes in children | |
obs.observe( obj, { childList:true, subtree:true }); | |
} | |
else if( eventListenerSupported ){ | |
obj.addEventListener('DOMNodeInserted', callback, false); | |
obj.addEventListener('DOMNodeRemoved', callback, false); | |
} | |
} | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment