From: Magnus Kühn Date: Sun, 10 Feb 2013 18:27:02 +0000 (+0100) Subject: Added WCF.LoadingOverlayHandler X-Git-Tag: 2.0.0_Beta_1~493^2~3^2~1 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=093162ccf8e6a1f81d971c2ab449608533b3a30b;p=GitHub%2FWoltLab%2FWCF.git Added WCF.LoadingOverlayHandler --- diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index dbdf319441..30139f5b9c 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -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 = $('
' + WCF.Language.get('wcf.global.loading') + '
').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 = $('
' + WCF.Language.get('wcf.global.loading') + '
').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