/**
* Handler for loading overlays
+ *
+ * @deprecated 2.2 - Please use WoltLab/WCF/Ajax/Status
*/
WCF.LoadingOverlayHandler = {
- /**
- * count of active loading-requests
- * @var integer
- */
- _activeRequests: 0,
-
- /**
- * loading overlay
- * @var jQuery
- */
- _loadingOverlay: null,
-
- /**
- * WCF.PeriodicalExecuter instance
- * @var WCF.PeriodicalExecuter
- */
- _pending: null,
-
/**
* Adds one loading-request and shows the loading overlay if nessercery
*/
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>').appendTo($('body'));
-
- // fix position
- var $width = this._loadingOverlay.outerWidth();
- if ($width < 70) $width = 70;
- this._loadingOverlay.css({
- marginLeft: Math.ceil(-1 * $width / 2),
- width: $width
- }).hide();
- }
-
- this._activeRequests++;
- if (this._activeRequests == 1) {
- 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);
- }
- }
+ require(['WoltLab/WCF/Ajax/Status'], function(AjaxStatus) {
+ AjaxStatus.show();
+ });
},
/**
* Removes one loading-request and hides loading overlay if there're no more pending requests
*/
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);
- }
+ require(['WoltLab/WCF/Ajax/Status'], function(AjaxStatus) {
+ AjaxStatus.hide();
+ });
},
/**
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLab/WCF/Ajax
*/
-define(['Core', 'Language', 'DOM/Util', 'UI/Dialog'], function(Core, Language, DOMUtil, UIDialog) {
+define(['Core', 'Language', 'DOM/Util', 'UI/Dialog', 'WoltLab/WCF/Ajax/Status'], function(Core, Language, DOMUtil, UIDialog, AjaxStatus) {
"use strict";
var _didInit = false;
}
if (!this._options.silent) {
- WCF.LoadingOverlayHandler.show();
+ AjaxStatus.show();
}
if (this._xhr instanceof XMLHttpRequest) {
this._previousXhr = null;
if (!this._options.silent) {
- WCF.LoadingOverlayHandler.hide();
+ AjaxStatus.hide();
}
},
*/
_success: function(xhr) {
if (!this._options.silent) {
- WCF.LoadingOverlayHandler.hide();
+ AjaxStatus.hide();
}
if (typeof this._options.success === 'function') {
}
if (!this._options.silent) {
- WCF.LoadingOverlayHandler.hide();
+ AjaxStatus.hide();
}
var data = null;
--- /dev/null
+/**
+ * Provides the AJAX status overlay.
+ *
+ * @author Alexander Ebert
+ * @copyright 2001-2015 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module WoltLab/WCF/Ajax/Status
+ */
+define(['Language'], function(Language) {
+ "use strict";
+
+ var _activeRequests = 0;
+ var _overlay = null;
+ var _timeoutShow = null;
+
+ /**
+ * @constructor
+ */
+ function AjaxStatus() {}
+ AjaxStatus.prototype = {
+ /**
+ * Initializes the status overlay on first usage.
+ */
+ _init: function() {
+ _overlay = document.createElement('div');
+ _overlay.classList.add('spinner');
+
+ var icon = document.createElement('span');
+ icon.className = 'icon icon48 fa-spinner';
+ _overlay.appendChild(icon);
+
+ var title = document.createElement('span');
+ title.textContent = Language.get('wcf.global.loading');
+ _overlay.appendChild(title);
+
+ document.body.appendChild(_overlay);
+ },
+
+ /**
+ * Shows the loading overlay.
+ */
+ show: function() {
+ if (_overlay === null) {
+ this._init();
+ }
+
+ _activeRequests++;
+
+ if (_timeoutShow === null) {
+ _timeoutShow = window.setTimeout(function() {
+ if (_activeRequests) {
+ _overlay.classList.add('active');
+ }
+
+ _timeoutShow = null;
+ }, 250);
+ }
+ },
+
+ /**
+ * Hides the loading overlay.
+ */
+ hide: function() {
+ _activeRequests--;
+
+ if (_activeRequests === 0) {
+ if (_timeoutShow !== null) {
+ window.clearTimeout(_timeoutShow);
+ }
+
+ _overlay.classList.remove('active');
+ }
+ }
+ };
+
+ return new AjaxStatus();
+});
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLab/WCF/Controller/Notice/Dismiss
*/
-define([], function() {
+define(['Ajax'], function(Ajax) {
"use strict";
/**
_click: function(event) {
var button = event.currentTarget;
- new WCF.Action.Proxy({
- autoSend: true,
+ Ajax.api({
data: {
actionName: 'dismiss',
className: 'wcf\\data\\notice\\NoticeAction',
* className: 'fooLink',
* identifier: 'com.example.bar.foo',
* loadCallback: function(objectId, popover) {
- * // request data for object id (e.g. via WCF.Action.Proxy)
+ * // request data for object id (e.g. via Ajax)
*
* // then call this to set the content
* popover.setContent('com.example.bar.foo', objectId, htmlTemplateString);
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLab/WCF/Controller/Sitemap
*/
-define(['EventHandler', 'Language', 'DOM/Util', 'UI/Dialog', 'UI/TabMenu'], function(EventHandler, Language, DOMUtil, UIDialog, UITabMenu) {
+define(['Ajax', 'EventHandler', 'Language', 'DOM/Util', 'UI/Dialog', 'UI/TabMenu'], function(Ajax, EventHandler, Language, DOMUtil, UIDialog, UITabMenu) {
"use strict";
var _cache = [];
event.preventDefault();
if (UIDialog.getDialog('sitemapDialog') === undefined) {
- new WCF.Action.Proxy({
- autoSend: true,
+ Ajax.api({
data: {
actionName: 'getSitemap',
className: 'wcf\\data\\sitemap\\SitemapAction'
var name = tabData.active.getAttribute('data-name').replace(/^sitemap_/, '');
if (_cache.indexOf(name) === -1) {
- new WCF.Action.Proxy({
- autoSend: true,
+ Ajax.api({
data: {
actionName: 'getSitemap',
className: 'wcf\\data\\sitemap\\SitemapAction',
* @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
* @module WoltLab/WCF/Controller/Style/Changer
*/
-define(['Language', 'UI/Dialog'], function(Language, UIDialog) {
+define(['Ajax', 'Language', 'UI/Dialog'], function(Ajax, Language, UIDialog) {
"use strict";
/**
event.preventDefault();
if (UIDialog.getDialog('styleChanger') === undefined) {
- new WCF.Action.Proxy({
- autoSend: true,
+ Ajax.api({
data: {
actionName: 'getStyleChooser',
className: 'wcf\\data\\style\\StyleAction'
_click: function(event) {
event.preventDefault();
- new WCF.Action.Proxy({
- autoSend: true,
+ Ajax.api({
data: {
actionName: 'changeStyle',
className: 'wcf\\data\\style\\StyleAction',