[TASK] Migrate TYPO3/CMS/Backend/FormEngine/Element/SelectSingleElement to TypeScript 70/59670/4
authorFrank Naegler <frank.naegler@typo3.org>
Fri, 8 Feb 2019 14:46:18 +0000 (15:46 +0100)
committerAnja Leichsenring <aleichsenring@ab-softlab.de>
Fri, 1 Mar 2019 17:59:10 +0000 (18:59 +0100)
Resolves: #84422
Releases: master
Change-Id: I59af07e8abbe54cb09c7d4c0159f3f2ca2213672
Reviewed-on: https://review.typo3.org/c/59670
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
Reviewed-by: Anja Leichsenring <aleichsenring@ab-softlab.de>
typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/Element/SelectSingleElement.ts [new file with mode: 0644]
typo3/sysext/backend/Resources/Public/JavaScript/FormEngine/Element/SelectSingleElement.js

diff --git a/typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/Element/SelectSingleElement.ts b/typo3/sysext/backend/Resources/Private/TypeScript/FormEngine/Element/SelectSingleElement.ts
new file mode 100644 (file)
index 0000000..6940297
--- /dev/null
@@ -0,0 +1,66 @@
+/*
+ * 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!
+ */
+
+import * as $ from 'jquery';
+
+interface SelectSingleElementOptions {
+  [key: string]: any;
+}
+
+/**
+ * Module: TYPO3/CMS/Backend/FormEngine/Element/SelectSingleElement
+ * Logic for SelectSingleElement
+ */
+class SelectSingleElement {
+  public initialize = (selector: string, options: SelectSingleElementOptions): void => {
+    let $selectElement: JQuery = $(selector);
+    let $groupIconContainer: JQuery = $selectElement.prev('.input-group-icon');
+    options = options || {};
+
+    $selectElement.on('change', (e: JQueryEventObject): void => {
+      let $me: JQuery = $(e.target);
+
+      // Update prepended select icon
+      $groupIconContainer.html($selectElement.find(':selected').data('icon'));
+
+      let $selectIcons: JQuery = $me.closest('.t3js-formengine-field-item').find('.t3js-forms-select-single-icons');
+      $selectIcons.find('.item.active').removeClass('active');
+      $selectIcons.find('[data-select-index="' + $me.prop('selectedIndex') + '"]').closest('.item').addClass('active');
+    });
+
+    // Append optionally passed additional "change" event callback
+    if (typeof options.onChange === 'function') {
+      $selectElement.on('change', options.onChange);
+    }
+
+    // Append optionally passed additional "focus" event callback
+    if (typeof options.onFocus === 'function') {
+      $selectElement.on('focus', options.onFocus);
+    }
+
+    $selectElement.closest('.form-control-wrap').find('.t3js-forms-select-single-icons a').on('click', (e: JQueryEventObject): boolean => {
+      let $me: JQuery = $(e.target);
+      let $selectIcon: JQuery = $me.closest('[data-select-index]');
+
+      $me.closest('.t3js-forms-select-single-icons').find('.item.active').removeClass('active');
+      $selectElement
+        .prop('selectedIndex', $selectIcon.data('selectIndex'))
+        .trigger('change');
+      $selectIcon.closest('.item').addClass('active');
+
+      return false;
+    });
+  }
+}
+
+export = new SelectSingleElement();
index 56d6f81..e068d29 100644 (file)
  *
  * The TYPO3 project - inspiring people to share!
  */
-
-/**
- * Module: TYPO3/CMS/Backend/FormEngine/Element/SelectSingleElement
- * Logic for SelectSingleElement
- */
-define(['jquery'], function($) {
-
-  /**
-   *
-   * @type {{}}
-   * @exports TYPO3/CMS/Backend/FormEngine/Element/SelectSingleElement
-   */
-  var SelectSingleElement = {};
-
-  /**
-   * Initializes the SelectSingleEleemnt
-   *
-   * @param {String} selector
-   * @param {Object} options
-   */
-  SelectSingleElement.initialize = function(selector, options) {
-
-    var $selectElement = $(selector);
-    var $groupIconContainer = $selectElement.prev('.input-group-icon');
-    var options = options || {};
-
-    $selectElement.on('change', function(e) {
-      var $me = $(e.target);
-
-      // Update prepended select icon
-      $groupIconContainer.html($selectElement.find(':selected').data('icon'));
-
-      var $selectIcons = $me.closest('.t3js-formengine-field-item').find('.t3js-forms-select-single-icons');
-      $selectIcons.find('.item.active').removeClass('active');
-      $selectIcons.find('[data-select-index="' + $me.prop('selectedIndex') + '"]').closest('.item').addClass('active');
-    });
-
-    // Append optionally passed additional "change" event callback
-    if (typeof options.onChange === 'function') {
-      $selectElement.on('change', options.onChange);
-    }
-
-    // Append optionally passed additional "focus" event callback
-    if (typeof options.onFocus === 'function') {
-      $selectElement.on('focus', options.onFocus);
-    }
-
-    $selectElement.closest('.form-control-wrap').find('.t3js-forms-select-single-icons a').on('click', function(e) {
-      var $me = $(e.target);
-      var $selectIcon = $me.closest('[data-select-index]');
-
-      $me.closest('.t3js-forms-select-single-icons').find('.item.active').removeClass('active');
-      $selectElement
-        .prop('selectedIndex', $selectIcon.data('selectIndex'))
-        .trigger('change');
-      $selectIcon.closest('.item').addClass('active');
-
-      return false;
-    });
-  };
-
-  return SelectSingleElement;
-});
+define(["require","exports","jquery"],function(e,t,n){"use strict";return new function(){this.initialize=function(e,t){var s=n(e),i=s.prev(".input-group-icon");t=t||{},s.on("change",function(e){var t=n(e.target);i.html(s.find(":selected").data("icon"));var o=t.closest(".t3js-formengine-field-item").find(".t3js-forms-select-single-icons");o.find(".item.active").removeClass("active"),o.find('[data-select-index="'+t.prop("selectedIndex")+'"]').closest(".item").addClass("active")}),"function"==typeof t.onChange&&s.on("change",t.onChange),"function"==typeof t.onFocus&&s.on("focus",t.onFocus),s.closest(".form-control-wrap").find(".t3js-forms-select-single-icons a").on("click",function(e){var t=n(e.target),i=t.closest("[data-select-index]");return t.closest(".t3js-forms-select-single-icons").find(".item.active").removeClass("active"),s.prop("selectedIndex",i.data("selectIndex")).trigger("change"),i.closest(".item").addClass("active"),!1})}}});
\ No newline at end of file