[ Index ]

PHP Cross Reference of vtigercrm-6.1.0

title

Body

[close]

/libraries/jquery/ckeditor/plugins/scayt/ -> plugin.js (source)

   1  /**

   2   * @license Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.

   3   * For licensing, see LICENSE.html or http://ckeditor.com/license

   4   */
   5  
   6  /**

   7   * @fileOverview Spell Check As You Type (SCAYT).

   8   * Button name : Scayt.

   9   */
  10  
  11  (function() {
  12      var commandName = 'scaytcheck',
  13          wscCommandName = 'checkspell',
  14          openPage = '';
  15  
  16      // Checks if a value exists in an array

  17  	function in_array( needle, haystack ) {
  18          var found = 0,
  19              key;
  20          for ( key in haystack ) {
  21              if ( haystack[ key ] == needle ) {
  22                  found = 1;
  23                  break;
  24              }
  25          }
  26          return found;
  27      }
  28  
  29      var onEngineLoad = function() {
  30              var editor = this;
  31  
  32              var createInstance = function( ev ) // Create new instance every time Document is created.
  33                  {
  34                      if ( typeof plugin.instances[ editor.name ] != 'undefined' || plugin.instances[ editor.name ] != null )
  35                          return;
  36  
  37                      var config = editor.config;
  38                      // Initialise Scayt instance.

  39                      var oParams = {};
  40                      // Get the iframe.

  41  
  42                      if(editor.editable().$.nodeName == 'BODY')
  43                          oParams.srcNodeRef = editor.document.getWindow().$.frameElement;
  44                      else
  45                          oParams.srcNodeRef = editor.editable().$;
  46  
  47                      // syntax : AppName.AppVersion@AppRevision

  48                      oParams.assocApp = 'CKEDITOR.' + CKEDITOR.version + '@' + CKEDITOR.revision;
  49                      oParams.customerid = config.scayt_customerid || '1:WvF0D4-UtPqN1-43nkD4-NKvUm2-daQqk3-LmNiI-z7Ysb4-mwry24-T8YrS3-Q2tpq2';
  50                      oParams.customDictionaryIds = config.scayt_customDictionaryIds || '';
  51                      oParams.userDictionaryName = config.scayt_userDictionaryName || '';
  52                      oParams.sLang = config.scayt_sLang || 'en_US';
  53  
  54                      // Introduce SCAYT onLoad callback. (#5632)

  55                      oParams.onLoad = function() {
  56                          // Draw down word marker to avoid being covered by background-color style.(#5466)

  57                          if ( !( CKEDITOR.env.ie && CKEDITOR.env.version < 8 ) )
  58                              this.addStyle( this.selectorCss(), 'padding-bottom: 2px !important;' );
  59  
  60                          // Call scayt_control.focus when SCAYT loaded

  61                          // and only if editor has focus and scayt control creates at first time (#5720)

  62                          if ( editor.editable().hasFocus && !plugin.isControlRestored( editor ) )
  63                              this.focus();
  64  
  65                      };
  66  
  67                      oParams.onBeforeChange = function() {
  68                          if ( plugin.getScayt( editor ) && !editor.checkDirty() )
  69                              setTimeout( function() {
  70                              editor.resetDirty();
  71                          }, 0 );
  72                      };
  73  
  74                      var scayt_custom_params = window.scayt_custom_params;
  75                      if ( typeof scayt_custom_params == 'object' ) {
  76                          for ( var k in scayt_custom_params )
  77                              oParams[ k ] = scayt_custom_params[ k ];
  78                      }
  79                      // needs for restoring a specific scayt control settings

  80                      if ( plugin.getControlId( editor ) )
  81                          oParams.id = plugin.getControlId( editor );
  82  
  83                      var scayt_control = new window.scayt( oParams );
  84  
  85                      scayt_control.afterMarkupRemove.push( function( node ) {
  86                          ( new CKEDITOR.dom.element( node, scayt_control.document ) ).mergeSiblings();
  87                      });
  88  
  89                      // Copy config.

  90                      var lastInstance = plugin.instances[ editor.name ];
  91                      if ( lastInstance ) {
  92                          scayt_control.sLang = lastInstance.sLang;
  93                          scayt_control.option( lastInstance.option() );
  94                          scayt_control.paused = lastInstance.paused;
  95                      }
  96  
  97                      plugin.instances[ editor.name ] = scayt_control;
  98  
  99                      try {
 100                          scayt_control.setDisabled( plugin.isPaused( editor ) === false );
 101                      } catch ( e ) {}
 102  
 103                      editor.fire( 'showScaytState' );
 104                  };
 105  
 106  			function bindInlineModeEvents() {
 107                  editor.once( 'focus', createInstance );
 108                  editor.once( 'blur', destroyInstance );
 109              }
 110  
 111  			function destroyInstance( ev ) {
 112                  var editor = ev.editor,
 113                      scayt_instance = plugin.getScayt( editor ),
 114                      inline_mode = ( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE );
 115  
 116                  // SCAYT instance might already get destroyed by mode switch (#5744).

 117                  if ( !scayt_instance )
 118                      return;
 119  
 120                  plugin.setPaused( editor, !scayt_instance.disabled );
 121                  // store a control id for restore a specific scayt control settings

 122                  plugin.setControlId( editor, scayt_instance.id );
 123                  scayt_instance.destroy( true );
 124                  delete plugin.instances[ editor.name ];
 125  
 126                  if ( inline_mode ) bindInlineModeEvents();
 127              }
 128  
 129              ( editor.elementMode == CKEDITOR.ELEMENT_MODE_INLINE ) ? bindInlineModeEvents() : editor.on( 'contentDom', createInstance );
 130  
 131              editor.on( 'contentDomUnload', function() {
 132                  // Remove scripts.

 133                  var scripts = CKEDITOR.document.getElementsByTag( 'script' ),
 134                      scaytIdRegex = /^dojoIoScript(\d+)$/i,
 135                      scaytSrcRegex = /^https?:\/\/svc\.webspellchecker\.net\/spellcheck\/script\/ssrv\.cgi/i;
 136  
 137                  for ( var i = 0; i < scripts.count(); i++ ) {
 138                      var script = scripts.getItem( i ),
 139                          id = script.getId(),
 140                          src = script.getAttribute( 'src' );
 141  
 142                      if ( id && src && id.match( scaytIdRegex ) && src.match( scaytSrcRegex ) )
 143                          script.remove();
 144                  }
 145              });
 146  
 147              editor.on( 'beforeCommandExec', function( ev ) // Disable SCAYT before Source command execution.
 148              {
 149                  if ( ev.data.name == 'source'  && editor.mode == 'source' )
 150                      plugin.markControlRestore( editor );
 151              });
 152  
 153              editor.on( 'afterCommandExec', function( ev ) {
 154                  if ( !plugin.isScaytEnabled( editor ) )
 155                      return;
 156  
 157                  if ( editor.mode == 'wysiwyg' && ( ev.data.name == 'undo' || ev.data.name == 'redo' ) )
 158                      window.setTimeout( function() {
 159                      plugin.getScayt( editor ).refresh();
 160                  }, 10 );
 161              });
 162  
 163              editor.on( 'destroy', destroyInstance );
 164  
 165              // Listen to data manipulation to reflect scayt markup.

 166              editor.on( 'setData', destroyInstance );
 167  
 168              // Reload spell-checking for current word after insertion completed.

 169              editor.on( 'insertElement', function() {
 170                  var scayt_instance = plugin.getScayt( editor );
 171                  if ( plugin.isScaytEnabled( editor ) ) {
 172                      // Unlock the selection before reload, SCAYT will take

 173                      // care selection update.

 174                      if ( CKEDITOR.env.ie )
 175                          editor.getSelection().unlock( true );
 176  
 177                      // Return focus to the editor and refresh SCAYT markup (#5573).

 178                      window.setTimeout( function() {
 179                          scayt_instance.focus();
 180                          scayt_instance.refresh();
 181                      }, 10 );
 182                  }
 183              }, this, null, 50 );
 184  
 185              editor.on( 'insertHtml', function() {
 186                  var scayt_instance = plugin.getScayt( editor );
 187                  if ( plugin.isScaytEnabled( editor ) ) {
 188                      // Unlock the selection before reload, SCAYT will take

 189                      // care selection update.

 190                      if ( CKEDITOR.env.ie )
 191                          editor.getSelection().unlock( true );
 192  
 193                      // Return focus to the editor (#5573)

 194                      // Refresh SCAYT markup

 195                      window.setTimeout( function() {
 196                          scayt_instance.focus();
 197                          scayt_instance.refresh();
 198                      }, 10 );
 199                  }
 200              }, this, null, 50 );
 201  
 202              editor.on( 'scaytDialog', function( ev ) // Communication with dialog.
 203              {
 204                  ev.data.djConfig = window.djConfig;
 205                  ev.data.scayt_control = plugin.getScayt( editor );
 206                  ev.data.tab = openPage;
 207                  ev.data.scayt = window.scayt;
 208              });
 209  
 210              var dataProcessor = editor.dataProcessor,
 211                  htmlFilter = dataProcessor && dataProcessor.htmlFilter;
 212  
 213              if ( htmlFilter ) {
 214                  htmlFilter.addRules({
 215                      elements: {
 216                          span: function( element ) {
 217                              if ( element.attributes[ 'data-scayt_word' ] && element.attributes[ 'data-scaytid' ] ) {
 218                                  delete element.name; // Write children, but don't write this node.

 219                                  return element;
 220                              }
 221                          }
 222                      }
 223                  });
 224              }
 225  
 226              // Override Image.equals method avoid CK snapshot module to add SCAYT markup to snapshots. (#5546)

 227              var undoImagePrototype = CKEDITOR.plugins.undo.Image.prototype;
 228  
 229              // add backword compatibility for CKEDITOR 4.2. method equals was repleced on other method

 230              var equalsContent = (typeof undoImagePrototype.equalsContent == "function") ? undoImagePrototype.equalsContent : undoImagePrototype.equals;
 231  
 232              equalsContent = CKEDITOR.tools.override( equalsContent, function( org ) {
 233                  return function( otherImage ) {
 234                      var thisContents = this.contents,
 235                          otherContents = otherImage.contents;
 236                      var scayt_instance = plugin.getScayt( this.editor );
 237                      // Making the comparison based on content without SCAYT word markers.

 238                      if ( scayt_instance && plugin.isScaytReady( this.editor ) ) {
 239                          // scayt::reset might return value undefined. (#5742)

 240                          this.contents = scayt_instance.reset( thisContents ) || '';
 241                          otherImage.contents = scayt_instance.reset( otherContents ) || '';
 242                      }
 243  
 244                      var retval = org.apply( this, arguments );
 245  
 246                      this.contents = thisContents;
 247                      otherImage.contents = otherContents;
 248                      return retval;
 249                  };
 250              });
 251  
 252             if(editor.document && (editor.elementMode != CKEDITOR.ELEMENT_MODE_INLINE || editor.focusManager.hasFocus)){
 253                  createInstance();
 254             }
 255          };
 256  
 257      CKEDITOR.plugins.scayt = {
 258          engineLoaded: false,
 259          instances: {},
 260          // Data storage for SCAYT control, based on editor instances

 261          controlInfo: {},
 262          setControlInfo: function( editor, o ) {
 263              if ( editor && editor.name && typeof( this.controlInfo[ editor.name ] ) != 'object' )
 264                  this.controlInfo[ editor.name ] = {};
 265  
 266              for ( var infoOpt in o )
 267                  this.controlInfo[ editor.name ][ infoOpt ] = o[ infoOpt ];
 268          },
 269          isControlRestored: function( editor ) {
 270              if ( editor && editor.name && this.controlInfo[ editor.name ] ) {
 271                  return this.controlInfo[ editor.name ].restored;
 272              }
 273              return false;
 274          },
 275          markControlRestore: function( editor ) {
 276              this.setControlInfo( editor, { restored: true } );
 277          },
 278          setControlId: function( editor, id ) {
 279              this.setControlInfo( editor, { id: id } );
 280          },
 281          getControlId: function( editor ) {
 282              if ( editor && editor.name && this.controlInfo[ editor.name ] && this.controlInfo[ editor.name ].id ) {
 283                  return this.controlInfo[ editor.name ].id;
 284              }
 285              return null;
 286          },
 287          setPaused: function( editor, bool ) {
 288              this.setControlInfo( editor, { paused: bool } );
 289          },
 290          isPaused: function( editor ) {
 291              if ( editor && editor.name && this.controlInfo[ editor.name ] ) {
 292                  return this.controlInfo[ editor.name ].paused;
 293              }
 294              return undefined;
 295          },
 296          getScayt: function( editor ) {
 297              return this.instances[ editor.name ];
 298          },
 299          isScaytReady: function( editor ) {
 300              return this.engineLoaded === true && 'undefined' !== typeof window.scayt && this.getScayt( editor );
 301          },
 302          isScaytEnabled: function( editor ) {
 303              var scayt_instance = this.getScayt( editor );
 304              return ( scayt_instance ) ? scayt_instance.disabled === false : false;
 305          },
 306          getUiTabs: function( editor ) {
 307              var uiTabs = [];
 308  
 309              // read UI tabs value from config

 310              var configUiTabs = editor.config.scayt_uiTabs || "1,1,1";
 311  
 312              // convert string to array

 313              configUiTabs = configUiTabs.split( ',' );
 314  
 315              // "About us" should be always shown for standard config

 316              configUiTabs[ 3 ] = "1";
 317  
 318              for ( var i = 0; i < 4; i++ ) {
 319                  uiTabs[ i ] = ( typeof window.scayt != "undefined" && typeof window.scayt.uiTags != "undefined" ) ? ( parseInt( configUiTabs[ i ], 10 ) && window.scayt.uiTags[ i ] ) : parseInt( configUiTabs[ i ], 10 );
 320              }
 321  
 322              if(typeof editor.plugins.wsc == "object")
 323                  uiTabs.push(1);
 324              else
 325                  uiTabs.push(0);
 326  
 327              return uiTabs;
 328          },
 329          loadEngine: function( editor ) {
 330              // SCAYT doesn't work with Firefox2, Opera and AIR.

 331              if ( CKEDITOR.env.gecko && CKEDITOR.env.version < 10900 || CKEDITOR.env.opera || CKEDITOR.env.air )
 332                  return editor.fire( 'showScaytState' );
 333  
 334              if ( this.engineLoaded === true )
 335                  return onEngineLoad.apply( editor ); // Add new instance.

 336              else if ( this.engineLoaded == -1 ) // We are waiting.
 337              return CKEDITOR.on( 'scaytReady', function() {
 338                  onEngineLoad.apply( editor );
 339              }); // Use function(){} to avoid rejection as duplicate.

 340  
 341              CKEDITOR.on( 'scaytReady', onEngineLoad, editor );
 342              CKEDITOR.on( 'scaytReady', function() {
 343                  this.engineLoaded = true;
 344              }, this, null, 0 ); // First to run.

 345  
 346              this.engineLoaded = -1; // Loading in progress.

 347  
 348              // compose scayt url

 349              var protocol = document.location.protocol;
 350              // Default to 'http' for unknown.

 351              protocol = protocol.search( /https?:/ ) != -1 ? protocol : 'http:';
 352              var baseUrl = 'svc.webspellchecker.net/scayt26/loader__base.js';
 353  
 354              var scaytUrl = editor.config.scayt_srcUrl || ( protocol + '//' + baseUrl );
 355              var scaytConfigBaseUrl = plugin.parseUrl( scaytUrl ).path + '/';
 356  
 357              if ( window.scayt == undefined ) {
 358                  CKEDITOR._djScaytConfig = {
 359                      baseUrl: scaytConfigBaseUrl,
 360                      addOnLoad: [
 361                          function()
 362                          {
 363                          CKEDITOR.fireOnce( 'scaytReady' );
 364                      }
 365                      ],
 366                      isDebug: false
 367                  };
 368                  // Append javascript code.

 369                  CKEDITOR.document.getHead().append( CKEDITOR.document.createElement( 'script', {
 370                      attributes: {
 371                          type: 'text/javascript',
 372                          async: 'true',
 373                          src: scaytUrl
 374                      }
 375                  }));
 376              } else
 377                  CKEDITOR.fireOnce( 'scaytReady' );
 378  
 379              return null;
 380          },
 381          parseUrl: function( data ) {
 382              var match;
 383              if ( data.match && ( match = data.match( /(.*)[\/\\](.*?\.\w+)$/ ) ) )
 384                  return { path: match[ 1 ], file: match[ 2 ] };
 385              else
 386                  return data;
 387          }
 388      };
 389  
 390      var plugin = CKEDITOR.plugins.scayt;
 391  
 392      // Context menu constructing.

 393      var addButtonCommand = function( editor, buttonName, buttonLabel, commandName, command, menugroup, menuOrder ) {
 394              editor.addCommand( commandName, command );
 395  
 396              // If the "menu" plugin is loaded, register the menu item.

 397              editor.addMenuItem( commandName, {
 398                  label: buttonLabel,
 399                  command: commandName,
 400                  group: menugroup,
 401                  order: menuOrder
 402              });
 403          };
 404  
 405      var commandDefinition = {
 406          preserveState: true,
 407          editorFocus: false,
 408          canUndo: false,
 409  
 410          exec: function( editor ) {
 411              if ( plugin.isScaytReady( editor ) ) {
 412                  var isEnabled = plugin.isScaytEnabled( editor );
 413  
 414                  this.setState( isEnabled ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_ON );
 415  
 416                  var scayt_control = plugin.getScayt( editor );
 417                  // the place where the status of editor focus should be restored

 418                  // after there will be ability to store its state before SCAYT button click

 419                  // if (storedFocusState is focused )

 420                  //   scayt_control.focus();

 421                  //

 422                  // now focus is set certainly

 423                  scayt_control.focus();
 424                  scayt_control.setDisabled( isEnabled );
 425              } else if ( !editor.config.scayt_autoStartup && plugin.engineLoaded >= 0 ) // Load first time
 426              {
 427                  editor.focus();
 428                  this.setState( CKEDITOR.TRISTATE_DISABLED );
 429                  plugin.loadEngine( editor );
 430              }
 431          }
 432      };
 433  
 434      // Add scayt plugin.

 435      CKEDITOR.plugins.add( 'scayt', {
 436          requires: 'menubutton,dialog',
 437          lang: 'af,ar,bg,bn,bs,ca,cs,cy,da,de,el,en-au,en-ca,en-gb,en,eo,es,et,eu,fa,fi,fo,fr-ca,fr,gl,gu,he,hi,hr,hu,is,it,ja,ka,km,ko,lt,lv,mk,mn,ms,nb,nl,no,pl,pt-br,pt,ro,ru,sk,sl,sr-latn,sr,sv,th,tr,ug,uk,vi,zh-cn,zh', // %REMOVE_LINE_CORE%
 438          icons: 'scayt', // %REMOVE_LINE_CORE%
 439          hidpi: true, // %REMOVE_LINE_CORE%
 440  
 441          beforeInit: function( editor ) {
 442  
 443              var items_order = editor.config.scayt_contextMenuItemsOrder || 'suggest|moresuggest|control',
 444                  items_order_str = "";
 445  
 446              items_order = items_order.split( '|' );
 447  
 448              if ( items_order && items_order.length ) {
 449                  for ( var pos = 0; pos < items_order.length; pos++ )
 450                      items_order_str += 'scayt_' + items_order[ pos ] + ( items_order.length != parseInt( pos, 10 ) + 1 ? ',' : '' );
 451              }
 452  
 453              // Put it on top of all context menu items (#5717)

 454              editor.config.menu_groups = items_order_str + ',' + editor.config.menu_groups;
 455          },
 456  
 457          checkEnvironment: function(){
 458              return ( CKEDITOR.env.opera || CKEDITOR.env.air ) ? 0 : 1;
 459          },
 460  
 461          init: function( editor ) {
 462  
 463              var self = this;
 464              // Delete span[data-scaytid] when text pasting in editor (#6921)

 465              var dataFilter = editor.dataProcessor && editor.dataProcessor.dataFilter;
 466              var dataFilterRules = {
 467                  elements: {
 468                      span: function( element ) {
 469                          var attrs = element.attributes;
 470                          if ( attrs && attrs[ 'data-scaytid' ] )
 471                              delete element.name;
 472                      }
 473                  }
 474              };
 475              dataFilter && dataFilter.addRules( dataFilterRules );
 476  
 477              var moreSuggestions = {},
 478                  mainSuggestions = {};
 479  
 480              // Scayt command.

 481              var command = editor.addCommand( commandName, commandDefinition );
 482  
 483              // Add Options dialog.

 484              CKEDITOR.dialog.add( commandName, CKEDITOR.getUrl( this.path + 'dialogs/options.js' ) );
 485  
 486              var uiTabs = plugin.getUiTabs( editor );
 487  
 488              var menuGroup = 'scaytButton';
 489              editor.addMenuGroup( menuGroup );
 490              // Temporary hack - place scayt's groups at the beginning of the context menu.

 491              editor.addMenuGroup( 'scayt_suggest', -10 );
 492              editor.addMenuGroup( 'scayt_moresuggest', -9 );
 493              editor.addMenuGroup( 'scayt_control', -8 );
 494  
 495              // combine menu items to render

 496              var uiMenuItems = {};
 497  
 498              var lang = editor.lang.scayt;
 499  
 500              // always added

 501              uiMenuItems.scaytToggle = {
 502                  label: lang.enable,
 503                  command: commandName,
 504                  group: menuGroup
 505              };
 506  
 507              if ( uiTabs[ 0 ] == 1 )
 508                  uiMenuItems.scaytOptions = {
 509                  label: lang.options,
 510                  group: menuGroup,
 511                  onClick: function() {
 512                      openPage = 'options';
 513                      editor.openDialog( commandName );
 514                  }
 515              };
 516  
 517              if ( uiTabs[ 1 ] == 1 )
 518                  uiMenuItems.scaytLangs = {
 519                  label: lang.langs,
 520                  group: menuGroup,
 521                  onClick: function() {
 522                      openPage = 'langs';
 523                      editor.openDialog( commandName );
 524                  }
 525              };
 526              if ( uiTabs[ 2 ] == 1 )
 527                  uiMenuItems.scaytDict = {
 528                  label: lang.dictionariesTab,
 529                  group: menuGroup,
 530                  onClick: function() {
 531                      openPage = 'dictionaries';
 532                      editor.openDialog( commandName );
 533                  }
 534              };
 535              // always added

 536              uiMenuItems.scaytAbout = {
 537                  label: editor.lang.scayt.about,
 538                  group: menuGroup,
 539                  onClick: function() {
 540                      openPage = 'about';
 541                      editor.openDialog( commandName );
 542                  }
 543              };
 544  
 545              if ( uiTabs[4] == 1 )
 546                  uiMenuItems.scaytWSC =    {
 547                          label : editor.lang.wsc.toolbar,
 548                          group : menuGroup,
 549                          command : wscCommandName
 550                  };
 551  
 552              editor.addMenuItems( uiMenuItems );
 553  
 554              editor.ui.add( 'Scayt', CKEDITOR.UI_MENUBUTTON, {
 555                  label: lang.title,
 556                  title: CKEDITOR.env.opera ? lang.opera_title : lang.title,
 557                  modes: { wysiwyg: self.checkEnvironment() },
 558                  toolbar: 'spellchecker,20',
 559                  onRender: function() {
 560                      command.on( 'state', function() {
 561                          this.setState( command.state );
 562                      }, this );
 563                  },
 564                  onMenu: function() {
 565                      var isEnabled = plugin.isScaytEnabled( editor );
 566  
 567                      editor.getMenuItem( 'scaytToggle' ).label = lang[ isEnabled ? 'disable' : 'enable' ];
 568  
 569                      var uiTabs = plugin.getUiTabs( editor );
 570  
 571                      return {
 572                          scaytToggle: CKEDITOR.TRISTATE_OFF,
 573                          scaytOptions: isEnabled && uiTabs[ 0 ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
 574                          scaytLangs: isEnabled && uiTabs[ 1 ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
 575                          scaytDict: isEnabled && uiTabs[ 2 ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
 576                          scaytAbout: isEnabled && uiTabs[ 3 ] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED,
 577                          scaytWSC: uiTabs[4] ? CKEDITOR.TRISTATE_OFF : CKEDITOR.TRISTATE_DISABLED
 578                      };
 579                  }
 580              });
 581  
 582              // If the "contextmenu" plugin is loaded, register the listeners.

 583              if ( editor.contextMenu && editor.addMenuItems ) {
 584                  editor.contextMenu.addListener( function( element, selection ) {
 585                      if ( !plugin.isScaytEnabled( editor ) || selection.getRanges()[ 0 ].checkReadOnly() )
 586                          return null;
 587  
 588                      var scayt_control = plugin.getScayt( editor ),
 589                          node = scayt_control.getScaytNode();
 590  
 591                      if ( !node )
 592                          return null;
 593  
 594                      var word = scayt_control.getWord( node );
 595  
 596                      if ( !word )
 597                          return null;
 598  
 599                      var sLang = scayt_control.getLang(),
 600                          _r = {}, contextCommands = editor.config.scayt_contextCommands || 'all',
 601                          items_suggestion = window.scayt.getSuggestion( word, sLang );
 602  
 603                      contextCommands = contextCommands.split( '|' );
 604  
 605                      // Remove unused commands and menuitems

 606  
 607                      for ( var m in moreSuggestions ) {
 608                          delete editor._.menuItems[ m ];
 609                          delete editor.commands[ m ];
 610                      }
 611                      for ( m in mainSuggestions ) {
 612                          delete editor._.menuItems[ m ];
 613                          delete editor.commands[ m ];
 614                      }
 615  
 616                      if ( !items_suggestion || !items_suggestion.length ){
 617                              var no_sugg = {
 618                                  exec: function() {}
 619                              };
 620                              addButtonCommand( editor, 'no_sugg', lang.noSuggestions, 'scayt_no_sugg', no_sugg, 'scayt_control', 1, true );
 621                              mainSuggestions[ 'scayt_no_sugg' ] = CKEDITOR.TRISTATE_OFF;
 622                      }else{
 623                          // Reset items.

 624                          moreSuggestions = {};
 625                          mainSuggestions = {};
 626  
 627                          var moreSuggestionsUnable = editor.config.scayt_moreSuggestions || 'on';
 628                          var moreSuggestionsUnableAdded = false;
 629  
 630                          var maxSuggestions = editor.config.scayt_maxSuggestions;
 631                          ( typeof maxSuggestions != 'number' ) && ( maxSuggestions = 5 );
 632                          !maxSuggestions && ( maxSuggestions = items_suggestion.length );
 633  
 634                          for ( var i = 0, l = items_suggestion.length; i < l; i += 1 ) {
 635                              var commandName = 'scayt_suggestion_' + items_suggestion[ i ].replace( ' ', '_' );
 636                              var exec = (function( el, s ) {
 637                                  return {
 638                                      exec: function() {
 639                                          scayt_control.replace( el, s );
 640                                      }
 641                                  };
 642                              })( node, items_suggestion[ i ] );
 643  
 644                              if ( i < maxSuggestions ) {
 645                                  addButtonCommand( editor, 'button_' + commandName, items_suggestion[ i ], commandName, exec, 'scayt_suggest', i + 1 );
 646                                  _r[ commandName ] = CKEDITOR.TRISTATE_OFF;
 647                                  mainSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
 648                              } else if ( moreSuggestionsUnable == 'on' ) {
 649                                  addButtonCommand( editor, 'button_' + commandName, items_suggestion[ i ], commandName, exec, 'scayt_moresuggest', i + 1 );
 650                                  moreSuggestions[ commandName ] = CKEDITOR.TRISTATE_OFF;
 651                                  moreSuggestionsUnableAdded = true;
 652                              }
 653                          }
 654  
 655                          if ( moreSuggestionsUnableAdded ) {
 656                              // Register the More suggestions group;

 657                              editor.addMenuItem( 'scayt_moresuggest', {
 658                                  label: lang.moreSuggestions,
 659                                  group: 'scayt_moresuggest',
 660                                  order: 10,
 661                                  getItems: function() {
 662                                      return moreSuggestions;
 663                                  }
 664                              });
 665                              mainSuggestions[ 'scayt_moresuggest' ] = CKEDITOR.TRISTATE_OFF;
 666                          }
 667                      }
 668  
 669                      if ( in_array( 'all', contextCommands ) || in_array( 'ignore', contextCommands ) ) {
 670                          var ignore_command = {
 671                              exec: function() {
 672                                  scayt_control.ignore( node );
 673                              }
 674                          };
 675                          addButtonCommand( editor, 'ignore', lang.ignore, 'scayt_ignore', ignore_command, 'scayt_control', 2 );
 676                          mainSuggestions[ 'scayt_ignore' ] = CKEDITOR.TRISTATE_OFF;
 677                      }
 678  
 679                      if ( in_array( 'all', contextCommands ) || in_array( 'ignoreall', contextCommands ) ) {
 680                          var ignore_all_command = {
 681                              exec: function() {
 682                                  scayt_control.ignoreAll( node );
 683                              }
 684                          };
 685                          addButtonCommand( editor, 'ignore_all', lang.ignoreAll, 'scayt_ignore_all', ignore_all_command, 'scayt_control', 3 );
 686                          mainSuggestions[ 'scayt_ignore_all' ] = CKEDITOR.TRISTATE_OFF;
 687                      }
 688  
 689                      if ( in_array( 'all', contextCommands ) || in_array( 'add', contextCommands ) ) {
 690                          var addword_command = {
 691                              exec: function() {
 692                                  window.scayt.addWordToUserDictionary( node );
 693                              }
 694                          };
 695                          addButtonCommand( editor, 'add_word', lang.addWord, 'scayt_add_word', addword_command, 'scayt_control', 4 );
 696                          mainSuggestions[ 'scayt_add_word' ] = CKEDITOR.TRISTATE_OFF;
 697                      }
 698  
 699                      if ( scayt_control.fireOnContextMenu )
 700                          scayt_control.fireOnContextMenu( editor );
 701  
 702                      return mainSuggestions;
 703                  });
 704              }
 705  
 706              var showInitialState = function( evt ) {
 707                      evt.removeListener();
 708                      if ( CKEDITOR.env.opera || CKEDITOR.env.air )
 709                          command.setState( CKEDITOR.TRISTATE_DISABLED );
 710                      else
 711                          command.setState( plugin.isScaytEnabled( editor ) ? CKEDITOR.TRISTATE_ON : CKEDITOR.TRISTATE_OFF );
 712                  };
 713  
 714              editor.on( 'showScaytState', showInitialState );
 715              editor.on( 'instanceReady', showInitialState );
 716  
 717              // Start plugin

 718              if ( editor.config.scayt_autoStartup ) {
 719                  editor.on( 'instanceReady', function() {
 720                      plugin.loadEngine( editor );
 721                  });
 722              }
 723          },
 724  
 725          afterInit: function( editor ) {
 726  
 727              // Prevent word marker line from displaying in elements path and been removed when cleaning format. (#3570) (#4125)

 728              var elementsPathFilters,
 729                  scaytFilter = function( element ) {
 730                      if ( element.hasAttribute( 'data-scaytid' ) )
 731                          return false;
 732                  };
 733  
 734              if ( editor._.elementsPath && ( elementsPathFilters = editor._.elementsPath.filters ) )
 735                  elementsPathFilters.push( scaytFilter );
 736  
 737              editor.addRemoveFormatFilter && editor.addRemoveFormatFilter( scaytFilter );
 738  
 739          }
 740      });
 741  })();
 742  
 743  /**

 744   * If enabled (set to `true`), turns on SCAYT automatically

 745   * after loading the editor.

 746   *

 747   *        config.scayt_autoStartup = true;

 748   *

 749   * @cfg {Boolean} [scayt_autoStartup=false]

 750   * @member CKEDITOR.config

 751   */
 752  
 753  /**

 754   * Defines the number of SCAYT suggestions to show in the main context menu.

 755   * Possible values are:

 756   *

 757   * * `0` (zero) &ndash; All suggestions are displayed in the main context menu.

 758   * * Positive number &ndash; The maximum number of suggestions to show in the context

 759   *     menu. Other entries will be shown in the "More Suggestions" sub-menu.

 760   * * Negative number &ndash; No suggestions are shown in the main context menu. All

 761   *     entries will be listed in the the "Suggestions" sub-menu.

 762   *

 763   * Examples:

 764   *

 765   *        // Display only three suggestions in the main context menu.

 766   *        config.scayt_maxSuggestions = 3;

 767   *

 768   *        // Do not show the suggestions directly.

 769   *        config.scayt_maxSuggestions = -1;

 770   *

 771   * @cfg {Number} [scayt_maxSuggestions=5]

 772   * @member CKEDITOR.config

 773   */
 774  
 775  /**

 776   * Sets the customer ID for SCAYT. Required for migration from free,

 777   * ad-supported version to paid, ad-free version.

 778   *

 779   *        // Load SCAYT using my customer ID.

 780   *        config.scayt_customerid  = 'your-encrypted-customer-id';

 781   *

 782   * @cfg {String} [scayt_customerid='']

 783   * @example

 784   * @member CKEDITOR.config

 785   */
 786  
 787  /**

 788   * Enables/disables the "More Suggestions" sub-menu in the context menu.

 789   * Possible values are `'on'` and `'off'`.

 790   *

 791   *        // Disables the "More Suggestions" sub-menu.

 792   *        config.scayt_moreSuggestions = 'off';

 793   *

 794   * @cfg {String} [scayt_moreSuggestions='on']

 795   * @member CKEDITOR.config

 796   */
 797  
 798  /**

 799   * Customizes the display of SCAYT context menu commands ("Add Word", "Ignore"

 800   * and "Ignore All"). This must be a string with one or more of the following

 801   * words separated by a pipe character (`'|'`):

 802   *

 803   * * `off` &ndash; disables all options.

 804   * * `all` &ndash; enables all options.

 805   * * `ignore` &ndash; enables the "Ignore" option.

 806   * * `ignoreall` &ndash; enables the "Ignore All" option.

 807   * * `add` &ndash; enables the "Add Word" option.

 808   *

 809   * Example:

 810   *

 811   *        // Show only "Add Word" and "Ignore All" in the context menu.

 812   *        config.scayt_contextCommands = 'add|ignoreall';

 813   *

 814   * @cfg {String} [scayt_contextCommands='all']

 815   * @member CKEDITOR.config

 816   */
 817  
 818  /**

 819   * Sets the default spell checking language for SCAYT. Possible values are:

 820   * `'en_US'`, `'en_GB'`, `'pt_BR'`, `'da_DK'`,

 821   * `'nl_NL'`, `'en_CA'`, `'fi_FI'`, `'fr_FR'`,

 822   * `'fr_CA'`, `'de_DE'`, `'el_GR'`, `'it_IT'`,

 823   * `'nb_NO'`, `'pt_PT'`, `'es_ES'`, `'sv_SE'`.

 824   *

 825   *        // Sets SCAYT to German.

 826   *        config.scayt_sLang = 'de_DE';

 827   *

 828   * @cfg {String} [scayt_sLang='en_US']

 829   * @member CKEDITOR.config

 830   */
 831  
 832  /**

 833   * Sets the visibility of particular tabs in the SCAYT dialog window and toolbar

 834   * button. This setting must contain a `1` (enabled) or `0`

 835   * (disabled) value for each of the following entries, in this precise order,

 836   * separated by a comma (`','`): `'Options'`, `'Languages'`, and `'Dictionary'`.

 837   *

 838   *        // Hides the "Languages" tab.

 839   *        config.scayt_uiTabs = '1,0,1';

 840   *

 841   * @cfg {String} [scayt_uiTabs='1,1,1']

 842   * @member CKEDITOR.config

 843   */
 844  
 845  
 846  /**

 847   * Sets the URL to SCAYT core. Required to switch to the licensed version of SCAYT application.

 848   *

 849   * Further details available at [http://wiki.webspellchecker.net/doku.php?id=migration:hosredfreetolicensedck](http://wiki.webspellchecker.net/doku.php?id=migration:hosredfreetolicensedck)

 850   *

 851   *        config.scayt_srcUrl = "http://my-host/spellcheck/lf/scayt/scayt.js";

 852   *

 853   * @cfg {String} [scayt_srcUrl='']

 854   * @member CKEDITOR.config

 855   */
 856  
 857  /**

 858   * Links SCAYT to custom dictionaries. This is a string containing dictionary IDs

 859   * separared by commas (`','`). Available only for the licensed version.

 860   *

 861   * Further details at [http://wiki.webspellchecker.net/doku.php?id=installationandconfiguration:customdictionaries:licensed](http://wiki.webspellchecker.net/doku.php?id=installationandconfiguration:customdictionaries:licensed)

 862   *

 863   *        config.scayt_customDictionaryIds = '3021,3456,3478"';

 864   *

 865   * @cfg {String} [scayt_customDictionaryIds='']

 866   * @member CKEDITOR.config

 867   */
 868  
 869  /**

 870   * Makes it possible to activate a custom dictionary in SCAYT. The user

 871   * dictionary name must be used. Available only for the licensed version.

 872   *

 873   *        config.scayt_userDictionaryName = 'MyDictionary';

 874   *

 875   * @cfg {String} [scayt_userDictionaryName='']

 876   * @member CKEDITOR.config

 877   */
 878  
 879  /**

 880   * Defines the order SCAYT context menu items by groups.

 881   * This must be a string with one or more of the following

 882   * words separated by a pipe character (`'|'`):

 883   *

 884   * * `suggest` &ndash; main suggestion word list,

 885   * * `moresuggest` &ndash; more suggestions word list,

 886   * * `control` &ndash; SCAYT commands, such as "Ignore" and "Add Word".

 887   *

 888   * Example:

 889   *

 890   *        config.scayt_contextMenuItemsOrder = 'moresuggest|control|suggest';

 891   *

 892   * @cfg {String} [scayt_contextMenuItemsOrder='suggest|moresuggest|control']

 893   * @member CKEDITOR.config

 894   */


Generated: Fri Nov 28 20:08:37 2014 Cross-referenced by PHPXref 0.7.1