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