[TASK] Port RteLinkBrowser to TypeScript 62/53062/6
authorJohannes Goslar <jogo@kronberger-spiele.de>
Fri, 2 Jun 2017 20:01:30 +0000 (22:01 +0200)
committerFrank Naegler <frank.naegler@typo3.org>
Sat, 17 Jun 2017 16:26:22 +0000 (18:26 +0200)
Resolves: #81444
Releases: master
Change-Id: I7247ef2c88ff60c484c3ca7ff0af48d3b8e72aac
Reviewed-on: https://review.typo3.org/53062
Tested-by: TYPO3com <no-reply@typo3.com>
Reviewed-by: Christian Kuhn <lolli@schwarzbu.ch>
Tested-by: Christian Kuhn <lolli@schwarzbu.ch>
Reviewed-by: Frank Naegler <frank.naegler@typo3.org>
Tested-by: Frank Naegler <frank.naegler@typo3.org>
Build/types/TYPO3/index.d.ts
typo3/sysext/rte_ckeditor/Resources/Private/TypeScript/RteLinkBrowser.ts [new file with mode: 0644]
typo3/sysext/rte_ckeditor/Resources/Public/JavaScript/RteLinkBrowser.js

index 87d5e16..ad98311 100644 (file)
@@ -31,6 +31,12 @@ declare namespace TYPO3 {
         public readonly: number;
       }
     }
+
+    export namespace RecordList {
+      export class LinkBrowser {
+        public getLinkAttributeValues(): {[key: string]: string};
+      }
+    }
   }
 }
 
@@ -54,6 +60,10 @@ declare module 'TYPO3/CMS/Backend/Severity' {
   export = new TYPO3.CMS.Backend.Severity();
 }
 
