Added AjaxStatus and using Ajax.api
authorAlexander Ebert <ebert@woltlab.com>
Tue, 19 May 2015 16:31:12 +0000 (18:31 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Tue, 19 May 2015 16:31:46 +0000 (18:31 +0200)
wcfsetup/install/files/js/WCF.js
wcfsetup/install/files/js/WoltLab/WCF/Ajax.js
wcfsetup/install/files/js/WoltLab/WCF/Ajax/Status.js [new file with mode: 0644]
wcfsetup/install/files/js/WoltLab/WCF/Controller/Notice/Dismiss.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Popover.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Sitemap.js
wcfsetup/install/files/js/WoltLab/WCF/Controller/Style/Changer.js

index ce88b235502ee198d81da8f4a6203b576d915e25..eec52b467bf5a088ce89fdd7e9c33267a84eaf1c 100755 (executable)
@@ -2068,71 +2068,26 @@ WCF.PeriodicalExecuter = Class.extend({
 
 /**
  * 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();
+               });
        },
        
        /**
index ea015aa89345b1aa682773b4ed03d7b2b0e8f2cf..ffb37e5865550285ede4f66efec4adead1c83268 100644 (file)
@@ -6,7 +6,7 @@
  * @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;
@@ -66,7 +66,7 @@ define(['Core', 'Language', 'DOM/Util', 'UI/Dialog'], function(Core, Language, D
                        }
                        
                        if (!this._options.silent) {
-                               WCF.LoadingOverlayHandler.show();
+                               AjaxStatus.show();
                        }
                        
                        if (this._xhr instanceof XMLHttpRequest) {
@@ -118,7 +118,7 @@ define(['Core', 'Language', 'DOM/Util', 'UI/Dialog'], function(Core, Language, D
                        this._previousXhr = null;
                        
                        if (!this._options.silent) {
-                               WCF.LoadingOverlayHandler.hide();
+                               AjaxStatus.hide();
                        }
                },
                
@@ -144,7 +144,7 @@ define(['Core', 'Language', 'DOM/Util', 'UI/Dialog'], function(Core, Language, D
                 */
                _success: function(xhr) {
                        if (!this._options.silent) {
-                               WCF.LoadingOverlayHandler.hide();
+                               AjaxStatus.hide();
                        }
                        
                        if (typeof this._options.success === 'function') {
@@ -174,7 +174,7 @@ define(['Core', 'Language', 'DOM/Util', 'UI/Dialog'], function(Core, Language, D
                        }
                        
                        if (!this._options.silent) {
-                               WCF.LoadingOverlayHandler.hide();
+                               AjaxStatus.hide();
                        }
                        
                        var data = null;
diff --git a/wcfsetup/install/files/js/WoltLab/WCF/Ajax/Status.js b/wcfsetup/install/files/js/WoltLab/WCF/Ajax/Status.js
new file mode 100644 (file)
index 0000000..7eedcc8
--- /dev/null
@@ -0,0 +1,77 @@
+/**
+ * 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();
+});
index 7df379022ff0d6a84750cce86718715d43218f45..757db6e2467060b79fc0a6cbc7dc3f9c2e646974 100644 (file)
@@ -6,7 +6,7 @@
  * @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";
        
        /**
@@ -34,8 +34,7 @@ define([], function() {
                _click: function(event) {
                        var button = event.currentTarget;
                        
-                       new WCF.Action.Proxy({
-                               autoSend: true,
+                       Ajax.api({
                                data: {
                                        actionName: 'dismiss',
                                        className: 'wcf\\data\\notice\\NoticeAction',
index 80a13d0c24cecc69355633f1fefd87a4e451dfd7..5793d0b9284d897ae95d0a4753d441823fab7ca0 100644 (file)
@@ -109,7 +109,7 @@ define(['Dictionary', 'DOM/Util', 'UI/Alignment'], function(Dictionary, DOMUtil,
                 *      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);
index e2e81d042fca67c104a3128cd8375a7a2e09eb9f..4a4197ae0e733040fdf527120f8936412719a6f0 100644 (file)
@@ -6,7 +6,7 @@
  * @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 = [];
@@ -33,8 +33,7 @@ define(['EventHandler', 'Language', 'DOM/Util', 'UI/Dialog', 'UI/TabMenu'], func
                        event.preventDefault();
                        
                        if (UIDialog.getDialog('sitemapDialog') === undefined) {
-                               new WCF.Action.Proxy({
-                                       autoSend: true,
+                               Ajax.api({
                                        data: {
                                                actionName: 'getSitemap',
                                                className: 'wcf\\data\\sitemap\\SitemapAction'
@@ -70,8 +69,7 @@ define(['EventHandler', 'Language', 'DOM/Util', 'UI/Dialog', 'UI/TabMenu'], func
                        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',
index 5841090083920696b5feb8836c8806567366ea7a..d966ea3ef3a6e9b6d9fd08c20aa66ccdeaf12cec 100644 (file)
@@ -6,7 +6,7 @@
  * @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";
        
        /**
@@ -44,8 +44,7 @@ define(['Language', 'UI/Dialog'], function(Language, UIDialog) {
                        event.preventDefault();
                        
                        if (UIDialog.getDialog('styleChanger') === undefined) {
-                               new WCF.Action.Proxy({
-                                       autoSend: true,
+                               Ajax.api({
                                        data: {
                                                actionName: 'getStyleChooser',
                                                className: 'wcf\\data\\style\\StyleAction'
@@ -79,8 +78,7 @@ define(['Language', 'UI/Dialog'], function(Language, UIDialog) {
                _click: function(event) {
                        event.preventDefault();
                        
-                       new WCF.Action.Proxy({
-                               autoSend: true,
+                       Ajax.api({
                                data: {
                                        actionName: 'changeStyle',
                                        className: 'wcf\\data\\style\\StyleAction',