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_attachment.js
12
* Scripts related to the Attachment dialog window.
15
* Modified: 2005-03-12 15:16:39
18
* Frederico Caldeira Knabben (fredck@fckeditor.net)
21
var oEditor = window.parent.InnerDialogLoaded();
22
var FCK = oEditor.FCK;
23
var FCKLang = oEditor.FCKLang;
24
var FCKConfig = oEditor.FCKConfig;
28
// Set the dialog tabs.
29
window.parent.AddTab('Info', FCKLang.DlgLnkInfoTab);
31
// Function called when a dialog tag is selected.
32
function OnDialogTabChange(tabCode)
34
ShowE('divInfo' , (tabCode == 'Info'));
37
//#### Regular Expressions library.
38
var oRegex = new Object();
40
oRegex.UriProtocol = new RegExp('');
41
oRegex.UriProtocol.compile('^(((http|https|ftp|news):\/\/)|mailto:)', 'gi');
43
oRegex.UrlOnChangeProtocol = new RegExp('');
44
oRegex.UrlOnChangeProtocol.compile('^(http|https|ftp|news)://(?=.)', 'gi');
46
oRegex.UrlOnChangeTestOther = new RegExp('');
47
oRegex.UrlOnChangeTestOther.compile('^(javascript:|#|/)', 'gi');
49
oRegex.ReserveTarget = new RegExp('');
50
oRegex.ReserveTarget.compile('^_(blank|self|top|parent)$', 'i');
52
//#### Parser Functions
54
var oParser = new Object();
56
//#### Initialization Code
58
// oLink: The actual selected link in the editor.
59
var oLink = FCK.Selection.MoveToAncestorNode('A');
61
FCK.Selection.SelectNode(oLink);
63
window.onload = function()
65
// Translate the dialog box texts.
66
oEditor.FCKLanguageManager.TranslatePage(document);
68
// Load the selected link information (if any).
71
// Show the initial dialog content.
72
GetE('divInfo').style.display = '';
74
// Activate the "OK" button.
75
window.parent.SetOkButton(true);
78
function LoadSelection()
82
if (oLink.getAttribute('title') &&
83
oLink.getAttribute('title').startsWith('attachment:'))
85
GetE('txtAttachmentname').value = decodeUrl(
86
oLink.getAttribute('title').remove(0, 'attachment:'.length));
91
//#### Link type selection.
92
function SetLinkType(linkType)
94
ShowE('divLinkTypeAttachment' , (linkType == 'attachment'));
97
//#### Called when user selects Wikipage.
98
function OnChangePagename(pagename)
100
GetE("txtPagename").value = pagename;
103
//#### Called while the user types the URL.
104
function OnUrlChange()
106
var sUrl = GetE('txtUrl').value;
107
var sProtocol = oRegex.UrlOnChangeProtocol.exec(sUrl);
111
sUrl = sUrl.substr(sProtocol[0].length);
112
GetE('txtUrl').value = sUrl;
114
else if (oRegex.UrlOnChangeTestOther.test(sUrl))
116
GetE('cmbLinkProtocol').value = '';
120
//#### The OK button was hit.
126
sUri = GetE('txtAttachmentname').value;
127
if (sUri.length == 0)
129
alert(FCKLang.DlnLnkMsgNoUrl);
133
sUri = encodeUrl(sUri);
135
if (oLink) // Modifying an existent link.
137
else // Creating a new link.
139
oLink = oEditor.FCK.CreateLink(sUri);
142
oLink = oEditor.FCK.CreateElement('A');
144
oLink.appendChild(oEditor.FCK.EditorDocument.createTextNode(sText));
148
SetAttribute(oLink, 'title', 'attachment:' + sUri);
155
document.getElementById('txtUrl').value = url;