a7d2a45d5f75142030be9b25c9124c86c7ce492a
[Packages/TYPO3.CMS.git] / typo3 / sysext / rtehtmlarea / 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
14 /**
15 * Module: TYPO3/CMS/Rtehtmlarea/RteLinkBrowser
16 * LinkBrowser communication with parent window
17 */
18 define(['jquery', 'TYPO3/CMS/Recordlist/LinkBrowser'], function($, LinkBrowser) {
19 'use strict';
20
21 /**
22 *
23 * @type {{plugin: null, HTMLArea: null, siteUrl: string, defaultLinkTarget: string}}
24 * @exports TYPO3/CMS/Rtehtmlarea/RteLinkBrowser
25 */
26 var RteLinkBrowser = {
27 plugin: null,
28 HTMLArea: null,
29 siteUrl: '',
30 defaultLinkTarget: ''
31 };
32
33 RteLinkBrowser.changeClassSelector = function() {
34 if (document.lclassform.lclass) {
35 document.lclassform.lclass.value = document.lclassform.lclass.options[document.lclassform.lclass.selectedIndex].value;
36 if (document.lclassform.lclass.value && RteLinkBrowser.HTMLArea.classesAnchorSetup) {
37 for (var i = RteLinkBrowser.HTMLArea.classesAnchorSetup.length; --i >= 0;) {
38 var anchorClass = RteLinkBrowser.HTMLArea.classesAnchorSetup[i];
39 if (anchorClass['name'] === document.lclassform.lclass.value) {
40 if (anchorClass['titleText'] && document.ltitleform.ltitle) {
41 document.ltitleform.ltitle.value = anchorClass['titleText'];
42 document.getElementById('rtehtmlarea-browse-links-title-readonly').innerHTML = anchorClass['titleText'];
43 }
44 if (typeof anchorClass['target'] !== 'undefined') {
45 if (document.ltargetform.ltarget) {
46 document.ltargetform.ltarget.value = anchorClass['target'];
47 }
48 } else if (document.ltargetform.ltarget && document.getElementById('ltargetrow').style.display === 'none') {
49 // Reset target to default if field is not displayed and class has no configured target
50 document.ltargetform.ltarget.value = RteLinkBrowser.defaultLinkTarget;
51 }
52 break;
53 }
54
55 }
56 }
57 }
58 };
59
60 RteLinkBrowser.handleRelAttrib = function() {
61 // @todo The rel field can be handled as a normal link attribute, at least lets check for that.
62 LinkBrowser.setAdditionalLinkAttribute('rel', '');
63 };
64
65 /**
66 *
67 */
68 RteLinkBrowser.initialize = function() {
69 var callerWindow;
70 if (typeof top.TYPO3.Backend !== 'undefined' && typeof top.TYPO3.Backend.ContentContainer.get() !== 'undefined') {
71 callerWindow = top.TYPO3.Backend.ContentContainer.get();
72 } else {
73 callerWindow = window.parent;
74 }
75 RteLinkBrowser.plugin = callerWindow.RTEarea[LinkBrowser.urlParameters.editorNo].editor.getPlugin("TYPO3Link");
76 RteLinkBrowser.HTMLArea = callerWindow.HTMLArea;
77
78 $.extend(RteLinkBrowser, $('body').data());
79
80 $('.t3js-removeCurrentLink').on('click', function(event) {
81 event.preventDefault();
82 RteLinkBrowser.plugin.unLink();
83 });
84
85 $('.t3js-class-selector').on('change', RteLinkBrowser.changeClassSelector);
86 };
87
88 LinkBrowser.finalizeFunction = function(input) {
89 var attributes = LinkBrowser.getLinkAttributeValues();
90 var curTitle = attributes.title ? attributes.title : '';
91 var curClass = attributes.class ? attributes.class : '';
92 var curTarget = attributes.target ? attributes.target : '';
93 var curParams = attributes.params ? attributes.params : '';
94 delete attributes.title;
95 delete attributes.class;
96 delete attributes.target;
97 delete attributes.params;
98
99 // replace page: prefix
100 if (input.indexOf('page:') === 0) {
101 input = 'id=' + input.substr(5);
102 }
103
104 // if there is no handler keyword (mailto:, record:, etc) or an external link, we always prepend the siteUrl
105 if (!/^\w+:/.test(input) && !attributes['data-htmlarea-external']) {
106 input = RteLinkBrowser.siteUrl + '?' + input;
107 }
108
109 RteLinkBrowser.plugin.createLink(
110 input + curParams,
111 curTarget,
112 curClass,
113 curTitle,
114 attributes
115 );
116 };
117
118 $(RteLinkBrowser.initialize);
119
120 return RteLinkBrowser;
121 });