From c17ad0f0d5601051cab6628969c9f01cd2bc4168 Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Thu, 5 Nov 2020 00:20:59 +0100 Subject: [PATCH] Convert `Ui/Redactor/Page` to TypeScript --- .../js/WoltLabSuite/Core/Ui/Redactor/Page.js | 43 ++++++++---------- .../ts/WoltLabSuite/Core/Ui/Redactor/Page.js | 44 ------------------- .../ts/WoltLabSuite/Core/Ui/Redactor/Page.ts | 38 ++++++++++++++++ 3 files changed, 56 insertions(+), 69 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Page.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Page.js index cfae93e7f4..54cd720940 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Page.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Page.js @@ -1,36 +1,29 @@ /** * Converts `` into the bbcode representation. * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Ui/Redactor/Page + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/Redactor/Page */ -define(['WoltLabSuite/Core/Ui/Page/Search'], function (UiPageSearch) { +define(["require", "exports", "tslib", "../../Core", "../Page/Search"], function (require, exports, tslib_1, Core, UiPageSearch) { "use strict"; - if (!COMPILER_TARGET_DEFAULT) { - var Fake = function () { }; - Fake.prototype = { - init: function () { }, - _click: function () { }, - _insert: function () { } - }; - return Fake; - } - function UiRedactorPage(editor, button) { this.init(editor, button); } - UiRedactorPage.prototype = { - init: function (editor, button) { + Core = tslib_1.__importStar(Core); + UiPageSearch = tslib_1.__importStar(UiPageSearch); + class UiRedactorPage { + constructor(editor, button) { this._editor = editor; - button.addEventListener('click', this._click.bind(this)); - }, - _click: function (event) { + button.addEventListener("click", (ev) => this._click(ev)); + } + _click(event) { event.preventDefault(); - UiPageSearch.open(this._insert.bind(this)); - }, - _insert: function (pageID) { + UiPageSearch.open((pageId) => this._insert(pageId)); + } + _insert(pageId) { this._editor.buffer.set(); - this._editor.insert.text("[wsp='" + pageID + "'][/wsp]"); + this._editor.insert.text(`[wsp='${pageId}'][/wsp]`); } - }; + } + Core.enableLegacyInheritance(UiRedactorPage); return UiRedactorPage; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.js deleted file mode 100644 index 2ba6bd9a6f..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.js +++ /dev/null @@ -1,44 +0,0 @@ -/** - * Converts `` into the bbcode representation. - * - * @author Alexander Ebert - * @copyright 2001-2019 WoltLab GmbH - * @license GNU Lesser General Public License - * @module WoltLabSuite/Core/Ui/Redactor/Page - */ -define(['WoltLabSuite/Core/Ui/Page/Search'], function(UiPageSearch) { - "use strict"; - - if (!COMPILER_TARGET_DEFAULT) { - var Fake = function() {}; - Fake.prototype = { - init: function() {}, - _click: function() {}, - _insert: function() {} - }; - return Fake; - } - - function UiRedactorPage(editor, button) { this.init(editor, button); } - UiRedactorPage.prototype = { - init: function (editor, button) { - this._editor = editor; - - button.addEventListener('click', this._click.bind(this)); - }, - - _click: function (event) { - event.preventDefault(); - - UiPageSearch.open(this._insert.bind(this)); - }, - - _insert: function (pageID) { - this._editor.buffer.set(); - - this._editor.insert.text("[wsp='" + pageID + "'][/wsp]"); - } - }; - - return UiRedactorPage; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.ts new file mode 100644 index 0000000000..8a8c5be374 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.ts @@ -0,0 +1,38 @@ +/** + * Converts `` into the bbcode representation. + * + * @author Alexander Ebert + * @copyright 2001-2019 WoltLab GmbH + * @license GNU Lesser General Public License + * @module WoltLabSuite/Core/Ui/Redactor/Page + */ + +import * as Core from "../../Core"; +import * as UiPageSearch from "../Page/Search"; +import { RedactorEditor } from "./Editor"; + +class UiRedactorPage { + protected _editor: RedactorEditor; + + constructor(editor: RedactorEditor, button: HTMLAnchorElement) { + this._editor = editor; + + button.addEventListener("click", (ev) => this._click(ev)); + } + + protected _click(event: MouseEvent): void { + event.preventDefault(); + + UiPageSearch.open((pageId) => this._insert(pageId)); + } + + protected _insert(pageId: string): void { + this._editor.buffer.set(); + + this._editor.insert.text(`[wsp='${pageId}'][/wsp]`); + } +} + +Core.enableLegacyInheritance(UiRedactorPage); + +export = UiRedactorPage; -- 2.20.1