2
* FCKeditor - The text editor for internet
3
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
5
* Licensed under the terms of the GNU Lesser General Public License:
6
* http://www.opensource.org/licenses/lgpl-license.php
8
* For further information visit:
9
* http://www.fckeditor.net/
11
* File Name: fck_link.js
12
* Scripts related to the Link dialog window (see fck_link.html).
14
* Version: 2.0 FC (Preview)
15
* Modified: 2005-03-12 15:16:39
18
* Frederico Caldeira Knabben (fredck@fckeditor.net)
21
var dialog = window.parent ;
22
var oEditor = dialog.InnerDialogLoaded();
23
var FCK = oEditor.FCK;
24
var FCKLang = oEditor.FCKLang;
25
var FCKConfig = oEditor.FCKConfig;
26
var isNameRelatedLink = false;
30
// Set the dialog tabs.
31
window.parent.AddTab('Info', FCKLang.DlgLnkInfoTab);
33
// Function called when a dialog tag is selected.
34
function OnDialogTabChange(tabCode)
36
ShowE('divInfo' , (tabCode == 'Info'));
39
// Extends the String object, creating a "EndsWith" method on it.
40
// this method is part of fckeditor dialog common library
41
String.prototype.EndsWith = function( value, ignoreCase )
43
var L1 = this.length ;
44
var L2 = value.length ;
51
var oRegex = new RegExp( value + '$' , 'i' ) ;
52
return oRegex.test( this ) ;
55
return ( L2 == 0 || this.substr( L1 - L2, L2 ) == value ) ;
58
//#### Regular Expressions library.
59
var oRegex = new Object();
61
oRegex.UriProtocol = new RegExp('');
62
oRegex.UriProtocol.compile('^(((http|https|ftp|file|news):\/\/)|mailto:)', 'gi');
64
oRegex.UrlOnChangeProtocol = new RegExp('');
65
oRegex.UrlOnChangeProtocol.compile('^(http|https|ftp|file|news)://(?=.)', 'gi');
67
oRegex.UrlOnChangeTestOther = new RegExp('');
68
oRegex.UrlOnChangeTestOther.compile('^(javascript:|#)', 'gi'); // was: (...#|/)
70
oRegex.ReserveTarget = new RegExp('');
71
oRegex.ReserveTarget.compile('^_(blank|self|top|parent)$', 'i');
73
//#### Parser Functions
75
var oParser = new Object();
77
oParser.ParseEMailUrl = function(emailUrl)
79
// Initializes the EMailInfo object.
80
var oEMailInfo = new Object();
81
oEMailInfo.Address = '';
82
oEMailInfo.Subject = '';
85
var oParts = emailUrl.match(/^([^\?]+)\??(.+)?/);
88
// Set the e-mail address.
89
oEMailInfo.Address = oParts[1];
91
// Look for the optional e-mail parameters.
94
var oMatch = oParts[2].match(/(^|&)subject=([^&]+)/i);
96
oEMailInfo.Subject = unescape(oMatch[2]);
98
oMatch = oParts[2].match(/(^|&)body=([^&]+)/i);
100
oEMailInfo.Body = unescape(oMatch[2]);
106
oParser.CreateEMailUri = function(address, subject, body)
108
var sBaseUri = 'mailto:' + address;
112
if (subject.length > 0)
113
sParams = '?subject=' + escape(subject);
117
sParams += (sParams.length == 0 ? '?' : '&');
118
sParams += 'body=' + escape(body);
121
return sBaseUri + sParams;
124
//#### Initialization Code
126
// oLink: The actual selected link in the editor.
127
var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
129
FCK.Selection.SelectNode( oLink ) ;
131
window.onload = function()
133
// Translate the dialog box texts.
134
oEditor.FCKLanguageManager.TranslatePage(document);
136
// Load the selected link information (if any).
137
var firstElement = LoadSelection();
139
// Update the dialog box.
140
SetLinkType(GetE('cmbLinkType').value);
142
// Show the initial dialog content.
143
GetE('divInfo').style.display = '';
145
// Activate the "OK" button.
146
window.parent.SetOkButton(true);
148
// select first text input element of dialog for usability
149
SelectField(firstElement);
152
function LoadSelection()
154
// variable for first element of dialog
155
var firstElement = 'txtPagename';
157
if (!oLink) return firstElement;
161
// Get the actual Link href.
162
var sHRef = ''+oLink.getAttribute('href',2);
164
// Search for the protocol.
165
var sProtocol = oRegex.UriProtocol.exec(sHRef);
169
sProtocol = sProtocol[0].toLowerCase();
170
GetE('cmbLinkProtocol').value = sProtocol;
172
// Remove the protocol and get the remainig URL.
173
var sUrl = sHRef.replace(oRegex.UriProtocol, '');
175
if (sProtocol == 'mailto:') // It is an e-mail link.
177
var oEMailInfo = oParser.ParseEMailUrl(sUrl);
178
GetE('txtUrl').value = oEMailInfo.Address;
180
else // It is a normal link.
183
GetE('txtUrl').value = sUrl;
186
firstElement = 'txtUrl';
188
else if (oLink.getAttribute('class')=='interwiki' || oLink.getAttribute('class')=='badinterwiki')
191
GetE('sctInterwiki').value = oLink.getAttribute('title');
192
GetE('txtInterwikipagename').value = decodeUrl(sHRef);
193
firstElement = 'txtInterwikipagename';
195
else if (sHRef.StartsWith(FCKConfig['WikiBasePath']))
198
sHRef = sHRef.Remove(0, FCKConfig['WikiBasePath'].length);
200
// make links to subpages of own page relative links
201
if (sHRef.StartsWith(FCKConfig['WikiPage']))
202
sHRef = sHRef.Remove(0, FCKConfig['WikiPage'].length);
205
if (oLink.innerHTML.StartsWith('../') && sHRef.EndsWith(oLink.innerHTML.substring(3, oLink.innerHTML.length)))
206
sHRef = oLink.innerHTML;
208
GetE('txtPagename').value = decodeUrl(sHRef);
209
firstElement = 'txtPagename';
211
else // It is another type of link.
215
GetE('cmbLinkProtocol').value = '';
216
GetE('txtUrl').value = sHRef;
217
firstElement = 'txtUrl';
220
// Update the Link type combo.
221
GetE('cmbLinkType').value = sType;
223
// when inner html of link and url of link are same set isNameRelatedLink true
224
// if isNameRelatedLink is true, inner html is change when url change
225
if (sHRef == oLink.innerHTML) {
226
isNameRelatedLink = true;
232
//#### Link type selection.
233
function SetLinkType(linkType)
235
ShowE('divLinkTypeWiki' , (linkType == 'wiki'));
236
ShowE('divLinkTypeInterwiki' , (linkType == 'interwiki'));
237
ShowE('divLinkTypeUrl' , (linkType == 'url'));
240
//#### Called when user selects Wikipage.
241
function OnChangePagename(pagename)
243
GetE("txtPagename").value = pagename;
246
//#### Called while the user types the URL.
247
function OnUrlChange()
249
var sUrl = GetE('txtUrl').value;
250
var sProtocol = oRegex.UrlOnChangeProtocol.exec(sUrl);
254
sUrl = sUrl.substr(sProtocol[0].length);
255
GetE('txtUrl').value = sUrl;
256
GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase();
258
else if (oRegex.UrlOnChangeTestOther.test(sUrl))
260
GetE('cmbLinkProtocol').value = '';
264
//#### The OK button was hit.
270
switch (GetE('cmbLinkType').value)
273
sUri = GetE('txtPagename').value;
274
if (sUri.length == 0)
276
alert(FCKLang.DlnLnkMsgNoUrl);
282
// pages starting with "/" are sub pages of current page, e.g. /SubPage
285
sUri = GetE('basepage').value + sUri
288
sUri = FCKConfig['WikiBasePath'] + encodeUrl(sUri);
292
sUri = GetE('txtInterwikipagename').value;
294
if (sUri.length == 0)
296
alert(FCKLang.DlnLnkMsgNoUrl);
301
sUri = encodeUrl(sUri);
305
sUri = GetE('txtUrl').value;
307
if (sUri.length == 0)
309
alert(FCKLang.DlnLnkMsgNoUrl);
313
sUri = GetE('cmbLinkProtocol').value + sUri;
315
sUri = encodeUrl(sUri);
319
// Modifying an existent link.
322
SetAttribute( oLink, '_fcksavedurl', sUri ) ;
323
if (isNameRelatedLink) {
324
oLink.innerHTML = sText;
327
else // Creating a new link.
329
oLink = oEditor.FCK.CreateLink(sUri)[0];
332
oLink = oEditor.FCK.CreateElement('A');
334
oLink.appendChild(oEditor.FCK.EditorDocument.createTextNode(sText));
338
if (GetE('cmbLinkType').value == 'interwiki')
340
SetAttribute(oLink, 'class', 'badinterwiki'); // Bug on IE.5.5 makes this ineffective! Works on IE6/Moz....
341
SetAttribute(oLink, 'title', GetE('sctInterwiki').value);
349
document.getElementById('txtUrl').value = url;