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