Subversion Repositories Applications.papyrus

Rev

Rev 431 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
431 ddelon 1
/*
2
 * FCKeditor - The text editor for internet
3
 * Copyright (C) 2003-2005 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
 *
521 ddelon 11
 * "Support Open Source software. What about a donation today?"
12
 *
431 ddelon 13
 * File Name: fck_flash.js
14
 * 	Scripts related to the Flash dialog window (see fck_flash.html).
15
 *
16
 * File Authors:
17
 * 		Frederico Caldeira Knabben (fredck@fckeditor.net)
18
 */
19
 
20
var oEditor		= window.parent.InnerDialogLoaded() ;
21
var FCK			= oEditor.FCK ;
22
var FCKLang		= oEditor.FCKLang ;
23
var FCKConfig	= oEditor.FCKConfig ;
24
 
25
//#### Dialog Tabs
26
 
27
// Set the dialog tabs.
28
window.parent.AddTab( 'Info', oEditor.FCKLang.DlgInfoTab ) ;
29
 
30
if ( FCKConfig.FlashUpload )
31
	window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;
32
 
33
if ( !FCKConfig.FlashDlgHideAdvanced )
34
	window.parent.AddTab( 'Advanced', oEditor.FCKLang.DlgAdvancedTag ) ;
35
 
36
// Function called when a dialog tag is selected.
37
function OnDialogTabChange( tabCode )
38
{
39
	ShowE('divInfo'		, ( tabCode == 'Info' ) ) ;
40
	ShowE('divUpload'	, ( tabCode == 'Upload' ) ) ;
41
	ShowE('divAdvanced'	, ( tabCode == 'Advanced' ) ) ;
42
}
43
 
44
// Get the selected flash embed (if available).
45
var oFakeImage = FCK.Selection.GetSelectedElement() ;
46
var oEmbed ;
47
 
48
if ( oFakeImage )
49
{
50
	if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckflash') )
51
		oEmbed = FCK.GetRealElement( oFakeImage ) ;
52
	else
53
		oFakeImage = null ;
54
}
55
 
56
window.onload = function()
57
{
58
	// Translate the dialog box texts.
59
	oEditor.FCKLanguageManager.TranslatePage(document) ;
60
 
61
	// Load the selected element information (if any).
62
	LoadSelection() ;
63
 
64
	// Show/Hide the "Browse Server" button.
65
	GetE('tdBrowse').style.display = FCKConfig.FlashBrowser	? '' : 'none' ;
66
 
67
	// Set the actual uploader URL.
68
	if ( FCKConfig.FlashUpload )
69
		GetE('frmUpload').action = FCKConfig.FlashUploadURL ;
70
 
71
	window.parent.SetAutoSize( true ) ;
72
 
73
	// Activate the "OK" button.
74
	window.parent.SetOkButton( true ) ;
75
}
76
 
77
function LoadSelection()
78
{
79
	if ( ! oEmbed ) return ;
80
 
81
	var sUrl = GetAttribute( oEmbed, 'src', '' ) ;
82
 
83
	GetE('txtUrl').value    = GetAttribute( oEmbed, 'src', '' ) ;
84
	GetE('txtWidth').value  = GetAttribute( oEmbed, 'width', '' ) ;
85
	GetE('txtHeight').value = GetAttribute( oEmbed, 'height', '' ) ;
86
 
87
	// Get Advances Attributes
88
	GetE('txtAttId').value		= oEmbed.id ;
89
	GetE('chkAutoPlay').checked	= GetAttribute( oEmbed, 'play', 'true' ) == 'true' ;
90
	GetE('chkLoop').checked		= GetAttribute( oEmbed, 'loop', 'true' ) == 'true' ;
91
	GetE('chkMenu').checked		= GetAttribute( oEmbed, 'menu', 'true' ) == 'true' ;
92
	GetE('cmbScale').value		= GetAttribute( oEmbed, 'scale', '' ).toLowerCase() ;
93
 
94
	GetE('txtAttTitle').value		= oEmbed.title ;
95
	GetE('txtAttClasses').value		= oEmbed.getAttribute('class',2) || '' ;
96
 
97
	if ( oEditor.FCKBrowserInfo.IsIE )
98
		GetE('txtAttStyle').value	= oEmbed.style.cssText ;
99
	else
100
		GetE('txtAttStyle').value	= oEmbed.getAttribute('style',2) ;
101
 
102
	UpdatePreview() ;
103
}
104
 
105
//#### The OK button was hit.
106
function Ok()
107
{
108
	if ( GetE('txtUrl').value.length == 0 )
109
	{
110
		window.parent.SetSelectedTab( 'Info' ) ;
111
		GetE('txtUrl').focus() ;
112
 
113
		alert( oEditor.FCKLang.DlgAlertUrl ) ;
114
 
115
		return false ;
116
	}
117
 
118
	if ( !oEmbed )
119
	{
120
		oEmbed		= FCK.EditorDocument.createElement( 'EMBED' ) ;
121
		oFakeImage  = null ;
122
	}
123
	UpdateEmbed( oEmbed ) ;
124
 
125
	if ( !oFakeImage )
126
	{
127
		oFakeImage	= oEditor.FCKDocumentProcessors_CreateFakeImage( 'FCK__Flash', oEmbed ) ;
128
		oFakeImage.setAttribute( '_fckflash', 'true', 0 ) ;
129
		oFakeImage	= FCK.InsertElementAndGetIt( oFakeImage ) ;
130
	}
131
	else
132
		oEditor.FCKUndo.SaveUndoStep() ;
133
 
134
	oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oEmbed ) ;
135
 
136
	return true ;
137
}
138
 
