1
/* FCKeditor - The text editor for internet
2
* Copyright (C) 2003-2004 Frederico Caldeira Knabben
4
* Licensed under the terms of the GNU Lesser General Public License:
5
* http://www.opensource.org/licenses/lgpl-license.php
7
* For further information visit:
8
* http://www.fckeditor.net/
10
* File Name: fck_image.js
11
* Scripts related to the Image dialog window
14
* Frederico Caldeira Knabben (fredck@fckeditor.net)
18
var dialog = window.parent ;
19
var oEditor = window.parent.InnerDialogLoaded();
20
var FCK = oEditor.FCK;
21
var FCKLang = oEditor.FCKLang;
22
var FCKConfig = oEditor.FCKConfig;
24
var UriProtocol = new RegExp('');
25
UriProtocol.compile('^((http|https):\/\/|attachment:|drawing:|)', 'gi');
26
var UrlOnChangeProtocol = new RegExp('');
27
UrlOnChangeProtocol.compile('^(http|https)://(?=.)|attachment:|drawing:', 'gi');
29
var oImage = FCK.Selection.GetSelectedElement() ;
30
if ( oImage && oImage.tagName != 'IMG')
33
// Get the active link.
34
var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
36
FCK.Selection.SelectNode( oLink ) ;
38
window.onload = function()
40
// Load the selected element information (if any).
46
// Activate the "OK" button.
47
window.parent.SetOkButton( true ) ;
49
// select first text input element of dialog for usability
50
SelectField('txtUrl');
53
function LoadSelection()
56
var sUrl = GetAttribute(oImage, 'src', '');
57
var sTitle = GetAttribute(oImage, 'title', '');
59
if (sTitle) sUrl = sTitle;
61
// Search for the protocol.
62
var sProtocol = UriProtocol.exec(sUrl);
66
sProtocol = sProtocol[0].toLowerCase();
67
GetE('cmbLinkProtocol').value = sProtocol;
69
// Remove the protocol and get the remainig URL.
70
sUrl = sUrl.replace(UriProtocol, '');
73
GetE('txtUrl').value = decodeUrl(sUrl);
76
GetE('chkLink').checked = 1;
78
GetE('chkLink').checked = 0;
81
function OnProtocolChange()
83
var sProtocol = GetE('cmbLinkProtocol').value;
84
ShowE('divChkLink', (sProtocol!='attachment:' && sProtocol!='drawing:'));
85
// select first text input element of dialog for usability
86
SelectField('txtUrl');
89
//#### Called while the user types the URL.
90
function OnUrlChange()
92
var sUrl = GetE('txtUrl').value;
93
var sProtocol = UrlOnChangeProtocol.exec(sUrl);
97
sUrl = sUrl.substr(sProtocol[0].length);
98
GetE('txtUrl').value = sUrl;
99
GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase();
103
function getAttachUrl(sUrl)
105
// XXX assumes attachments are not served directly!!!
106
var iIdx = sUrl.lastIndexOf('/');
110
sPage = sUrl.substring(0, iIdx);
111
sUrl = sUrl.substring(iIdx+1, sUrl.length);
114
sPage = FCKConfig['WikiPage'];
116
return FCKConfig['WikiBasePath'] + sPage +
117
"?action=AttachFile&do=get&target=" + sUrl;
120
//#### The OK button was hit.
123
if ( GetE('txtUrl').value.length == 0 )
125
window.parent.SetSelectedTab( 'Info' ) ;
126
GetE('txtUrl').focus() ;
127
alert( oEditor.FCKLang.DlgImgAlertUrl ) ;
133
oImage = FCK.CreateElement('IMG');
134
oEditor.FCKSelection.SelectNode(oImage);
137
var sProtocol = GetE('cmbLinkProtocol').value;
139
var sSrc = GetE('txtUrl').value;
141
if (sProtocol!='drawing:')
143
// Check for valid image Url
144
var sEnd = sSrc.substring(sSrc.length-4, sSrc.length).toLowerCase();
145
if (!(sEnd==".gif" || sEnd=='.png' || sEnd=='.jpg' || sSrc.substring(sSrc.length-5, sSrc.length).toLowerCase()=='.jpeg'))
147
alert("Image Url must end with .gif, .png, .jpg or .jpeg"); //XXX i18n!
152
if (sProtocol=='attachment:' || sProtocol=='drawing:')
154
sTitle = sProtocol + encodeUrl(sSrc);
155
if (sProtocol=='drawing:')
156
sSrc = sSrc + '.png';
157
sSrc = getAttachUrl(encodeUrl(sSrc));
160
sSrc = sProtocol + encodeUrl(sSrc);
163
if (GetE('chkLink').checked)
166
oLink = oEditor.FCK.CreateLink(sSrc);
171
if (oLink) FCK.ExecuteNamedCommand('Unlink');
175
oImage.title = sTitle;