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 Link dialog window (see fck_link.html). 22 */ 23 24var oEditor = window.parent.InnerDialogLoaded() ; 25var FCK = oEditor.FCK ; 26var FCKLang = oEditor.FCKLang ; 27var FCKConfig = oEditor.FCKConfig ; 28var FCKRegexLib = oEditor.FCKRegexLib ; 29var FCKTools = oEditor.FCKTools ; 30 31//#### Dialog Tabs 32 33// Set the dialog tabs. 34window.parent.AddTab( 'Info', FCKLang.DlgLnkInfoTab ) ; 35 36if ( !FCKConfig.LinkDlgHideTarget ) 37 window.parent.AddTab( 'Target', FCKLang.DlgLnkTargetTab, true ) ; 38 39if ( FCKConfig.LinkUpload ) 40 window.parent.AddTab( 'Upload', FCKLang.DlgLnkUpload, true ) ; 41 42if ( !FCKConfig.LinkDlgHideAdvanced ) 43 window.parent.AddTab( 'Advanced', FCKLang.DlgAdvancedTag ) ; 44 45// Function called when a dialog tag is selected. 46function OnDialogTabChange( tabCode ) 47{ 48 ShowE('divInfo' , ( tabCode == 'Info' ) ) ; 49 ShowE('divTarget' , ( tabCode == 'Target' ) ) ; 50 ShowE('divUpload' , ( tabCode == 'Upload' ) ) ; 51 ShowE('divAttribs' , ( tabCode == 'Advanced' ) ) ; 52 53 window.parent.SetAutoSize( true ) ; 54} 55 56//#### Regular Expressions library. 57var oRegex = new Object() ; 58 59oRegex.UriProtocol = /^(((http|https|ftp|news):\/\/)|mailto:)/gi ; 60 61oRegex.UrlOnChangeProtocol = /^(http|https|ftp|news):\/\/(?=.)/gi ; 62 63oRegex.UrlOnChangeTestOther = /^((javascript:)|[#\/\.])/gi ; 64 65oRegex.ReserveTarget = /^_(blank|self|top|parent)$/i ; 66 67oRegex.PopupUri = /^javascript:void\(\s*window.open\(\s*'([^']+)'\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*\)\s*$/ ; 68 69// Accessible popups 70oRegex.OnClickPopup = /^\s*on[cC]lick="\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*"$/ ; 71 72oRegex.PopupFeatures = /(?:^|,)([^=]+)=(\d+|yes|no)/gi ; 73 74//#### Parser Functions 75 76var oParser = new Object() ; 77 78oParser.ParseEMailUrl = function( emailUrl ) 79{ 80 // Initializes the EMailInfo object. 81 var oEMailInfo = new Object() ; 82 oEMailInfo.Address = '' ; 83 oEMailInfo.Subject = '' ; 84 oEMailInfo.Body = '' ; 85 86 var oParts = emailUrl.match( /^([^\?]+)\??(.+)?/ ) ; 87 if ( oParts ) 88 { 89 // Set the e-mail address. 90 oEMailInfo.Address = oParts[1] ; 91 92 // Look for the optional e-mail parameters. 93 if ( oParts[2] ) 94 { 95 var oMatch = oParts[2].match( /(^|&)subject=([^&]+)/i ) ; 96 if ( oMatch ) oEMailInfo.Subject = decodeURIComponent( oMatch[2] ) ; 97 98 oMatch = oParts[2].match( /(^|&)body=([^&]+)/i ) ; 99 if ( oMatch ) oEMailInfo.Body = decodeURIComponent( oMatch[2] ) ; 100 } 101 } 102 103 return oEMailInfo ; 104} 105 106oParser.CreateEMailUri = function( address, subject, body ) 107{ 108 var sBaseUri = 'mailto:' + address ; 109 110 var sParams = '' ; 111 112 if ( subject.length > 0 ) 113 sParams = '?subject=' + encodeURIComponent( subject ) ; 114 115 if ( body.length > 0 ) 116 { 117 sParams += ( sParams.length == 0 ? '?' : '&' ) ; 118 sParams += 'body=' + encodeURIComponent( body ) ; 119 } 120 121 return sBaseUri + sParams ; 122} 123 124//#### Initialization Code 125 126// oLink: The actual selected link in the editor. 127var oLink = FCK.Selection.MoveToAncestorNode( 'A' ) ; 128if ( oLink ) 129 FCK.Selection.SelectNode( oLink ) ; 130 131window.onload = function() 132{ 133 // Translate the dialog box texts. 134 oEditor.FCKLanguageManager.TranslatePage(document) ; 135 136 // Fill the Anchor Names and Ids combos. 137 LoadAnchorNamesAndIds() ; 138 139 // Load the selected link information (if any). 140 LoadSelection() ; 141 142 // Update the dialog box. 143 SetLinkType( GetE('cmbLinkType').value ) ; 144 145 // Show/Hide the "Browse Server" button. 146 GetE('divBrowseServer').style.display = FCKConfig.LinkBrowser ? '' : 'none' ; 147 148 // Show the initial dialog content. 149 GetE('divInfo').style.display = '' ; 150 151 // Set the actual uploader URL. 152 if ( FCKConfig.LinkUpload ) 153 GetE('frmUpload').action = FCKConfig.LinkUploadURL ; 154 155 // Set the default target (from configuration). 156 SetDefaultTarget() ; 157 158 // Activate the "OK" button. 159 window.parent.SetOkButton( true ) ; 160} 161 162var bHasAnchors ; 163 164function LoadAnchorNamesAndIds() 165{ 166 // Since version 2.0, the anchors are replaced in the DOM by IMGs so the user see the icon 167 // to edit them. So, we must look for that images now. 168 var aAnchors = new Array() ; 169 var i ; 170 var oImages = oEditor.FCK.EditorDocument.getElementsByTagName( 'IMG' ) ; 171 for( i = 0 ; i < oImages.length ; i++ ) 172 { 173 if ( oImages[i].getAttribute('_fckanchor') ) 174 aAnchors[ aAnchors.length ] = oEditor.FCK.GetRealElement( oImages[i] ) ; 175 } 176 177 // Add also real anchors 178 var oLinks = oEditor.FCK.EditorDocument.getElementsByTagName( 'A' ) ; 179 for( i = 0 ; i < oLinks.length ; i++ ) 180 { 181 if ( oLinks[i].name && ( oLinks[i].name.length > 0 ) ) 182 aAnchors[ aAnchors.length ] = oLinks[i] ; 183 } 184 185 var aIds = FCKTools.GetAllChildrenIds( oEditor.FCK.EditorDocument.body ) ; 186 187 bHasAnchors = ( aAnchors.length > 0 || aIds.length > 0 ) ; 188 189 for ( i = 0 ; i < aAnchors.length ; i++ ) 190 { 191 var sName = aAnchors[i].name ; 192 if ( sName && sName.length > 0 ) 193 FCKTools.AddSelectOption( GetE('cmbAnchorName'), sName, sName ) ; 194 } 195 196 for ( i = 0 ; i < aIds.length ; i++ ) 197 { 198 FCKTools.AddSelectOption( GetE('cmbAnchorId'), aIds[i], aIds[i] ) ; 199 } 200 201 ShowE( 'divSelAnchor' , bHasAnchors ) ; 202 ShowE( 'divNoAnchor' , !bHasAnchors ) ; 203} 204 205function LoadSelection() 206{ 207 if ( !oLink ) return ; 208 209 var sType = 'url' ; 210 211 // Get the actual Link href. 212 var sHRef = oLink.getAttribute( '_fcksavedurl' ) ; 213 if ( sHRef == null ) 214 sHRef = oLink.getAttribute( 'href' , 2 ) || '' ; 215 216 // Look for a popup javascript link. 217 var oPopupMatch = oRegex.PopupUri.exec( sHRef ) ; 218 if( oPopupMatch ) 219 { 220 GetE('cmbTarget').value = 'popup' ; 221 sHRef = oPopupMatch[1] ; 222 FillPopupFields( oPopupMatch[2], oPopupMatch[3] ) ; 223 SetTarget( 'popup' ) ; 224 } 225 226 // Accessible popups, the popup data is in the onclick attribute 227 if ( !oPopupMatch ) 228 { 229 var onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ; 230 if ( onclick ) 231 { 232 // Decode the protected string 233 onclick = decodeURIComponent( onclick ) ; 234 235 oPopupMatch = oRegex.OnClickPopup.exec( onclick ) ; 236 if( oPopupMatch ) 237 { 238 GetE( 'cmbTarget' ).value = 'popup' ; 239 FillPopupFields( oPopupMatch[1], oPopupMatch[2] ) ; 240 SetTarget( 'popup' ) ; 241 } 242 } 243 } 244 245 // Search for the protocol. 246 var sProtocol = oRegex.UriProtocol.exec( sHRef ) ; 247 248 if ( sProtocol ) 249 { 250 sProtocol = sProtocol[0].toLowerCase() ; 251 GetE('cmbLinkProtocol').value = sProtocol ; 252 253 // Remove the protocol and get the remaining URL. 254 var sUrl = sHRef.replace( oRegex.UriProtocol, '' ) ; 255 256 if ( sProtocol == 'mailto:' ) // It is an e-mail link. 257 { 258 sType = 'email' ; 259 260 var oEMailInfo = oParser.ParseEMailUrl( sUrl ) ; 261 GetE('txtEMailAddress').value = oEMailInfo.Address ; 262 GetE('txtEMailSubject').value = oEMailInfo.Subject ; 263 GetE('txtEMailBody').value = oEMailInfo.Body ; 264 } 265 else // It is a normal link. 266 { 267 sType = 'url' ; 268 GetE('txtUrl').value = sUrl ; 269 } 270 } 271 else if ( sHRef.substr(0,1) == '#' && sHRef.length > 1 ) // It is an anchor link. 272 { 273 sType = 'anchor' ; 274 GetE('cmbAnchorName').value = GetE('cmbAnchorId').value = sHRef.substr(1) ; 275 } 276 else // It is another type of link. 277 { 278 sType = 'url' ; 279 280 GetE('cmbLinkProtocol').value = '' ; 281 GetE('txtUrl').value = sHRef ; 282 } 283 284 if ( !oPopupMatch ) 285 { 286 // Get the target. 287 var sTarget = oLink.target ; 288 289 if ( sTarget && sTarget.length > 0 ) 290 { 291 if ( oRegex.ReserveTarget.test( sTarget ) ) 292 { 293 sTarget = sTarget.toLowerCase() ; 294 GetE('cmbTarget').value = sTarget ; 295 } 296 else 297 GetE('cmbTarget').value = 'frame' ; 298 GetE('txtTargetFrame').value = sTarget ; 299 } 300 } 301 302 // Get Advances Attributes 303 GetE('txtAttId').value = oLink.id ; 304 GetE('txtAttName').value = oLink.name ; 305 GetE('cmbAttLangDir').value = oLink.dir ; 306 GetE('txtAttLangCode').value = oLink.lang ; 307 GetE('txtAttAccessKey').value = oLink.accessKey ; 308 GetE('txtAttTabIndex').value = oLink.tabIndex <= 0 ? '' : oLink.tabIndex ; 309 GetE('txtAttTitle').value = oLink.title ; 310 GetE('txtAttContentType').value = oLink.type ; 311 GetE('txtAttCharSet').value = oLink.charset ; 312 313 var sClass ; 314 if ( oEditor.FCKBrowserInfo.IsIE ) 315 { 316 sClass = oLink.getAttribute('className',2) || '' ; 317 // Clean up temporary classes for internal use: 318 sClass = sClass.replace( FCKRegexLib.FCK_Class, '' ) ; 319 320 GetE('txtAttStyle').value = oLink.style.cssText ; 321 } 322 else 323 { 324 sClass = oLink.getAttribute('class',2) || '' ; 325 GetE('txtAttStyle').value = oLink.getAttribute('style',2) || '' ; 326 } 327 GetE('txtAttClasses').value = sClass ; 328 329 // Update the Link type combo. 330 GetE('cmbLinkType').value = sType ; 331} 332 333//#### Link type selection. 334function SetLinkType( linkType ) 335{ 336 ShowE('divLinkTypeUrl' , (linkType == 'url') ) ; 337 ShowE('divLinkTypeAnchor' , (linkType == 'anchor') ) ; 338 ShowE('divLinkTypeEMail' , (linkType == 'email') ) ; 339 340 if ( !FCKConfig.LinkDlgHideTarget ) 341 window.parent.SetTabVisibility( 'Target' , (linkType == 'url') ) ; 342 343 if ( FCKConfig.LinkUpload ) 344 window.parent.SetTabVisibility( 'Upload' , (linkType == 'url') ) ; 345 346 if ( !FCKConfig.LinkDlgHideAdvanced ) 347 window.parent.SetTabVisibility( 'Advanced' , (linkType != 'anchor' || bHasAnchors) ) ; 348 349 if ( linkType == 'email' ) 350 window.parent.SetAutoSize( true ) ; 351} 352 353//#### Target type selection. 354function SetTarget( targetType ) 355{ 356 GetE('tdTargetFrame').style.display = ( targetType == 'popup' ? 'none' : '' ) ; 357 GetE('tdPopupName').style.display = 358 GetE('tablePopupFeatures').style.display = ( targetType == 'popup' ? '' : 'none' ) ; 359 360 switch ( targetType ) 361 { 362 case "_blank" : 363 case "_self" : 364 case "_parent" : 365 case "_top" : 366 GetE('txtTargetFrame').value = targetType ; 367 break ; 368 case "" : 369 GetE('txtTargetFrame').value = '' ; 370 break ; 371 } 372 373 if ( targetType == 'popup' ) 374 window.parent.SetAutoSize( true ) ; 375} 376 377//#### Called while the user types the URL. 378function OnUrlChange() 379{ 380 var sUrl = GetE('txtUrl').value ; 381 var sProtocol = oRegex.UrlOnChangeProtocol.exec( sUrl ) ; 382 383 if ( sProtocol ) 384 { 385 sUrl = sUrl.substr( sProtocol[0].length ) ; 386 GetE('txtUrl').value = sUrl ; 387 GetE('cmbLinkProtocol').value = sProtocol[0].toLowerCase() ; 388 } 389 else if ( oRegex.UrlOnChangeTestOther.test( sUrl ) ) 390 { 391 GetE('cmbLinkProtocol').value = '' ; 392 } 393} 394 395//#### Called while the user types the target name. 396function OnTargetNameChange() 397{ 398 var sFrame = GetE('txtTargetFrame').value ; 399 400 if ( sFrame.length == 0 ) 401 GetE('cmbTarget').value = '' ; 402 else if ( oRegex.ReserveTarget.test( sFrame ) ) 403 GetE('cmbTarget').value = sFrame.toLowerCase() ; 404 else 405 GetE('cmbTarget').value = 'frame' ; 406} 407 408// Accessible popups 409function BuildOnClickPopup() 410{ 411 var sWindowName = "'" + GetE('txtPopupName').value.replace(/\W/gi, "") + "'" ; 412 413 var sFeatures = '' ; 414 var aChkFeatures = document.getElementsByName( 'chkFeature' ) ; 415 for ( var i = 0 ; i < aChkFeatures.length ; i++ ) 416 { 417 if ( i > 0 ) sFeatures += ',' ; 418 sFeatures += aChkFeatures[i].value + '=' + ( aChkFeatures[i].checked ? 'yes' : 'no' ) ; 419 } 420 421 if ( GetE('txtPopupWidth').value.length > 0 ) sFeatures += ',width=' + GetE('txtPopupWidth').value ; 422 if ( GetE('txtPopupHeight').value.length > 0 ) sFeatures += ',height=' + GetE('txtPopupHeight').value ; 423 if ( GetE('txtPopupLeft').value.length > 0 ) sFeatures += ',left=' + GetE('txtPopupLeft').value ; 424 if ( GetE('txtPopupTop').value.length > 0 ) sFeatures += ',top=' + GetE('txtPopupTop').value ; 425 426 if ( sFeatures != '' ) 427 sFeatures = sFeatures + ",status" ; 428 429 return ( "window.open(this.href," + sWindowName + ",'" + sFeatures + "'); return false" ) ; 430} 431 432//#### Fills all Popup related fields. 433function FillPopupFields( windowName, features ) 434{ 435 if ( windowName ) 436 GetE('txtPopupName').value = windowName ; 437 438 var oFeatures = new Object() ; 439 var oFeaturesMatch ; 440 while( ( oFeaturesMatch = oRegex.PopupFeatures.exec( features ) ) != null ) 441 { 442 var sValue = oFeaturesMatch[2] ; 443 if ( sValue == ( 'yes' || '1' ) ) 444 oFeatures[ oFeaturesMatch[1] ] = true ; 445 else if ( ! isNaN( sValue ) && sValue != 0 ) 446 oFeatures[ oFeaturesMatch[1] ] = sValue ; 447 } 448 449 // Update all features check boxes. 450 var aChkFeatures = document.getElementsByName('chkFeature') ; 451 for ( var i = 0 ; i < aChkFeatures.length ; i++ ) 452 { 453 if ( oFeatures[ aChkFeatures[i].value ] ) 454 aChkFeatures[i].checked = true ; 455 } 456 457 // Update position and size text boxes. 458 if ( oFeatures['width'] ) GetE('txtPopupWidth').value = oFeatures['width'] ; 459 if ( oFeatures['height'] ) GetE('txtPopupHeight').value = oFeatures['height'] ; 460 if ( oFeatures['left'] ) GetE('txtPopupLeft').value = oFeatures['left'] ; 461 if ( oFeatures['top'] ) GetE('txtPopupTop').value = oFeatures['top'] ; 462} 463 464//#### The OK button was hit. 465function Ok() 466{ 467 var sUri, sInnerHtml ; 468 oEditor.FCKUndo.SaveUndoStep() ; 469 470 switch ( GetE('cmbLinkType').value ) 471 { 472 case 'url' : 473 sUri = GetE('txtUrl').value ; 474 475 if ( sUri.length == 0 ) 476 { 477 alert( FCKLang.DlnLnkMsgNoUrl ) ; 478 return false ; 479 } 480 481 sUri = GetE('cmbLinkProtocol').value + sUri ; 482 483 break ; 484 485 case 'email' : 486 sUri = GetE('txtEMailAddress').value ; 487 488 if ( sUri.length == 0 ) 489 { 490 alert( FCKLang.DlnLnkMsgNoEMail ) ; 491 return false ; 492 } 493 494 sUri = oParser.CreateEMailUri( 495 sUri, 496 GetE('txtEMailSubject').value, 497 GetE('txtEMailBody').value ) ; 498 break ; 499 500 case 'anchor' : 501 var sAnchor = GetE('cmbAnchorName').value ; 502 if ( sAnchor.length == 0 ) sAnchor = GetE('cmbAnchorId').value ; 503 504 if ( sAnchor.length == 0 ) 505 { 506 alert( FCKLang.DlnLnkMsgNoAnchor ) ; 507 return false ; 508 } 509 510 sUri = '#' + sAnchor ; 511 break ; 512 } 513 514 // If no link is selected, create a new one (it may result in more than one link creation - #220). 515 var aLinks = oLink ? [ oLink ] : oEditor.FCK.CreateLink( sUri, true ) ; 516 517 // If no selection, no links are created, so use the uri as the link text (by dom, 2006-05-26) 518 var aHasSelection = ( aLinks.length > 0 ) ; 519 if ( !aHasSelection ) 520 { 521 sInnerHtml = sUri; 522 523 // Built a better text for empty links. 524 switch ( GetE('cmbLinkType').value ) 525 { 526 // anchor: use old behavior --> return true 527 case 'anchor': 528 sInnerHtml = sInnerHtml.replace( /^#/, '' ) ; 529 break ; 530 531 // url: try to get path 532 case 'url': 533 var oLinkPathRegEx = new RegExp("//?([^?\"']+)([?].*)?$") ; 534 var asLinkPath = oLinkPathRegEx.exec( sUri ) ; 535 if (asLinkPath != null) 536 sInnerHtml = asLinkPath[1]; // use matched path 537 break ; 538 539 // mailto: try to get email address 540 case 'email': 541 sInnerHtml = GetE('txtEMailAddress').value ; 542 break ; 543 } 544 545 // Create a new (empty) anchor. 546 aLinks = [ oEditor.FCK.InsertElement( 'a' ) ] ; 547 } 548 549 for ( var i = 0 ; i < aLinks.length ; i++ ) 550 { 551 oLink = aLinks[i] ; 552 553 if ( aHasSelection ) 554 sInnerHtml = oLink.innerHTML ; // Save the innerHTML (IE changes it if it is like an URL). 555 556 oLink.href = sUri ; 557 SetAttribute( oLink, '_fcksavedurl', sUri ) ; 558 559 var onclick; 560 // Accessible popups 561 if( GetE('cmbTarget').value == 'popup' ) 562 { 563 onclick = BuildOnClickPopup() ; 564 // Encode the attribute 565 onclick = encodeURIComponent( " onclick=\"" + onclick + "\"" ) ; 566 SetAttribute( oLink, 'onclick_fckprotectedatt', onclick ) ; 567 } 568 else 569 { 570 // Check if the previous onclick was for a popup: 571 // In that case remove the onclick handler. 572 onclick = oLink.getAttribute( 'onclick_fckprotectedatt' ) ; 573 if ( onclick ) 574 { 575 // Decode the protected string 576 onclick = decodeURIComponent( onclick ) ; 577 578 if( oRegex.OnClickPopup.test( onclick ) ) 579 SetAttribute( oLink, 'onclick_fckprotectedatt', '' ) ; 580 } 581 } 582 583 oLink.innerHTML = sInnerHtml ; // Set (or restore) the innerHTML 584 585 // Target 586 if( GetE('cmbTarget').value != 'popup' ) 587 SetAttribute( oLink, 'target', GetE('txtTargetFrame').value ) ; 588 else 589 SetAttribute( oLink, 'target', null ) ; 590 591 // Let's set the "id" only for the first link to avoid duplication. 592 if ( i == 0 ) 593 SetAttribute( oLink, 'id', GetE('txtAttId').value ) ; 594 595 // Advances Attributes 596 SetAttribute( oLink, 'name' , GetE('txtAttName').value ) ; 597 SetAttribute( oLink, 'dir' , GetE('cmbAttLangDir').value ) ; 598 SetAttribute( oLink, 'lang' , GetE('txtAttLangCode').value ) ; 599 SetAttribute( oLink, 'accesskey', GetE('txtAttAccessKey').value ) ; 600 SetAttribute( oLink, 'tabindex' , ( GetE('txtAttTabIndex').value > 0 ? GetE('txtAttTabIndex').value : null ) ) ; 601 SetAttribute( oLink, 'title' , GetE('txtAttTitle').value ) ; 602 SetAttribute( oLink, 'type' , GetE('txtAttContentType').value ) ; 603 SetAttribute( oLink, 'charset' , GetE('txtAttCharSet').value ) ; 604 605 if ( oEditor.FCKBrowserInfo.IsIE ) 606 { 607 var sClass = GetE('txtAttClasses').value ; 608 // If it's also an anchor add an internal class 609 if ( GetE('txtAttName').value.length != 0 ) 610 sClass += ' FCK__AnchorC' ; 611 SetAttribute( oLink, 'className', sClass ) ; 612 613 oLink.style.cssText = GetE('txtAttStyle').value ; 614 } 615 else 616 { 617 SetAttribute( oLink, 'class', GetE('txtAttClasses').value ) ; 618 SetAttribute( oLink, 'style', GetE('txtAttStyle').value ) ; 619 } 620 } 621 622 // Select the (first) link. 623 oEditor.FCKSelection.SelectNode( aLinks[0] ); 624 625 return true ; 626} 627 628function BrowseServer() 629{ 630 OpenFileBrowser( FCKConfig.LinkBrowserURL, FCKConfig.LinkBrowserWindowWidth, FCKConfig.LinkBrowserWindowHeight ) ; 631} 632 633function SetUrl( url ) 634{ 635 document.getElementById('txtUrl').value = url ; 636 OnUrlChange() ; 637 window.parent.SetSelectedTab( 'Info' ) ; 638} 639 640function OnUploadCompleted( errorNumber, fileUrl, fileName, customMsg ) 641{ 642 switch ( errorNumber ) 643 { 644 case 0 : // No errors 645 alert( 'Your file has been successfully uploaded' ) ; 646 break ; 647 case 1 : // Custom error 648 alert( customMsg ) ; 649 return ; 650 case 101 : // Custom warning 651 alert( customMsg ) ; 652 break ; 653 case 201 : 654 alert( 'A file with the same name is already available. The uploaded file has been renamed to "' + fileName + '"' ) ; 655 break ; 656 case 202 : 657 alert( 'Invalid file type' ) ; 658 return ; 659 case 203 : 660 alert( "Security error. You probably don't have enough permissions to upload. Please check your server." ) ; 661 return ; 662 default : 663 alert( 'Error on file upload. Error number: ' + errorNumber ) ; 664 return ; 665 } 666 667 SetUrl( fileUrl ) ; 668 GetE('frmUpload').reset() ; 669} 670 671var oUploadAllowedExtRegex = new RegExp( FCKConfig.LinkUploadAllowedExtensions, 'i' ) ; 672var oUploadDeniedExtRegex = new RegExp( FCKConfig.LinkUploadDeniedExtensions, 'i' ) ; 673 674function CheckUpload() 675{ 676 var sFile = GetE('txtUploadFile').value ; 677 678 if ( sFile.length == 0 ) 679 { 680 alert( 'Please select a file to upload' ) ; 681 return false ; 682 } 683 684 if ( ( FCKConfig.LinkUploadAllowedExtensions.length > 0 && !oUploadAllowedExtRegex.test( sFile ) ) || 685 ( FCKConfig.LinkUploadDeniedExtensions.length > 0 && oUploadDeniedExtRegex.test( sFile ) ) ) 686 { 687 OnUploadCompleted( 202 ) ; 688 return false ; 689 } 690 691 return true ; 692} 693 694function SetDefaultTarget() 695{ 696 var target = FCKConfig.DefaultLinkTarget || '' ; 697 698 if ( oLink || target.length == 0 ) 699 return ; 700 701 switch ( target ) 702 { 703 case '_blank' : 704 case '_self' : 705 case '_parent' : 706 case '_top' : 707 GetE('cmbTarget').value = target ; 708 break ; 709 default : 710 GetE('cmbTarget').value = 'frame' ; 711 break ; 712 } 713 714 GetE('txtTargetFrame').value = target ; 715} 716