Project

General

Profile

1
/*
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 * Copyright (C) 2003-2008 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 dialog	= window.parent ;
25
var oEditor = dialog.InnerDialogLoaded() ;
26

    
27
var FCK			= oEditor.FCK ;
28
var FCKLang		= oEditor.FCKLang ;
29
var FCKConfig	= oEditor.FCKConfig ;
30
var FCKRegexLib	= oEditor.FCKRegexLib ;
31
var FCKTools	= oEditor.FCKTools ;
32

    
33
//#### Dialog Tabs
34

    
35
// Set the dialog tabs.
36
dialog.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ;
37

    
38
if ( !FCKConfig.LinkDlgHideTarget )
39
	dialog.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ;
40

    
41
if ( FCKConfig.LinkUpload )
42
	dialog.AddTab( 'Upload', FCKLang.DlgLnkUpload, true ) ;
43

    
44
if ( !FCKConfig.LinkDlgHideAdvanced )
45
	dialog.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ;
46

    
47
// Function called when a dialog tag is selected.
48
function OnDialogTabChange( tabCode )
49
{
50
	ShowE('divInfo'		, ( tabCode == 'Info' ) ) ;
51
	ShowE('divTarget'	, ( tabCode == 'Target' ) ) ;
52
	ShowE('divUpload'	, ( tabCode == 'Upload' ) ) ;
53
	ShowE('divAttribs'	, ( tabCode == 'Advanced' ) ) ;
54

    
55
	dialog.SetAutoSize( true ) ;
56
}
57

    
58
//#### Regular Expressions library.
59
var oRegex = new Object() ;
60

    
61
oRegex.UriProtocol = /^(((http|https|ftp|news):\/\/)|mailto:)/gi ;
62

    
63
oRegex.UrlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi ;
64

    
65
oRegex.UrlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi ;
66

    
67
oRegex.ReserveTarget = /^_(blank|self|top|parent)$/i ;
68

    
69
oRegex.PopupUri = /^javascript:void\(\s*window.open\(\s*'([^']+)'\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*\)\s*$/ ;
70

    
71
// Accessible popups
72
oRegex.OnClickPopup = /^\s*on[cC]lick="\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*"$/ ;
73

    
74
oRegex.PopupFeatures = /(?:^|,)([^=]+)=(\d+|yes|no)/gi ;
75

    
76
//#### Parser Functions
77

    
78
var oParser = new Object() ;
79

    
80
oParser.ParseEMailUrl = function( emailUrl )
81
{
82
	// Initializes the EMailInfo object.
83
	var oEMailInfo = new Object() ;
84
	oEMailInfo.Address	= '' ;
85
	oEMailInfo.Subject	= '' ;
86
	oEMailInfo.Body		= '' ;
87

    
88
	var oParts = emailUrl.match( /^([^\?]+)\??(.+)?/ ) ;
89
	if ( oParts )
90
	{
91
		// Set the e-mail address.
92
		oEMailInfo.Address = oParts[1] ;
93

    
94
		// Look for the optional e-mail parameters.
95
		if ( oParts[2] )
96
		{
97
			var oMatch = oParts[2].match( /(^|&)subject=([^&]+)/i ) ;
98
			if ( oMatch ) oEMailInfo.Subject = decodeURIComponent( oMatch[2] ) ;
99

    
100
			oMatch = oParts[2].match( /(^|&)body=([^&]+)/i ) ;
101
			if ( oMatch ) oEMailInfo.Body = decodeURIComponent( oMatch[2] ) ;
102
		}
103
	}
104

    
105
	return oEMailInfo ;
106
}
107

    
108
oParser.CreateEMailUri = function( address, subject, body )
109
{
110
	var sBaseUri = 'mailto:' + address ;
111

    
112
	var sParams = '' ;
113

    
114
	if ( subject.length > 0 )
115
		sParams = '?subject=' + encodeURIComponent( subject ) ;
116

    
117
	if ( body.length > 0 )
118
	{
119
		sParams += ( sParams.length == 0 ? '?' : '&' ) ;
120
		sParams += 'body=' + encodeURIComponent( body ) ;
121
	}
122

    
123
	return sBaseUri + sParams ;
124
}
125

    
126
//#### Initialization Code
127

    
128
// oLink: The actual selected link in the editor.
129
var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
130
if ( oLink )
131
	FCK.Selection.SelectNode( oLink ) ;
132

    
133
window.onload = function()
134
{
135
	// Translate the dialog box texts.
136
	oEditor.FCKLanguageManager.TranslatePage(document) ;
137

    
138
	// Fill the Anchor Names and Ids combos.
139
	LoadAnchorNamesAndIds() ;
140

    
141
	// Load the selected link information (if any).
142
	LoadSelection() ;
143

    
144
	// Update the dialog box.
145
	SetLinkType( GetE('cmbLinkType').value ) ;
146

    
147
	// Show/Hide the "Browse Server" button.
148
	GetE('divBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ;
149

    
150
	// Show the initial dialog content.
151
	GetE('divInfo').style.display = '' ;
152

    
153
	// Set the actual uploader URL.
154
	if ( FCKConfig.LinkUpload )
155
		GetE('frmUpload').action = FCKConfig.LinkUploadURL ;
156

    
157
	// Set the default target (from configuration).
158
	SetDefaultTarget() ;
159

    
160
	// Activate the "OK" button.
161
	dialog.SetOkButton( true ) ;
162

    
163
	// Select the first field.
164
	switch( GetE('cmbLinkType').value )
165
	{
166
		case 'url' :
167
			SelectField( 'txtUrl' ) ;
168
			break ;
169
		case 'email' :
170
			SelectField( 'txtEMailAddress' ) ;
171
			break ;
172
		case 'anchor' :
173
			if ( GetE('divSelAnchor').style.display != 'none' )
174
				SelectField( 'cmbAnchorName' ) ;
175
			else
176
				SelectField( 'cmbLinkType' ) ;
177
	}
178
}
179

    
180
var bHasAnchors ;
181

    
182
function LoadAnchorNamesAndIds()
183
{
184
	// Since version 2.0, the anchors are replaced in the DOM by IMGs so the user see the icon
185
	// to edit them. So, we must look for that images now.
186
	var aAnchors = new Array() ;
187
	var i ;
188
	var oImages = oEditor.FCK.EditorDocument.getElementsByTagName( 'IMG' ) ;
189
	for( i = 0 ; i < oImages.length ; i++ )
190
	{
191
		if ( oImages[i].getAttribute('_fckanchor') )
192
			aAnchors[ aAnchors.length ] = oEditor.FCK.GetRealElement( oImages[i] ) ;
193
	}
194

    
195
	// Add also real anchors
196
	var oLinks = oEditor.FCK.EditorDocument.getElementsByTagName( 'A' ) ;
197
	for( i = 0 ; i < oLinks.length ; i++ )
198
	{
199
		if ( oLinks[i].name && ( oLinks[i].name.length > 0 ) )
200
			aAnchors[ aAnchors.length ] = oLinks[i] ;
201
	}
202

    
203
	var aIds = FCKTools.GetAllChildrenIds( oEditor.FCK.EditorDocument.body ) ;
204

    
205
	bHasAnchors = ( aAnchors.length > 0 || aIds.length > 0 ) ;
206

    
207
	for ( i = 0 ; i < aAnchors.length ; i++ )
208
	{
209
		var sName = aAnchors[i].name ;
210
		if ( sName && sName.length > 0 )
211
			FCKTools.AddSelectOption( GetE('cmbAnchorName'), sName, sName ) ;
212
	}
213

    
214
	for ( i = 0 ; i < aIds.length ; i++ )
215
	{
216
		FCKTools.AddSelectOption( GetE('cmbAnchorId'), aIds[i], aIds[i] ) ;
217
	}
218

    
219
	ShowE( 'divSelAnchor'	, bHasAnchors ) ;
220
	ShowE( 'divNoAnchor'	, !bHasAnchors ) ;
221
}
222

    
223
function LoadSelection()
224
{
225
	if ( !oLink ) return ;
226

    
227
	var sType = 'url' ;
228

    
229
	// Get the actual Link href.
230
	var sHRef = oLink.getAttribute( '_fcksavedurl' ) ;
231
	if ( sHRef == null )
232
		sHRef = oLink.getAttribute( 'href' , 2 ) || '' ;
233

    
234
	// Look for a popup javascript link.
235
	var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ;
236
	if( oPopupMatch )
237
	{
238
		GetE('cmbTarget').value = 'popup' ;
239
		sHRef = oPopupMatch[1] ;
240
		FillPopupFields( oPopupMatch[2], oPopupMatch[3] ) ;
241
		SetTarget( 'popup' ) ;
242
	}
243

    
244
	// Accessible popups, the popup data is in the onclick attribute
245
	if ( !oPopupMatch )
246
	{
247
		var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ;
248
		if ( onclick )
249
		{
250
			// Decode the protected string
251
			onclick = decodeURIComponent( onclick ) ;
252

    
253
			oPopupMatch = oRegex.OnClickPopup.exec( onclick ) ;
254
			if( oPopupMatch )
255
			{
256
				GetE( 'cmbTarget' ).value = 'popup' ;
257
				FillPopupFields( oPopupMatch[1], oPopupMatch[2] ) ;
258
				SetTarget( 'popup' ) ;
259
			}
260
		}
261
	}
262

    
263
	// Search for the protocol.
264
	var sProtocol = oRegex.UriProtocol.exec( sHRef ) ;
265

    
266
	if ( sProtocol )
267
	{
268
		sProtocol = sProtocol[0].toLowerCase() ;
269
		GetE('cmbLinkProtocol').value = sProtocol ;
270

    
271
		// Remove the protocol and get the remaining URL.
272
		var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ;
273

    
274
		if ( sProtocol == 'mailto:' )	// It is an e-mail link.
275
		{
276
			sType = 'email' ;
277

    
278
			var oEMailInfo = oParser.ParseEMailUrl( sUrl ) ;
279
			GetE('txtEMailAddress').value	= oEMailInfo.Address ;
280
			GetE('txtEMailSubject').value	= oEMailInfo.Subject ;
281
			GetE('txtEMailBody').value		= oEMailInfo.Body ;
282
		}
283
		else				// It is a normal link.
284
		{
285
			sType = 'url' ;
286
			GetE('txtUrl').value = sUrl ;
287
		}
288
	}
289
	else if ( sHRef.substr(0,1) == '#' && sHRef.length > 1 )	// It is an anchor link.
290
	{
291
		sType = 'anchor' ;
292
		GetE('cmbAnchorName').value = GetE('cmbAnchorId').value = sHRef.substr(1) ;
293
	}
294
	else					// It is another type of link.
295
	{
296
		sType = 'url' ;
297

    
298
		GetE('cmbLinkProtocol').value = '' ;
299
		GetE('txtUrl').value = sHRef ;
300
	}
301

    
302
	if ( !oPopupMatch )
303
	{
304
		// Get the target.
305
		var sTarget = oLink.target ;
306

    
307
		if ( sTarget && sTarget.length > 0 )
308
		{
309
			if ( oRegex.ReserveTarget.test( sTarget ) )
310
			{
311
				sTarget = sTarget.toLowerCase() ;
312
				GetE('cmbTarget').value = sTarget ;
313
			}
314
			else
315
				GetE('cmbTarget').value = 'frame' ;
316
			GetE('txtTargetFrame').value = sTarget ;
317
		}
318
	}
319

    
320
	// Get Advances Attributes
321
	GetE('txtAttId').value			= oLink.id ;
322
	GetE('txtAttName').value		= oLink.name ;
323
	GetE('cmbAttLangDir').value		= oLink.dir ;
324
	GetE('txtAttLangCode').value	= oLink.lang ;
325
	GetE('txtAttAccessKey').value	= oLink.accessKey ;
326
	GetE('txtAttTabIndex').value	= oLink.tabIndex <= 0 ? '' : oLink.tabIndex ;
327
	GetE('txtAttTitle').value		= oLink.title ;
328
	GetE('txtAttContentType').value	= oLink.type ;
329
	GetE('txtAttCharSet').value		= oLink.charset ;
330

    
331
	var sClass ;
332
	if ( oEditor.FCKBrowserInfo.IsIE )
333
	{
334
		sClass	= oLink.getAttribute('className',2) || '' ;
335
		// Clean up temporary classes for internal use:
336
		sClass = sClass.replace( FCKRegexLib.FCK_Class, '' ) ;
337

    
338
		GetE('txtAttStyle').value	= oLink.style.cssText ;
339
	}
340
	else
341
	{
342
		sClass	= oLink.getAttribute('class',2) || '' ;
343
		GetE('txtAttStyle').value	= oLink.getAttribute('style',2) || '' ;
344
	}
345
	GetE('txtAttClasses').value	= sClass ;
346

    
347
	// Update the Link type combo.
348
	GetE('cmbLinkType').value = sType ;
349
}
350

    
351
//#### Link type selection.
352
function SetLinkType( linkType )
353
{
354
	ShowE('divLinkTypeUrl'		, (linkType == 'url') ) ;
355
	ShowE('divLinkTypeAnchor'	, (linkType == 'anchor') ) ;
356
	ShowE('divLinkTypeEMail'	, (linkType == 'email') ) ;
357

    
358
	if ( !FCKConfig.LinkDlgHideTarget )
359
		dialog.SetTabVisibility( 'Target'	, (linkType == 'url') ) ;
360

    
361
	if ( FCKConfig.LinkUpload )
362
		dialog.SetTabVisibility( 'Upload'	, (linkType == 'url') ) ;
363

    
364
	if ( !FCKConfig.LinkDlgHideAdvanced )
365
		dialog.SetTabVisibility( 'Advanced'	, (linkType != 'anchor' || bHasAnchors) ) ;
366

    
367
	if ( linkType == 'email' )
368
		dialog.SetAutoSize( true ) ;
369
}
370

    
371
//#### Target type selection.
372
function SetTarget( targetType )
373
{
374
	GetE('tdTargetFrame').style.display	= ( targetType == 'popup' ? 'none' : '' ) ;
375
	GetE('tdPopupName').style.display	=
376
	GetE('tablePopupFeatures').style.display = ( targetType == 'popup' ? '' : 'none' ) ;
377

    
378
	switch ( targetType )
379
	{
380
		case "_blank" :
381
		case "_self" :
382
		case "_parent" :
383
		case "_top" :
384
			GetE('txtTargetFrame').value = targetType ;
385
			break ;
386
		case "" :
387
			GetE('txtTargetFrame').value = '' ;
388
			break ;
389
	}
390

    
391
	if ( targetType == 'popup' )
392
		dialog.SetAutoSize( true ) ;
393
}
394

    
395
//#### Called while the user types the URL.
396
function OnUrlChange()
397
{
398
	var sUrl = GetE('txtUrl').value ;
399
	var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ;
400

    
401
	if ( sProtocol )
402
	{
403
		sUrl = sUrl.substr( sProtocol[0].length ) ;
404
		GetE('txtUrl').value = sUrl ;
405
		GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ;
406
	}
407
	else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) )
408
	{
409
		GetE('cmbLinkProtocol').value = '' ;
410
	}
411
}
412

    
413
//#### Called while the user types the target name.
414
function OnTargetNameChange()
415
{
416
	var sFrame = GetE('txtTargetFrame').value ;
417

    
418
	if ( sFrame.length == 0 )
419
		GetE('cmbTarget').value = '' ;
420
	else if ( oRegex.ReserveTarget.test( sFrame ) )
421
		GetE('cmbTarget').value = sFrame.toLowerCase() ;
422
	else
423
		GetE('cmbTarget').value = 'frame' ;
424
}
425

    
426
// Accessible popups
427
function BuildOnClickPopup()
428
{
429
	var sWindowName = "'" + GetE('txtPopupName').value.replace(/\W/gi, "") + "'" ;
430

    
431
	var sFeatures = '' ;
432
	var aChkFeatures = document.getElementsByName( 'chkFeature' ) ;
433
	for ( var i = 0 ; i < aChkFeatures.length ; i++ )
434
	{
435
		if ( i > 0 ) sFeatures += ',' ;
436
		sFeatures += aChkFeatures[i].value + '=' + ( aChkFeatures[i].checked ? 'yes' : 'no' ) ;
437
	}
438

    
439
	if ( GetE('txtPopupWidth').value.length > 0 )	sFeatures += ',width=' + GetE('txtPopupWidth').value ;
440
	if ( GetE('txtPopupHeight').value.length > 0 )	sFeatures += ',height=' + GetE('txtPopupHeight').value ;
441
	if ( GetE('txtPopupLeft').value.length > 0 )	sFeatures += ',left=' + GetE('txtPopupLeft').value ;
442
	if ( GetE('txtPopupTop').value.length > 0 )		sFeatures += ',top=' + GetE('txtPopupTop').value ;
443

    
444
	if ( sFeatures != '' )
445
		sFeatures = sFeatures + ",status" ;
446

    
447
	return ( "window.open(this.href," + sWindowName + ",'" + sFeatures + "'); return false" ) ;
448
}
449

    
450
//#### Fills all Popup related fields.
451
function FillPopupFields( windowName, features )
452
{
453
	if ( windowName )
454
		GetE('txtPopupName').value = windowName ;
455

    
456
	var oFeatures = new Object() ;
457
	var oFeaturesMatch ;
458
	while( ( oFeaturesMatch = oRegex.PopupFeatures.exec( features ) ) != null )
459
	{
460
		var sValue = oFeaturesMatch[2] ;
461
		if ( sValue == ( 'yes' || '1' ) )
462
			oFeatures[ oFeaturesMatch[1] ] = true ;
463
		else if ( ! isNaN( sValue ) && sValue != 0 )
464
			oFeatures[ oFeaturesMatch[1] ] = sValue ;
465
	}
466

    
467
	// Update all features check boxes.
468
	var aChkFeatures = document.getElementsByName('chkFeature') ;
469
	for ( var i = 0 ; i < aChkFeatures.length ; i++ )
470
	{
471
		if ( oFeatures[ aChkFeatures[i].value ] )
472
			aChkFeatures[i].checked = true ;
473
	}
474

    
475
	// Update position and size text boxes.
476
	if ( oFeatures['width'] )	GetE('txtPopupWidth').value		= oFeatures['width'] ;
477
	if ( oFeatures['height'] )	GetE('txtPopupHeight').value	= oFeatures['height'] ;
478
	if ( oFeatures['left'] )	GetE('txtPopupLeft').value		= oFeatures['left'] ;
479
	if ( oFeatures['top'] )		GetE('txtPopupTop').value		= oFeatures['top'] ;
480
}
481

    
482
//#### The OK button was hit.
483
function Ok()
484
{
485
	var sUri, sInnerHtml ;
486
	oEditor.FCKUndo.SaveUndoStep() ;
487

    
488
	switch ( GetE('cmbLinkType').value )
489
	{
490
		case 'url' :
491
			sUri = GetE('txtUrl').value ;
492

    
493
			if ( sUri.length == 0 )
494
			{
495
				alert( FCKLang.DlnLnkMsgNoUrl ) ;
496
				return false ;
497
			}
498

    
499
			sUri = GetE('cmbLinkProtocol').value + sUri ;
500

    
501
			break ;
502

    
503
		case 'email' :
504
			sUri = GetE('txtEMailAddress').value ;
505

    
506
			if ( sUri.length == 0 )
507
			{
508
				alert( FCKLang.DlnLnkMsgNoEMail ) ;
509
				return false ;
510
			}
511

    
512
			sUri = oParser.CreateEMailUri(
513
				sUri,
514
				GetE('txtEMailSubject').value,
515
				GetE('txtEMailBody').value ) ;
516
			break ;
517

    
518
		case 'anchor' :
519
			var sAnchor = GetE('cmbAnchorName').value ;
520
			if ( sAnchor.length == 0 ) sAnchor = GetE('cmbAnchorId').value ;
521

    
522
			if ( sAnchor.length == 0 )
523
			{
524
				alert( FCKLang.DlnLnkMsgNoAnchor ) ;
525
				return false ;
526
			}
527

    
528
			sUri = '#' + sAnchor ;
529
			break ;
530
	}
531

    
532
	// If no link is selected, create a new one (it may result in more than one link creation - #220).
533
	var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri, true ) ;
534

    
535
	// If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26)
536
	var aHasSelection = ( aLinks.length > 0 ) ;
537
	if ( !aHasSelection )
538
	{
539
		sInnerHtml = sUri;
540

    
541
		// Built a better text for empty links.
542
		switch ( GetE('cmbLinkType').value )
543
		{
544
			// anchor: use old behavior --> return true
545
			case 'anchor':
546
				sInnerHtml = sInnerHtml.replace( /^#/, '' ) ;
547
				break ;
548

    
549
			// url: try to get path
550
			case 'url':
551
				var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ;
552
				var asLinkPath = oLinkPathRegEx.exec( sUri ) ;
553
				if (asLinkPath != null)
554
					sInnerHtml = asLinkPath[1];  // use matched path
555
				break ;
556

    
557
			// mailto: try to get email address
558
			case 'email':
559
				sInnerHtml = GetE('txtEMailAddress').value ;
560
				break ;
561
		}
562

    
563
		// Create a new (empty) anchor.
564
		aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ;
565
	}
566

    
567
	for ( var i = 0 ; i < aLinks.length ; i++ )
568
	{
569
		oLink = aLinks[i] ;
570

    
571
		if ( aHasSelection )
572
			sInnerHtml = oLink.innerHTML ;		// Save the innerHTML (IE changes it if it is like an URL).
573

    
574
		oLink.href = sUri ;
575
		SetAttribute( oLink, '_fcksavedurl', sUri ) ;
576

    
577
		var onclick;
578
		// Accessible popups
579
		if( GetE('cmbTarget').value == 'popup' )
580
		{
581
			onclick = BuildOnClickPopup() ;
582
			// Encode the attribute
583
			onclick = encodeURIComponent( " onclick=\"" + onclick + "\"" )  ;
584
			SetAttribute( oLink, 'onclick_fckprotectedatt', onclick ) ;
585
		}
586
		else
587
		{
588
			// Check if the previous onclick was for a popup:
589
			// In that case remove the onclick handler.
590
			onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ;
591
			if ( onclick )
592
			{
593
				// Decode the protected string
594
				onclick = decodeURIComponent( onclick ) ;
595

    
596
				if( oRegex.OnClickPopup.test( onclick ) )
597
					SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ;
598
			}
599
		}
600

    
601
		oLink.innerHTML = sInnerHtml ;		// Set (or restore) the innerHTML
602

    
603
		// Target
604
		if( GetE('cmbTarget').value != 'popup' )
605
			SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ;
606
		else
607
			SetAttribute( oLink, 'target', null ) ;
608

    
609
		// Let's set the "id" only for the first link to avoid duplication.
610
		if ( i == 0 )
611
			SetAttribute( oLink, 'id', GetE('txtAttId').value ) ;
612

    
613
		// Advances Attributes
614
		SetAttribute( oLink, 'name'		, GetE('txtAttName').value ) ;
615
		SetAttribute( oLink, 'dir'		, GetE('cmbAttLangDir').value ) ;
616
		SetAttribute( oLink, 'lang'		, GetE('txtAttLangCode').value ) ;
617
		SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ;
618
		SetAttribute( oLink, 'tabindex'	, ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ;
619
		SetAttribute( oLink, 'title'	, GetE('txtAttTitle').value ) ;
620
		SetAttribute( oLink, 'type'		, GetE('txtAttContentType').value ) ;
621
		SetAttribute( oLink, 'charset'	, GetE('txtAttCharSet').value ) ;
622

    
623
		if ( oEditor.FCKBrowserInfo.IsIE )
624
		{
625
			var sClass = GetE('txtAttClasses').value ;
626
			// If it's also an anchor add an internal class
627
			if ( GetE('txtAttName').value.length != 0 )
628
				sClass += ' FCK__AnchorC' ;
629
			SetAttribute( oLink, 'className', sClass ) ;
630

    
631
			oLink.style.cssText = GetE('txtAttStyle').value ;
632
		}
633
		else
634
		{
635
			SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ;
636
			SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ;
637
		}
638
	}
639

    
640
	// Select the (first) link.
641
	oEditor.FCKSelection.SelectNode( aLinks[0] );
642

    
643
	return true ;
644
}
645

    
646
function BrowseServer()
647
{
648
	OpenFileBrowser( FCKConfig.LinkBrowserURL, FCKConfig.LinkBrowserWindowWidth, FCKConfig.LinkBrowserWindowHeight ) ;
649
}
650

    
651
function SetUrl( url )
652
{
653
	document.getElementById('txtUrl').value = url ;
654
	OnUrlChange() ;
655
	dialog.SetSelectedTab( 'Info' ) ;
656
}
657

    
658
function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
659
{
660
	switch ( errorNumber )
661
	{
662
		case 0 :	// No errors
663
			alert( 'Your file has been successfully uploaded' ) ;
664
			break ;
665
		case 1 :	// Custom error
666
			alert( customMsg ) ;
667
			return ;
668
		case 101 :	// Custom warning
669
			alert( customMsg ) ;
670
			break ;
671
		case 201 :
672
			alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
673
			break ;
674
		case 202 :
675
			alert( 'Invalid file type' ) ;
676
			return ;
677
		case 203 :
678
			alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
679
			return ;
680
		case 500 :
681
			alert( 'The connector is disabled' ) ;
682
			break ;
683
		default :
684
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
685
			return ;
686
	}
687

    
688
	SetUrl( fileUrl ) ;
689
	GetE('frmUpload').reset() ;
690
}
691

    
692
var oUploadAllowedExtRegex	= new RegExp( FCKConfig.LinkUploadAllowedExtensions, 'i' ) ;
693
var oUploadDeniedExtRegex	= new RegExp( FCKConfig.LinkUploadDeniedExtensions, 'i' ) ;
694

    
695
function CheckUpload()
696
{
697
	var sFile = GetE('txtUploadFile').value ;
698

    
699
	if ( sFile.length == 0 )
700
	{
701
		alert( 'Please select a file to upload' ) ;
702
		return false ;
703
	}
704

    
705
	if ( ( FCKConfig.LinkUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
706
		( FCKConfig.LinkUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
707
	{
708
		OnUploadCompleted( 202 ) ;
709
		return false ;
710
	}
711

    
712
	return true ;
713
}
714

    
715
function SetDefaultTarget()
716
{
717
	var target = FCKConfig.DefaultLinkTarget || '' ;
718

    
719
	if ( oLink || target.length == 0 )
720
		return ;
721

    
722
	switch ( target )
723
	{
724
		case '_blank' :
725
		case '_self' :
726
		case '_parent' :
727
		case '_top' :
728
			GetE('cmbTarget').value = target ;
729
			break ;
730
		default :
731
			GetE('cmbTarget').value = 'frame' ;
732
			break ;
733
	}
734

    
735
	GetE('txtTargetFrame').value = target ;
736
}
(1-1/2)