+declare module 'TYPO3/CMS/Recordlist/LinkBrowser' {
+  export = new TYPO3.CMS.RecordList.LinkBrowser();
+}
+
 // Type definition for global namespace object
 interface Window {
   TYPO3: any;
diff --git a/typo3/sysext/rte_ckeditor/Resources/Private/TypeScript/RteLinkBrowser.ts b/typo3/sysext/rte_ckeditor/Resources/Private/TypeScript/RteLinkBrowser.ts
new file mode 100644 (file)
index 0000000..4ff8fd8
--- /dev/null
@@ -0,0 +1,102 @@
+/*
+ * This file is part of the TYPO3 CMS project.
+ *
+ * It is free software; you can redistribute it and/or modify it under
+ * the terms of the GNU General Public License, either version 2
+ * of the License, or any later version.
+ *
+ * For the full copyright and license information, please read the
+ * LICENSE.txt file that was distributed with this source code.
+ *
+ * The TYPO3 project - inspiring people to share!
+ */
+
+/**
+ * Module: TYPO3/CMS/RteCkeditor/RteLinkBrowser
+ * LinkBrowser communication with parent window
+ */
+import $ = require('jquery');
+import LinkBrowser = require('TYPO3/CMS/Recordlist/LinkBrowser');
+import Modal = require('TYPO3/CMS/Backend/Modal');
+
+class RteLinkBrowser {
+  private plugin: any = null;
+
+  private CKEditor: CKEDITOR.editor = null;
+
+  private siteUrl = '';
+
+  /**
+   * @param {string} editorId Id of CKEditor
+   */
+  public initialize(editorId: string): void {
+    let callerWindow: Window;
+    if (typeof top.TYPO3.Backend !== 'undefined' && typeof top.TYPO3.Backend.ContentContainer.get() !== 'undefined') {
+      callerWindow = top.TYPO3.Backend.ContentContainer.get();
+    } else {
+      callerWindow = window.parent;
+    }
+
+    $.each((callerWindow as any).CKEDITOR.instances, (name: string, editor: CKEDITOR.editor) => {
+      if (editor.id === editorId) {
+        this.CKEditor = editor;
+      }
+    });
+
+    // siteUrl etc are added as data attributes to the body tag
+    $.extend(RteLinkBrowser, $('body').data());
+
+    $('.t3js-removeCurrentLink').on('click', (event: Event) => {
+      event.preventDefault();
+      this.CKEditor.execCommand('unlink');
+      Modal.dismiss();
+    });
+  }
+
+  /**
+   * Store the final link
+   *
+   * @param {stringify} link The select element or anything else which identifies
+   * the link (e.g. "page:<pageUid>" or "file:<uid>")
+   */
+  public finalizeFunction(link: string): void {
+    const linkElement: CKEDITOR.dom.element = this.CKEditor.document.createElement('a');
+    const attributes = LinkBrowser.getLinkAttributeValues();
+    const params: string = attributes.params ? attributes.params : '';
+
+    if (attributes.target) {
+      linkElement.setAttribute('target', attributes.target);
+    }
+    if (attributes.class) {
+      linkElement.setAttribute('class', attributes.class);
+    }
+    if (attributes.title) {
+      linkElement.setAttribute('title', attributes.title);
+    }
+    delete attributes.title;
+    delete attributes.class;
+    delete attributes.target;
+    delete attributes.params;
+
+    $.each(attributes, (attrName: string, attrValue: string) => {
+      linkElement.setAttribute(attrName, attrValue);
+    });
+
+    linkElement.setAttribute('href', link + params);
+
+    const selection: CKEDITOR.dom.selection = this.CKEditor.getSelection();
+    if (selection && selection.getSelectedText() === '') {
+      selection.selectElement(selection.getStartElement());
+    }
+    if (selection && selection.getSelectedText()) {
+      linkElement.setText(selection.getSelectedText());
+    } else {
+      linkElement.setText(linkElement.getAttribute('href'));
+    }
+    this.CKEditor.insertElement(linkElement);
+
+    Modal.dismiss();
+  }
+}
+
+export = new RteLinkBrowser();
index e59c571..a0a4200 100644 (file)
  *
  * The TYPO3 project - inspiring people to share!
  */
-
-/**
- * Module: TYPO3/CMS/RteCkeditor/RteLinkBrowser
- * LinkBrowser communication with parent window
- */
-define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser', 'TYPO3/CMS/Backend/Modal'], function ($, LinkBrowser, Modal) {
-       'use strict';
-
-       /**
-        *
-        * @type {{plugin: null, CKEditor: null, siteUrl: string}}
-        * @exports TYPO3/CMS/RteCkeditor/RteLinkBrowser
-        */
-       var RteLinkBrowser = {
-               plugin: null,
-               CKEditor: null,
-               siteUrl: ''
-       };
-
-       /**
-        * @param {String} editorId Id of CKEditor
-        */
-       RteLinkBrowser.initialize = function (editorId) {
-               var callerWindow;
-               if (typeof top.TYPO3.Backend !== 'undefined' && typeof top.TYPO3.Backend.ContentContainer.get() !== 'undefined') {
-                       callerWindow = top.TYPO3.Backend.ContentContainer.get();
-               } else {
-                       callerWindow = window.parent;
-               }
-
-               $.each(callerWindow.CKEDITOR.instances, function (name, editor) {
-                       if (editor.id === editorId) {
-                               RteLinkBrowser.CKEditor = editor;
-                       }
-               });
-
-               // siteUrl etc are added as data attributes to the body tag
-               $.extend(RteLinkBrowser, $('body').data());
-
-               $('.t3js-removeCurrentLink').on('click', function (event) {
-                       event.preventDefault();
-                       RteLinkBrowser.CKEditor.execCommand('unlink');
-                       Modal.dismiss();
-               });
-       };
-
-       /**
-        * Store the final link
-        *
-        * @param {String} link The select element or anything else which identifies the link (e.g. "page:<pageUid>" or "file:<uid>")
-        */
-       LinkBrowser.finalizeFunction = function (link) {
-
-               var linkElement = RteLinkBrowser.CKEditor.document.createElement('a');
-               var attributes = LinkBrowser.getLinkAttributeValues();
-               var params = attributes.params ? attributes.params : '';
-
-               if (attributes.target) {
-                       linkElement.setAttribute('target', attributes.target);
-               }
-               if (attributes.class) {
-                       linkElement.setAttribute('class', attributes.class);
-               }
-               if (attributes.title) {
-                       linkElement.setAttribute('title', attributes.title);
-               }
-               delete attributes.title;
-               delete attributes.class;
-               delete attributes.target;
-               delete attributes.params;
-
-               $.each(attributes, function (attrName, attrValue) {
-                       linkElement.setAttribute(attrName, attrValue);
-               });
-
-               linkElement.setAttribute('href', link + params);
-
-               var selection = RteLinkBrowser.CKEditor.getSelection();
-               if (selection && selection.getSelectedText() === '') {
-                       selection.selectElement(selection.getStartElement());
-               }
-               if (selection && selection.getSelectedText()) {
-                       linkElement.setText(selection.getSelectedText());
-               } else {
-                       linkElement.setText(linkElement.getAttribute('href'));
-               }
-               RteLinkBrowser.CKEditor.insertElement(linkElement);
-
-               Modal.dismiss();
-       };
-
-       return RteLinkBrowser;
+define(["require", "exports", "jquery", "TYPO3/CMS/Recordlist/LinkBrowser", "TYPO3/CMS/Backend/Modal"], function (require, exports, $, LinkBrowser, Modal) {
+    "use strict";
+    var RteLinkBrowser = (function () {
+        function RteLinkBrowser() {
+            this.plugin = null;
+            this.CKEditor = null;
+            this.siteUrl = '';
+        }
+        /**
+         * @param {string} editorId Id of CKEditor
+         */
+        RteLinkBrowser.prototype.initialize = function (editorId) {
+            var _this = this;
+            var callerWindow;
+            if (typeof top.TYPO3.Backend !== 'undefined' && typeof top.TYPO3.Backend.ContentContainer.get() !== 'undefined') {
+                callerWindow = top.TYPO3.Backend.ContentContainer.get();
+            }
+            else {
+                callerWindow = window.parent;
+            }
+            $.each(callerWindow.CKEDITOR.instances, function (name, editor) {
+                if (editor.id === editorId) {
+                    _this.CKEditor = editor;
+                }
+            });
+            // siteUrl etc are added as data attributes to the body tag
+            $.extend(RteLinkBrowser, $('body').data());
+            $('.t3js-removeCurrentLink').on('click', function (event) {
+                event.preventDefault();
+                _this.CKEditor.execCommand('unlink');
+                Modal.dismiss();
+            });
+        };
+        /**
+         * Store the final link
+         *
+         * @param {stringify} link The select element or anything else which identifies
+         * the link (e.g. "page:<pageUid>" or "file:<uid>")
+         */
+        RteLinkBrowser.prototype.finalizeFunction = function (link) {
+            var linkElement = this.CKEditor.document.createElement('a');
+            var attributes = LinkBrowser.getLinkAttributeValues();
+            var params = attributes.params ? attributes.params : '';
+            if (attributes.target) {
+                linkElement.setAttribute('target', attributes.target);
+            }
+            if (attributes.class) {
+                linkElement.setAttribute('class', attributes.class);
+            }
+            if (attributes.title) {
+                linkElement.setAttribute('title', attributes.title);
+            }
+            delete attributes.title;
+            delete attributes.class;
+            delete attributes.target;
+            delete attributes.params;
+            $.each(attributes, function (attrName, attrValue) {
+                linkElement.setAttribute(attrName, attrValue);
+            });
+            linkElement.setAttribute('href', link + params);
+            var selection = this.CKEditor.getSelection();
+            if (selection && selection.getSelectedText() === '') {
+                selection.selectElement(selection.getStartElement());
+            }
+            if (selection && selection.getSelectedText()) {
+                linkElement.setText(selection.getSelectedText());
+            }
+            else {
+                linkElement.setText(linkElement.getAttribute('href'));
+            }
+            this.CKEditor.insertElement(linkElement);
+            Modal.dismiss();
+        };
+        return RteLinkBrowser;
+    }());
+    return new RteLinkBrowser();
 });