From: Matthias Schmidt Date: Tue, 5 Jan 2021 17:42:45 +0000 (+0100) Subject: Convert `Media/List/Upload` to TypeScript X-Git-Tag: 5.4.0_Alpha_1~461^2~10 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=c7e50101cc91c9025aa26b82ac69a39b1e8cb746;p=GitHub%2FWoltLab%2FWCF.git Convert `Media/List/Upload` to TypeScript --- diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js index ed0695849f..4a8966db7a 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Media/List/Upload.js @@ -1,62 +1,34 @@ /** * Uploads media files. * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Media/List/Upload + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @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 index 3c8b07c250..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.js +++ /dev/null @@ -1,75 +0,0 @@ -/** - * Uploads media files. - * - * @author Matthias Schmidt - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @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 index 0000000000..7ac7a9878b --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Media/List/Upload.ts @@ -0,0 +1,44 @@ +/** + * Uploads media files. + * + * @author Matthias Schmidt + * @copyright 2001-2021 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Media/List/Upload + */ + +import MediaUpload from "../Upload"; +import { MediaListUploadOptions } from "../Data"; +import * as Core from "../../Core"; + +class MediaListUpload extends MediaUpload { + 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;