Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1688 Rev 1921
Line 1... Line 1...
1
/*
1
/*
2
 * FCKeditor - The text editor for internet
2
 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3
 * Copyright (C) 2003-2006 Frederico Caldeira Knabben
3
 * Copyright (C) 2003-2008 Frederico Caldeira Knabben
-
 
4
 *
-
 
5
 * == BEGIN LICENSE ==
4
 * 
6
 *
5
 * Licensed under the terms of the GNU Lesser General Public License:
7
 * Licensed under the terms of any of the following licenses at your
6
 * 		http://www.opensource.org/licenses/lgpl-license.php
8
 * choice:
7
 * 
9
 *
8
 * For further information visit:
10
 *  - GNU General Public License Version 2 or later (the "GPL")
9
 * 		http://www.fckeditor.net/
11
 *    http://www.gnu.org/licenses/gpl.html
10
 * 
12
 *
11
 * "Support Open Source software. What about a donation today?"
13
 *  - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
-
 
14
 *    http://www.gnu.org/licenses/lgpl.html
12
 * 
15
 *
13
 * File Name: fck_image.js
16
 *  - Mozilla Public License Version 1.1 or later (the "MPL")
14
 * 	Scripts related to the Image dialog window (see fck_image.html).
17
 *    http://www.mozilla.org/MPL/MPL-1.1.html
15
 * 
18
 *
16
 * File Authors:
19
 * == END LICENSE ==
-
 
20
 *
17
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
21
 * Scripts related to the Image dialog window (see fck_image.html).
18
 */
22
 */
Line -... Line 23...
-
 
23
 
19
 
24
var dialog		= window.parent ;
20
var oEditor		= window.parent.InnerDialogLoaded() ;
25
var oEditor		= dialog.InnerDialogLoaded() ;
21
var FCK			= oEditor.FCK ;
26
var FCK			= oEditor.FCK ;
22
var FCKLang		= oEditor.FCKLang ;
27
var FCKLang		= oEditor.FCKLang ;
23
var FCKConfig	= oEditor.FCKConfig ;
28
var FCKConfig	= oEditor.FCKConfig ;
-
 
29
var FCKDebug	= oEditor.FCKDebug ;
Line 24... Line 30...
24
var FCKDebug	= oEditor.FCKDebug ;
30
var FCKTools	= oEditor.FCKTools ;
Line 25... Line 31...
25
 
31
 
Line 26... Line 32...
26
var bImageButton = ( document.location.search.length > 0 && document.location.search.substr(1) == 'ImageButton' ) ;
32
var bImageButton = ( document.location.search.length > 0 && document.location.search.substr(1) == 'ImageButton' ) ;
27
 
33
 
Line 28... Line 34...
28
//#### Dialog Tabs
34
//#### Dialog Tabs
29
 
35
 
Line 30... Line 36...
30
// Set the dialog tabs.
36
// Set the dialog tabs.
31
window.parent.AddTab( 'Info', FCKLang.DlgImgInfoTab ) ;
37
dialog.AddTab( 'Info', FCKLang.DlgImgInfoTab ) ;
Line 32... Line 38...
32
 
38
 
33
if ( !bImageButton && !FCKConfig.ImageDlgHideLink )
39
if ( !bImageButton && !FCKConfig.ImageDlgHideLink )
Line 34... Line 40...
34
	window.parent.AddTab( 'Link', FCKLang.DlgImgLinkTab ) ;
40
	dialog.AddTab( 'Link', FCKLang.DlgImgLinkTab ) ;
35
 
41
 
36
if ( FCKConfig.ImageUpload )
42
if ( FCKConfig.ImageUpload )
37
	window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;
43
	dialog.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;
Line 47... Line 53...
47
	ShowE('divUpload'	, ( tabCode == 'Upload' ) ) ;
53
	ShowE('divUpload'	, ( tabCode == 'Upload' ) ) ;
