2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
\r
3 * Copyright (C) 2003-2007 Frederico Caldeira Knabben
\r
5 * == BEGIN LICENSE ==
\r
7 * Licensed under the terms of any of the following licenses at your
\r
10 * - GNU General Public License Version 2 or later (the "GPL")
\r
11 * http://www.gnu.org/licenses/gpl.html
\r
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
\r
14 * http://www.gnu.org/licenses/lgpl.html
\r
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
\r
17 * http://www.mozilla.org/MPL/MPL-1.1.html
\r
21 * Scripts related to the Flash dialog window (see fck_flash.html).
\r
24 var oEditor = window.parent.InnerDialogLoaded() ;
\r
25 var FCK = oEditor.FCK ;
\r
26 var FCKLang = oEditor.FCKLang ;
\r
27 var FCKConfig = oEditor.FCKConfig ;
\r
31 // Set the dialog tabs.
\r
32 window.parent.AddTab( 'Info', oEditor.FCKLang.DlgInfoTab ) ;
\r
34 if ( FCKConfig.FlashUpload )
\r
35 window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;
\r
37 if ( !FCKConfig.FlashDlgHideAdvanced )
\r
38 window.parent.AddTab( 'Advanced', oEditor.FCKLang.DlgAdvancedTag ) ;
\r
40 // Function called when a dialog tag is selected.
\r
41 function OnDialogTabChange( tabCode )
\r
43 ShowE('divInfo' , ( tabCode == 'Info' ) ) ;
\r
44 ShowE('divUpload' , ( tabCode == 'Upload' ) ) ;
\r
45 ShowE('divAdvanced' , ( tabCode == 'Advanced' ) ) ;
\r
48 // Get the selected flash embed (if available).
\r
49 var oFakeImage = FCK.Selection.GetSelectedElement() ;
\r
54 if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckflash') )
\r
55 oEmbed = FCK.GetRealElement( oFakeImage ) ;
\r
60 window.onload = function()
\r
62 // Translate the dialog box texts.
\r
63 oEditor.FCKLanguageManager.TranslatePage(document) ;
\r
65 // Load the selected element information (if any).
\r
68 // Show/Hide the "Browse Server" button.
\r
69 GetE('tdBrowse').style.display = FCKConfig.FlashBrowser ? '' : 'none' ;
\r
71 // Set the actual uploader URL.
\r
72 if ( FCKConfig.FlashUpload )
\r
73 GetE('frmUpload').action = FCKConfig.FlashUploadURL ;
\r
75 window.parent.SetAutoSize( true ) ;
\r
77 // Activate the "OK" button.
\r
78 window.parent.SetOkButton( true ) ;
\r
81 function LoadSelection()
\r
83 if ( ! oEmbed ) return ;
\r
85 GetE('txtUrl').value = GetAttribute( oEmbed, 'src', '' ) ;
\r
86 GetE('txtWidth').value = GetAttribute( oEmbed, 'width', '' ) ;
\r
87 GetE('txtHeight').value = GetAttribute( oEmbed, 'height', '' ) ;
\r
89 // Get Advances Attributes
\r
90 GetE('txtAttId').value = oEmbed.id ;
\r
91 GetE('chkAutoPlay').checked = GetAttribute( oEmbed, 'play', 'true' ) == 'true' ;
\r
92 GetE('chkLoop').checked = GetAttribute( oEmbed, 'loop', 'true' ) == 'true' ;
\r
93 GetE('chkMenu').checked = GetAttribute( oEmbed, 'menu', 'true' ) == 'true' ;
\r
94 GetE('cmbScale').value = GetAttribute( oEmbed, 'scale', '' ).toLowerCase() ;
\r
96 GetE('txtAttTitle').value = oEmbed.title ;
\r
98 if ( oEditor.FCKBrowserInfo.IsIE )
\r
100 GetE('txtAttClasses').value = oEmbed.getAttribute('className') || '' ;
\r
101 GetE('txtAttStyle').value = oEmbed.style.cssText ;
\r
105 GetE('txtAttClasses').value = oEmbed.getAttribute('class',2) || '' ;
\r
106 GetE('txtAttStyle').value = oEmbed.getAttribute('style',2) || '' ;
\r
112 //#### The OK button was hit.
\r
115 if ( GetE('txtUrl').value.length == 0 )
\r
117 window.parent.SetSelectedTab( 'Info' ) ;
\r
118 GetE('txtUrl').focus() ;
\r
120 alert( oEditor.FCKLang.DlgAlertUrl ) ;
\r
127 oEmbed = FCK.EditorDocument.createElement( 'EMBED' ) ;
\r
128 oFakeImage = null ;
\r
130 UpdateEmbed( oEmbed ) ;
\r
134 oFakeImage = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oEmbed ) ;
\r
135 oFakeImage.setAttribute( '_fckflash', 'true', 0 ) ;
\r
136 oFakeImage = FCK.InsertElementAndGetIt( oFakeImage ) ;
\r
139 oEditor.FCKUndo.SaveUndoStep() ;
\r
141 oEditor.FCKFlashProcessor.RefreshView( oFakeImage, oEmbed ) ;
\r
146 function UpdateEmbed( e )
\r
148 SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;
\r
149 SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;
\r
151 SetAttribute( e, 'src', GetE('txtUrl').value ) ;
\r
152 SetAttribute( e, "width" , GetE('txtWidth').value ) ;
\r
153 SetAttribute( e, "height", GetE('txtHeight').value ) ;
\r
155 // Advances Attributes
\r
157 SetAttribute( e, 'id' , GetE('txtAttId').value ) ;
\r
158 SetAttribute( e, 'scale', GetE('cmbScale').value ) ;
\r
160 SetAttribute( e, 'play', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
\r
161 SetAttribute( e, 'loop', GetE('chkLoop').checked ? 'true' : 'false' ) ;
\r
162 SetAttribute( e, 'menu', GetE('chkMenu').checked ? 'true' : 'false' ) ;
\r
164 SetAttribute( e, 'title' , GetE('txtAttTitle').value ) ;
\r
166 if ( oEditor.FCKBrowserInfo.IsIE )
\r
168 SetAttribute( e, 'className', GetE('txtAttClasses').value ) ;
\r
169 e.style.cssText = GetE('txtAttStyle').value ;
\r
173 SetAttribute( e, 'class', GetE('txtAttClasses').value ) ;
\r
174 SetAttribute( e, 'style', GetE('txtAttStyle').value ) ;
\r
180 function SetPreviewElement( previewEl )
\r
182 ePreview = previewEl ;
\r
184 if ( GetE('txtUrl').value.length > 0 )
\r
188 function UpdatePreview()
\r
193 while ( ePreview.firstChild )
\r
194 ePreview.removeChild( ePreview.firstChild ) ;
\r
196 if ( GetE('txtUrl').value.length == 0 )
\r
197 ePreview.innerHTML = ' ' ;
\r
200 var oDoc = ePreview.ownerDocument || ePreview.document ;
\r
201 var e = oDoc.createElement( 'EMBED' ) ;
\r
203 SetAttribute( e, 'src', GetE('txtUrl').value ) ;
\r
204 SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
\r
205 SetAttribute( e, 'width', '100%' ) ;
\r
206 SetAttribute( e, 'height', '100%' ) ;
\r
208 ePreview.appendChild( e ) ;
\r
212 // <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">
\r
214 function BrowseServer()
\r
216 OpenFileBrowser( FCKConfig.FlashBrowserURL, FCKConfig.FlashBrowserWindowWidth, FCKConfig.FlashBrowserWindowHeight ) ;
\r
219 function SetUrl( url, width, height )
\r
221 GetE('txtUrl').value = url ;
\r
224 GetE('txtWidth').value = width ;
\r
227 GetE('txtHeight').value = height ;
\r
231 window.parent.SetSelectedTab( 'Info' ) ;
\r
234 function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
\r
236 switch ( errorNumber )
\r
238 case 0 : // No errors
\r
239 alert( 'Your file has been successfully uploaded' ) ;
\r
241 case 1 : // Custom error
\r
242 alert( customMsg ) ;
\r
244 case 101 : // Custom warning
\r
245 alert( customMsg ) ;
\r
248 alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
\r
251 alert( 'Invalid file type' ) ;
\r
254 alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
\r
257 alert( 'Error on file upload. Error number: ' + errorNumber ) ;
\r
261 SetUrl( fileUrl ) ;
\r
262 GetE('frmUpload').reset() ;
\r
265 var oUploadAllowedExtRegex = new RegExp( FCKConfig.FlashUploadAllowedExtensions, 'i' ) ;
\r
266 var oUploadDeniedExtRegex = new RegExp( FCKConfig.FlashUploadDeniedExtensions, 'i' ) ;
\r
268 function CheckUpload()
\r
270 var sFile = GetE('txtUploadFile').value ;
\r
272 if ( sFile.length == 0 )
\r
274 alert( 'Please select a file to upload' ) ;
\r
278 if ( ( FCKConfig.FlashUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
\r
279 ( FCKConfig.FlashUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
\r
281 OnUploadCompleted( 202 ) ;
\r