From d2290f70106dc5a09385d3eafd8c60729ae9925d Mon Sep 17 00:00:00 2001 From: Alexander Ebert Date: Sat, 2 Jan 2021 16:36:11 +0100 Subject: [PATCH] Convert `Acp/Ui/CodeMirror/Page` --- .../Core/Acp/Ui/CodeMirror/Page.js | 29 ++++++++++--------- .../Core/Acp/Ui/CodeMirror/Page.js | 24 --------------- .../Core/Acp/Ui/CodeMirror/Page.ts | 27 +++++++++++++++++ 3 files changed, 43 insertions(+), 37 deletions(-) delete mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js create mode 100644 wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.ts diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js index 236aeaa097..a765c33cf2 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js @@ -1,18 +1,21 @@ -define(['WoltLabSuite/Core/Ui/Page/Search'], function (UiPageSearch) { +define(["require", "exports", "tslib", "../../../Core", "../../../Ui/Page/Search"], function (require, exports, tslib_1, Core, UiPageSearch) { "use strict"; - function AcpUiCodeMirrorPage(elementId) { this.init(elementId); } - AcpUiCodeMirrorPage.prototype = { - init: function (elementId) { - this._element = elById(elementId); - elById('codemirror-' + elementId + '-page').addEventListener('click', this._click.bind(this)); - }, - _click: function (event) { + Core = tslib_1.__importStar(Core); + UiPageSearch = tslib_1.__importStar(UiPageSearch); + class AcpUiCodeMirrorPage { + constructor(elementId) { + this.element = document.getElementById(elementId); + const insertButton = document.getElementById(`codemirror-${elementId}-page`); + insertButton.addEventListener("click", (ev) => this._click(ev)); + } + _click(event) { event.preventDefault(); - UiPageSearch.open(this._insert.bind(this)); - }, - _insert: function (pageID) { - this._element.codemirror.replaceSelection('{{ page="' + pageID + '" }}'); + UiPageSearch.open((pageID) => this._insert(pageID)); + } + _insert(pageID) { + this.element.codemirror.replaceSelection(`{{ page="${pageID}" }}`); } - }; + } + Core.enableLegacyInheritance(AcpUiCodeMirrorPage); return AcpUiCodeMirrorPage; }); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js deleted file mode 100644 index a85dfc8ce2..0000000000 --- a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.js +++ /dev/null @@ -1,24 +0,0 @@ -define(['WoltLabSuite/Core/Ui/Page/Search'], function(UiPageSearch) { - "use strict"; - - function AcpUiCodeMirrorPage(elementId) { this.init(elementId); } - AcpUiCodeMirrorPage.prototype = { - init: function(elementId) { - this._element = elById(elementId); - - elById('codemirror-' + elementId + '-page').addEventListener('click', this._click.bind(this)); - }, - - _click: function (event) { - event.preventDefault(); - - UiPageSearch.open(this._insert.bind(this)); - }, - - _insert: function (pageID) { - this._element.codemirror.replaceSelection('{{ page="' + pageID + '" }}'); - } - }; - - return AcpUiCodeMirrorPage; -}); diff --git a/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.ts b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.ts new file mode 100644 index 0000000000..90f753f1c3 --- /dev/null +++ b/wcfsetup/install/files/ts/WoltLabSuite/Core/Acp/Ui/CodeMirror/Page.ts @@ -0,0 +1,27 @@ +import * as Core from "../../../Core"; +import * as UiPageSearch from "../../../Ui/Page/Search"; + +class AcpUiCodeMirrorPage { + private element: HTMLElement; + + constructor(elementId: string) { + this.element = document.getElementById(elementId)!; + + const insertButton = document.getElementById(`codemirror-${elementId}-page`)!; + insertButton.addEventListener("click", (ev) => this._click(ev)); + } + + private _click(event: MouseEvent): void { + event.preventDefault(); + + UiPageSearch.open((pageID) => this._insert(pageID)); + } + + _insert(pageID: string): void { + (this.element as any).codemirror.replaceSelection(`{{ page="${pageID}" }}`); + } +} + +Core.enableLegacyInheritance(AcpUiCodeMirrorPage); + +export = AcpUiCodeMirrorPage; -- 2.20.1