48
	ShowE('divAdvanced'	, ( tabCode == 'Advanced' ) ) ;
54
	ShowE('divAdvanced'	, ( tabCode == 'Advanced' ) ) ;
49
}
55
}
Line 50... Line 56...
50
 
56
 
51
// Get the selected image (if available).
57
// Get the selected image (if available).
Line 52... Line 58...
52
var oImage = FCK.Selection.GetSelectedElement() ;
58
var oImage = dialog.Selection.GetSelectedElement() ;
53
 
59
 
Line 54... Line 60...
54
if ( oImage && oImage.tagName != 'IMG' && !( oImage.tagName == 'INPUT' && oImage.type == 'image' ) )
60
if ( oImage && oImage.tagName != 'IMG' && !( oImage.tagName == 'INPUT' && oImage.type == 'image' ) )
55
	oImage = null ;
61
	oImage = null ;
Line 56... Line 62...
56
 
62
 
Line 57... Line 63...
57
// Get the active link.
63
// Get the active link.
58
var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ;
64
var oLink = dialog.Selection.GetSelection().MoveToAncestorNode( 'A' ) ;
59
 
65
 
60
var oImageOriginal ;
66
var oImageOriginal ;
61
 
67
 
62
function UpdateOriginal( resetSize )
68
function UpdateOriginal( resetSize )
63
{
69
{
64
	if ( !eImgPreview )
70
	if ( !eImgPreview )
65
		return ;
71
		return ;
66
	
72
 
67
	if ( GetE('txtUrl').value.length == 0 )
73
	if ( GetE('txtUrl').value.length == 0 )
68
	{
74
	{
Line 69... Line 75...
69
		oImageOriginal = null ;
75
		oImageOriginal = null ;
70
		return ;
76
		return ;
71
	}
77
	}
Line 105... Line 111...
105
 
111
 
106
	// Set the actual uploader URL.
112
	// Set the actual uploader URL.
107
	if ( FCKConfig.ImageUpload )
113
	if ( FCKConfig.ImageUpload )
Line 108... Line 114...
108
		GetE('frmUpload').action = FCKConfig.ImageUploadURL ;
114
		GetE('frmUpload').action = FCKConfig.ImageUploadURL ;
Line 109... Line 115...
109
 
115
 
110
	window.parent.SetAutoSize( true ) ;
116
	dialog.SetAutoSize( true ) ;
-
 
117
 
-
 
118
	// Activate the "OK" button.
111
 
119
	dialog.SetOkButton( true ) ;
Line 112... Line 120...
112
	// Activate the "OK" button.
120
 
113
	window.parent.SetOkButton( true ) ;
121
	SelectField( 'txtUrl' ) ;
114
}
122
}
Line 129... Line 137...
129
	GetE('cmbAlign').value	= GetAttribute( oImage, 'align', '' ) ;
137
	GetE('cmbAlign').value	= GetAttribute( oImage, 'align', '' ) ;
Line 130... Line 138...
130
 
138
 
Line 131... Line 139...
131
	var iWidth, iHeight ;
139
	var iWidth, iHeight ;
132
 
140
 
133
	var regexSize = /^\s*(\d+)px\s*$/i ;
141
	var regexSize = /^\s*(\d+)px\s*$/i ;
134
	
142
 
135
	if ( oImage.style.width )
143
	if ( oImage.style.width )
136
	{
144
	{
137
		var aMatch  = oImage.style.width.match( regexSize ) ;
145
		var aMatchW  = oImage.style.width.match( regexSize ) ;
138
		if ( aMatch )
146
		if ( aMatchW )
139
		{
147
		{
-
 
148
			iWidth = aMatchW[1] ;
140
			iWidth = aMatch[1] ;
149
			oImage.style.width = '' ;
141
			oImage.style.width = '' ;
150
			SetAttribute( oImage, 'width' , iWidth ) ;
Line 142... Line 151...
142
		}
151
		}
143
	}
152
	}
