Convert `Ui/Redactor/Page` to TypeScript
authorAlexander Ebert <ebert@woltlab.com>
Wed, 4 Nov 2020 23:20:59 +0000 (00:20 +0100)
committerAlexander Ebert <ebert@woltlab.com>
Wed, 4 Nov 2020 23:20:59 +0000 (00:20 +0100)
wcfsetup/install/files/js/WoltLabSuite/Core/Ui/Redactor/Page.js
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.js [deleted file]
wcfsetup/install/files/ts/WoltLabSuite/Core/Ui/Redactor/Page.ts [new file with mode: 0644]

index cfae93e7f4f1b65bf7f8b065ebfa856f24d3ad39..54cd720940446d9a73da144ebfa99563c9956d22 100644 (file)
@@ -1,36 +1,29 @@
 /**
  * Converts `<woltlab-metacode>` into the bbcode representation.
  *
- * @author     Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @module     WoltLabSuite/Core/Ui/Redactor/Page
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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 (file)
index 2ba6bd9..0000000
+++ /dev/null
@@ -1,44 +0,0 @@
-/**
- * Converts `<woltlab-metacode>` into the bbcode representation.
- *
- * @author     Alexander Ebert
- * @copyright  2001-2019 WoltLab GmbH
- * @license    GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
- * @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 (file)
index 0000000..8a8c5be
--- /dev/null
@@ -0,0 +1,38 @@
+/**
+ * Converts `<woltlab-metacode>` into the bbcode representation.
+ *
+ * @author  Alexander Ebert
+ * @copyright  2001-2019 WoltLab GmbH
+ * @license  GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
+ * @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;