[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/ckeditor/plugins/linktomenu/dialogs/ -> link.js (source)

   1  /*
   2  Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
   3  For licensing, see LICENSE.html or http://ckeditor.com/license
   4  */
   5  
   6  CKEDITOR.dialog.add( 'linktomenu', function( editor )
   7  {
   8      //<!-- linktonode START -->
   9      CKEDITOR.scriptLoader.load( Drupal.settings.basePath + "misc/jquery.js");
  10      CKEDITOR.scriptLoader.load( Drupal.settings.ckeditor.module_path + "/plugins/linktomenu/jscripts/functions.js", function() {
  11          loadCategories(null);
  12      });
  13      //<!-- linktonode END -->
  14  
  15  
  16      // Handles the event when the "Target" selection box is changed.
  17      var targetChanged = function()
  18      {
  19          var dialog = this.getDialog(),
  20              popupFeatures = dialog.getContentElement( 'target', 'popupFeatures' ),
  21              targetName = dialog.getContentElement( 'target', 'linkTargetName' ),
  22              value = this.getValue();
  23  
  24          if ( !popupFeatures || !targetName )
  25              return;
  26  
  27          popupFeatures = popupFeatures.getElement();
  28  
  29          if ( value == 'popup' )
  30          {
  31              popupFeatures.show();
  32              targetName.setLabel( editor.lang.link.targetPopupName );
  33          }
  34          else
  35          {
  36              popupFeatures.hide();
  37              targetName.setLabel( editor.lang.link.targetFrameName );
  38              this.getDialog().setValueOf( 'target', 'linkTargetName', value.charAt( 0 ) == '_' ? value : '' );
  39          }
  40      };
  41  
  42      // Loads the parameters in a selected link to the link dialog fields.
  43      var emailRegex = /^mailto:([^?]+)(?:\?(.+))?$/,
  44          emailSubjectRegex = /subject=([^;?:@&=$,\/]*)/,
  45          emailBodyRegex = /body=([^;?:@&=$,\/]*)/,
  46          anchorRegex = /^#(.*)$/,
  47          urlRegex = /^((?:http|https|ftp|news):\/\/)?(.*)$/,
  48          selectableTargets = /^(_(?:self|top|parent|blank))$/;
  49  
  50      var popupRegex =
  51          /\s*window.open\(\s*this\.href\s*,\s*(?:'([^']*)'|null)\s*,\s*'([^']*)'\s*\)\s*;\s*return\s*false;*\s*/;
  52      var popupFeaturesRegex = /(?:^|,)([^=]+)=(\d+|yes|no)/gi;
  53  
  54      var parseLink = function( editor, element )
  55      {
  56          var href = element ? ( element.getAttribute( '_cke_saved_href' ) || element.getAttribute( 'href' ) ) : '',
  57              emailMatch = '',
  58              anchorMatch = '',
  59              urlMatch = false,
  60              retval = {};
  61  
  62          if ( href )
  63          {
  64              emailMatch = href.match( emailRegex );
  65              anchorMatch = href.match( anchorRegex );
  66              urlMatch = href.match( urlRegex );
  67          }
  68  
  69          // Load the link type and URL.
  70          if ( emailMatch )
  71          {
  72              var subjectMatch = href.match( emailSubjectRegex ),
  73                  bodyMatch = href.match( emailBodyRegex );
  74              retval.type = 'email';
  75              retval.email = {};
  76              retval.email.address = emailMatch[1];
  77              subjectMatch && ( retval.email.subject = decodeURIComponent( subjectMatch[1] ) );
  78              bodyMatch && ( retval.email.body = decodeURIComponent( bodyMatch[1] ) );
  79          }
  80          else if ( anchorMatch )
  81          {
  82              retval.type = 'anchor';
  83              retval.anchor = {};
  84              retval.anchor.name = retval.anchor.id = anchorMatch[1];
  85          }
  86          else if ( href && urlMatch )        // urlRegex matches empty strings, so need to check for href as well.
  87          {
  88              retval.type = 'url';
  89              retval.url = {};
  90              retval.url.protocol = urlMatch[1];
  91              retval.url.url = urlMatch[2];
  92          }
  93          else
  94              retval.type = 'url';
  95  
  96          // Load target and popup settings.
  97          if ( element )
  98          {
  99              var target = element.getAttribute( 'target' );
 100              retval.target = {};
 101              retval.adv = {};
 102  
 103              // IE BUG: target attribute is an empty string instead of null in IE if it's not set.
 104              if ( !target )
 105              {
 106                  var onclick = element.getAttribute( '_cke_pa_onclick' ) || element.getAttribute( 'onclick' ),
 107                      onclickMatch = onclick && onclick.match( popupRegex );
 108                  if ( onclickMatch )
 109                  {
 110                      retval.target.type = 'popup';
 111                      retval.target.name = onclickMatch[1];
 112  
 113                      var featureMatch;
 114                      while ( ( featureMatch = popupFeaturesRegex.exec( onclickMatch[2] ) ) )
 115                      {
 116                          if ( featureMatch[2] == 'yes' || featureMatch[2] == '1' )
 117                              retval.target[ featureMatch[1] ] = true;
 118                          else if ( isFinite( featureMatch[2] ) )
 119                              retval.target[ featureMatch[1] ] = featureMatch[2];
 120                      }
 121                  }
 122              }
 123              else
 124              {
 125                  var targetMatch = target.match( selectableTargets );
 126                  if ( targetMatch )
 127                      retval.target.type = retval.target.name = target;
 128                  else
 129                  {
 130                      retval.target.type = 'frame';
 131                      retval.target.name = target;
 132                  }
 133              }
 134  
 135              var me = this;
 136              var advAttr = function( inputName, attrName )
 137              {
 138                  var value = element.getAttribute( attrName );
 139                  if ( value !== null )
 140                      retval.adv[ inputName ] = value || '';
 141              };
 142              advAttr( 'advId', 'id' );
 143              advAttr( 'advLangDir', 'dir' );
 144              advAttr( 'advAccessKey', 'accessKey' );
 145              advAttr( 'advName', 'name' );
 146              advAttr( 'advLangCode', 'lang' );
 147              advAttr( 'advTabIndex', 'tabindex' );
 148              advAttr( 'advTitle', 'title' );
 149              advAttr( 'advContentType', 'type' );
 150              advAttr( 'advCSSClasses', 'class' );
 151              advAttr( 'advCharset', 'charset' );
 152              advAttr( 'advStyles', 'style' );
 153          }
 154  
 155          // Find out whether we have any anchors in the editor.
 156          // Get all IMG elements in CK document.
 157          var elements = editor.document.getElementsByTag( 'img' ),
 158              realAnchors = new CKEDITOR.dom.nodeList( editor.document.$.anchors ),
 159              anchors = retval.anchors = [];
 160  
 161          for( var i = 0; i < elements.count() ; i++ )
 162          {
 163              var item = elements.getItem( i );
 164              if ( item.getAttribute( '_cke_realelement' ) && item.getAttribute( '_cke_real_element_type' ) == 'anchor' )
 165              {
 166                  anchors.push( editor.restoreRealElement( item ) );
 167              }
 168          }
 169  
 170          for ( i = 0 ; i < realAnchors.count() ; i++ )
 171              anchors.push( realAnchors.getItem( i ) );
 172  
 173          for ( i = 0 ; i < anchors.length ; i++ )
 174          {
 175              item = anchors[ i ];
 176              anchors[ i ] = { name : item.getAttribute( 'name' ), id : item.getAttribute( 'id' ) };
 177          }
 178  
 179          // Record down the selected element in the dialog.
 180          this._.selectedElement = element;
 181  
 182          return retval;
 183      };
 184  
 185      var setupParams = function( page, data )
 186      {
 187          if ( data[page] )
 188              this.setValue( data[page][this.id] || '' );
 189      };
 190  
 191      var setupPopupParams = function( data )
 192      {
 193          return setupParams.call( this, 'target', data );
 194      };
 195  
 196      var setupAdvParams = function( data )
 197      {
 198          return setupParams.call( this, 'adv', data );
 199      };
 200  
 201      var commitParams = function( page, data )
 202      {
 203          if ( !data[page] )
 204              data[page] = {};
 205  
 206          data[page][this.id] = this.getValue() || '';
 207      };
 208  
 209      var commitPopupParams = function( data )
 210      {
 211          return commitParams.call( this, 'target', data );
 212      };
 213  
 214      var commitAdvParams = function( data )
 215      {
 216          return commitParams.call( this, 'adv', data );
 217      };
 218  
 219      return {
 220          title : 'Link to menu',
 221          minWidth : 350,
 222          minHeight : 230,
 223          contents : [
 224              {
 225                  id : 'info',
 226                  label : editor.lang.link.info,
 227                  title : editor.lang.link.info,
 228                  elements :
 229                  [
 230                      {
 231                          type : 'html',
 232                          html : 
 233      '<link rel="stylesheet" href="' + Drupal.settings.ckeditor.module_path + '/plugins/linktomenu/css/linktocontent.css" type="text/css" />' +
 234      '<input id="linktomenu_url" type="hidden" />' +
 235      '<input id="linktomenu_text" type="hidden" />' +
 236      '<div class="panel_wrap">' +
 237      '<div id="browse_panel" class="panel current">' +
 238          '<form id="form_browse" action="#" onsubmit="return false;">' +
 239          '<strong>Browse</strong>' +
 240          '</form>' +
 241      '</div>' +
 242      '</div>' +
 243      '<!-- node list -->' +
 244      '<div class="panel_wrap" id="list">' +
 245          '<div class="nodes">' +
 246              '<div id="nodelist" class="scrollable accessible">' +
 247                  '<table cellspacing="0" summary="item list">' +
 248                  '<thead>' +
 249                  '<tr>' +
 250                      '<th><strong>Title</strong></th>' +
 251                  '</tr>' +
 252                  '</thead>' +
 253                  '<tbody>' +
 254                  '</tbody>' +
 255                  '</table>' +
 256              '</div>' +
 257          '</div>' +
 258      '</div>' +
 259      '<div id="statusImg"><img alt="loading" src="' + Drupal.settings.ckeditor.module_path + '/plugins/linktomenu/images/loading.gif" />loading...</div>'
 260                      }
 261                  ]
 262              },
 263              {
 264                  id : 'target',
 265                  label : editor.lang.link.target,
 266                  title : editor.lang.link.target,
 267                  elements :
 268                  [
 269                      {
 270                          type : 'hbox',
 271                          widths : [ '50%', '50%' ],
 272                          children :
 273                          [
 274                              {
 275                                  type : 'select',
 276                                  id : 'linkTargetType',
 277                                  label : editor.lang.link.target,
 278                                  'default' : 'notSet',
 279                                  style : 'width : 100%;',
 280                                  'items' :
 281                                  [
 282                                      [ editor.lang.link.targetNotSet, 'notSet' ],
 283                                      [ editor.lang.link.targetFrame, 'frame' ],
 284                                      [ editor.lang.link.targetPopup, 'popup' ],
 285                                      [ editor.lang.link.targetNew, '_blank' ],
 286                                      [ editor.lang.link.targetTop, '_top' ],
 287                                      [ editor.lang.link.targetSelf, '_self' ],
 288                                      [ editor.lang.link.targetParent, '_parent' ]
 289                                  ],
 290                                  onChange : targetChanged,
 291                                  setup : function( data )
 292                                  {
 293                                      if ( data.target )
 294                                          this.setValue( data.target.type );
 295                                  },
 296                                  commit : function( data )
 297                                  {
 298                                      if ( !data.target )
 299                                          data.target = {};
 300  
 301                                      data.target.type = this.getValue();
 302                                  }
 303                              },
 304                              {
 305                                  type : 'text',
 306                                  id : 'linkTargetName',
 307                                  label : editor.lang.link.targetFrameName,
 308                                  'default' : '',
 309                                  setup : function( data )
 310                                  {
 311                                      if ( data.target )
 312                                          this.setValue( data.target.name );
 313                                  },
 314                                  commit : function( data )
 315                                  {
 316                                      if ( !data.target )
 317                                          data.target = {};
 318  
 319                                      data.target.name = this.getValue();
 320                                  }
 321                              }
 322                          ]
 323                      },
 324                      {
 325                          type : 'vbox',
 326                          width : 260,
 327                          align : 'center',
 328                          padding : 2,
 329                          id : 'popupFeatures',
 330                          children :
 331                          [
 332                              {
 333                                  type : 'html',
 334                                  html : CKEDITOR.tools.htmlEncode( editor.lang.link.popupFeatures )
 335                              },
 336                              {
 337                                  type : 'hbox',
 338                                  children :
 339                                  [
 340                                      {
 341                                          type : 'checkbox',
 342                                          id : 'resizable',
 343                                          label : editor.lang.link.popupResizable,
 344                                          setup : setupPopupParams,
 345                                          commit : commitPopupParams
 346                                      },
 347                                      {
 348                                          type : 'checkbox',
 349                                          id : 'status',
 350                                          label : editor.lang.link.popupStatusBar,
 351                                          setup : setupPopupParams,
 352                                          commit : commitPopupParams
 353  
 354                                      }
 355                                  ]
 356                              },
 357                              {
 358                                  type : 'hbox',
 359                                  children :
 360                                  [
 361                                      {
 362                                          type : 'checkbox',
 363                                          id : 'location',
 364                                          label : editor.lang.link.popupLocationBar,
 365                                          setup : setupPopupParams,
 366                                          commit : commitPopupParams
 367  
 368                                      },
 369                                      {
 370                                          type : 'checkbox',
 371                                          id : 'toolbar',
 372                                          label : editor.lang.link.popupToolbar,
 373                                          setup : setupPopupParams,
 374                                          commit : commitPopupParams
 375  
 376                                      }
 377                                  ]
 378                              },
 379                              {
 380                                  type : 'hbox',
 381                                  children :
 382                                  [
 383                                      {
 384                                          type : 'checkbox',
 385                                          id : 'menubar',
 386                                          label : editor.lang.link.popupMenuBar,
 387                                          setup : setupPopupParams,
 388                                          commit : commitPopupParams
 389  
 390                                      },
 391                                      {
 392                                          type : 'checkbox',
 393                                          id : 'fullscreen',
 394                                          label : editor.lang.link.popupFullScreen,
 395                                          setup : setupPopupParams,
 396                                          commit : commitPopupParams
 397  
 398                                      }
 399                                  ]
 400                              },
 401                              {
 402                                  type : 'hbox',
 403                                  children :
 404                                  [
 405                                      {
 406                                          type : 'checkbox',
 407                                          id : 'scrollbars',
 408                                          label : editor.lang.link.popupScrollBars,
 409                                          setup : setupPopupParams,
 410                                          commit : commitPopupParams
 411  
 412                                      },
 413                                      {
 414                                          type : 'checkbox',
 415                                          id : 'dependent',
 416                                          label : editor.lang.link.popupDependent,
 417                                          setup : setupPopupParams,
 418                                          commit : commitPopupParams
 419  
 420                                      }
 421                                  ]
 422                              },
 423                              {
 424                                  type : 'hbox',
 425                                  children :
 426                                  [
 427                                      {
 428                                          type :  'text',
 429                                          widths : [ '30%', '70%' ],
 430                                          labelLayout : 'horizontal',
 431                                          label : editor.lang.link.popupWidth,
 432                                          id : 'width',
 433                                          setup : setupPopupParams,
 434                                          commit : commitPopupParams
 435  
 436                                      },
 437                                      {
 438                                          type :  'text',
 439                                          labelLayout : 'horizontal',
 440                                          widths : [ '55%', '45%' ],
 441                                          label : editor.lang.link.popupLeft,
 442                                          id : 'left',
 443                                          setup : setupPopupParams,
 444                                          commit : commitPopupParams
 445  
 446                                      }
 447                                  ]
 448                              },
 449                              {
 450                                  type : 'hbox',
 451                                  children :
 452                                  [
 453                                      {
 454                                          type :  'text',
 455                                          labelLayout : 'horizontal',
 456                                          widths : [ '30%', '70%' ],
 457                                          label : editor.lang.link.popupHeight,
 458                                          id : 'height',
 459                                          setup : setupPopupParams,
 460                                          commit : commitPopupParams
 461  
 462                                      },
 463                                      {
 464                                          type :  'text',
 465                                          labelLayout : 'horizontal',
 466                                          label : editor.lang.link.popupTop,
 467                                          widths : [ '55%', '45%' ],
 468                                          id : 'top',
 469                                          setup : setupPopupParams,
 470                                          commit : commitPopupParams
 471  
 472                                      }
 473                                  ]
 474                              }
 475                          ]
 476                      }
 477                  ]
 478              },
 479              {
 480                  id : 'advanced',
 481                  label : editor.lang.link.advanced,
 482                  title : editor.lang.link.advanced,
 483                  elements :
 484                  [
 485                      {
 486                          type : 'vbox',
 487                          padding : 1,
 488                          children :
 489                          [
 490                              {
 491                                  type : 'hbox',
 492                                  widths : [ '45%', '35%', '20%' ],
 493                                  children :
 494                                  [
 495                                      {
 496                                          type : 'text',
 497                                          id : 'advId',
 498                                          label : editor.lang.link.id,
 499                                          setup : setupAdvParams,
 500                                          commit : commitAdvParams
 501                                      },
 502                                      {
 503                                          type : 'select',
 504                                          id : 'advLangDir',
 505                                          label : editor.lang.link.langDir,
 506                                          'default' : '',
 507                                          style : 'width:110px',
 508                                          items :
 509                                          [
 510                                              [ editor.lang.link.langDirNotSet, '' ],
 511                                              [ editor.lang.link.langDirLTR, 'ltr' ],
 512                                              [ editor.lang.link.langDirRTL, 'rtl' ]
 513                                          ],
 514                                          setup : setupAdvParams,
 515                                          commit : commitAdvParams
 516                                      },
 517                                      {
 518                                          type : 'text',
 519                                          id : 'advAccessKey',
 520                                          width : '80px',
 521                                          label : editor.lang.link.acccessKey,
 522                                          maxLength : 1,
 523                                          setup : setupAdvParams,
 524                                          commit : commitAdvParams
 525  
 526                                      }
 527                                  ]
 528                              },
 529                              {
 530                                  type : 'hbox',
 531                                  widths : [ '45%', '35%', '20%' ],
 532                                  children :
 533                                  [
 534                                      {
 535                                          type : 'text',
 536                                          label : editor.lang.link.name,
 537                                          id : 'advName',
 538                                          setup : setupAdvParams,
 539                                          commit : commitAdvParams
 540  
 541                                      },
 542                                      {
 543                                          type : 'text',
 544                                          label : editor.lang.link.langCode,
 545                                          id : 'advLangCode',
 546                                          width : '110px',
 547                                          'default' : '',
 548                                          setup : setupAdvParams,
 549                                          commit : commitAdvParams
 550  
 551                                      },
 552                                      {
 553                                          type : 'text',
 554                                          label : editor.lang.link.tabIndex,
 555                                          id : 'advTabIndex',
 556                                          width : '80px',
 557                                          maxLength : 5,
 558                                          setup : setupAdvParams,
 559                                          commit : commitAdvParams
 560  
 561                                      }
 562                                  ]
 563                              }
 564                          ]
 565                      },
 566                      {
 567                          type : 'vbox',
 568                          padding : 1,
 569                          children :
 570                          [
 571                              {
 572                                  type : 'hbox',
 573                                  widths : [ '45%', '55%' ],
 574                                  children :
 575                                  [
 576                                      {
 577                                          type : 'text',
 578                                          label : editor.lang.link.advisoryTitle,
 579                                          'default' : '',
 580                                          id : 'advTitle',
 581                                          setup : setupAdvParams,
 582                                          commit : commitAdvParams
 583  
 584                                      },
 585                                      {
 586                                          type : 'text',
 587                                          label : editor.lang.link.advisoryContentType,
 588                                          'default' : '',
 589                                          id : 'advContentType',
 590                                          setup : setupAdvParams,
 591                                          commit : commitAdvParams
 592  
 593                                      }
 594                                  ]
 595                              },
 596                              {
 597                                  type : 'hbox',
 598                                  widths : [ '45%', '55%' ],
 599                                  children :
 600                                  [
 601                                      {
 602                                          type : 'text',
 603                                          label : editor.lang.link.cssClasses,
 604                                          'default' : '',
 605                                          id : 'advCSSClasses',
 606                                          setup : setupAdvParams,
 607                                          commit : commitAdvParams
 608  
 609                                      },
 610                                      {
 611                                          type : 'text',
 612                                          label : editor.lang.link.charset,
 613                                          'default' : '',
 614                                          id : 'advCharset',
 615                                          setup : setupAdvParams,
 616                                          commit : commitAdvParams
 617  
 618                                      }
 619                                  ]
 620                              },
 621                              {
 622                                  type : 'hbox',
 623                                  children :
 624                                  [
 625                                      {
 626                                          type : 'text',
 627                                          label : editor.lang.link.styles,
 628                                          'default' : '',
 629                                          id : 'advStyles',
 630                                          setup : setupAdvParams,
 631                                          commit : commitAdvParams
 632  
 633                                      }
 634                                  ]
 635                              }
 636                          ]
 637                      }
 638                  ]
 639              }
 640          ],
 641          onShow : function()
 642          {
 643              this.fakeObj = false;
 644  
 645              var editor = this.getParentEditor(),
 646                  selection = editor.getSelection(),
 647                  ranges = selection.getRanges(),
 648                  element = null,
 649                  me = this;
 650              // Fill in all the relevant fields if there's already one link selected.
 651              if ( ranges.length == 1 )
 652              {
 653  
 654                  var rangeRoot = ranges[0].getCommonAncestor( true );
 655                  element = rangeRoot.getAscendant( 'a', true );
 656                  if ( element && element.getAttribute( 'href' ) )
 657                  {
 658                      selection.selectElement( element );
 659                  }
 660                  else if ( ( element = rangeRoot.getAscendant( 'img', true ) ) &&
 661                           element.getAttribute( '_cke_real_element_type' ) &&
 662                           element.getAttribute( '_cke_real_element_type' ) == 'anchor' )
 663                  {
 664                      this.fakeObj = element;
 665                      element = editor.restoreRealElement( this.fakeObj );
 666                      selection.selectElement( this.fakeObj );
 667                  }
 668                  else
 669                      element = null;
 670              }
 671  
 672              this.setupContent( parseLink.apply( this, [ editor, element ] ) );
 673          },
 674          onOk : function()
 675          {
 676              var attributes = { href : 'javascript:void(0)/*' + CKEDITOR.tools.getNextNumber() + '*/' },
 677                  removeAttributes = [],
 678                  data = { href : attributes.href },
 679                  me = this, editor = this.getParentEditor();
 680  
 681              this.commitContent( data );
 682              //<!-- linktonode START -->
 683              attributes._cke_saved_href = (Drupal.settings.ckeditor.linktomenu_basepath || '' ) + $('#linktomenu_url').val();
 684              //<!-- linktonode END -->
 685  
 686              // Popups and target.
 687              if ( data.target )
 688              {
 689                  if ( data.target.type == 'popup' )
 690                  {
 691                      var onclickList = [ 'window.open(this.href, \'',
 692                              data.target.name || '', '\', \'' ];
 693                      var featureList = [ 'resizable', 'status', 'location', 'toolbar', 'menubar', 'fullscreen',
 694                              'scrollbars', 'dependent' ];
 695                      var featureLength = featureList.length;
 696                      var addFeature = function( featureName )
 697                      {
 698                          if ( data.target[ featureName ] )
 699                              featureList.push( featureName + '=' + data.target[ featureName ] );
 700                      };
 701  
 702                      for ( var i = 0 ; i < featureLength ; i++ )
 703                          featureList[i] = featureList[i] + ( data.target[ featureList[i] ] ? '=yes' : '=no' ) ;
 704                      addFeature( 'width' );
 705                      addFeature( 'left' );
 706                      addFeature( 'height' );
 707                      addFeature( 'top' );
 708  
 709                      onclickList.push( featureList.join( ',' ), '\'); return false;' );
 710                      attributes[ CKEDITOR.env.ie || CKEDITOR.env.webkit ? '_cke_pa_onclick' : 'onclick' ] = onclickList.join( '' );
 711                  }
 712                  else
 713                  {
 714                      if ( data.target.type != 'notSet' && data.target.name )
 715                          attributes.target = data.target.name;
 716                      removeAttributes.push( '_cke_pa_onclick', 'onclick' );
 717                  }
 718              }
 719  
 720              // Advanced attributes.
 721              if ( data.adv )
 722              {
 723                  var advAttr = function( inputName, attrName )
 724                  {
 725                      var value = data.adv[ inputName ];
 726                      if ( value )
 727                          attributes[attrName] = value;
 728                      else
 729                          removeAttributes.push( attrName );
 730                  };
 731  
 732                  if ( this._.selectedElement )
 733                      advAttr( 'advId', 'id' );
 734                  advAttr( 'advLangDir', 'dir' );
 735                  advAttr( 'advAccessKey', 'accessKey' );
 736                  advAttr( 'advName', 'name' );
 737                  advAttr( 'advLangCode', 'lang' );
 738                  advAttr( 'advTabIndex', 'tabindex' );
 739                  advAttr( 'advTitle', 'title' );
 740                  advAttr( 'advContentType', 'type' );
 741                  advAttr( 'advCSSClasses', 'class' );
 742                  advAttr( 'advCharset', 'charset' );
 743                  advAttr( 'advStyles', 'style' );
 744              }
 745  
 746              if ( !this._.selectedElement )
 747              {
 748                  // Create element if current selection is collapsed.
 749                  var selection = editor.getSelection(),
 750                      ranges = selection.getRanges();
 751                  if ( ranges.length == 1 && ranges[0].collapsed )
 752                  {
 753                      // <!-- linktonode START -->
 754                      var text = new CKEDITOR.dom.text( $('#linktomenu_text').val() || attributes._cke_saved_href, editor.document );
 755                      // <!-- linktonode END -->
 756                      ranges[0].insertNode( text );
 757                      ranges[0].selectNodeContents( text );
 758                      selection.selectRanges( ranges );
 759                  }
 760  
 761                  // Apply style.
 762                  var style = new CKEDITOR.style( { element : 'a', attributes : attributes } );
 763                  style.type = CKEDITOR.STYLE_INLINE;        // need to override... dunno why.
 764                  style.apply( editor.document );
 765  
 766                  // Id. Apply only to the first link.
 767                  if ( data.adv && data.adv.advId )
 768                  {
 769                      var links = this.getParentEditor().document.$.getElementsByTagName( 'a' );
 770                      for ( i = 0 ; i < links.length ; i++ )
 771                      {
 772                          if ( links[i].href == attributes.href )
 773                          {
 774                              links[i].id = data.adv.advId;
 775                              break;
 776                          }
 777                      }
 778                  }
 779              }
 780              else
 781              {
 782                  // We're only editing an existing link, so just overwrite the attributes.
 783                  var element = this._.selectedElement;
 784  
 785                  // IE BUG: Setting the name attribute to an existing link doesn't work.
 786                  // Must re-create the link from weired syntax to workaround.
 787                  if ( CKEDITOR.env.ie && attributes.name != element.getAttribute( 'name' ) )
 788                  {
 789                      var newElement = new CKEDITOR.dom.element( '<a name="' + CKEDITOR.tools.htmlEncode( attributes.name ) + '">',
 790                              editor.document );
 791  
 792                      selection = editor.getSelection();
 793  
 794                      element.moveChildren( newElement );
 795                      element.copyAttributes( newElement, { name : 1 } );
 796                      newElement.replace( element );
 797                      element = newElement;
 798  
 799                      selection.selectElement( element );
 800                  }
 801  
 802                  element.setAttributes( attributes );
 803                  element.removeAttributes( removeAttributes );
 804  
 805                  // Make the element display as an anchor if a name has been set.
 806                  if ( element.getAttribute( 'name' ) )
 807                      element.addClass( 'cke_anchor' );
 808                  else
 809                      element.removeClass( 'cke_anchor' );
 810  
 811                  if ( this.fakeObj )
 812                      editor.createFakeElement( element, 'cke_anchor', 'anchor' ).replace( this.fakeObj );
 813  
 814                  delete this._.selectedElement;
 815              }
 816          },
 817          onLoad : function()
 818          {
 819              if ( !editor.config.linkShowAdvancedTab )
 820                  this.hidePage( 'advanced' );        //Hide Advanded tab.
 821  
 822              if ( !editor.config.linkShowTargetTab )
 823                  this.hidePage( 'target' );        //Hide Target tab.
 824  
 825          }
 826      };
 827  } );


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