Convert `Media/List/Upload` to TypeScript
authorMatthias Schmidt <gravatronics@live.com>
Tue, 5 Jan 2021 17:42:45 +0000 (18:42 +0100)
committerMatthias Schmidt <gravatronics@live.com>
Tue, 5 Jan 2021 17:42:45 +0000 (18:42 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.ts [new file with mode: 0644]

index ed0695849f5366aeedeadaad2d6036cc4302dfc0..4a8966db7a27cb6e28f24993d54007860aa72103 100644 (file)
@@ -1,62 +1,34 @@
 /**
  * Uploads media files.
  *
- * @author     Matthias Schmidt
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Media/List/Upload
+ * @author  Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Media/List/Upload
  */
-define([
-    'Core', 'Dom/Util', '../Upload'
-], function (Core, DomUtil, MediaUpload) {
+define(["require", "exports", "tslib", "../Upload", "../../Core"], function (require, exports, tslib_1, Upload_1, Core) {
     "use strict";
-    if (!COMPILER_TARGET_DEFAULT) {
-        var Fake = function () { };
-        Fake.prototype = {
-            _createButton: function () { },
-            _success: function () { },
-            _upload: function () { },
-            _createFileElement: function () { },
-            _getParameters: function () { },
-            _uploadFiles: function () { },
-            _createFileElements: function () { },
-            _failure: function () { },
-            _insertButton: function () { },
-            _progress: function () { },
-            _removeButton: function () { }
-        };
-        return Fake;
-    }
-    /**
-     * @constructor
-     */
-    function MediaListUpload(buttonContainerId, targetId, options) {
-        MediaUpload.call(this, buttonContainerId, targetId, options);
-    }
-    Core.inherit(MediaListUpload, MediaUpload, {
-        /**
-         * Creates the upload button.
-         */
-        _createButton: function () {
-            MediaListUpload._super.prototype._createButton.call(this);
-            var span = elBySel('span', this._button);
-            var space = document.createTextNode(' ');
-            DomUtil.prepend(space, span);
-            var icon = elCreate('span');
-            icon.className = 'icon icon16 fa-upload';
-            DomUtil.prepend(icon, span);
-        },
-        /**
-         * @see        WoltLabSuite/Core/Upload#_getParameters
-         */
-        _getParameters: function () {
+    Upload_1 = tslib_1.__importDefault(Upload_1);
+    Core = tslib_1.__importStar(Core);
+    class MediaListUpload extends Upload_1.default {
+        _createButton() {
+            super._createButton();
+            const span = this._button.querySelector("span");
+            const space = document.createTextNode(" ");
+            span.insertBefore(space, span.childNodes[0]);
+            const icon = document.createElement("span");
+            icon.className = "icon icon16 fa-upload";
+            span.insertBefore(icon, span.childNodes[0]);
+        }
+        _getParameters() {
             if (this._options.categoryId) {
-                return Core.extend(MediaListUpload._super.prototype._getParameters.call(this), {
-                    categoryID: this._options.categoryId
+                return Core.extend(super._getParameters(), {
+                    categoryID: this._options.categoryId,
                 });
             }
-            return MediaListUpload._super.prototype._getParameters.call(this);
+            return super._getParameters();
         }
-    });
+    }
+    Core.enableLegacyInheritance(MediaListUpload);
     return MediaListUpload;
 });
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.js
deleted file mode 100644 (file)
index 3c8b07c..0000000
+++ /dev/null
@@ -1,75 +0,0 @@
-/**
- * Uploads media files.
- *
- * @author     Matthias Schmidt
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Media/List/Upload
- */
-define(
-       [
-               'Core', 'Dom/Util', '../Upload'
-       ],
-       function(
-               Core, DomUtil, MediaUpload
-       )
-{
-       "use strict";
-       
-       if (!COMPILER_TARGET_DEFAULT) {
-               var Fake = function() {};
-               Fake.prototype = {
-                       _createButton: function() {},
-                       _success: function() {},
-                       _upload: function() {},
-                       _createFileElement: function() {},
-                       _getParameters: function() {},
-                       _uploadFiles: function() {},
-                       _createFileElements: function() {},
-                       _failure: function() {},
-                       _insertButton: function() {},
-                       _progress: function() {},
-                       _removeButton: function() {}
-               };
-               return Fake;
-       }
-       
-       /**
-        * @constructor
-        */
-       function MediaListUpload(buttonContainerId, targetId, options) {
-               MediaUpload.call(this, buttonContainerId, targetId, options);
-       }
-       Core.inherit(MediaListUpload, MediaUpload, {
-               /**
-                * Creates the upload button.
-                */
-               _createButton: function() {
-                       MediaListUpload._super.prototype._createButton.call(this);
-                       
-                       var span = elBySel('span', this._button);
-                       
-                       var space = document.createTextNode(' ');
-                       DomUtil.prepend(space, span);
-                       
-                       var icon = elCreate('span');
-                       icon.className = 'icon icon16 fa-upload';
-                       DomUtil.prepend(icon, span);
-               },
-               
-               /**
-                * @see WoltLabSuite/Core/Upload#_getParameters
-                */
-               _getParameters: function() {
-                       if (this._options.categoryId) {
-                               return Core.extend(MediaListUpload._super.prototype._getParameters.call(this), {
-                                       categoryID: this._options.categoryId
-                               });
-                       }
-                       
-                       return MediaListUpload._super.prototype._getParameters.call(this);
-               }
-       });
-       
-       return MediaListUpload;
-});
diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.ts
new file mode 100644 (file)
index 0000000..7ac7a98
--- /dev/null
@@ -0,0 +1,44 @@
+/**
+ * Uploads media files.
+ *
+ * @author  Matthias Schmidt
+ * @copyright 2001-2021 WoltLab GmbH
+ * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @module  WoltLabSuite/Core/Media/List/Upload
+ */
+
+import MediaUpload from "../Upload";
+import { MediaListUploadOptions } from "../Data";
+import * as Core from "../../Core";
+
+class MediaListUpload extends MediaUpload<MediaListUploadOptions> {
+  protected _createButton(): void {
+    super._createButton();
+
+    const span = this._button.querySelector("span") as HTMLSpanElement;
+
+    const space = document.createTextNode(" ");
+    span.insertBefore(space, span.childNodes[0]);
+
+    const icon = document.createElement("span");
+    icon.className = "icon icon16 fa-upload";
+    span.insertBefore(icon, span.childNodes[0]);
+  }
+
+  protected _getParameters(): ArbitraryObject {
+    if (this._options.categoryId) {
+      return Core.extend(
+        super._getParameters() as object,
+        {
+          categoryID: this._options.categoryId,
+        } as object,
+      ) as ArbitraryObject;
+    }
+
+    return super._getParameters();
+  }
+}
+
+Core.enableLegacyInheritance(MediaListUpload);
+
+export = MediaListUpload;