Commit 38eb1650 authored by Frank Nägler's avatar Frank Nägler Committed by Josef Glatz
Browse files

[TASK] Migrate TYPO3/CMS/RteCkeditor/* to TypeScript

Resolves: #87924
Releases: master
Change-Id: I50332d97fbbfa9b04f1a2d8de761aabe84b3c367
Reviewed-on: https://review.typo3.org/c/Packages/TYPO3.CMS/+/60260

Tested-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Tested-by: default avatarTYPO3com <noreply@typo3.com>
Tested-by: default avatarJosef Glatz <josefglatz@gmail.com>
Reviewed-by: Andreas Fernandez's avatarAndreas Fernandez <a.fernandez@scripting-base.de>
Reviewed-by: default avatarJosef Glatz <josefglatz@gmail.com>
parent a776d58d
/*
* 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); };
......@@ -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",
......
......@@ -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"
......
......@@ -10,107 +10,4 @@
*
* 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 editor = Modal.currentModal.data('ckeditor');
if (typeof editor !== 'undefined') {
RteLinkBrowser.CKEditor = editor;
} else {
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-class-selector').on('change', function() {
if ($('option:selected', this).data('linkTitle')) {
$('.t3js-linkTitle').val($('option:selected', this).data('linkTitle'));
}
});
$('.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","ckeditor"],function(t,e,i,n,r){"use strict";var o=new(function(){function t(){this.plugin=null,this.CKEditor=null,this.siteUrl=""}return t.prototype.initialize=function(e){var n=this,o=r.currentModal.data("ckeditor");if(void 0!==o)this.CKEditor=o;else{var a=void 0;a=void 0!==top.TYPO3.Backend&&void 0!==top.TYPO3.Backend.ContentContainer.get()?top.TYPO3.Backend.ContentContainer.get():window.parent,i.each(a.CKEDITOR.instances,function(t,i){i.id===e&&(n.CKEditor=i)})}i.extend(t,i("body").data()),i(".t3js-class-selector").on("change",function(){i("option:selected",n).data("linkTitle")&&i(".t3js-linkTitle").val(i("option:selected",n).data("linkTitle"))}),i(".t3js-removeCurrentLink").on("click",function(t){t.preventDefault(),n.CKEditor.execCommand("unlink"),r.dismiss()})},t.prototype.finalizeFunction=function(t){var e=this.CKEditor.document.createElement("a"),o=n.getLinkAttributeValues(),a=o.params?o.params:"";o.target&&e.setAttribute("target",o.target),o.class&&e.setAttribute("class",o.class),o.title&&e.setAttribute("title",o.title),delete o.title,delete o.class,delete o.target,delete o.params,i.each(o,function(t,i){e.setAttribute(t,i)}),e.setAttribute("href",t+a);var s=this.CKEditor.getSelection();s&&""===s.getSelectedText()&&s.selectElement(s.getStartElement()),s&&s.getSelectedText()?e.setText(s.getSelectedText()):e.setText(e.getAttribute("href")),this.CKEditor.insertElement(e),r.dismiss()},t}());return n.finalizeFunction=function(t){o.finalizeFunction(t)},o});
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment