Showing loading overlay if requests takes longer than 250ms
authorAlexander Ebert <ebert@woltlab.com>
Sun, 16 Jun 2013 18:59:39 +0000 (20:59 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 16 Jun 2013 18:59:39 +0000 (20:59 +0200)
wcfsetup/install/files/js/WCF.js

index db67d0310b86ff5b195805f8af3e8a0764248132..fb791b37990cd995b5cc82c6c69f071b2164207c 100755 (executable)
@@ -1648,6 +1648,12 @@ WCF.LoadingOverlayHandler = {
         */
        _loadingOverlay: null,
        
+       /**
+        * WCF.PeriodicalExecuter instance
+        * @var WCF.PeriodicalExecuter
+        */
+       _pending: null,
+       
        /**
         * Adds one loading-request and shows the loading overlay if nessercery
         */
@@ -1658,7 +1664,18 @@ WCF.LoadingOverlayHandler = {
                
                this._activeRequests++;
                if (this._activeRequests == 1) {
-                       this._loadingOverlay.stop(true, true).fadeIn(100);
+                       if (this._pending === null) {
+                               var self = this;
+                               this._pending = new WCF.PeriodicalExecuter(function(pe) {
+                                       if (self._activeRequests) {
+                                               self._loadingOverlay.stop(true, true).fadeIn(100);
+                                       }
+                                       
+                                       pe.stop();
+                                       self._pending = null;
+                               }, 250); 
+                       }
+                       
                }
        },
        
@@ -1668,6 +1685,11 @@ WCF.LoadingOverlayHandler = {
        hide: function() {
                this._activeRequests--;
                if (this._activeRequests == 0) {
+                       if (this._pending !== null) {
+                               this._pending.stop();
+                               this._pending = null;
+                       }
+                       
                        this._loadingOverlay.stop(true, true).fadeOut(100);
                }
        },