Skip to content

Commit

Permalink
[TASK] Migrate TYPO3/CMS/RteCkeditor/* to TypeScript
Browse files Browse the repository at this point in the history
Resolves: #87924
Releases: master
Change-Id: I50332d97fbbfa9b04f1a2d8de761aabe84b3c367
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60260
Tested-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: TYPO3com <noreply@typo3.com>
Tested-by: Josef Glatz <josefglatz@gmail.com>
Reviewed-by: Andreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: Josef Glatz <josefglatz@gmail.com>
  • Loading branch information
NeoBlack authored and josefglatz committed May 10, 2019
1 parent a776d58 commit 38eb165
Show file tree
Hide file tree
Showing 4 changed files with 119 additions and 109 deletions.
@@ -0,0 +1,113 @@
/*
* 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!
*/

import * as $ from 'jquery';
import LinkBrowser = require('TYPO3/CMS/Recordlist/LinkBrowser');
import 'ckeditor';
import Modal = require('TYPO3/CMS/Backend/Modal');

/**
* Module: TYPO3/CMS/RteCkeditor/RteLinkBrowser
* LinkBrowser communication with parent window
*/
class RteLinkBrowser {
protected plugin: any = null;
protected CKEditor: CKEDITOR.editor = null;
protected siteUrl: string = '';

/**
* @param {String} editorId Id of CKEditor
*/
public initialize(editorId: string): void {
let editor: CKEDITOR.editor = Modal.currentModal.data('ckeditor');
if (typeof editor !== 'undefined') {
this.CKEditor = editor;
} else {
let 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, (name: number, instance: any): void => {
if (instance.id === editorId) {
this.CKEditor = instance;
}
});
}

// siteUrl etc are added as data attributes to the body tag
$.extend(RteLinkBrowser, $('body').data());

$('.t3js-class-selector').on('change', (): void => {
if ($('option:selected', this).data('linkTitle')) {
$('.t3js-linkTitle').val($('option:selected', this).data('linkTitle'));
}
});

$('.t3js-removeCurrentLink').on('click', (event: JQueryEventObject): void => {
event.preventDefault();
this.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>")
*/
public finalizeFunction(link: string): void {
const linkElement = this.CKEditor.document.createElement('a');
const attributes = LinkBrowser.getLinkAttributeValues();
const 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, (attrName: string, attrValue: string): void => {
linkElement.setAttribute(attrName, attrValue);
});

linkElement.setAttribute('href', link + params);

const 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();
}
}

let rteLinkBrowser = new RteLinkBrowser();
export = rteLinkBrowser;
LinkBrowser.finalizeFunction = (link: string): void => { rteLinkBrowser.finalizeFunction(link); };
2 changes: 1 addition & 1 deletion Build/package.json
Expand Up @@ -16,7 +16,7 @@
"@types/bootstrap": "^3.3.34",
"@types/chosen-js": "^1.8.1",
"@types/chrome": "^0.0.69",
"@types/ckeditor": "4.9.1",
"@types/ckeditor": "^4.9.8",
"@types/datatables.net": "^1.10.17",
"@types/imagesloaded": "^4.1.1",
"@types/jasmine": "^2.5.53",
Expand Down
8 changes: 4 additions & 4 deletions Build/yarn.lock
Expand Up @@ -30,10 +30,10 @@
dependencies:
"@types/filesystem" "*"

"@types/ckeditor@4.9.1":
version "4.9.1"
resolved "https://registry.yarnpkg.com/@types/ckeditor/-/ckeditor-4.9.1.tgz#d8e81fb840c3f248772ab90efd508b6061cbd138"
integrity sha512-32BCMWLSSSkBKXf57cN/1Xv7VKXNOKXW5YPo3D2igCaevDAiiVtuMwPOFzOeO+5/CkGd4zt/Rf9RXl1J/vUsRA==
"@types/ckeditor@^4.9.8":
version "4.9.8"
resolved "https://registry.yarnpkg.com/@types/ckeditor/-/ckeditor-4.9.8.tgz#2585bfea409c0d9e970d04611fb22726c6a6d219"
integrity sha512-UM2t8mRul1vT/Al3c1L5elal925YstzcBQHLHk+hVvEoFOUkQKokePnGgD1L7K9n4h3hoPDDwc5jEKeUU3UxMw==

"@types/datatables.net@^1.10.17":
version "1.10.17"
Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 38eb165

Please sign in to comment.