[TASK] Refactor util.js to AMD module 86/38486/3
authorFrank Nägler <typo3@naegler.net>
Sat, 4 Apr 2015 20:54:37 +0000 (22:54 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Sun, 3 May 2015 12:55:39 +0000 (14:55 +0200)
Resolves: #66275
Releases: master
Change-Id: I7269002dc5a5a656f407273a3c0dc87752758a39
Reviewed-on: http://review.typo3.org/38486
Reviewed-by: Wouter Wolters <typo3@wouterwolters.nl>
Tested-by: Wouter Wolters <typo3@wouterwolters.nl>
Reviewed-by: Andreas Fernandez <typo3@scripting-base.de>
Tested-by: Andreas Fernandez <typo3@scripting-base.de>
typo3/sysext/backend/Classes/Controller/BackendController.php
typo3/sysext/backend/Resources/Public/JavaScript/Utility.js [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/util.js [deleted file]

index d34bf19..e94dc70 100644 (file)
@@ -123,13 +123,15 @@ class BackendController {
                        'iframepanel' => 'sysext/backend/Resources/Public/JavaScript/iframepanel.js',
                        'backendcontentiframe' => 'sysext/backend/Resources/Public/JavaScript/extjs/backendcontentiframe.js',
                        'viewportConfiguration' => 'sysext/backend/Resources/Public/JavaScript/extjs/viewportConfiguration.js',
-                       'util' => 'sysext/backend/Resources/Public/JavaScript/util.js'
                );
                $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/LoginRefresh', 'function(LoginRefresh) {
                        LoginRefresh.setLoginFramesetUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('login_frameset')) . ');
                        LoginRefresh.setLogoutUrl(' . GeneralUtility::quoteJSvalue(BackendUtility::getModuleUrl('logout')) . ');
                }');
 
+               // load Utility class
+               $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Utility');
+
                // load Notification functionality
                $this->pageRenderer->loadRequireJsModule('TYPO3/CMS/Backend/Notification');
 
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/Utility.js b/typo3/sysext/backend/Resources/Public/JavaScript/Utility.js
new file mode 100644 (file)
index 0000000..d28b4b4
--- /dev/null
@@ -0,0 +1,67 @@
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Utility helper
+ */
+define('TYPO3/CMS/Backend/Utility', ['jquery'], function($) {
+
+       /**
+        * The main Utility object
+        */
+       var Utility = {
+       };
+
+       /**
+        * Checks if a given number is really a number
+        *
+        * Taken from:
+        * http://dl.dropbox.com/u/35146/js/tests/isNumber.html
+        *
+        * @param {string} number
+        * @returns {boolean|*}
+        */
+       Utility.isNumber = function(number) {
+               return !isNaN(parseFloat(number)) && isFinite(number);
+       };
+
+       /**
+        * Gets a parameter from a given url
+        *
+        * @param {string} url
+        * @param {string} parameter
+        * @returns {string}
+        */
+       Utility.getParameterFromUrl = function(url, parameter) {
+               var parts = url.split('?'),
+                       value = '';
+
+               if (parts.length >= 2) {
+                       var queryString = parts.join('?');
+
+                       var prefix = encodeURIComponent(parameter) + '=';
+                       var parameters = queryString.split(/[&;]/g);
+                       for (var i = parameters.length; i-- > 0;) {
+                               if (parameters[i].lastIndexOf(prefix, 0) !== -1) {
+                                       value = parameters[i].split('=')[1];
+                                       break;
+                               }
+                       }
+               }
+
+               return value;
+       };
+
+       TYPO3.Utility = Utility;
+       return Utility;
+});
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/util.js b/typo3/sysext/backend/Resources/Public/JavaScript/util.js
deleted file mode 100644 (file)
index 2753067..0000000
+++ /dev/null
@@ -1,64 +0,0 @@
-/*
- * This file is part of the TYPO3 CMS project.
- *
- * It is free software; you can redistribute it and/or modify it under
- * the terms of the GNU General Public License, either version 2
- * of the License, or any later version.
- *
- * For the full copyright and license information, please read the
- * LICENSE.txt file that was distributed with this source code.
- *
- * The TYPO3 project - inspiring people to share!
- */
-Ext.namespace('TYPO3');
-
-/**
- * @class TYPO3.Utility
- *
- * Generic utility methods that are not provided by ExtJs
- *
- * @namespace TYPO3
- * @author Stefan Galinski <stefan.galinski@gmail.com>
- */
-TYPO3.Utility = {
-       /**
-        * Checks if a given number is really a number
-        *
-        * Taken from:
-        * http://dl.dropbox.com/u/35146/js/tests/isNumber.html
-        *
-        * @param {String} number
-        * @return {Boolean}
-        */
-       isNumber: function(number) {
-               return !isNaN(parseFloat(number)) && isFinite(number);
-       },
-
-       /**
-        * Gets a parameter from a given url
-        *
-        * @param {string} url
-        * @param {string} parameter
-        * @return {string}
-        */
-       getParameterFromUrl: function(url, parameter) {
-         var parts = url.split('?'),
-                 value = '';
-
-         if (parts.length >= 2) {
-                 var urlBase = parts.shift();
-                 var queryString = parts.join('?');
-
-                 var prefix = encodeURIComponent(parameter) + '=';
-                 var parameters = queryString.split(/[&;]/g);
-                 for (var i = parameters.length; i-- > 0;) {
-                         if (parameters[i].lastIndexOf(prefix, 0) !== -1) {
-                                 value = parameters[i].split('=')[1];
-                                 break;
-                         }
-                 }
-         }
-
-         return value;
-       }
-};