2 * FCKeditor - The text editor for Internet - http://www.fckeditor.net
3 * Copyright (C) 2003-2010 Frederico Caldeira Knabben
7 * Licensed under the terms of any of the following licenses at your
10 * - GNU General Public License Version 2 or later (the "GPL")
11 * http://www.gnu.org/licenses/gpl.html
13 * - GNU Lesser General Public License Version 2.1 or later (the "LGPL")
14 * http://www.gnu.org/licenses/lgpl.html
16 * - Mozilla Public License Version 1.1 or later (the "MPL")
17 * http://www.mozilla.org/MPL/MPL-1.1.html
21 * Scripts related to the Flash dialog window (see fck_flash.html).
24 var dialog = window.parent ;
25 var oEditor = dialog.InnerDialogLoaded() ;
26 var FCK = oEditor.FCK ;
27 var FCKLang = oEditor.FCKLang ;
28 var FCKConfig = oEditor.FCKConfig ;
29 var FCKTools = oEditor.FCKTools ;
33 // Set the dialog tabs.
34 dialog.AddTab( 'Info', oEditor.FCKLang.DlgInfoTab ) ;
36 if ( FCKConfig.FlashUpload )
37 dialog.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ;
39 if ( !FCKConfig.FlashDlgHideAdvanced )
40 dialog.AddTab( 'Advanced', oEditor.FCKLang.DlgAdvancedTag ) ;
42 // Function called when a dialog tag is selected.
43 function OnDialogTabChange( tabCode )
45 ShowE('divInfo' , ( tabCode == 'Info' ) ) ;
46 ShowE('divUpload' , ( tabCode == 'Upload' ) ) ;
47 ShowE('divAdvanced' , ( tabCode == 'Advanced' ) ) ;
50 // Get the selected flash embed (if available).
51 var oFakeImage = dialog.Selection.GetSelectedElement() ;
56 if ( oFakeImage.tagName == 'IMG' && oFakeImage.getAttribute('_fckflash') )
57 oEmbed = FCK.GetRealElement( oFakeImage ) ;
62 window.onload = function()
64 // Translate the dialog box texts.
65 oEditor.FCKLanguageManager.TranslatePage(document) ;
67 // Load the selected element information (if any).
70 // Show/Hide the "Browse Server" button.
71 GetE('tdBrowse').style.display = FCKConfig.FlashBrowser ? '' : 'none' ;
73 // Set the actual uploader URL.
74 if ( FCKConfig.FlashUpload )
75 GetE('frmUpload').action = FCKConfig.FlashUploadURL ;
77 dialog.SetAutoSize( true ) ;
79 // Activate the "OK" button.
80 dialog.SetOkButton( true ) ;
82 SelectField( 'txtUrl' ) ;
85 function LoadSelection()
87 if ( ! oEmbed ) return ;
89 GetE('txtUrl').value = GetAttribute( oEmbed, 'src', '' ) ;
90 GetE('txtWidth').value = GetAttribute( oEmbed, 'width', '' ) ;
91 GetE('txtHeight').value = GetAttribute( oEmbed, 'height', '' ) ;
93 // Get Advances Attributes
94 GetE('txtAttId').value = oEmbed.id ;
95 GetE('chkAutoPlay').checked = GetAttribute( oEmbed, 'play', 'true' ) == 'true' ;
96 GetE('chkLoop').checked = GetAttribute( oEmbed, 'loop', 'true' ) == 'true' ;
97 GetE('chkMenu').checked = GetAttribute( oEmbed, 'menu', 'true' ) == 'true' ;
98 GetE('cmbScale').value = GetAttribute( oEmbed, 'scale', '' ).toLowerCase() ;
100 GetE('txtAttTitle').value = oEmbed.title ;
102 if ( oEditor.FCKBrowserInfo.IsIE )
104 GetE('txtAttClasses').value = oEmbed.getAttribute('className') || '' ;
105 GetE('txtAttStyle').value = oEmbed.style.cssText ;
109 GetE('txtAttClasses').value = oEmbed.getAttribute('class',2) || '' ;
110 GetE('txtAttStyle').value = oEmbed.getAttribute('style',2) || '' ;
116 //#### The OK button was hit.
119 if ( GetE('txtUrl').value.length == 0 )
121 dialog.SetSelectedTab( 'Info' ) ;
122 GetE('txtUrl').focus() ;
124 alert( oEditor.FCKLang.DlgAlertUrl ) ;
129 oEditor.FCKUndo.SaveUndoStep() ;
132 oEmbed = FCK.EditorDocument.createElement( 'EMBED' ) ;
135 UpdateEmbed( oEmbed ) ;
139 oFakeImage = oEditor.FCKDocumentProcessor_CreateFakeImage( 'FCK__Flash', oEmbed ) ;
140 oFakeImage.setAttribute( '_fckflash', 'true', 0 ) ;
141 oFakeImage = FCK.InsertElement( oFakeImage ) ;
144 oEditor.FCKEmbedAndObjectProcessor.RefreshView( oFakeImage, oEmbed ) ;
149 function UpdateEmbed( e )
151 SetAttribute( e, 'type' , 'application/x-shockwave-flash' ) ;
152 SetAttribute( e, 'pluginspage' , 'http://www.macromedia.com/go/getflashplayer' ) ;
154 SetAttribute( e, 'src', GetE('txtUrl').value ) ;
155 SetAttribute( e, "width" , GetE('txtWidth').value ) ;
156 SetAttribute( e, "height", GetE('txtHeight').value ) ;
158 // Advances Attributes
160 SetAttribute( e, 'id' , GetE('txtAttId').value ) ;
161 SetAttribute( e, 'scale', GetE('cmbScale').value ) ;
163 SetAttribute( e, 'play', GetE('chkAutoPlay').checked ? 'true' : 'false' ) ;
164 SetAttribute( e, 'loop', GetE('chkLoop').checked ? 'true' : 'false' ) ;
165 SetAttribute( e, 'menu', GetE('chkMenu').checked ? 'true' : 'false' ) ;
167 SetAttribute( e, 'title' , GetE('txtAttTitle').value ) ;
169 if ( oEditor.FCKBrowserInfo.IsIE )
171 SetAttribute( e, 'className', GetE('txtAttClasses').value ) ;
172 e.style.cssText = GetE('txtAttStyle').value ;
176 SetAttribute( e, 'class', GetE('txtAttClasses').value ) ;
177 SetAttribute( e, 'style', GetE('txtAttStyle').value ) ;
183 function SetPreviewElement( previewEl )
185 ePreview = previewEl ;
187 if ( GetE('txtUrl').value.length > 0 )
191 function UpdatePreview()
196 while ( ePreview.firstChild )
197 ePreview.removeChild( ePreview.firstChild ) ;
199 if ( GetE('txtUrl').value.length == 0 )
200 ePreview.innerHTML = ' ' ;
203 var oDoc = ePreview.ownerDocument || ePreview.document ;
204 var e = oDoc.createElement( 'EMBED' ) ;
206 SetAttribute( e, 'src', GetE('txtUrl').value ) ;
207 SetAttribute( e, 'type', 'application/x-shockwave-flash' ) ;
208 SetAttribute( e, 'width', '100%' ) ;
209 SetAttribute( e, 'height', '100%' ) ;
211 ePreview.appendChild( e ) ;
215 // <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">
217 function BrowseServer()
219 OpenFileBrowser( FCKConfig.FlashBrowserURL, FCKConfig.FlashBrowserWindowWidth, FCKConfig.FlashBrowserWindowHeight ) ;
222 function SetUrl( url, width, height )
224 GetE('txtUrl').value = url ;
227 GetE('txtWidth').value = width ;
230 GetE('txtHeight').value = height ;
234 dialog.SetSelectedTab( 'Info' ) ;
237 function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg )
240 window.parent.Throbber.Hide() ;
241 GetE( 'divUpload' ).style.display = '' ;
243 switch ( errorNumber )
245 case 0 : // No errors
246 alert( 'Your file has been successfully uploaded' ) ;
248 case 1 : // Custom error
251 case 101 : // Custom warning
255 alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ;
258 alert( 'Invalid file type' ) ;
261 alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ;
264 alert( 'The connector is disabled' ) ;
267 alert( 'Error on file upload. Error number: ' + errorNumber ) ;
272 GetE('frmUpload').reset() ;
275 var oUploadAllowedExtRegex = new RegExp( FCKConfig.FlashUploadAllowedExtensions, 'i' ) ;
276 var oUploadDeniedExtRegex = new RegExp( FCKConfig.FlashUploadDeniedExtensions, 'i' ) ;
278 function CheckUpload()
280 var sFile = GetE('txtUploadFile').value ;
282 if ( sFile.length == 0 )
284 alert( 'Please select a file to upload' ) ;
288 if ( ( FCKConfig.FlashUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) ||
289 ( FCKConfig.FlashUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) )
291 OnUploadCompleted( 202 ) ;
296 window.parent.Throbber.Show( 100 ) ;
297 GetE( 'divUpload' ).style.display = 'none' ;