Using MutationObserver for supported browsers
authorAlexander Ebert <ebert@woltlab.com>
Sun, 8 Feb 2015 10:07:04 +0000 (11:07 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 8 Feb 2015 10:07:04 +0000 (11:07 +0100)
wcfsetup/install/files/js/WCF.js

index a327938d5ee7e22b8466cc35a7a5dbe7e5cd0c45..5d796ea34cc56c852103c8c9af01c437a25fbedb 100755 (executable)
@@ -5951,7 +5951,29 @@ WCF.DOMNodeRemovedHandler = {
        _bindListener: function() {
                if (this._isListening) return;
                
-               $(document).bind('DOMNodeRemoved', $.proxy(this._executeCallbacks, this));
+               if (window.MutationObserver) {
+                       var $mutationObserver = new MutationObserver((function(mutations) {
+                               var $triggerEvent = false;
+                               
+                               mutations.forEach((function(mutation) {
+                                       if (mutation.removedNodes.length) {
+                                               $triggerEvent = true;
+                                       }
+                               }).bind(this));
+                               
+                               if ($triggerEvent) {
+                                       this._executeCallbacks({ });
+                               }
+                       }).bind(this));
+                       
+                       $mutationObserver.observe(document.body, {
+                               childList: true,
+                               subtree: true
+                       });
+               }
+               else {
+                       $(document).bind('DOMNodeRemoved', $.proxy(this._executeCallbacks, this));
+               }
                
                this._isListening = true;
        },