});
/**
- * 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,
_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
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();
}
},
this.options.after();
}
+ if (this.options.showLoadingOverlay) {
+ WCF.LoadingOverlayHandler.hide();
+ }
+
this._activeRequests--;
// disable DOMNodeInserted event