Added WCF.LoadingOverlayHandler
authorMagnus Kühn <magnus.khn@gmail.com>
Sun, 10 Feb 2013 18:27:02 +0000 (19:27 +0100)
committerMagnus Kühn <magnus.khn@gmail.com>
Sun, 10 Feb 2013 18:27:02 +0000 (19:27 +0100)
wcfsetup/install/files/js/WCF.js

index dbdf319441f8358b9c65f79998e1bbe984924788..30139f5b9c6892f37ee437f1f01597a744c49d8b 100755 (executable)
@@ -1352,18 +1352,11 @@ WCF.PeriodicalExecuter = Class.extend({
 });
 
 /**
- * Namespace for AJAXProxies
- */
-WCF.Action = {};
-
-/**
- * Basic implementation for AJAX-based proxyies
- * 
- * @param      object          options
+ * Handler for loading overlays
  */
-WCF.Action.Proxy = Class.extend({
+WCF.LoadingOverlayHandler = {
        /**
-        * count of active requests
+        * count of active loading-requests
         * @var integer
         */
        _activeRequests: 0,
@@ -1375,16 +1368,46 @@ WCF.Action.Proxy = Class.extend({
        _loadingOverlay: null,
        
        /**
-        * loading overlay state
-        * @var boolean
+        * Adds one loading-request and shows the loading overlay if nessercery
         */
-       _loadingOverlayVisible: false,
+       show: function() {
+               if (this._loadingOverlay === null) { // create loading overlay on first run
+                       this._loadingOverlay = $('<div class="spinner"><span class="icon icon48 icon-spinner" /> <span>' + WCF.Language.get('wcf.global.loading') + '</span></div>').hide().appendTo($('body'));
+               }
+               
+               this._activeRequests++;
+               if (this._activeRequests == 1) {
+                       this._loadingOverlay.stop(true, true).fadeIn(100);
+               }
+       },
        
        /**
-        * timer for overlay activity
+        * Removes one loading-request and hides loading overlay if there're no more pending requests
+        */
+       hide: function() {
+               this._activeRequests--;
+               if (this._activeRequests == 0) {
+                       this._loadingOverlay.stop(true, true).fadeOut(100);
+               }
+       }
+};
+
+/**
+ * Namespace for AJAXProxies
+ */
+WCF.Action = {};
+
+/**
+ * Basic implementation for AJAX-based proxyies
+ * 
+ * @param      object          options
+ */
+WCF.Action.Proxy = Class.extend({
+       /**
+        * count of active requests
         * @var integer
         */
-       _loadingOverlayVisibleTimer: 0,
+       _activeRequests: 0,
        
        /**
         * suppresses errors
@@ -1451,42 +1474,7 @@ WCF.Action.Proxy = Class.extend({
                this._activeRequests++;
                
                if (this.options.showLoadingOverlay) {
-                       this._showLoadingOverlay();
-               }
-       },
-       
-       /**
-        * Displays the loading overlay if not already visible due to an active request.
-        */
-       _showLoadingOverlay: function() {
-               // create loading overlay on first run
-               if (this._loadingOverlay === null) {
-                       this._loadingOverlay = $('<div class="spinner"><span class="icon icon48 icon-spinner" /> <span>' + WCF.Language.get('wcf.global.loading') + '</span></div>').hide().appendTo($('body'));
-               }
-               
-               // fade in overlay
-               if (!this._loadingOverlayVisible) {
-                       this._loadingOverlayVisible = true;
-                       this._loadingOverlay.stop(true, true).fadeIn(100, $.proxy(function() {
-                               new WCF.PeriodicalExecuter($.proxy(this._hideLoadingOverlay, this), 100);
-                       }, this));
-               }
-       },
-       
-       /**
-        * Hides loading overlay if no requests are active and the timer reached at least 1 second.
-        * 
-        * @param       object          pe
-        */
-       _hideLoadingOverlay: function(pe) {
-               this._loadingOverlayVisibleTimer += 100;
-               
-               if (this._activeRequests == 0 && this._loadingOverlayVisibleTimer >= 100) {
-                       this._loadingOverlayVisible = false;
-                       this._loadingOverlayVisibleTimer = 0;
-                       pe.stop();
-                       
-                       this._loadingOverlay.fadeOut(100);
+                       WCF.LoadingOverlayHandler.show();
                }
        },
        
@@ -1554,6 +1542,10 @@ WCF.Action.Proxy = Class.extend({
                        this.options.after();
                }
                
+               if (this.options.showLoadingOverlay) {
+                       WCF.LoadingOverlayHandler.hide();
+               }
+               
                this._activeRequests--;
                
                // disable DOMNodeInserted event