139
function UpdateEmbed( e )
140
{
141
	SetAttribute( e, 'type'			, 'application/x-shockwave-flash' ) ;
142
	SetAttribute( e, 'pluginspage'	, 'http://www.macromedia.com/go/getflashplayer' ) ;
143
 
144
	e.src = GetE('txtUrl').value ;
145
	SetAttribute( e, "width" , GetE('txtWidth').value ) ;
146
	SetAttribute( e, "height", GetE('txtHeight').value ) ;
147
 
148
	// Advances Attributes
149
 
150
	SetAttribute( e, 'id'	, GetE('txtAttId').value ) ;
151
	SetAttribute( e, 'scale', GetE('cmbScale').value ) ;
152
 
153
	if ( !GetE('chkAutoPlay').checked )	SetAttribute( e, 'play', 'false' ) ;
154
	if ( !GetE('chkLoop').checked )		SetAttribute( e, 'loop', 'false' ) ;
155
	if ( !GetE('chkMenu').checked )		SetAttribute( e, 'menu', 'false' ) ;
156
 
157
	SetAttribute( e, 'title'	, GetE('txtAttTitle').value ) ;
158
	SetAttribute( e, 'class'	, GetE('txtAttClasses').value ) ;
159
 
160
	if ( oEditor.FCKBrowserInfo.IsIE )
161
		e.style.cssText = GetE('txtAttStyle').value ;
162
	else
163
		SetAttribute( e, 'style', GetE('txtAttStyle').value ) ;
164
}
165
 
166
function UpdatePreview()
167
{
168
	var oCell = GetE('ePreviewCell') ;
169
 
170
	while ( oCell.firstChild )
171
		oCell.removeChild( oCell.firstChild ) ;
172
 
173
	if ( GetE('txtUrl').value.length == 0 )
174
		oCell.innerHTML = ' ' ;
175
	else
176
	{
177
		var e = document.createElement( 'EMBED' ) ;
178
 
179
		e.src		= GetE('txtUrl').value ;
180
		e.type		= 'application/x-shockwave-flash' ;
181
		e.width		= '100%' ;
182
		e.height	= '100%' ;
183
 
184
		oCell.appendChild( e ) ;
185
	}
186
}
187
 
188
// <embed id="ePreview" src="fck_flash/claims.swf" width="100%" height="100%" style="visibility:hidden" type="application/x-shockwave-flash" pluginspage="http://www.macromedia.com/go/getflashplayer">
189
 
190
function BrowseServer()
191
{
192
	OpenServerBrowser(
193
		'Flash',
194
		FCKConfig.FlashBrowserURL,
195
		FCKConfig.FlashBrowserWindowWidth,
196
		FCKConfig.FlashBrowserWindowHeight ) ;
197
}
198
 
199
function OpenServerBrowser( type, url, width, height )
200
{
521 ddelon 201
	var iLeft = (FCKConfig.ScreenWidth  - width) / 2 ;
202
	var iTop  = (FCKConfig.ScreenHeight - height) / 2 ;
431 ddelon 203
 
204
	var sOptions = "toolbar=no,status=no,resizable=yes,dependent=yes" ;
205
	sOptions += ",width=" + width ;
206
	sOptions += ",height=" + height ;
207
	sOptions += ",left=" + iLeft ;
208
	sOptions += ",top=" + iTop ;
209
 
521 ddelon 210
	if ( oEditor.FCKBrowserInfo.IsIE )
211
	{
212
		// The following change has been made otherwise IE will open the file
213
		// browser on a different server session (on some cases):
214
		// http://support.microsoft.com/default.aspx?scid=kb;en-us;831678
215
		// by Simone Chiaretta.
216
		var oWindow = oEditor.window.open( url, "FCKBrowseWindow", sOptions ) ;
217
		oWindow.opener = window ;
218
    }
219
    else
220
		window.open( url, "FCKBrowseWindow", sOptions ) ;
431 ddelon 221
}
222
 
223
function SetUrl( url )
224
{
225
	GetE('txtUrl').value = url ;
226
	UpdatePreview() ;
227
 
228
	window.parent.SetSelectedTab( 'Info' ) ;
229
}
230
 
231
function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
232
{
233
	switch ( errorNumber )
234
	{
235
		case 0 :	// No errors
236
			alert( 'Your file has been successfully uploaded' ) ;
237
			break ;
238
		case 1 :	// Custom error
239
			alert( customMsg ) ;
240
			return ;
241
		case 101 :	// Custom warning
242
			alert( customMsg ) ;
243
			break ;
244
		case 201 :
245
			alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
246
			break ;
247
		case 202 :
248
			alert( 'Invalid file type' ) ;
249
			return ;
250
		case 203 :
251
			alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
252
			return ;
253
		default :
254
			alert( 'Error on file upload. Error number: ' + errorNumber ) ;
255
			return ;
256
	}
257
 
258
	SetUrl( fileUrl ) ;
259
	GetE('frmUpload').reset() ;
260
}
261
 
262
var oUploadAllowedExtRegex	= new RegExp( FCKConfig.FlashUploadAllowedExtensions, 'i' ) ;
263
var oUploadDeniedExtRegex	= new RegExp( FCKConfig.FlashUploadDeniedExtensions, 'i' ) ;
264
 
265
function CheckUpload()
266
{
267
	var sFile = GetE('txtUploadFile').value ;
268
 
269
	if ( sFile.length == 0 )
270
	{
271
		alert( 'Please select a file to upload' ) ;
272
		return false ;
273
	}
274
 
275
	if ( ( FCKConfig.FlashUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
276
		( FCKConfig.FlashUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
277
	{
278
		OnUploadCompleted( 202 ) ;
279
		return false ;
280
	}
281
 
282
	return true ;
283
}