[ Index ] |
|
Code source de GeekLog 1.4.1 |
1 /* 2 * FCKeditor - The text editor for internet 3 * Copyright (C) 2003-2006 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 * 11 * "Support Open Source software. What about a donation today?" 12 * 13 * File Name: fck_image.js 14 * Scripts related to the Image dialog window (see fck_image.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 var FCKDebug = oEditor.FCKDebug ; 25 26 var bImageButton = ( document.location.search.length > 0 && document.location.search.substr(1) == 'ImageButton' ) ; 27 28 //#### Dialog Tabs 29 30 // Set the dialog tabs. 31 window.parent.AddTab( 'Info', FCKLang.DlgImgInfoTab ) ; 32 33 if ( !bImageButton && !FCKConfig.ImageDlgHideLink ) 34 window.parent.AddTab( 'Link', FCKLang.DlgImgLinkTab ) ; 35 36 if ( FCKConfig.ImageUpload ) 37 window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload ) ; 38 39 if ( !FCKConfig.ImageDlgHideAdvanced ) 40 window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ; 41 42 // Function called when a dialog tag is selected. 43 function OnDialogTabChange( tabCode ) 44 { 45 ShowE('divInfo' , ( tabCode == 'Info' ) ) ; 46 ShowE('divLink' , ( tabCode == 'Link' ) ) ; 47 ShowE('divUpload' , ( tabCode == 'Upload' ) ) ; 48 ShowE('divAdvanced' , ( tabCode == 'Advanced' ) ) ; 49 } 50 51 // Get the selected image (if available). 52 var oImage = FCK.Selection.GetSelectedElement() ; 53 54 if ( oImage && oImage.tagName != 'IMG' && !( oImage.tagName == 'INPUT' && oImage.type == 'image' ) ) 55 oImage = null ; 56 57 // Get the active link. 58 var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; 59 60 var oImageOriginal ; 61 62 function UpdateOriginal( resetSize ) 63 { 64 if ( !eImgPreview ) 65 return ; 66 67 if ( GetE('txtUrl').value.length == 0 ) 68 { 69 oImageOriginal = null ; 70 return ; 71 } 72 73 oImageOriginal = document.createElement( 'IMG' ) ; // new Image() ; 74 75 if ( resetSize ) 76 { 77 oImageOriginal.onload = function() 78 { 79 this.onload = null ; 80 ResetSizes() ; 81 } 82 } 83 84 oImageOriginal.src = eImgPreview.src ; 85 } 86 87 var bPreviewInitialized ; 88 89 window.onload = function() 90 { 91 // Translate the dialog box texts. 92 oEditor.FCKLanguageManager.TranslatePage(document) ; 93 94 GetE('btnLockSizes').title = FCKLang.DlgImgLockRatio ; 95 GetE('btnResetSize').title = FCKLang.DlgBtnResetSize ; 96 97 // Load the selected element information (if any). 98 LoadSelection() ; 99 100 // Show/Hide the "Browse Server" button. 101 GetE('tdBrowse').style.display = FCKConfig.ImageBrowser ? '' : 'none' ; 102 GetE('divLnkBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ; 103 104 UpdateOriginal() ; 105 106 // Set the actual uploader URL. 107 if ( FCKConfig.ImageUpload ) 108 GetE('frmUpload').action = FCKConfig.ImageUploadURL ; 109 110 window.parent.SetAutoSize( true ) ; 111 112 // Activate the "OK" button. 113 window.parent.SetOkButton( true ) ; 114 } 115 116 function LoadSelection() 117 { 118 if ( ! oImage ) return ; 119 120 var sUrl = GetAttribute( oImage, '_fcksavedurl', '' ) ; 121 if ( sUrl.length == 0 ) 122 sUrl = GetAttribute( oImage, 'src', '' ) ; 123 124 // TODO: Wait stable version and remove the following commented lines. 125 // if ( sUrl.startsWith( FCK.BaseUrl ) ) 126 // sUrl = sUrl.remove( 0, FCK.BaseUrl.length ) ; 127 128 GetE('txtUrl').value = sUrl ; 129 GetE('txtAlt').value = GetAttribute( oImage, 'alt', '' ) ; 130 GetE('txtVSpace').value = GetAttribute( oImage, 'vspace', '' ) ; 131 GetE('txtHSpace').value = GetAttribute( oImage, 'hspace', '' ) ; 132 GetE('txtBorder').value = GetAttribute( oImage, 'border', '' ) ; 133 GetE('cmbAlign').value = GetAttribute( oImage, 'align', '' ) ; 134 135 var iWidth, iHeight ; 136 137 var regexSize = /^\s*(\d+)px\s*$/i ; 138 139 if ( oImage.style.width ) 140 { 141 var aMatch = oImage.style.width.match( regexSize ) ; 142 if ( aMatch ) 143 { 144 iWidth = aMatch[1] ; 145 oImage.style.width = '' ; 146 } 147 } 148 149 if ( oImage.style.height ) 150 { 151 var aMatch = oImage.style.height.match( regexSize ) ; 152 if ( aMatch ) 153 { 154 iHeight = aMatch[1] ; 155 oImage.style.height = '' ; 156 } 157 } 158 159 GetE('txtWidth').value = iWidth ? iWidth : GetAttribute( oImage, "width", '' ) ; 160 GetE('txtHeight').value = iHeight ? iHeight : GetAttribute( oImage, "height", '' ) ; 161 162 // Get Advances Attributes 163 GetE('txtAttId').value = oImage.id ; 164 GetE('cmbAttLangDir').value = oImage.dir ; 165 GetE('txtAttLangCode').value = oImage.lang ; 166 GetE('txtAttTitle').value = oImage.title ; 167 GetE('txtAttClasses').value = oImage.getAttribute('class',2) || '' ; 168 GetE('txtLongDesc').value = oImage.longDesc ; 169 170 if ( oEditor.FCKBrowserInfo.IsIE ) 171 GetE('txtAttStyle').value = oImage.style.cssText ; 172 else 173 GetE('txtAttStyle').value = oImage.getAttribute('style',2) ; 174 175 if ( oLink ) 176 { 177 var sUrl = GetAttribute( oLink, '_fcksavedurl', '' ) ; 178 if ( sUrl.length == 0 ) 179 sUrl = oLink.getAttribute('href',2) ; 180 181 GetE('txtLnkUrl').value = sUrl ; 182 GetE('cmbLnkTarget').value = oLink.target ; 183 } 184 185 UpdatePreview() ; 186 } 187 188 //#### The OK button was hit. 189 function Ok() 190 { 191 if ( GetE('txtUrl').value.length == 0 ) 192 { 193 window.parent.SetSelectedTab( 'Info' ) ; 194 GetE('txtUrl').focus() ; 195 196 alert( FCKLang.DlgImgAlertUrl ) ; 197 198 return false ; 199 } 200 201 var bHasImage = ( oImage != null ) ; 202 203 if ( bHasImage && bImageButton && oImage.tagName == 'IMG' ) 204 { 205 if ( confirm( 'Do you want to transform the selected image on a image button?' ) ) 206 oImage = null ; 207 } 208 else if ( bHasImage && !bImageButton && oImage.tagName == 'INPUT' ) 209 { 210 if ( confirm( 'Do you want to transform the selected image button on a simple image?' ) ) 211 oImage = null ; 212 } 213 214 if ( !bHasImage ) 215 { 216 if ( bImageButton ) 217 { 218 oImage = FCK.EditorDocument.createElement( 'INPUT' ) ; 219 oImage.type = 'image' ; 220 oImage = FCK.InsertElementAndGetIt( oImage ) ; 221 } 222 else 223 oImage = FCK.CreateElement( 'IMG' ) ; 224 } 225 else 226 oEditor.FCKUndo.SaveUndoStep() ; 227 228 UpdateImage( oImage ) ; 229 230 var sLnkUrl = GetE('txtLnkUrl').value.trim() ; 231 232 if ( sLnkUrl.length == 0 ) 233 { 234 if ( oLink ) 235 FCK.ExecuteNamedCommand( 'Unlink' ) ; 236 } 237 else 238 { 239 if ( oLink ) // Modifying an existent link. 240 oLink.href = sLnkUrl ; 241 else // Creating a new link. 242 { 243 if ( !bHasImage ) 244 oEditor.FCKSelection.SelectNode( oImage ) ; 245 246 oLink = oEditor.FCK.CreateLink( sLnkUrl ) ; 247 248 if ( !bHasImage ) 249 { 250 oEditor.FCKSelection.SelectNode( oLink ) ; 251 oEditor.FCKSelection.Collapse( false ) ; 252 } 253 } 254 255 SetAttribute( oLink, '_fcksavedurl', sLnkUrl ) ; 256 SetAttribute( oLink, 'target', GetE('cmbLnkTarget').value ) ; 257 } 258 259 return true ; 260 } 261 262 function UpdateImage( e, skipId ) 263 { 264 e.src = GetE('txtUrl').value ; 265 SetAttribute( e, "_fcksavedurl", GetE('txtUrl').value ) ; 266 SetAttribute( e, "alt" , GetE('txtAlt').value ) ; 267 SetAttribute( e, "width" , GetE('txtWidth').value ) ; 268 SetAttribute( e, "height", GetE('txtHeight').value ) ; 269 SetAttribute( e, "vspace", GetE('txtVSpace').value ) ; 270 SetAttribute( e, "hspace", GetE('txtHSpace').value ) ; 271 SetAttribute( e, "border", GetE('txtBorder').value ) ; 272 SetAttribute( e, "align" , GetE('cmbAlign').value ) ; 273 274 // Advances Attributes 275 276 if ( ! skipId ) 277 SetAttribute( e, 'id', GetE('txtAttId').value ) ; 278 279 SetAttribute( e, 'dir' , GetE('cmbAttLangDir').value ) ; 280 SetAttribute( e, 'lang' , GetE('txtAttLangCode').value ) ; 281 SetAttribute( e, 'title' , GetE('txtAttTitle').value ) ; 282 SetAttribute( e, 'class' , GetE('txtAttClasses').value ) ; 283 SetAttribute( e, 'longDesc' , GetE('txtLongDesc').value ) ; 284 285 if ( oEditor.FCKBrowserInfo.IsIE ) 286 e.style.cssText = GetE('txtAttStyle').value ; 287 else 288 SetAttribute( e, 'style', GetE('txtAttStyle').value ) ; 289 } 290 291 var eImgPreview ; 292 var eImgPreviewLink ; 293 294 function SetPreviewElements( imageElement, linkElement ) 295 { 296 eImgPreview = imageElement ; 297 eImgPreviewLink = linkElement ; 298 299 UpdatePreview() ; 300 UpdateOriginal() ; 301 302 bPreviewInitialized = true ; 303 } 304 305 function UpdatePreview() 306 { 307 if ( !eImgPreview || !eImgPreviewLink ) 308 return ; 309 310 if ( GetE('txtUrl').value.length == 0 ) 311 eImgPreviewLink.style.display = 'none' ; 312 else 313 { 314 UpdateImage( eImgPreview, true ) ; 315 316 if ( GetE('txtLnkUrl').value.trim().length > 0 ) 317 eImgPreviewLink.href = 'javascript:void(null);' ; 318 else 319 SetAttribute( eImgPreviewLink, 'href', '' ) ; 320 321 eImgPreviewLink.style.display = '' ; 322 } 323 } 324 325 var bLockRatio = true ; 326 327 function SwitchLock( lockButton ) 328 { 329 bLockRatio = !bLockRatio ; 330 lockButton.className = bLockRatio ? 'BtnLocked' : 'BtnUnlocked' ; 331 lockButton.title = bLockRatio ? 'Lock sizes' : 'Unlock sizes' ; 332 333 if ( bLockRatio ) 334 { 335 if ( GetE('txtWidth').value.length > 0 ) 336 OnSizeChanged( 'Width', GetE('txtWidth').value ) ; 337 else 338 OnSizeChanged( 'Height', GetE('txtHeight').value ) ; 339 } 340 } 341 342 // Fired when the width or height input texts change 343 function OnSizeChanged( dimension, value ) 344 { 345 // Verifies if the aspect ration has to be mantained 346 if ( oImageOriginal && bLockRatio ) 347 { 348 var e = dimension == 'Width' ? GetE('txtHeight') : GetE('txtWidth') ; 349 350 if ( value.length == 0 || isNaN( value ) ) 351 { 352 e.value = '' ; 353 return ; 354 } 355 356 if ( dimension == 'Width' ) 357 value = value == 0 ? 0 : Math.round( oImageOriginal.height * ( value / oImageOriginal.width ) ) ; 358 else 359 value = value == 0 ? 0 : Math.round( oImageOriginal.width * ( value / oImageOriginal.height ) ) ; 360 361 if ( !isNaN( value ) ) 362 e.value = value ; 363 } 364 365 UpdatePreview() ; 366 } 367 368 // Fired when the Reset Size button is clicked 369 function ResetSizes() 370 { 371 if ( ! oImageOriginal ) return ; 372 373 GetE('txtWidth').value = oImageOriginal.width ; 374 GetE('txtHeight').value = oImageOriginal.height ; 375 376 UpdatePreview() ; 377 } 378 379 function BrowseServer() 380 { 381 OpenServerBrowser( 382 'Image', 383 FCKConfig.ImageBrowserURL, 384 FCKConfig.ImageBrowserWindowWidth, 385 FCKConfig.ImageBrowserWindowHeight ) ; 386 } 387 388 function LnkBrowseServer() 389 { 390 OpenServerBrowser( 391 'Link', 392 FCKConfig.LinkBrowserURL, 393 FCKConfig.LinkBrowserWindowWidth, 394 FCKConfig.LinkBrowserWindowHeight ) ; 395 } 396 397 function OpenServerBrowser( type, url, width, height ) 398 { 399 sActualBrowser = type ; 400 OpenFileBrowser( url, width, height ) ; 401 } 402 403 var sActualBrowser ; 404 405 function SetUrl( url, width, height, alt ) 406 { 407 if ( sActualBrowser == 'Link' ) 408 { 409 GetE('txtLnkUrl').value = url ; 410 UpdatePreview() ; 411 } 412 else 413 { 414 GetE('txtUrl').value = url ; 415 GetE('txtWidth').value = width ? width : '' ; 416 GetE('txtHeight').value = height ? height : '' ; 417 418 if ( alt ) 419 GetE('txtAlt').value = alt; 420 421 UpdatePreview() ; 422 UpdateOriginal( true ) ; 423 } 424 425 window.parent.SetSelectedTab( 'Info' ) ; 426 } 427 428 function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg ) 429 { 430 switch ( errorNumber ) 431 { 432 case 0 : // No errors 433 alert( 'Your file has been successfully uploaded' ) ; 434 break ; 435 case 1 : // Custom error 436 alert( customMsg ) ; 437 return ; 438 case 101 : // Custom warning 439 alert( customMsg ) ; 440 break ; 441 case 201 : 442 alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ; 443 break ; 444 case 202 : 445 alert( 'Invalid file type' ) ; 446 return ; 447 case 203 : 448 alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ; 449 return ; 450 default : 451 alert( 'Error on file upload. Error number: ' + errorNumber ) ; 452 return ; 453 } 454 455 sActualBrowser = '' 456 SetUrl( fileUrl ) ; 457 GetE('frmUpload').reset() ; 458 } 459 460 var oUploadAllowedExtRegex = new RegExp( FCKConfig.ImageUploadAllowedExtensions, 'i' ) ; 461 var oUploadDeniedExtRegex = new RegExp( FCKConfig.ImageUploadDeniedExtensions, 'i' ) ; 462 463 function CheckUpload() 464 { 465 var sFile = GetE('txtUploadFile').value ; 466 467 if ( sFile.length == 0 ) 468 { 469 alert( 'Please select a file to upload' ) ; 470 return false ; 471 } 472 473 if ( ( FCKConfig.ImageUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) || 474 ( FCKConfig.ImageUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) ) 475 { 476 OnUploadCompleted( 202 ) ; 477 return false ; 478 } 479 480 return true ; 481 }
titre
Description
Corps
titre
Description
Corps
titre
Description
Corps
titre
Corps
Généré le : Wed Nov 21 12:27:40 2007 | par Balluche grâce à PHPXref 0.7 |
![]() |