2 * This file is part of the TYPO3 CMS project.
4 * It is free software; you can redistribute it and/or modify it under
5 * the terms of the GNU General Public License, either version 2
6 * of the License, or any later version.
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
11 * The TYPO3 project - inspiring people to share!
18 CKEDITOR
.plugins
.add('typo3link', {
20 init
: function(editor
) {
21 var allowedAttributes
= ['!href', 'title', 'class', 'target', 'rel'],
24 var additionalAttributes
= getAdditionalAttributes(editor
);
25 if (additionalAttributes
.length
) {
26 allowedAttributes
.push
.apply(allowedAttributes
, additionalAttributes
);
29 // Override link command
30 editor
.addCommand('link', {
31 exec
: openLinkBrowser
,
32 allowedContent
: 'a[' + allowedAttributes
.join(',') + ']',
33 requiredContent
: required
36 // Override doubleclick opening default link dialog
37 editor
.on('doubleclick', function(evt
) {
38 var element
= CKEDITOR
.plugins
.link
.getSelectedLink(editor
) || evt
.data
.element
;
39 if (!element
.isReadOnly() && element
.is('a') && element
.getAttribute('href')) {
41 openLinkBrowser(editor
, element
);
51 * @param {Object} editor CKEditor object
52 * @param {Object} element Selected link element
54 function openLinkBrowser(editor
, element
) {
55 var additionalParameters
= '';
57 if ($.isEmptyObject(element
)) {
58 element
= CKEDITOR
.plugins
.link
.getSelectedLink(editor
);
61 additionalParameters
= '&P[curUrl][url]=' + encodeURIComponent(element
.getAttribute('href'));
63 attributeNames
= ["target", "class", "title", "rel"];
64 for (i
= 0; i
< attributeNames
.length
; ++i
) {
65 if (element
.getAttribute(attributeNames
[i
])) {
66 additionalParameters
+= '&P[curUrl][' + attributeNames
[i
] + ']=';
67 additionalParameters
+= encodeURIComponent(element
.getAttribute(attributeNames
[i
]));
71 var additionalAttributes
= getAdditionalAttributes(editor
);
72 for (i
= additionalAttributes
.length
; --i
>= 0;) {
73 if (element
.hasAttribute(additionalAttributes
[i
])) {
74 additionalParameters
+= '&P[curUrl][' + additionalAttributes
[i
] + ']=';
75 additionalParameters
+= encodeURIComponent(element
.getAttribute(additionalAttributes
[i
]));
82 editor
.lang
.link
.toolbar
,
83 TYPO3
.settings
.Textarea
.RTEPopupWindow
.height
,
84 makeUrlFromModulePath(
86 editor
.config
.typo3link
.routeUrl
,
94 * @param {Object} editor CKEditor object
95 * @param {String} routeUrl URL
96 * @param {String} parameters Additional parameters
98 * @return {String} The url
100 function makeUrlFromModulePath(editor
, routeUrl
, parameters
) {
103 + (routeUrl
.indexOf('?') === -1 ? '?' : '&')
104 + '&contentsLanguage=' + editor
.config
.contentsLanguage
105 + '&editorId=' + editor
.id
106 + (parameters
? parameters
: '');
110 * Open a window with container iframe
112 * @param {Object} editor The CKEditor instance
113 * @param {String} title The window title (will be localized here)
114 * @param {Integer} height The height of the containing iframe
115 * @param {String} url The url to load ino the iframe
117 function openElementBrowser(editor
, title
, height
, url
) {
120 'TYPO3/CMS/Backend/Modal'
121 ], function($, Modal
) {
124 type
: Modal
.types
.iframe
,
127 size
: Modal
.sizes
.large
,
128 callback
: function(currentModal
) {
129 // Add the instance to the iframe itself
130 currentModal
.data('ckeditor', editor
);
131 currentModal
.find('.t3js-modal-body')
132 .addClass('rte-ckeditor-window')
133 .attr('id', editor
.id
);
140 * Fetch attributes for the <a> tag which are allowed additionally
141 * @param {Object} editor The CKEditor instance
143 * @return {Array} registered attributes available for the link
145 function getAdditionalAttributes(editor
) {
146 if (editor
.config
.typo3link
.additionalAttributes
&& editor
.config
.typo3link
.additionalAttributes
.length
) {
147 return editor
.config
.typo3link
.additionalAttributes
;