a0a42005c095d2f010c2b42df6b82a46e2e27811
[Packages/TYPO3.CMS.git] / typo3 / sysext / rte_ckeditor / Resources / Public / JavaScript / RteLinkBrowser.js
1 /*
2 * This file is part of the TYPO3 CMS project.
3 *
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.
7 *
8 * For the full copyright and license information, please read the
9 * LICENSE.txt file that was distributed with this source code.
10 *
11 * The TYPO3 project - inspiring people to share!
12 */
13 define(["require", "exports", "jquery", "TYPO3/CMS/Recordlist/LinkBrowser", "TYPO3/CMS/Backend/Modal"], function (require, exports, $, LinkBrowser, Modal) {
14 "use strict";
15 var RteLinkBrowser = (function () {
16 function RteLinkBrowser() {
17 this.plugin = null;
18 this.CKEditor = null;
19 this.siteUrl = '';
20 }
21 /**
22 * @param {string} editorId Id of CKEditor
23 */
24 RteLinkBrowser.prototype.initialize = function (editorId) {
25 var _this = this;
26 var callerWindow;
27 if (typeof top.TYPO3.Backend !== 'undefined' && typeof top.TYPO3.Backend.ContentContainer.get() !== 'undefined') {
28 callerWindow = top.TYPO3.Backend.ContentContainer.get();
29 }
30 else {
31 callerWindow = window.parent;
32 }
33 $.each(callerWindow.CKEDITOR.instances, function (name, editor) {
34 if (editor.id === editorId) {
35 _this.CKEditor = editor;
36 }
37 });
38 // siteUrl etc are added as data attributes to the body tag
39 $.extend(RteLinkBrowser, $('body').data());
40 $('.t3js-removeCurrentLink').on('click', function (event) {
41 event.preventDefault();
42 _this.CKEditor.execCommand('unlink');
43 Modal.dismiss();
44 });
45 };
46 /**
47 * Store the final link
48 *
49 * @param {stringify} link The select element or anything else which identifies
50 * the link (e.g. "page:<pageUid>" or "file:<uid>")
51 */
52 RteLinkBrowser.prototype.finalizeFunction = function (link) {
53 var linkElement = this.CKEditor.document.createElement('a');
54 var attributes = LinkBrowser.getLinkAttributeValues();
55 var params = attributes.params ? attributes.params : '';
56 if (attributes.target) {
57 linkElement.setAttribute('target', attributes.target);
58 }
59 if (attributes.class) {
60 linkElement.setAttribute('class', attributes.class);
61 }
62 if (attributes.title) {
63 linkElement.setAttribute('title', attributes.title);
64 }
65 delete attributes.title;
66 delete attributes.class;
67 delete attributes.target;
68 delete attributes.params;
69 $.each(attributes, function (attrName, attrValue) {
70 linkElement.setAttribute(attrName, attrValue);
71 });
72 linkElement.setAttribute('href', link + params);
73 var selection = this.CKEditor.getSelection();
74 if (selection && selection.getSelectedText() === '') {
75 selection.selectElement(selection.getStartElement());
76 }
77 if (selection && selection.getSelectedText()) {
78 linkElement.setText(selection.getSelectedText());
79 }
80 else {
81 linkElement.setText(linkElement.getAttribute('href'));
82 }
83 this.CKEditor.insertElement(linkElement);
84 Modal.dismiss();
85 };
86 return RteLinkBrowser;
87 }());
88 return new RteLinkBrowser();
89 });