[TASK] Move jquery.clearable.js to ext:backend 60/38360/5
authorWouter Wolters <typo3@wouterwolters.nl>
Mon, 30 Mar 2015 19:03:31 +0000 (21:03 +0200)
committerAndreas Fernandez <typo3@scripting-base.de>
Tue, 5 May 2015 09:37:35 +0000 (11:37 +0200)
This also makes jquery.clearable a solid standalone
AMD module.

Resolves: #66161
Releases: master
Change-Id: Id0f01b36c7e4d5050a9b3099db44c760c2234e10
Reviewed-on: http://review.typo3.org/38360
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/contrib/jquery/jquery.clearable.js [deleted file]
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine.js
typo3/sysext/backend/Resources/Public/JavaScript/Login.js
typo3/sysext/backend/Resources/Public/JavaScript/jquery.clearable.js [new file with mode: 0644]
typo3/sysext/core/Classes/Page/PageRenderer.php
typo3/sysext/documentation/Resources/Public/JavaScript/Main.js
typo3/sysext/extensionmanager/Resources/Public/JavaScript/Main.js
typo3/sysext/lang/Resources/Public/JavaScript/LanguageModule.js
typo3/sysext/recycler/Resources/Public/JavaScript/Recycler.js

diff --git a/typo3/contrib/jquery/jquery.clearable.js b/typo3/contrib/jquery/jquery.clearable.js
deleted file mode 100644 (file)
index e5d43e2..0000000
+++ /dev/null
@@ -1,97 +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!
- */
-
-/**
- * This file provides a jQuery plugin for generating 'clearable' input fields.
- * These fields show a "clear"-button when someone hovers over them and
- * they are not empty.
- * Options:
- *   * 'onClear':      Function that is called after clearing. Takes no arguments,
- *                                     'this' is set to the clearable input element. Defaults to an
- *                                     empty function.
- */
-(function($) {
-       $.fn.clearable = function(options) {
-
-               var defaults = {
-                       'onClear': function() {}
-               };
-
-               // Merge defaults and given options. Given options have higher priority
-               // because they are the last argument.
-               var settings = $.extend({}, defaults, options);
-
-               // Iterate over the list of inputs and make each clearable. Return
-               // the list to allow chaining.
-               return this.each(function() {
-
-                       // The input element to make clearable.
-                       var $input = $(this);
-
-                       // make sure the input field is not used twice for a clearable
-                       if (!$input.data('clearable')) {
-                               $input.data('clearable', 'loaded');
-
-                               // Wrap it with a div and add a span that is the trigger for
-                               // clearing.
-                               $input.wrap('<div class="form-control-clearable" />');
-                               $input.after('<button type="button" class="close" tabindex="-1" aria-hidden="true"><span class="fa fa-times" /></button>');
-                               $input.addClass('t3js-clearable');
-
-                               var $clearer = $input.next();
-
-                               // Register a listener the various events triggering the clearer to
-                               // be shown or hidden.
-                               var handler = function() {
-                                       var $element = $(this);
-                                       if ($element.next('input[type=hidden]').length) {
-                                               $element = $element.next('input[type=hidden]');
-                                       }
-                                       var value = $element.val();
-                                       var hasEmptyValue = (value.length === 0);
-                                       if (value === "0" && $element.closest('.t3js-datetimepicker').length) {
-                                               hasEmptyValue = true;
-                                       }
-
-                                       // only show the clearing button if the value is set, or if the value is not "0" on a datetime field
-                                       if (!hasEmptyValue) {
-                                               $clearer.show();
-                                       } else {
-                                               $clearer.hide();
-                                       }
-                               };
-                               $input.on('keyup', handler);
-                               $input.on('mouseenter', handler);
-                               $input.on('change', handler);
-                               $input.on('initialize', handler);
-
-                               // The actual clearing action. Focus the input element afterwards,
-                               // the user probably wants to type into it after clearing.
-                               $clearer.click(function(e) {
-                                       e.preventDefault();
-                                       $input.val('').change();
-                                       if (!$input.hasClass("t3js-datetimepicker")) {
-                                               $input.focus();
-                                       }
-                                       $input.trigger('keyup');
-
-                                       if ('function' === typeof(settings.onClear)) {
-                                               settings.onClear.call($input.get());
-                                       }
-                               });
-
-                               $input.trigger('initialize');
-                       }
-               });
-       };
-})(jQuery || TYPO3.jQuery);
index 9b4216d..de80ace 100644 (file)
@@ -710,7 +710,7 @@ define('TYPO3/CMS/Backend/FormEngine', ['jquery'], function ($) {
        FormEngine.reinitialize = function() {
                // apply "close" button to all input / datetime fields
                if ($('.t3js-clearable').length) {
-                       require(['jquery/jquery.clearable'], function() {
+                       require(['TYPO3/CMS/Backend/jquery.clearable'], function() {
                                $('.t3js-clearable').clearable();
                        });
                }
index f757388..e7949fb 100755 (executable)
@@ -14,7 +14,7 @@
 /**
  * JavaScript module for the backend login form
  */
-define('TYPO3/CMS/Backend/Login', ['jquery', 'jquery/jquery.clearable', 'bootstrap'], function($) {
+define('TYPO3/CMS/Backend/Login', ['jquery', 'TYPO3/CMS/Backend/jquery.clearable', 'bootstrap'], function($) {
        var BackendLogin = {
                options: {
                        interfaceField: '.t3js-login-interface-field',
diff --git a/typo3/sysext/backend/Resources/Public/JavaScript/jquery.clearable.js b/typo3/sysext/backend/Resources/Public/JavaScript/jquery.clearable.js
new file mode 100644 (file)
index 0000000..ad98ea4
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+ * 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!
+ */
+
+/**
+ * This file provides a jQuery plugin for generating 'clearable' input fields.
+ * These fields show a "clear"-button when someone hovers over them and
+ * they are not empty.
+ * Options:
+ *   * 'onClear':      Function that is called after clearing. Takes no arguments,
+ *                                     'this' is set to the clearable input element. Defaults to an
+ *                                     empty function.
+ */
+(function(factory) {
+       if (typeof define === "function" && define.amd) {
+               // AMD. Register as an anonymous module.
+               define([ "jquery" ], factory);
+       } else {
+               // Browser globals, TYPO3.jQuery kept for backwards-compatibility, will be removed with CMS 8
+               factory(jQuery || TYPO3.jQuery);
+       }
+}(function($) {
+       $.fn.clearable = function(options) {
+
+               var defaults = {
+                       'onClear': function() {}
+               };
+
+               // Merge defaults and given options. Given options have higher priority
+               // because they are the last argument.
+               var settings = $.extend({}, defaults, options);
+
+               // Iterate over the list of inputs and make each clearable. Return
+               // the list to allow chaining.
+               return this.each(function() {
+
+                       // The input element to make clearable.
+                       var $input = $(this);
+
+                       // make sure the input field is not used twice for a clearable
+                       if (!$input.data('clearable')) {
+                               $input.data('clearable', 'loaded');
+
+                               // Wrap it with a div and add a span that is the trigger for
+                               // clearing.
+                               $input.wrap('<div class="form-control-clearable" />');
+                               $input.after('<button type="button" class="close" tabindex="-1" aria-hidden="true"><span class="fa fa-times" /></button>');
+                               $input.addClass('t3js-clearable');
+
+                               var $clearer = $input.next();
+
+                               // Register a listener the various events triggering the clearer to
+                               // be shown or hidden.
+                               var handler = function() {
+                                       var $element = $(this);
+                                       if ($element.next('input[type=hidden]').length) {
+                                               $element = $element.next('input[type=hidden]');
+                                       }
+                                       var value = $element.val();
+                                       var hasEmptyValue = (value.length === 0);
+                                       if (value === "0" && $element.closest('.t3js-datetimepicker').length) {
+                                               hasEmptyValue = true;
+                                       }
+
+                                       // only show the clearing button if the value is set, or if the value is not "0" on a datetime field
+                                       if (!hasEmptyValue) {
+                                               $clearer.show();
+                                       } else {
+                                               $clearer.hide();
+                                       }
+                               };
+                               $input.on('keyup', handler);
+                               $input.on('mouseenter', handler);
+                               $input.on('change', handler);
+                               $input.on('initialize', handler);
+
+                               // The actual clearing action. Focus the input element afterwards,
+                               // the user probably wants to type into it after clearing.
+                               $clearer.click(function(e) {
+                                       e.preventDefault();
+                                       $input.val('').change();
+                                       if (!$input.hasClass("t3js-datetimepicker")) {
+                                               $input.focus();
+                                       }
+                                       $input.trigger('keyup');
+
+                                       if ('function' === typeof(settings.onClear)) {
+                                               settings.onClear.call($input.get());
+                                       }
+                               });
+
+                               $input.trigger('initialize');
+                       }
+               });
+       };
+}));
index d988d2a..d6f4b40 100644 (file)
@@ -1606,7 +1606,7 @@ class PageRenderer implements \TYPO3\CMS\Core\SingletonInterface {
                                'imagesloaded' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/imagesloaded.pkgd.min',
                                'bootstrap' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap/bootstrap',
                                'twbs/bootstrap-datetimepicker' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/bootstrap-datetimepicker',
-                               'autosize' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/autosize',
+                               'autosize' => $this->backPath . 'sysext/core/Resources/Public/JavaScript/Contrib/autosize'
                        );
                        // get all extensions that are loaded
                        $loadedExtensions = \TYPO3\CMS\Core\Utility\ExtensionManagementUtility::getLoadedExtensionListArray();
index be16bd2..6012ea7 100644 (file)
@@ -14,7 +14,7 @@
 /**
  * JavaScript module for ext:documentation
  */
-define('TYPO3/CMS/Documentation/Main', ['jquery', 'datatables', 'jquery/jquery.clearable'], function($) {
+define('TYPO3/CMS/Documentation/Main', ['jquery', 'datatables', 'TYPO3/CMS/Backend/jquery.clearable'], function($) {
 
        var Documentation = {
                datatable: null
index 12daa03..4d51cb2 100644 (file)
@@ -17,7 +17,7 @@
  * ExtensionManager.Update => Various AJAX functions to display updates
  * ExtensionManager.uploadForm => helper to show the upload form
  */
-define(['jquery', 'nprogress', 'datatables', 'jquery/jquery.clearable'], function($, NProgress) {
+define(['jquery', 'nprogress', 'datatables', 'TYPO3/CMS/Backend/jquery.clearable'], function($, NProgress) {
        var ExtensionManager = {
                identifier: {
                        extensionlist: '#typo3-extension-list',
index b2588d6..f104519 100644 (file)
@@ -16,7 +16,7 @@
  *
  * @author Kai Vogel <k.vogel@reply.de>
  */
-define('TYPO3/CMS/Lang/LanguageModule', ['jquery', 'datatables', 'jquery/jquery.clearable', 'moment'], function($) {
+define('TYPO3/CMS/Lang/LanguageModule', ['jquery', 'datatables', 'TYPO3/CMS/Backend/jquery.clearable', 'moment'], function($) {
        var LanguageModule = {
                me: this,
                context: null,
index 80a1965..880461e 100644 (file)
@@ -14,7 +14,7 @@
 /**
  * RequireJS module for Recycler
  */
-define(['jquery', 'nprogress', 'jquery/jquery.clearable'], function($, NProgress) {
+define(['jquery', 'nprogress', 'TYPO3/CMS/Backend/jquery.clearable'], function($, NProgress) {
        var Recycler = {
                identifiers: {
                        searchForm: '#recycler-form',