From 71ee3d7f7951f55915db5e9da15ae78ef7d56faf Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Mon, 2 Nov 2020 01:16:46 +0100 Subject: [PATCH] Convert `Ui/Sortable/List` to TypeScript --- .../js/WoltLabSuite/Core/Ui/Sortable/List.js | 81 +++++++---------- .../ts/WoltLabSuite/Core/Ui/Sortable/List.js | 86 ------------------ .../ts/WoltLabSuite/Core/Ui/Sortable/List.ts | 89 +++++++++++++++++++ 3 files changed, 122 insertions(+), 134 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Sortable/List.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Sortable/List.js index 6b0fc29931..f73258bcc0 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Sortable/List.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Sortable/List.js @@ -1,72 +1,57 @@ /** * Sortable lists with optimized handling per device sizes. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Ui/Sortable/List + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/Sortable/List */ -define(['Core', 'Ui/Screen'], function (Core, UiScreen) { +define(["require", "exports", "tslib", "../../Core", "../Screen"], function (require, exports, tslib_1, Core, UiScreen) { "use strict"; - if (!COMPILER_TARGET_DEFAULT) { - var Fake = function () { }; - Fake.prototype = { - init: function () { }, - _enable: function () { }, - _disable: function () { } - }; - return Fake; - } - /** - * @constructor - */ - function UiSortableList(options) { this.init(options); } - UiSortableList.prototype = { + Core = tslib_1.__importStar(Core); + UiScreen = tslib_1.__importStar(UiScreen); + class UiSortableList { /** * Initializes the sortable list controller. - * - * @param {Object} options initialization options for `WCF.Sortable.List` */ - init: function (options) { + constructor(opts) { this._options = Core.extend({ - containerId: '', - className: '', + containerId: "", + className: "", offset: 0, options: {}, isSimpleSorting: false, - additionalParameters: {} - }, options); - UiScreen.on('screen-sm-md', { - match: this._enable.bind(this, true), - unmatch: this._disable.bind(this), - setup: this._enable.bind(this, true) + additionalParameters: {}, + }, opts); + UiScreen.on("screen-sm-md", { + match: () => this._enable(true), + unmatch: () => this._disable(), + setup: () => this._enable(true), }); - UiScreen.on('screen-lg', { - match: this._enable.bind(this, false), - unmatch: this._disable.bind(this), - setup: this._enable.bind(this, false) + UiScreen.on("screen-lg", { + match: () => this._enable(false), + unmatch: () => this._disable(), + setup: () => this._enable(false), }); - }, + } /** * Enables sorting with an optional sort handle. - * - * @param {boolean} hasHandle true if sort can only be started with the sort handle - * @protected */ - _enable: function (hasHandle) { - var options = this._options.options; - if (hasHandle) - options.handle = '.sortableNodeHandle'; + _enable(hasHandle) { + const options = this._options.options; + if (hasHandle) { + options.handle = ".sortableNodeHandle"; + } new window.WCF.Sortable.List(this._options.containerId, this._options.className, this._options.offset, options, this._options.isSimpleSorting, this._options.additionalParameters); - }, + } /** * Disables sorting for registered containers. - * - * @protected */ - _disable: function () { - window.jQuery('#' + this._options.containerId + ' .sortableList')[(this._options.isSimpleSorting ? 'sortable' : 'nestedSortable')]('destroy'); + _disable() { + window + .jQuery(`#${this._options.containerId} .sortableList`)[this._options.isSimpleSorting ? "sortable" : "nestedSortable"]("destroy"); } - }; + } + Core.enableLegacyInheritance(UiSortableList); return UiSortableList; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.js deleted file mode 100644 index 34974844ca..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.js +++ /dev/null @@ -1,86 +0,0 @@ -/** - * Sortable lists with optimized handling per device sizes. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Ui/Sortable/List - */ -define(['Core', 'Ui/Screen'], function (Core, UiScreen) { - "use strict"; - - if (!COMPILER_TARGET_DEFAULT) { - var Fake = function() {}; - Fake.prototype = { - init: function() {}, - _enable: function() {}, - _disable: function() {} - }; - return Fake; - } - - /** - * @constructor - */ - function UiSortableList(options) { this.init(options); } - UiSortableList.prototype = { - /** - * Initializes the sortable list controller. - * - * @param {Object} options initialization options for `WCF.Sortable.List` - */ - init: function (options) { - this._options = Core.extend({ - containerId: '', - className: '', - offset: 0, - options: {}, - isSimpleSorting: false, - additionalParameters: {} - }, options); - - UiScreen.on('screen-sm-md', { - match: this._enable.bind(this, true), - unmatch: this._disable.bind(this), - setup: this._enable.bind(this, true) - }); - - UiScreen.on('screen-lg', { - match: this._enable.bind(this, false), - unmatch: this._disable.bind(this), - setup: this._enable.bind(this, false) - }); - }, - - /** - * Enables sorting with an optional sort handle. - * - * @param {boolean} hasHandle true if sort can only be started with the sort handle - * @protected - */ - _enable: function (hasHandle) { - var options = this._options.options; - if (hasHandle) options.handle = '.sortableNodeHandle'; - - new window.WCF.Sortable.List( - this._options.containerId, - this._options.className, - this._options.offset, - options, - this._options.isSimpleSorting, - this._options.additionalParameters - ); - }, - - /** - * Disables sorting for registered containers. - * - * @protected - */ - _disable: function () { - window.jQuery('#' + this._options.containerId + ' .sortableList')[(this._options.isSimpleSorting ? 'sortable' : 'nestedSortable')]('destroy'); - } - }; - - return UiSortableList; -}); \ No newline at end of file diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.ts new file mode 100644 index 0000000000..8d9fff06ed --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Sortable/List.ts @@ -0,0 +1,89 @@ +/** + * Sortable lists with optimized handling per device sizes. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/Sortable/List + */ + +import * as Core from "../../Core"; +import * as UiScreen from "../Screen"; + +interface UnknownObject { + [key: string]: unknown; +} + +interface SortableListOptions { + containerId: string; + className: string; + offset: number; + options: UnknownObject; + isSimpleSorting: boolean; + additionalParameters: UnknownObject; +} + +class UiSortableList { + protected readonly _options: SortableListOptions; + + /** + * Initializes the sortable list controller. + */ + constructor(opts: Partial) { + this._options = Core.extend( + { + containerId: "", + className: "", + offset: 0, + options: {}, + isSimpleSorting: false, + additionalParameters: {}, + }, + opts + ) as SortableListOptions; + + UiScreen.on("screen-sm-md", { + match: () => this._enable(true), + unmatch: () => this._disable(), + setup: () => this._enable(true), + }); + + UiScreen.on("screen-lg", { + match: () => this._enable(false), + unmatch: () => this._disable(), + setup: () => this._enable(false), + }); + } + + /** + * Enables sorting with an optional sort handle. + */ + protected _enable(hasHandle: boolean): void { + const options = this._options.options; + if (hasHandle) { + options.handle = ".sortableNodeHandle"; + } + + new window.WCF.Sortable.List( + this._options.containerId, + this._options.className, + this._options.offset, + options, + this._options.isSimpleSorting, + this._options.additionalParameters + ); + } + + /** + * Disables sorting for registered containers. + */ + protected _disable(): void { + window + .jQuery(`#${this._options.containerId} .sortableList`) + [this._options.isSimpleSorting ? "sortable" : "nestedSortable"]("destroy"); + } +} + +Core.enableLegacyInheritance(UiSortableList); + +export = UiSortableList; -- 2.20.1