[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/fckeditor/plugins/linktonode/jscripts/ -> fck_link.js (source)

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


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7