1 | /* |
---|
2 | * FCKeditor - The text editor for internet |
---|
3 | * Copyright (C) 2003-2006 Frederico Caldeira Knabben |
---|
4 | * |
---|
5 | * Licensed under the terms of the GNU Lesser General Public License: |
---|
6 | * http://www.opensource.org/licenses/lgpl-license.php |
---|
7 | * |
---|
8 | * For further information visit: |
---|
9 | * http://www.fckeditor.net/ |
---|
10 | * |
---|
11 | * "Support Open Source software. What about a donation today?" |
---|
12 | * |
---|
13 | * File Name: fck_link.js |
---|
14 | * Scripts related to the Link dialog window (see fck_link.html). |
---|
15 | * |
---|
16 | * File Authors: |
---|
17 | * Frederico Caldeira Knabben (fredck@fckeditor.net) |
---|
18 | * Dominik Pesch ?dom? (empty selection patch) (d.pesch@11com7.de) |
---|
19 | */ |
---|
20 | |
---|
21 | var oEditor = window.parent.InnerDialogLoaded() ; |
---|
22 | var FCK = oEditor.FCK ; |
---|
23 | var FCKLang = oEditor.FCKLang ; |
---|
24 | var FCKConfig = oEditor.FCKConfig ; |
---|
25 | |
---|
26 | //#### Dialog Tabs |
---|
27 | |
---|
28 | // Set the dialog tabs. |
---|
29 | window.parent.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ; |
---|
30 | |
---|
31 | if ( !FCKConfig.LinkDlgHideTarget ) |
---|
32 | window.parent.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ; |
---|
33 | |
---|
34 | if ( FCKConfig.LinkUpload ) |
---|
35 | window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload, true ) ; |
---|
36 | |
---|
37 | if ( !FCKConfig.LinkDlgHideAdvanced ) |
---|
38 | window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ; |
---|
39 | |
---|
40 | // Function called when a dialog tag is selected. |
---|
41 | function OnDialogTabChange( tabCode ) |
---|
42 | { |
---|
43 | ShowE('divInfo' , ( tabCode == 'Info' ) ) ; |
---|
44 | ShowE('divTarget' , ( tabCode == 'Target' ) ) ; |
---|
45 | ShowE('divUpload' , ( tabCode == 'Upload' ) ) ; |
---|
46 | ShowE('divAttribs' , ( tabCode == 'Advanced' ) ) ; |
---|
47 | |
---|
48 | window.parent.SetAutoSize( true ) ; |
---|
49 | } |
---|
50 | |
---|
51 | //#### Regular Expressions library. |
---|
52 | var oRegex = new Object() ; |
---|
53 | |
---|
54 | oRegex.UriProtocol = new RegExp('') ; |
---|
55 | oRegex.UriProtocol.compile( '^(((http|https|ftp|news):\/\/)|mailto:)', 'gi' ) ; |
---|
56 | |
---|
57 | oRegex.UrlOnChangeProtocol = new RegExp('') ; |
---|
58 | oRegex.UrlOnChangeProtocol.compile( '^(http|https|ftp|news)://(?=.)', 'gi' ) ; |
---|
59 | |
---|
60 | oRegex.UrlOnChangeTestOther = new RegExp('') ; |
---|
61 | //oRegex.UrlOnChangeTestOther.compile( '^(javascript:|#|/)', 'gi' ) ; |
---|
62 | oRegex.UrlOnChangeTestOther.compile( '^((javascript:)|[#/\.])', 'gi' ) ; |
---|
63 | |
---|
64 | oRegex.ReserveTarget = new RegExp('') ; |
---|
65 | oRegex.ReserveTarget.compile( '^_(blank|self|top|parent)$', 'i' ) ; |
---|
66 | |
---|
67 | oRegex.PopupUri = new RegExp('') ; |
---|
68 | oRegex.PopupUri.compile( "^javascript:void\\(\\s*window.open\\(\\s*'([^']+)'\\s*,\\s*(?:'([^']*)'|null)\\s*,\\s*'([^']*)'\\s*\\)\\s*\\)\\s*$" ) ; |
---|
69 | |
---|
70 | oRegex.PopupFeatures = new RegExp('') ; |
---|
71 | oRegex.PopupFeatures.compile( '(?:^|,)([^=]+)=(\\d+|yes|no)', 'gi' ) ; |
---|
72 | |
---|
73 | //#### Parser Functions |
---|
74 | |
---|
75 | var oParser = new Object() ; |
---|
76 | |
---|
77 | oParser.ParseEMailUrl = function( emailUrl ) |
---|
78 | { |
---|
79 | // Initializes the EMailInfo object. |
---|
80 | var oEMailInfo = new Object() ; |
---|
81 | oEMailInfo.Address = '' ; |
---|
82 | oEMailInfo.Subject = '' ; |
---|
83 | oEMailInfo.Body = '' ; |
---|
84 | |
---|
85 | var oParts = emailUrl.match( /^([^\?]+)\??(.+)?/ ) ; |
---|
86 | if ( oParts ) |
---|
87 | { |
---|
88 | // Set the e-mail address. |
---|
89 | oEMailInfo.Address = oParts[1] ; |
---|
90 | |
---|
91 | // Look for the optional e-mail parameters. |
---|
92 | if ( oParts[2] ) |
---|
93 | { |
---|
94 | var oMatch = oParts[2].match( /(^|&)subject=([^&]+)/i ) ; |
---|
95 | if ( oMatch ) oEMailInfo.Subject = unescape( oMatch[2] ) ; |
---|
96 | |
---|
97 | oMatch = oParts[2].match( /(^|&)body=([^&]+)/i ) ; |
---|
98 | if ( oMatch ) oEMailInfo.Body = unescape( oMatch[2] ) ; |
---|
99 | } |
---|
100 | } |
---|
101 | |
---|
102 | return oEMailInfo ; |
---|
103 | } |
---|
104 | |
---|
105 | oParser.CreateEMailUri = function( address, subject, body ) |
---|
106 | { |
---|
107 | var sBaseUri = 'mailto:' + address ; |
---|
108 | |
---|
109 | var sParams = '' ; |
---|
110 | |
---|
111 | if ( subject.length > 0 ) |
---|
112 | sParams = '?subject=' + escape( subject ) ; |
---|
113 | |
---|
114 | if ( body.length > 0 ) |
---|
115 | { |
---|
116 | sParams += ( sParams.length == 0 ? '?' : '&' ) ; |
---|
117 | sParams += 'body=' + escape( body ) ; |
---|
118 | } |
---|
119 | |
---|
120 | return sBaseUri + sParams ; |
---|
121 | } |
---|
122 | |
---|
123 | //#### Initialization Code |
---|
124 | |
---|
125 | // oLink: The actual selected link in the editor. |
---|
126 | var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; |
---|
127 | if ( oLink ) |
---|
128 | FCK.Selection.SelectNode( oLink ) ; |
---|
129 | |
---|
130 | window.onload = function() |
---|
131 | { |
---|
132 | // Translate the dialog box texts. |
---|
133 | oEditor.FCKLanguageManager.TranslatePage(document) ; |
---|
134 | |
---|
135 | // Fill the Anchor Names and Ids combos. |
---|
136 | LoadAnchorNamesAndIds() ; |
---|
137 | |
---|
138 | // Load the selected link information (if any). |
---|
139 | LoadSelection() ; |
---|
140 | |
---|
141 | // Update the dialog box. |
---|
142 | SetLinkType( GetE('cmbLinkType').value ) ; |
---|
143 | |
---|
144 | // Show/Hide the "Browse Server" button. |
---|
145 | GetE('divBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ; |
---|
146 | |
---|
147 | // Show the initial dialog content. |
---|
148 | GetE('divInfo').style.display = '' ; |
---|
149 | |
---|
150 | // Set the actual uploader URL. |
---|
151 | if ( FCKConfig.LinkUpload ) |
---|
152 | GetE('frmUpload').action = FCKConfig.LinkUploadURL ; |
---|
153 | |
---|
154 | // Activate the "OK" button. |
---|
155 | window.parent.SetOkButton( true ) ; |
---|
156 | } |
---|
157 | |
---|
158 | var bHasAnchors ; |
---|
159 | |
---|
160 | function LoadAnchorNamesAndIds() |
---|
161 | { |
---|
162 | // Since version 2.0, the anchors are replaced in the DOM by IMGs so the user see the icon |
---|
163 | // to edit them. So, we must look for that images now. |
---|
164 | var aAnchors = new Array() ; |
---|
165 | |
---|
166 | var oImages = oEditor.FCK.EditorDocument.getElementsByTagName( 'IMG' ) ; |
---|
167 | for( var i = 0 ; i < oImages.length ; i++ ) |
---|
168 | { |
---|
169 | if ( oImages[i].getAttribute('_fckanchor') ) |
---|
170 | aAnchors[ aAnchors.length ] = oEditor.FCK.GetRealElement( oImages[i] ) ; |
---|
171 | } |
---|
172 | |
---|
173 | var aIds = oEditor.FCKTools.GetAllChildrenIds( oEditor.FCK.EditorDocument.body ) ; |
---|
174 | |
---|
175 | bHasAnchors = ( aAnchors.length > 0 || aIds.length > 0 ) ; |
---|
176 | |
---|
177 | for ( var i = 0 ; i < aAnchors.length ; i++ ) |
---|
178 | { |
---|
179 | var sName = aAnchors[i].name ; |
---|
180 | if ( sName && sName.length > 0 ) |
---|
181 | oEditor.FCKTools.AddSelectOption( GetE('cmbAnchorName'), sName, sName ) ; |
---|
182 | } |
---|
183 | |
---|
184 | for ( var i = 0 ; i < aIds.length ; i++ ) |
---|
185 | { |
---|
186 | oEditor.FCKTools.AddSelectOption( GetE('cmbAnchorId'), aIds[i], aIds[i] ) ; |
---|
187 | } |
---|
188 | |
---|
189 | ShowE( 'divSelAnchor' , bHasAnchors ) ; |
---|
190 | ShowE( 'divNoAnchor' , !bHasAnchors ) ; |
---|
191 | } |
---|
192 | |
---|
193 | function LoadSelection() |
---|
194 | { |
---|
195 | if ( !oLink ) return ; |
---|
196 | |
---|
197 | var sType = 'url' ; |
---|
198 | |
---|
199 | // Get the actual Link href. |
---|
200 | var sHRef = oLink.getAttribute( '_fcksavedurl' ) ; |
---|
201 | if ( sHRef == null ) |
---|
202 | sHRef = oLink.getAttribute( 'href' , 2 ) + '' ; |
---|
203 | |
---|
204 | // Look for a popup javascript link. |
---|
205 | var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ; |
---|
206 | if( oPopupMatch ) |
---|
207 | { |
---|
208 | GetE('cmbTarget').value = 'popup' ; |
---|
209 | sHRef = oPopupMatch[1] ; |
---|
210 | FillPopupFields( oPopupMatch[2], oPopupMatch[3] ) ; |
---|
211 | SetTarget( 'popup' ) ; |
---|
212 | } |
---|
213 | |
---|
214 | // Search for the protocol. |
---|
215 | var sProtocol = oRegex.UriProtocol.exec( sHRef ) ; |
---|
216 | |
---|
217 | if ( sProtocol ) |
---|
218 | { |
---|
219 | sProtocol = sProtocol[0].toLowerCase() ; |
---|
220 | GetE('cmbLinkProtocol').value = sProtocol ; |
---|
221 | |
---|
222 | // Remove the protocol and get the remainig URL. |
---|
223 | var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ; |
---|
224 | |
---|
225 | if ( sProtocol == 'mailto:' ) // It is an e-mail link. |
---|
226 | { |
---|
227 | sType = 'email' ; |
---|
228 | |
---|
229 | var oEMailInfo = oParser.ParseEMailUrl( sUrl ) ; |
---|
230 | GetE('txtEMailAddress').value = oEMailInfo.Address ; |
---|
231 | GetE('txtEMailSubject').value = oEMailInfo.Subject ; |
---|
232 | GetE('txtEMailBody').value = oEMailInfo.Body ; |
---|
233 | } |
---|
234 | else // It is a normal link. |
---|
235 | { |
---|
236 | sType = 'url' ; |
---|
237 | GetE('txtUrl').value = sUrl ; |
---|
238 | } |
---|
239 | } |
---|
240 | else if ( sHRef.substr(0,1) == '#' && sHRef.length > 1 ) // It is an anchor link. |
---|
241 | { |
---|
242 | sType = 'anchor' ; |
---|
243 | GetE('cmbAnchorName').value = GetE('cmbAnchorId').value = sHRef.substr(1) ; |
---|
244 | } |
---|
245 | else // It is another type of link. |
---|
246 | { |
---|
247 | sType = 'url' ; |
---|
248 | |
---|
249 | GetE('cmbLinkProtocol').value = '' ; |
---|
250 | GetE('txtUrl').value = sHRef ; |
---|
251 | } |
---|
252 | |
---|
253 | if ( !oPopupMatch ) |
---|
254 | { |
---|
255 | // Get the target. |
---|
256 | var sTarget = oLink.target ; |
---|
257 | |
---|
258 | if ( sTarget && sTarget.length > 0 ) |
---|
259 | { |
---|
260 | if ( oRegex.ReserveTarget.test( sTarget ) ) |
---|
261 | { |
---|
262 | sTarget = sTarget.toLowerCase() ; |
---|
263 | GetE('cmbTarget').value = sTarget ; |
---|
264 | } |
---|
265 | else |
---|
266 | GetE('cmbTarget').value = 'frame' ; |
---|
267 | GetE('txtTargetFrame').value = sTarget ; |
---|
268 | } |
---|
269 | } |
---|
270 | |
---|
271 | // Get Advances Attributes |
---|
272 | GetE('txtAttId').value = oLink.id ; |
---|
273 | GetE('txtAttName').value = oLink.name ; |
---|
274 | GetE('cmbAttLangDir').value = oLink.dir ; |
---|
275 | GetE('txtAttLangCode').value = oLink.lang ; |
---|
276 | GetE('txtAttAccessKey').value = oLink.accessKey ; |
---|
277 | GetE('txtAttTabIndex').value = oLink.tabIndex <= 0 ? '' : oLink.tabIndex ; |
---|
278 | GetE('txtAttTitle').value = oLink.title ; |
---|
279 | GetE('txtAttContentType').value = oLink.type ; |
---|
280 | GetE('txtAttCharSet').value = oLink.charset ; |
---|
281 | |
---|
282 | if ( oEditor.FCKBrowserInfo.IsIE ) |
---|
283 | { |
---|
284 | GetE('txtAttClasses').value = oLink.getAttribute('className',2) || '' ; |
---|
285 | GetE('txtAttStyle').value = oLink.style.cssText ; |
---|
286 | } |
---|
287 | else |
---|
288 | { |
---|
289 | GetE('txtAttClasses').value = oLink.getAttribute('class',2) || '' ; |
---|
290 | GetE('txtAttStyle').value = oLink.getAttribute('style',2) ; |
---|
291 | } |
---|
292 | |
---|
293 | // Update the Link type combo. |
---|
294 | GetE('cmbLinkType').value = sType ; |
---|
295 | } |
---|
296 | |
---|
297 | //#### Link type selection. |
---|
298 | function SetLinkType( linkType ) |
---|
299 | { |
---|
300 | ShowE('divLinkTypeUrl' , (linkType == 'url') ) ; |
---|
301 | ShowE('divLinkTypeAnchor' , (linkType == 'anchor') ) ; |
---|
302 | ShowE('divLinkTypeEMail' , (linkType == 'email') ) ; |
---|
303 | |
---|
304 | if ( !FCKConfig.LinkDlgHideTarget ) |
---|
305 | window.parent.SetTabVisibility( 'Target' , (linkType == 'url') ) ; |
---|
306 | |
---|
307 | if ( FCKConfig.LinkUpload ) |
---|
308 | window.parent.SetTabVisibility( 'Upload' , (linkType == 'url') ) ; |
---|
309 | |
---|
310 | if ( !FCKConfig.LinkDlgHideAdvanced ) |
---|
311 | window.parent.SetTabVisibility( 'Advanced' , (linkType != 'anchor' || bHasAnchors) ) ; |
---|
312 | |
---|
313 | if ( linkType == 'email' ) |
---|
314 | window.parent.SetAutoSize( true ) ; |
---|
315 | } |
---|
316 | |
---|
317 | //#### Target type selection. |
---|
318 | function SetTarget( targetType ) |
---|
319 | { |
---|
320 | GetE('tdTargetFrame').style.display = ( targetType == 'popup' ? 'none' : '' ) ; |
---|
321 | GetE('tdPopupName').style.display = |
---|
322 | GetE('tablePopupFeatures').style.display = ( targetType == 'popup' ? '' : 'none' ) ; |
---|
323 | |
---|
324 | switch ( targetType ) |
---|
325 | { |
---|
326 | case "_blank" : |
---|
327 | case "_self" : |
---|
328 | case "_parent" : |
---|
329 | case "_top" : |
---|
330 | GetE('txtTargetFrame').value = targetType ; |
---|
331 | break ; |
---|
332 | case "" : |
---|
333 | GetE('txtTargetFrame').value = '' ; |
---|
334 | break ; |
---|
335 | } |
---|
336 | |
---|
337 | if ( targetType == 'popup' ) |
---|
338 | window.parent.SetAutoSize( true ) ; |
---|
339 | } |
---|
340 | |
---|
341 | //#### Called while the user types the URL. |
---|
342 | function OnUrlChange() |
---|
343 | { |
---|
344 | var sUrl = GetE('txtUrl').value ; |
---|
345 | var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ; |
---|
346 | |
---|
347 | if ( sProtocol ) |
---|
348 | { |
---|
349 | sUrl = sUrl.substr( sProtocol[0].length ) ; |
---|
350 | GetE('txtUrl').value = sUrl ; |
---|
351 | GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ; |
---|
352 | } |
---|
353 | else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) ) |
---|
354 | { |
---|
355 | GetE('cmbLinkProtocol').value = '' ; |
---|
356 | } |
---|
357 | } |
---|
358 | |
---|
359 | //#### Called while the user types the target name. |
---|
360 | function OnTargetNameChange() |
---|
361 | { |
---|
362 | var sFrame = GetE('txtTargetFrame').value ; |
---|
363 | |
---|
364 | if ( sFrame.length == 0 ) |
---|
365 | GetE('cmbTarget').value = '' ; |
---|
366 | else if ( oRegex.ReserveTarget.test( sFrame ) ) |
---|
367 | GetE('cmbTarget').value = sFrame.toLowerCase() ; |
---|
368 | else |
---|
369 | GetE('cmbTarget').value = 'frame' ; |
---|
370 | } |
---|
371 | |
---|
372 | //#### Builds the javascript URI to open a popup to the specified URI. |
---|
373 | function BuildPopupUri( uri ) |
---|
374 | { |
---|
375 | var oReg = new RegExp( "'", "g" ) ; |
---|
376 | var sWindowName = "'" + GetE('txtPopupName').value.replace(oReg, "\\'") + "'" ; |
---|
377 | |
---|
378 | var sFeatures = '' ; |
---|
379 | var aChkFeatures = document.getElementsByName('chkFeature') ; |
---|
380 | for ( var i = 0 ; i < aChkFeatures.length ; i++ ) |
---|
381 | { |
---|
382 | if ( i > 0 ) sFeatures += ',' ; |
---|
383 | sFeatures += aChkFeatures[i].value + '=' + ( aChkFeatures[i].checked ? 'yes' : 'no' ) ; |
---|
384 | } |
---|
385 | |
---|
386 | if ( GetE('txtPopupWidth').value.length > 0 ) sFeatures += ',width=' + GetE('txtPopupWidth').value ; |
---|
387 | if ( GetE('txtPopupHeight').value.length > 0 ) sFeatures += ',height=' + GetE('txtPopupHeight').value ; |
---|
388 | if ( GetE('txtPopupLeft').value.length > 0 ) sFeatures += ',left=' + GetE('txtPopupLeft').value ; |
---|
389 | if ( GetE('txtPopupTop').value.length > 0 ) sFeatures += ',top=' + GetE('txtPopupTop').value ; |
---|
390 | |
---|
391 | return ( "javascript:void(window.open('" + uri + "'," + sWindowName + ",'" + sFeatures + "'))" ) ; |
---|
392 | } |
---|
393 | |
---|
394 | //#### Fills all Popup related fields. |
---|
395 | function FillPopupFields( windowName, features ) |
---|
396 | { |
---|
397 | if ( windowName ) |
---|
398 | GetE('txtPopupName').value = windowName ; |
---|
399 | |
---|
400 | var oFeatures = new Object() ; |
---|
401 | var oFeaturesMatch ; |
---|
402 | while( ( oFeaturesMatch = oRegex.PopupFeatures.exec( features ) ) != null ) |
---|
403 | { |
---|
404 | var sValue = oFeaturesMatch[2] ; |
---|
405 | if ( sValue == ( 'yes' || '1' ) ) |
---|
406 | oFeatures[ oFeaturesMatch[1] ] = true ; |
---|
407 | else if ( ! isNaN( sValue ) && sValue != 0 ) |
---|
408 | oFeatures[ oFeaturesMatch[1] ] = sValue ; |
---|
409 | } |
---|
410 | |
---|
411 | // Update all features check boxes. |
---|
412 | var aChkFeatures = document.getElementsByName('chkFeature') ; |
---|
413 | for ( var i = 0 ; i < aChkFeatures.length ; i++ ) |
---|
414 | { |
---|
415 | if ( oFeatures[ aChkFeatures[i].value ] ) |
---|
416 | aChkFeatures[i].checked = true ; |
---|
417 | } |
---|
418 | |
---|
419 | // Update position and size text boxes. |
---|
420 | if ( oFeatures['width'] ) GetE('txtPopupWidth').value = oFeatures['width'] ; |
---|
421 | if ( oFeatures['height'] ) GetE('txtPopupHeight').value = oFeatures['height'] ; |
---|
422 | if ( oFeatures['left'] ) GetE('txtPopupLeft').value = oFeatures['left'] ; |
---|
423 | if ( oFeatures['top'] ) GetE('txtPopupTop').value = oFeatures['top'] ; |
---|
424 | } |
---|
425 | |
---|
426 | //#### The OK button was hit. |
---|
427 | function Ok() |
---|
428 | { |
---|
429 | var sUri, sInnerHtml ; |
---|
430 | |
---|
431 | switch ( GetE('cmbLinkType').value ) |
---|
432 | { |
---|
433 | case 'url' : |
---|
434 | sUri = GetE('txtUrl').value ; |
---|
435 | |
---|
436 | if ( sUri.length == 0 ) |
---|
437 | { |
---|
438 | alert( FCKLang.DlnLnkMsgNoUrl ) ; |
---|
439 | return false ; |
---|
440 | } |
---|
441 | |
---|
442 | sUri = GetE('cmbLinkProtocol').value + sUri ; |
---|
443 | |
---|
444 | if( GetE('cmbTarget').value == 'popup' ) |
---|
445 | { |
---|
446 | // Check the window name, according to http://www.w3.org/TR/html4/types.html#type-frame-target (IE throw erros with spaces). |
---|
447 | if ( /(^[^a-zA-Z])|(\s)/.test( GetE('txtPopupName').value ) ) |
---|
448 | { |
---|
449 | alert( FCKLang.DlnLnkMsgInvPopName ) ; |
---|
450 | return false ; |
---|
451 | } |
---|
452 | |
---|
453 | sUri = BuildPopupUri( sUri ) ; |
---|
454 | } |
---|
455 | |
---|
456 | break ; |
---|
457 | |
---|
458 | case 'email' : |
---|
459 | sUri = GetE('txtEMailAddress').value ; |
---|
460 | |
---|
461 | if ( sUri.length == 0 ) |
---|
462 | { |
---|
463 | alert( FCKLang.DlnLnkMsgNoEMail ) ; |
---|
464 | return false ; |
---|
465 | } |
---|
466 | |
---|
467 | sUri = oParser.CreateEMailUri( |
---|
468 | sUri, |
---|
469 | GetE('txtEMailSubject').value, |
---|
470 | GetE('txtEMailBody').value ) ; |
---|
471 | break ; |
---|
472 | |
---|
473 | case 'anchor' : |
---|
474 | var sAnchor = GetE('cmbAnchorName').value ; |
---|
475 | if ( sAnchor.length == 0 ) sAnchor = GetE('cmbAnchorId').value ; |
---|
476 | |
---|
477 | if ( sAnchor.length == 0 ) |
---|
478 | { |
---|
479 | alert( FCKLang.DlnLnkMsgNoAnchor ) ; |
---|
480 | return false ; |
---|
481 | } |
---|
482 | |
---|
483 | sUri = '#' + sAnchor ; |
---|
484 | break ; |
---|
485 | } |
---|
486 | |
---|
487 | // No link selected, so try to create one. |
---|
488 | if ( !oLink ) |
---|
489 | oLink = oEditor.FCK.CreateLink( sUri ) ; |
---|
490 | |
---|
491 | if ( oLink ) |
---|
492 | sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL). |
---|
493 | else |
---|
494 | { |
---|
495 | // If no selection, use the uri as the link text (by dom, 2006-05-26) |
---|
496 | |
---|
497 | sInnerHtml = sUri; |
---|
498 | |
---|
499 | // Built a better text for empty links. |
---|
500 | switch ( GetE('cmbLinkType').value ) |
---|
501 | { |
---|
502 | // anchor: use old behavior --> return true |
---|
503 | case 'anchor': |
---|
504 | sInnerHtml = sInnerHtml.replace( /^#/, '' ) ; |
---|
505 | break ; |
---|
506 | |
---|
507 | // url: try to get path |
---|
508 | case 'url': |
---|
509 | var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ; |
---|
510 | var asLinkPath = oLinkPathRegEx.exec( sUri ) ; |
---|
511 | if (asLinkPath != null) |
---|
512 | sInnerHtml = asLinkPath[1]; // use matched path |
---|
513 | break ; |
---|
514 | |
---|
515 | // mailto: try to get email address |
---|
516 | case 'email': |
---|
517 | sInnerHtml = GetE('txtEMailAddress').value ; |
---|
518 | break ; |
---|
519 | } |
---|
520 | |
---|
521 | // Create a new (empty) anchor. |
---|
522 | oLink = oEditor.FCK.CreateElement( 'a' ) ; |
---|
523 | } |
---|
524 | |
---|
525 | oEditor.FCKUndo.SaveUndoStep() ; |
---|
526 | |
---|
527 | oLink.href = sUri ; |
---|
528 | SetAttribute( oLink, '_fcksavedurl', sUri ) ; |
---|
529 | |
---|
530 | oLink.innerHTML = sInnerHtml ; // Set (or restore) the innerHTML |
---|
531 | |
---|
532 | // Target |
---|
533 | if( GetE('cmbTarget').value != 'popup' ) |
---|
534 | SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ; |
---|
535 | else |
---|
536 | SetAttribute( oLink, 'target', null ) ; |
---|
537 | |
---|
538 | // Advances Attributes |
---|
539 | SetAttribute( oLink, 'id' , GetE('txtAttId').value ) ; |
---|
540 | SetAttribute( oLink, 'name' , GetE('txtAttName').value ) ; // No IE. Set but doesnt't update the outerHTML. |
---|
541 | SetAttribute( oLink, 'dir' , GetE('cmbAttLangDir').value ) ; |
---|
542 | SetAttribute( oLink, 'lang' , GetE('txtAttLangCode').value ) ; |
---|
543 | SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ; |
---|
544 | SetAttribute( oLink, 'tabindex' , ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ; |
---|
545 | SetAttribute( oLink, 'title' , GetE('txtAttTitle').value ) ; |
---|
546 | SetAttribute( oLink, 'type' , GetE('txtAttContentType').value ) ; |
---|
547 | SetAttribute( oLink, 'charset' , GetE('txtAttCharSet').value ) ; |
---|
548 | |
---|
549 | if ( oEditor.FCKBrowserInfo.IsIE ) |
---|
550 | { |
---|
551 | SetAttribute( oLink, 'className', GetE('txtAttClasses').value ) ; |
---|
552 | oLink.style.cssText = GetE('txtAttStyle').value ; |
---|
553 | } |
---|
554 | else |
---|
555 | { |
---|
556 | SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ; |
---|
557 | SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ; |
---|
558 | } |
---|
559 | |
---|
560 | // Select the link. |
---|
561 | oEditor.FCKSelection.SelectNode(oLink); |
---|
562 | |
---|
563 | return true ; |
---|
564 | } |
---|
565 | |
---|
566 | function BrowseServer() |
---|
567 | { |
---|
568 | OpenFileBrowser( FCKConfig.LinkBrowserURL, FCKConfig.LinkBrowserWindowWidth, FCKConfig.LinkBrowserWindowHeight ) ; |
---|
569 | } |
---|
570 | |
---|
571 | function SetUrl( url ) |
---|
572 | { |
---|
573 | document.getElementById('txtUrl').value = url ; |
---|
574 | OnUrlChange() ; |
---|
575 | window.parent.SetSelectedTab( 'Info' ) ; |
---|
576 | } |
---|
577 | |
---|
578 | function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg ) |
---|
579 | { |
---|
580 | switch ( errorNumber ) |
---|
581 | { |
---|
582 | case 0 : // No errors |
---|
583 | alert( 'Your file has been successfully uploaded' ) ; |
---|
584 | break ; |
---|
585 | case 1 : // Custom error |
---|
586 | alert( customMsg ) ; |
---|
587 | return ; |
---|
588 | case 101 : // Custom warning |
---|
589 | alert( customMsg ) ; |
---|
590 | break ; |
---|
591 | case 201 : |
---|
592 | alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ; |
---|
593 | break ; |
---|
594 | case 202 : |
---|
595 | alert( 'Invalid file type' ) ; |
---|
596 | return ; |
---|
597 | case 203 : |
---|
598 | alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ; |
---|
599 | return ; |
---|
600 | default : |
---|
601 | alert( 'Error on file upload. Error number: ' + errorNumber ) ; |
---|
602 | return ; |
---|
603 | } |
---|
604 | |
---|
605 | SetUrl( fileUrl ) ; |
---|
606 | GetE('frmUpload').reset() ; |
---|
607 | } |
---|
608 | |
---|
609 | var oUploadAllowedExtRegex = new RegExp( FCKConfig.LinkUploadAllowedExtensions, 'i' ) ; |
---|
610 | var oUploadDeniedExtRegex = new RegExp( FCKConfig.LinkUploadDeniedExtensions, 'i' ) ; |
---|
611 | |
---|
612 | function CheckUpload() |
---|
613 | { |
---|
614 | var sFile = GetE('txtUploadFile').value ; |
---|
615 | |
---|
616 | if ( sFile.length == 0 ) |
---|
617 | { |
---|
618 | alert( 'Please select a file to upload' ) ; |
---|
619 | return false ; |
---|
620 | } |
---|
621 | |
---|
622 | if ( ( FCKConfig.LinkUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) || |
---|
623 | ( FCKConfig.LinkUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) ) |
---|
624 | { |
---|
625 | OnUploadCompleted( 202 ) ; |
---|
626 | return false ; |
---|
627 | } |
---|
628 | |
---|
629 | return true ; |
---|
630 | } |
---|