144
 
153
 
145
	if ( oImage.style.height )
154
	if ( oImage.style.height )
146
	{
155
	{
147
		var aMatch  = oImage.style.height.match( regexSize ) ;
156
		var aMatchH  = oImage.style.height.match( regexSize ) ;
148
		if ( aMatch )
157
		if ( aMatchH )
-
 
158
		{
149
		{
159
			iHeight = aMatchH[1] ;
150
			iHeight = aMatch[1] ;
160
			oImage.style.height = '' ;
Line 151... Line 161...
151
			oImage.style.height = '' ;
161
			SetAttribute( oImage, 'height', iHeight ) ;
152
		}
162
		}
Line 158... Line 168...
158
	// Get Advances Attributes
168
	// Get Advances Attributes
159
	GetE('txtAttId').value			= oImage.id ;
169
	GetE('txtAttId').value			= oImage.id ;
160
	GetE('cmbAttLangDir').value		= oImage.dir ;
170
	GetE('cmbAttLangDir').value		= oImage.dir ;
161
	GetE('txtAttLangCode').value	= oImage.lang ;
171
	GetE('txtAttLangCode').value	= oImage.lang ;
162
	GetE('txtAttTitle').value		= oImage.title ;
172
	GetE('txtAttTitle').value		= oImage.title ;
163
	GetE('txtAttClasses').value		= oImage.getAttribute('class',2) || '' ;
-
 
164
	GetE('txtLongDesc').value		= oImage.longDesc ;
173
	GetE('txtLongDesc').value		= oImage.longDesc ;
Line 165... Line 174...
165
 
174
 
-
 
175
	if ( oEditor.FCKBrowserInfo.IsIE )
-
 
176
	{
166
	if ( oEditor.FCKBrowserInfo.IsIE )
177
		GetE('txtAttClasses').value = oImage.className || '' ;
-
 
178
		GetE('txtAttStyle').value = oImage.style.cssText ;
167
		GetE('txtAttStyle').value	= oImage.style.cssText ;
179
	}
-
 
180
	else
-
 
181
	{
168
	else
182
		GetE('txtAttClasses').value = oImage.getAttribute('class',2) || '' ;
-
 
183
		GetE('txtAttStyle').value = oImage.getAttribute('style',2) ;
Line 169... Line 184...
169
		GetE('txtAttStyle').value	= oImage.getAttribute('style',2) ;
184
	}
170
 
185
 
171
	if ( oLink )
186
	if ( oLink )
172
	{
187
	{
173
		var sUrl = oLink.getAttribute( '_fcksavedurl' ) ;
188
		var sLinkUrl = oLink.getAttribute( '_fcksavedurl' ) ;
174
		if ( sUrl == null )
189
		if ( sLinkUrl == null )
175
			sUrl = oLink.getAttribute('href',2) ;
190
			sLinkUrl = oLink.getAttribute('href',2) ;
176
	
191
 
177
		GetE('txtLnkUrl').value		= sUrl ;
192
		GetE('txtLnkUrl').value		= sLinkUrl ;
Line 178... Line 193...
178
		GetE('cmbLnkTarget').value	= oLink.target ;
193
		GetE('cmbLnkTarget').value	= oLink.target ;
179
	}
194
	}
Line 184... Line 199...
184
//#### The OK button was hit.
199
//#### The OK button was hit.
185
function Ok()
200
function Ok()
186
{
201
{
187
	if ( GetE('txtUrl').value.length == 0 )
202
	if ( GetE('txtUrl').value.length == 0 )
188
	{
203
	{
189
		window.parent.SetSelectedTab( 'Info' ) ;
204
		dialog.SetSelectedTab( 'Info' ) ;
190
		GetE('txtUrl').focus() ;
205
		GetE('txtUrl').focus() ;
Line 191... Line 206...
191
 
206
 
Line 192... Line 207...
192
		alert( FCKLang.DlgImgAlertUrl ) ;
207
		alert( FCKLang.DlgImgAlertUrl ) ;
Line 204... Line 219...
204
	else if ( bHasImage && !bImageButton && oImage.tagName == 'INPUT' )
219
	else if ( bHasImage && !bImageButton && oImage.tagName == 'INPUT' )
205
	{
220
	{
206
		if ( confirm( 'Do you want to transform the selected image button on a simple image?' ) )
221
		if ( confirm( 'Do you want to transform the selected image button on a simple image?' ) )
207
			oImage = null ;
222
			oImage = null ;
208
	}
223
	}
209
	
224
 
-
 
225
	oEditor.FCKUndo.SaveUndoStep() ;
210
	if ( !bHasImage )
226
	if ( !bHasImage )
211
	{
227
	{
212
		if ( bImageButton )
228
		if ( bImageButton )
213
		{
229
		{
214
			oImage = FCK.EditorDocument.createElement( 'INPUT' ) ;
230
			oImage = FCK.EditorDocument.createElement( 'input' ) ;
215
			oImage.type = 'image' ;
231
			oImage.type = 'image' ;
216
			oImage = FCK.InsertElementAndGetIt( oImage ) ;
232
			oImage = FCK.InsertElement( oImage ) ;
217
		}
233
		}
218
		else
234
		else
219
			oImage = FCK.CreateElement( 'IMG' ) ;
235
			oImage = FCK.InsertElement( 'img' ) ;
220
	}
236
	}
221
	else
-
 
222
		oEditor.FCKUndo.SaveUndoStep() ;
-
 
223
	
237
 
224
	UpdateImage( oImage ) ;
238
	UpdateImage( oImage ) ;
Line 225... Line 239...
225
 
239
 
Line 226... Line 240...
226
	var sLnkUrl = GetE('txtLnkUrl').value.trim() ;
240
	var sLnkUrl = GetE('txtLnkUrl').value.Trim() ;
227
 
241
 
228
	if ( sLnkUrl.length == 0 )
242
	if ( sLnkUrl.length == 0 )
229
	{
243
	{
Line 237... Line 251...
237
		else			// Creating a new link.
251
		else			// Creating a new link.
238
		{
252
		{
239
			if ( !bHasImage )
253
			if ( !bHasImage )
240
				oEditor.FCKSelection.SelectNode( oImage ) ;
254
				oEditor.FCKSelection.SelectNode( oImage ) ;
Line 241... Line 255...
241
 
255
 
Line 242... Line 256...
242
			oLink = oEditor.FCK.CreateLink( sLnkUrl ) ;
256
			oLink = oEditor.FCK.CreateLink( sLnkUrl )[0] ;
243
 
257
 
244
			if ( !bHasImage )
258
			if ( !bHasImage )
245
			{
259
			{
Line 273... Line 287...
273
		SetAttribute( e, 'id', GetE('txtAttId').value ) ;
287
		SetAttribute( e, 'id', GetE('txtAttId').value ) ;
Line 274... Line 288...
274
 
288
 
275
	SetAttribute( e, 'dir'		, GetE('cmbAttLangDir').value ) ;
289
	SetAttribute( e, 'dir'		, GetE('cmbAttLangDir').value ) ;
276
	SetAttribute( e, 'lang'		, GetE('txtAttLangCode').value ) ;
290
	SetAttribute( e, 'lang'		, GetE('txtAttLangCode').value ) ;
277
	SetAttribute( e, 'title'	, GetE('txtAttTitle').value ) ;
-
 
278
	SetAttribute( e, 'class'	, GetE('txtAttClasses').value ) ;
291
	SetAttribute( e, 'title'	, GetE('txtAttTitle').value ) ;
Line 279... Line 292...
279
	SetAttribute( e, 'longDesc'	, GetE('txtLongDesc').value ) ;
292
	SetAttribute( e, 'longDesc'	, GetE('txtLongDesc').value ) ;
-
 
293
 
-
 
294
	if ( oEditor.FCKBrowserInfo.IsIE )
280
 
295
	{
-
 
296
		e.className = GetE('txtAttClasses').value ;
281
	if ( oEditor.FCKBrowserInfo.IsIE )
297
		e.style.cssText = GetE('txtAttStyle').value ;
-
 
298
	}
-
 
299
	else
282
		e.style.cssText = GetE('txtAttStyle').value ;
300
	{
-
 
301
		SetAttribute( e, 'class'	, GetE('txtAttClasses').value ) ;
283
	else
302
		SetAttribute( e, 'style', GetE('txtAttStyle').value ) ;
Line 284... Line 303...
284
		SetAttribute( e, 'style', GetE('txtAttStyle').value ) ;
303
	}
285
}
304
}
Line 292... Line 311...
292
	eImgPreview = imageElement ;
311
	eImgPreview = imageElement ;
293
	eImgPreviewLink = linkElement ;
312
	eImgPreviewLink = linkElement ;
Line 294... Line 313...
294
 
313
 
295
	UpdatePreview() ;
314
	UpdatePreview() ;
296
	UpdateOriginal() ;
315
	UpdateOriginal() ;
297
	
316
 
298
	bPreviewInitialized = true ;
317
	bPreviewInitialized = true ;
Line 299... Line 318...
299
}
318
}
300
 
319
 
Line 307... Line 326...
307
		eImgPreviewLink.style.display = 'none' ;
326
		eImgPreviewLink.style.display = 'none' ;
308
	else
327
	else
309
	{
328
	{
310
		UpdateImage( eImgPreview, true ) ;
329
		UpdateImage( eImgPreview, true ) ;
Line 311... Line 330...
311
 
330
 
312
		if ( GetE('txtLnkUrl').value.trim().length > 0 )
331
		if ( GetE('txtLnkUrl').value.Trim().length > 0 )
313
			eImgPreviewLink.href = 'javascript:void(null);' ;
332
			eImgPreviewLink.href = 'javascript:void(null);' ;
314
		else
333
		else
Line 315... Line 334...
315
			SetAttribute( eImgPreviewLink, 'href', '' ) ;
334
			SetAttribute( eImgPreviewLink, 'href', '' ) ;
Line 336... Line 355...
336
}
355
}
Line 337... Line 356...
337
 
356
 
338
// Fired when the width or height input texts change
357
// Fired when the width or height input texts change
339
function OnSizeChanged( dimension, value )
358
function OnSizeChanged( dimension, value )
340
{
359
{
341
	// Verifies if the aspect ration has to be mantained
360
	// Verifies if the aspect ration has to be maintained
342
	if ( oImageOriginal && bLockRatio )
361
	if ( oImageOriginal && bLockRatio )
343
	{
362
	{
344
		var e = dimension == 'Width' ? GetE('txtHeight') : GetE('txtWidth') ;
363
		var e = dimension == 'Width' ? GetE('txtHeight') : GetE('txtWidth') ;
345
		
364
 
346
		if ( value.length == 0 || isNaN( value ) )
365
		if ( value.length == 0 || isNaN( value ) )
347
		{
366
		{
348
			e.value = '' ;
367
			e.value = '' ;
349
			return ;
368
			return ;
Line 363... Line 382...
363
 
382
 
364
// Fired when the Reset Size button is clicked
383
// Fired when the Reset Size button is clicked
365
function ResetSizes()
384
function ResetSizes()
366
{
385
{
-
 
386
	if ( ! oImageOriginal ) return ;
-
 
387
	if ( oEditor.FCKBrowserInfo.IsGecko && !oImageOriginal.complete )
-
 
388
	{
-
 
389
		setTimeout( ResetSizes, 50 ) ;
-
 
390
		return ;
Line 367... Line 391...
367
	if ( ! oImageOriginal ) return ;
391
	}
368
 
392
 
Line 369... Line 393...
369
	GetE('txtWidth').value  = oImageOriginal.width ;
393
	GetE('txtWidth').value  = oImageOriginal.width ;
Line 415... Line 439...
415
			GetE('txtAlt').value = alt;
439
			GetE('txtAlt').value = alt;
Line 416... Line 440...
416
 
440
 
417
		UpdatePreview() ;
441
		UpdatePreview() ;
418
		UpdateOriginal( true ) ;
442
		UpdateOriginal( true ) ;
419
	}
443
	}
420
	
444
 
421
	window.parent.SetSelectedTab( 'Info' ) ;
445
	dialog.SetSelectedTab( 'Info' ) ;
Line 422... Line 446...
422
}
446
}
423
 
447
 
-
 
448
function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
-
 
449
{
-
 
450
	// Remove animation
-
 
451
	window.parent.Throbber.Hide() ;
424
function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
452
	GetE( 'divUpload' ).style.display  = '' ;
425
{
453
 
426
	switch ( errorNumber )
454
	switch ( errorNumber )
427
	{
455
	{
428
		case 0 :	// No errors
456
		case 0 :	// No errors
Line 441... Line 469...
441
			alert( 'Invalid file type' ) ;
469
			alert( 'Invalid file type' ) ;
442
			return ;
470
			return ;
443
		case 203 :
471
		case 203 :
444
			alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
472
			alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
445
			return ;
473
			return ;
-
 
474
		case 500 :
-
 
475
			alert( 'The connector is disabled' ) ;
-
 
476
			break ;
446
		default :
477
		default :
447
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
478
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
448
			return ;
479
			return ;
449
	}
480
	}
Line 450... Line 481...
450
 
481
 
451
	sActualBrowser = ''
482
	sActualBrowser = '' ;
452
	SetUrl( fileUrl ) ;
483
	SetUrl( fileUrl ) ;
453
	GetE('frmUpload').reset() ;
484
	GetE('frmUpload').reset() ;
Line 454... Line 485...
454
}
485
}
455
 
486
 
Line 456... Line 487...
456
var oUploadAllowedExtRegex	= new RegExp( FCKConfig.ImageUploadAllowedExtensions, 'i' ) ;
487
var oUploadAllowedExtRegex	= new RegExp( FCKConfig.ImageUploadAllowedExtensions, 'i' ) ;
457
var oUploadDeniedExtRegex	= new RegExp( FCKConfig.ImageUploadDeniedExtensions, 'i' ) ;
488
var oUploadDeniedExtRegex	= new RegExp( FCKConfig.ImageUploadDeniedExtensions, 'i' ) ;
458
 
489
 
459
function CheckUpload()
490
function CheckUpload()
460
{
491
{
461
	var sFile = GetE('txtUploadFile').value ;
492
	var sFile = GetE('txtUploadFile').value ;
462
	
493
 
463
	if ( sFile.length == 0 )
494
	if ( sFile.length == 0 )
464
	{
495
	{
465
		alert( 'Please select a file to upload' ) ;
496
		alert( 'Please select a file to upload' ) ;
466
		return false ;
497
		return false ;
467
	}
498
	}
468
	
499
 
469
	if ( ( FCKConfig.ImageUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
500
	if ( ( FCKConfig.ImageUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
470
		( FCKConfig.ImageUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
501
		( FCKConfig.ImageUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
471
	{
502
	{
472
		OnUploadCompleted( 202 ) ;
503
		OnUploadCompleted( 202 ) ;
-
 
504
		return false ;
-
 
505
	}
-
 
506
 
-
 
507
	// Show animation
473
		return false ;
508
	window.parent.Throbber.Show( 100 ) ;
474
	}
-
 
475
	
509
	GetE( 'divUpload' ).style.display  = 'none' ;
-
 
510