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