[ Index ]

PHP Cross Reference of Drupal 6 (gatewave)

title

Body

[close]

/sites/all/libraries/ckeditor/_source/plugins/find/dialogs/ -> find.js (source)

   1  /*

   2  Copyright (c) 2003-2010, CKSource - Frederico Knabben. All rights reserved.

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

   4  */
   5  
   6  (function()
   7  {
   8      var isReplace;
   9  
  10  	function findEvaluator( node )
  11      {
  12          return node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 && ( !isReplace || !node.isReadOnly() );
  13      }
  14  
  15      /**

  16       * Elements which break characters been considered as sequence.

  17      */
  18  	function nonCharactersBoundary( node )
  19      {
  20          return !( node.type == CKEDITOR.NODE_ELEMENT && node.isBlockBoundary(
  21              CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$empty, CKEDITOR.dtd.$nonEditable ) ) );
  22      }
  23  
  24      /**

  25       * Get the cursor object which represent both current character and it's dom

  26       * position thing.

  27       */
  28      var cursorStep = function()
  29      {
  30          return {
  31              textNode : this.textNode,
  32              offset : this.offset,
  33              character : this.textNode ?
  34                  this.textNode.getText().charAt( this.offset ) : null,
  35              hitMatchBoundary : this._.matchBoundary
  36          };
  37      };
  38  
  39      var pages = [ 'find', 'replace' ],
  40          fieldsMapping = [
  41          [ 'txtFindFind', 'txtFindReplace' ],
  42          [ 'txtFindCaseChk', 'txtReplaceCaseChk' ],
  43          [ 'txtFindWordChk', 'txtReplaceWordChk' ],
  44          [ 'txtFindCyclic', 'txtReplaceCyclic' ] ];
  45  
  46      /**

  47       * Synchronize corresponding filed values between 'replace' and 'find' pages.

  48       * @param {String} currentPageId    The page id which receive values.

  49       */
  50  	function syncFieldsBetweenTabs( currentPageId )
  51      {
  52          var sourceIndex, targetIndex,
  53              sourceField, targetField;
  54  
  55          sourceIndex = currentPageId === 'find' ? 1 : 0;
  56          targetIndex = 1 - sourceIndex;
  57          var i, l = fieldsMapping.length;
  58          for ( i = 0 ; i < l ; i++ )
  59          {
  60              sourceField = this.getContentElement( pages[ sourceIndex ],
  61                      fieldsMapping[ i ][ sourceIndex ] );
  62              targetField = this.getContentElement( pages[ targetIndex ],
  63                      fieldsMapping[ i ][ targetIndex ] );
  64  
  65              targetField.setValue( sourceField.getValue() );
  66          }
  67      }
  68  
  69      var findDialog = function( editor, startupPage )
  70      {
  71          // Style object for highlights: (#5018)

  72          // 1. Defined as full match style to avoid compromising ordinary text color styles.

  73          // 2. Must be apply onto inner-most text to avoid conflicting with ordinary text color styles visually.

  74          var highlightStyle = new CKEDITOR.style( CKEDITOR.tools.extend( { fullMatch : true, childRule : function(){ return false; } },
  75              editor.config.find_highlight ) );
  76  
  77          /**

  78           * Iterator which walk through the specified range char by char. By

  79           * default the walking will not stop at the character boundaries, until

  80           * the end of the range is encountered.

  81           * @param { CKEDITOR.dom.range } range

  82           * @param {Boolean} matchWord Whether the walking will stop at character boundary.

  83           */
  84          var characterWalker = function( range , matchWord )
  85          {
  86              var walker =
  87                  new CKEDITOR.dom.walker( range );
  88              walker.guard = matchWord ? nonCharactersBoundary : null;
  89              walker[ 'evaluator' ] = findEvaluator;
  90              walker.breakOnFalse = true;
  91  
  92              this._ = {
  93                  matchWord : matchWord,
  94                  walker : walker,
  95                  matchBoundary : false
  96              };
  97          };
  98  
  99          characterWalker.prototype = {
 100              next : function()
 101              {
 102                  return this.move();
 103              },
 104  
 105              back : function()
 106              {
 107                  return this.move( true );
 108              },
 109  
 110              move : function( rtl )
 111              {
 112                  var currentTextNode = this.textNode;
 113                  // Already at the end of document, no more character available.

 114                  if (  currentTextNode === null )
 115                      return cursorStep.call( this );
 116  
 117                  this._.matchBoundary = false;
 118  
 119                  // There are more characters in the text node, step forward.

 120                  if ( currentTextNode
 121                      && rtl
 122                      && this.offset > 0 )
 123                  {
 124                      this.offset--;
 125                      return cursorStep.call( this );
 126                  }
 127                  else if ( currentTextNode
 128                      && this.offset < currentTextNode.getLength() - 1 )
 129                  {
 130                      this.offset++;
 131                      return cursorStep.call( this );
 132                  }
 133                  else
 134                  {
 135                      currentTextNode = null;
 136                      // At the end of the text node, walking foward for the next.

 137                      while ( !currentTextNode )
 138                      {
 139                          currentTextNode =
 140                              this._.walker[ rtl ? 'previous' : 'next' ].call( this._.walker );
 141  
 142                          // Stop searching if we're need full word match OR

 143                          // already reach document end.

 144                          if ( this._.matchWord && !currentTextNode
 145                               ||this._.walker._.end )
 146                              break;
 147  
 148                          // Marking as match character boundaries.

 149                          if ( !currentTextNode
 150                             && !nonCharactersBoundary( this._.walker.current ) )
 151                              this._.matchBoundary = true;
 152  
 153                      }
 154                      // Found a fresh text node.

 155                      this.textNode = currentTextNode;
 156                      if ( currentTextNode )
 157                          this.offset = rtl ? currentTextNode.getLength() - 1 : 0;
 158                      else
 159                          this.offset = 0;
 160                  }
 161  
 162                  return cursorStep.call( this );
 163              }
 164  
 165          };
 166  
 167          /**

 168           * A range of cursors which represent a trunk of characters which try to

 169           * match, it has the same length as the pattern  string.

 170           */
 171          var characterRange = function( characterWalker, rangeLength )
 172          {
 173              this._ = {
 174                  walker : characterWalker,
 175                  cursors : [],
 176                  rangeLength : rangeLength,
 177                  highlightRange : null,
 178                  isMatched : false
 179              };
 180          };
 181  
 182          characterRange.prototype = {
 183              /**

 184               * Translate this range to {@link CKEDITOR.dom.range}

 185               */
 186              toDomRange : function()
 187              {
 188                  var range = new CKEDITOR.dom.range( editor.document );
 189                  var cursors = this._.cursors;
 190                  if ( cursors.length < 1 )
 191                  {
 192                      var textNode = this._.walker.textNode;
 193                      if ( textNode )
 194                              range.setStartAfter( textNode );
 195                      else
 196                          return null;
 197                  }
 198                  else
 199                  {
 200                      var first = cursors[0],
 201                              last = cursors[ cursors.length - 1 ];
 202  
 203                      range.setStart( first.textNode, first.offset );
 204                      range.setEnd( last.textNode, last.offset + 1 );
 205                  }
 206  
 207                  return range;
 208              },
 209              /**

 210               * Reflect the latest changes from dom range.

 211               */
 212              updateFromDomRange : function( domRange )
 213              {
 214                  var cursor,
 215                          walker = new characterWalker( domRange );
 216                  this._.cursors = [];
 217                  do
 218                  {
 219                      cursor = walker.next();
 220                      if ( cursor.character )
 221                          this._.cursors.push( cursor );
 222                  }
 223                  while ( cursor.character );
 224                  this._.rangeLength = this._.cursors.length;
 225              },
 226  
 227              setMatched : function()
 228              {
 229                  this._.isMatched = true;
 230              },
 231  
 232              clearMatched : function()
 233              {
 234                  this._.isMatched = false;
 235              },
 236  
 237              isMatched : function()
 238              {
 239                  return this._.isMatched;
 240              },
 241  
 242              /**

 243               * Hightlight the current matched chunk of text.

 244               */
 245              highlight : function()
 246              {
 247                  // Do not apply if nothing is found.

 248                  if ( this._.cursors.length < 1 )
 249                      return;
 250  
 251                  // Remove the previous highlight if there's one.

 252                  if ( this._.highlightRange )
 253                      this.removeHighlight();
 254  
 255                  // Apply the highlight.

 256                  var range = this.toDomRange(),
 257                      bookmark = range.createBookmark();
 258                  highlightStyle.applyToRange( range );
 259                  range.moveToBookmark( bookmark );
 260                  this._.highlightRange = range;
 261  
 262                  // Scroll the editor to the highlighted area.

 263                  var element = range.startContainer;
 264                  if ( element.type != CKEDITOR.NODE_ELEMENT )
 265                      element = element.getParent();
 266                  element.scrollIntoView();
 267  
 268                  // Update the character cursors.

 269                  this.updateFromDomRange( range );
 270              },
 271  
 272              /**

 273               * Remove highlighted find result.

 274               */
 275              removeHighlight : function()
 276              {
 277                  if ( !this._.highlightRange )
 278                      return;
 279  
 280                  var bookmark = this._.highlightRange.createBookmark();
 281                  highlightStyle.removeFromRange( this._.highlightRange );
 282                  this._.highlightRange.moveToBookmark( bookmark );
 283                  this.updateFromDomRange( this._.highlightRange );
 284                  this._.highlightRange = null;
 285              },
 286  
 287              isReadOnly : function()
 288              {
 289                  if ( !this._.highlightRange )
 290                      return 0;
 291  
 292                  return this._.highlightRange.startContainer.isReadOnly();
 293              },
 294  
 295              moveBack : function()
 296              {
 297                  var retval = this._.walker.back(),
 298                      cursors = this._.cursors;
 299  
 300                  if ( retval.hitMatchBoundary )
 301                      this._.cursors = cursors = [];
 302  
 303                  cursors.unshift( retval );
 304                  if ( cursors.length > this._.rangeLength )
 305                      cursors.pop();
 306  
 307                  return retval;
 308              },
 309  
 310              moveNext : function()
 311              {
 312                  var retval = this._.walker.next(),
 313                      cursors = this._.cursors;
 314  
 315                  // Clear the cursors queue if we've crossed a match boundary.

 316                  if ( retval.hitMatchBoundary )
 317                      this._.cursors = cursors = [];
 318  
 319                  cursors.push( retval );
 320                  if ( cursors.length > this._.rangeLength )
 321                      cursors.shift();
 322  
 323                  return retval;
 324              },
 325  
 326              getEndCharacter : function()
 327              {
 328                  var cursors = this._.cursors;
 329                  if ( cursors.length < 1 )
 330                      return null;
 331  
 332                  return cursors[ cursors.length - 1 ].character;
 333              },
 334  
 335              getNextCharacterRange : function( maxLength )
 336              {
 337                  var lastCursor,
 338                          nextRangeWalker,
 339                          cursors = this._.cursors;
 340  
 341                  if ( ( lastCursor = cursors[ cursors.length - 1 ] ) && lastCursor.textNode )
 342                      nextRangeWalker = new characterWalker( getRangeAfterCursor( lastCursor ) );
 343                  // In case it's an empty range (no cursors), figure out next range from walker (#4951).

 344                  else
 345                      nextRangeWalker = this._.walker;
 346  
 347                  return new characterRange( nextRangeWalker, maxLength );
 348              },
 349  
 350              getCursors : function()
 351              {
 352                  return this._.cursors;
 353              }
 354          };
 355  
 356  
 357          // The remaining document range after the character cursor.

 358  		function getRangeAfterCursor( cursor , inclusive )
 359          {
 360              var range = new CKEDITOR.dom.range();
 361              range.setStart( cursor.textNode,
 362                             ( inclusive ? cursor.offset : cursor.offset + 1 ) );
 363              range.setEndAt( editor.document.getBody(),
 364                              CKEDITOR.POSITION_BEFORE_END );
 365              return range;
 366          }
 367  
 368          // The document range before the character cursor.

 369  		function getRangeBeforeCursor( cursor )
 370          {
 371              var range = new CKEDITOR.dom.range();
 372              range.setStartAt( editor.document.getBody(),
 373                              CKEDITOR.POSITION_AFTER_START );
 374              range.setEnd( cursor.textNode, cursor.offset );
 375              return range;
 376          }
 377  
 378          var KMP_NOMATCH = 0,
 379              KMP_ADVANCED = 1,
 380              KMP_MATCHED = 2;
 381          /**

 382           * Examination the occurrence of a word which implement KMP algorithm.

 383           */
 384          var kmpMatcher = function( pattern, ignoreCase )
 385          {
 386              var overlap = [ -1 ];
 387              if ( ignoreCase )
 388                  pattern = pattern.toLowerCase();
 389              for ( var i = 0 ; i < pattern.length ; i++ )
 390              {
 391                  overlap.push( overlap[i] + 1 );
 392                  while ( overlap[ i + 1 ] > 0
 393                      && pattern.charAt( i ) != pattern
 394                          .charAt( overlap[ i + 1 ] - 1 ) )
 395                      overlap[ i + 1 ] = overlap[ overlap[ i + 1 ] - 1 ] + 1;
 396              }
 397  
 398              this._ = {
 399                  overlap : overlap,
 400                  state : 0,
 401                  ignoreCase : !!ignoreCase,
 402                  pattern : pattern
 403              };
 404          };
 405  
 406          kmpMatcher.prototype =
 407          {
 408              feedCharacter : function( c )
 409              {
 410                  if ( this._.ignoreCase )
 411                      c = c.toLowerCase();
 412  
 413                  while ( true )
 414                  {
 415                      if ( c == this._.pattern.charAt( this._.state ) )
 416                      {
 417                          this._.state++;
 418                          if ( this._.state == this._.pattern.length )
 419                          {
 420                              this._.state = 0;
 421                              return KMP_MATCHED;
 422                          }
 423                          return KMP_ADVANCED;
 424                      }
 425                      else if ( !this._.state )
 426                          return KMP_NOMATCH;
 427                      else
 428                          this._.state = this._.overlap[ this._.state ];
 429                  }
 430  
 431                  return null;
 432              },
 433  
 434              reset : function()
 435              {
 436                  this._.state = 0;
 437              }
 438          };
 439  
 440          var wordSeparatorRegex =
 441          /[.,"'?!;: \u0085\u00a0\u1680\u280e\u2028\u2029\u202f\u205f\u3000]/;
 442  
 443          var isWordSeparator = function( c )
 444          {
 445              if ( !c )
 446                  return true;
 447              var code = c.charCodeAt( 0 );
 448              return ( code >= 9 && code <= 0xd )
 449                  || ( code >= 0x2000 && code <= 0x200a )
 450                  || wordSeparatorRegex.test( c );
 451          };
 452  
 453          var finder = {
 454              searchRange : null,
 455              matchRange : null,
 456              find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched, cyclicRerun )
 457              {
 458                  if ( !this.matchRange )
 459                      this.matchRange =
 460                          new characterRange(
 461                              new characterWalker( this.searchRange ),
 462                              pattern.length );
 463                  else
 464                  {
 465                      this.matchRange.removeHighlight();
 466                      this.matchRange = this.matchRange.getNextCharacterRange( pattern.length );
 467                  }
 468  
 469                  var matcher = new kmpMatcher( pattern, !matchCase ),
 470                      matchState = KMP_NOMATCH,
 471                      character = '%';
 472  
 473                  while ( character !== null )
 474                  {
 475                      this.matchRange.moveNext();
 476                      while ( ( character = this.matchRange.getEndCharacter() ) )
 477                      {
 478                          matchState = matcher.feedCharacter( character );
 479                          if ( matchState == KMP_MATCHED )
 480                              break;
 481                          if ( this.matchRange.moveNext().hitMatchBoundary )
 482                              matcher.reset();
 483                      }
 484  
 485                      if ( matchState == KMP_MATCHED )
 486                      {
 487                          if ( matchWord )
 488                          {
 489                              var cursors = this.matchRange.getCursors(),
 490                                  tail = cursors[ cursors.length - 1 ],
 491                                  head = cursors[ 0 ];
 492  
 493                              var headWalker = new characterWalker( getRangeBeforeCursor( head ), true ),
 494                                  tailWalker = new characterWalker( getRangeAfterCursor( tail ), true );
 495  
 496                              if ( ! ( isWordSeparator( headWalker.back().character )
 497                                          && isWordSeparator( tailWalker.next().character ) ) )
 498                                  continue;
 499                          }
 500                          this.matchRange.setMatched();
 501                          if ( highlightMatched !== false )
 502                              this.matchRange.highlight();
 503                          return true;
 504                      }
 505                  }
 506  
 507                  this.matchRange.clearMatched();
 508                  this.matchRange.removeHighlight();
 509                  // Clear current session and restart with the default search

 510                  // range.

 511                  // Re-run the finding once for cyclic.(#3517)

 512                  if ( matchCyclic && !cyclicRerun )
 513                  {
 514                      this.searchRange = getSearchRange( true );
 515                      this.matchRange = null;
 516                      return arguments.callee.apply( this,
 517                          Array.prototype.slice.call( arguments ).concat( [ true ] ) );
 518                  }
 519  
 520                  return false;
 521              },
 522  
 523              /**

 524               * Record how much replacement occurred toward one replacing.

 525               */
 526              replaceCounter : 0,
 527  
 528              replace : function( dialog, pattern, newString, matchCase, matchWord,
 529                  matchCyclic , isReplaceAll )
 530              {
 531                  isReplace = 1;
 532  
 533                  // Successiveness of current replace/find.

 534                  var result = false;
 535  
 536                  // 1. Perform the replace when there's already a match here.

 537                  // 2. Otherwise perform the find but don't replace it immediately.

 538                  if ( this.matchRange && this.matchRange.isMatched()
 539                          && !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() )
 540                  {
 541                      // Turn off highlight for a while when saving snapshots.

 542                      this.matchRange.removeHighlight();
 543                      var domRange = this.matchRange.toDomRange();
 544                      var text = editor.document.createText( newString );
 545                      if ( !isReplaceAll )
 546                      {
 547                          // Save undo snaps before and after the replacement.

 548                          var selection = editor.getSelection();
 549                          selection.selectRanges( [ domRange ] );
 550                          editor.fire( 'saveSnapshot' );
 551                      }
 552                      domRange.deleteContents();
 553                      domRange.insertNode( text );
 554                      if ( !isReplaceAll )
 555                      {
 556                          selection.selectRanges( [ domRange ] );
 557                          editor.fire( 'saveSnapshot' );
 558                      }
 559                      this.matchRange.updateFromDomRange( domRange );
 560                      if ( !isReplaceAll )
 561                          this.matchRange.highlight();
 562                      this.matchRange._.isReplaced = true;
 563                      this.replaceCounter++;
 564                      result = true;
 565                  }
 566                  else
 567                      result = this.find( pattern, matchCase, matchWord, matchCyclic, !isReplaceAll );
 568  
 569                  isReplace = 0;
 570  
 571                  return result;
 572              }
 573          };
 574  
 575          /**

 576           * The range in which find/replace happened, receive from user

 577           * selection prior.

 578           */
 579  		function getSearchRange( isDefault )
 580          {
 581              var searchRange,
 582                  sel = editor.getSelection(),
 583                  body = editor.document.getBody();
 584              if ( sel && !isDefault )
 585              {
 586                  searchRange = sel.getRanges()[ 0 ].clone();
 587                  searchRange.collapse( true );
 588              }
 589              else
 590              {
 591                  searchRange = new CKEDITOR.dom.range();
 592                  searchRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START );
 593              }
 594              searchRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END );
 595              return searchRange;
 596          }
 597  
 598          return {
 599              title : editor.lang.findAndReplace.title,
 600              resizable : CKEDITOR.DIALOG_RESIZE_NONE,
 601              minWidth : 350,
 602              minHeight : 165,
 603              buttons : [ CKEDITOR.dialog.cancelButton ],        //Cancel button only.
 604              contents : [
 605                  {
 606                      id : 'find',
 607                      label : editor.lang.findAndReplace.find,
 608                      title : editor.lang.findAndReplace.find,
 609                      accessKey : '',
 610                      elements : [
 611                          {
 612                              type : 'hbox',
 613                              widths : [ '230px', '90px' ],
 614                              children :
 615                              [
 616                                  {
 617                                      type : 'text',
 618                                      id : 'txtFindFind',
 619                                      label : editor.lang.findAndReplace.findWhat,
 620                                      isChanged : false,
 621                                      labelLayout : 'horizontal',
 622                                      accessKey : 'F'
 623                                  },
 624                                  {
 625                                      type : 'button',
 626                                      align : 'left',
 627                                      style : 'width:100%',
 628                                      label : editor.lang.findAndReplace.find,
 629                                      onClick : function()
 630                                      {
 631                                          var dialog = this.getDialog();
 632                                          if ( !finder.find( dialog.getValueOf( 'find', 'txtFindFind' ),
 633                                                      dialog.getValueOf( 'find', 'txtFindCaseChk' ),
 634                                                      dialog.getValueOf( 'find', 'txtFindWordChk' ),
 635                                                      dialog.getValueOf( 'find', 'txtFindCyclic' ) ) )
 636                                              alert( editor.lang.findAndReplace
 637                                                  .notFoundMsg );
 638                                      }
 639                                  }
 640                              ]
 641                          },
 642                          {
 643                              type : 'vbox',
 644                              padding : 0,
 645                              children :
 646                              [
 647                                  {
 648                                      type : 'checkbox',
 649                                      id : 'txtFindCaseChk',
 650                                      isChanged : false,
 651                                      style : 'margin-top:28px',
 652                                      label : editor.lang.findAndReplace.matchCase
 653                                  },
 654                                  {
 655                                      type : 'checkbox',
 656                                      id : 'txtFindWordChk',
 657                                      isChanged : false,
 658                                      label : editor.lang.findAndReplace.matchWord
 659                                  },
 660                                  {
 661                                      type : 'checkbox',
 662                                      id : 'txtFindCyclic',
 663                                      isChanged : false,
 664                                      'default' : true,
 665                                      label : editor.lang.findAndReplace.matchCyclic
 666                                  }
 667                              ]
 668                          }
 669                      ]
 670                  },
 671                  {
 672                      id : 'replace',
 673                      label : editor.lang.findAndReplace.replace,
 674                      accessKey : 'M',
 675                      elements : [
 676                          {
 677                              type : 'hbox',
 678                              widths : [ '230px', '90px' ],
 679                              children :
 680                              [
 681                                  {
 682                                      type : 'text',
 683                                      id : 'txtFindReplace',
 684                                      label : editor.lang.findAndReplace.findWhat,
 685                                      isChanged : false,
 686                                      labelLayout : 'horizontal',
 687                                      accessKey : 'F'
 688                                  },
 689                                  {
 690                                      type : 'button',
 691                                      align : 'left',
 692                                      style : 'width:100%',
 693                                      label : editor.lang.findAndReplace.replace,
 694                                      onClick : function()
 695                                      {
 696                                          var dialog = this.getDialog();
 697                                          if ( !finder.replace( dialog,
 698                                                      dialog.getValueOf( 'replace', 'txtFindReplace' ),
 699                                                      dialog.getValueOf( 'replace', 'txtReplace' ),
 700                                                      dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ),
 701                                                      dialog.getValueOf( 'replace', 'txtReplaceWordChk' ),
 702                                                      dialog.getValueOf( 'replace', 'txtReplaceCyclic' ) ) )
 703                                              alert( editor.lang.findAndReplace
 704                                                  .notFoundMsg );
 705                                      }
 706                                  }
 707                              ]
 708                          },
 709                          {
 710                              type : 'hbox',
 711                              widths : [ '230px', '90px' ],
 712                              children :
 713                              [
 714                                  {
 715                                      type : 'text',
 716                                      id : 'txtReplace',
 717                                      label : editor.lang.findAndReplace.replaceWith,
 718                                      isChanged : false,
 719                                      labelLayout : 'horizontal',
 720                                      accessKey : 'R'
 721                                  },
 722                                  {
 723                                      type : 'button',
 724                                      align : 'left',
 725                                      style : 'width:100%',
 726                                      label : editor.lang.findAndReplace.replaceAll,
 727                                      isChanged : false,
 728                                      onClick : function()
 729                                      {
 730                                          var dialog = this.getDialog();
 731                                          var replaceNums;
 732  
 733                                          finder.replaceCounter = 0;
 734  
 735                                          // Scope to full document.

 736                                          finder.searchRange = getSearchRange( true );
 737                                          if ( finder.matchRange )
 738                                          {
 739                                              finder.matchRange.removeHighlight();
 740                                              finder.matchRange = null;
 741                                          }
 742                                          editor.fire( 'saveSnapshot' );
 743                                          while ( finder.replace( dialog,
 744                                              dialog.getValueOf( 'replace', 'txtFindReplace' ),
 745                                              dialog.getValueOf( 'replace', 'txtReplace' ),
 746                                              dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ),
 747                                              dialog.getValueOf( 'replace', 'txtReplaceWordChk' ),
 748                                              false, true ) )
 749                                          { /*jsl:pass*/ }
 750  
 751                                          if ( finder.replaceCounter )
 752                                          {
 753                                              alert( editor.lang.findAndReplace.replaceSuccessMsg.replace( /%1/, finder.replaceCounter ) );
 754                                              editor.fire( 'saveSnapshot' );
 755                                          }
 756                                          else
 757                                              alert( editor.lang.findAndReplace.notFoundMsg );
 758                                      }
 759                                  }
 760                              ]
 761                          },
 762                          {
 763                              type : 'vbox',
 764                              padding : 0,
 765                              children :
 766                              [
 767                                  {
 768                                      type : 'checkbox',
 769                                      id : 'txtReplaceCaseChk',
 770                                      isChanged : false,
 771                                      label : editor.lang.findAndReplace
 772                                          .matchCase
 773                                  },
 774                                  {
 775                                      type : 'checkbox',
 776                                      id : 'txtReplaceWordChk',
 777                                      isChanged : false,
 778                                      label : editor.lang.findAndReplace
 779                                          .matchWord
 780                                  },
 781                                  {
 782                                      type : 'checkbox',
 783                                      id : 'txtReplaceCyclic',
 784                                      isChanged : false,
 785                                      'default' : true,
 786                                      label : editor.lang.findAndReplace
 787                                          .matchCyclic
 788                                  }
 789                              ]
 790                          }
 791                      ]
 792                  }
 793              ],
 794              onLoad : function()
 795              {
 796                  var dialog = this;
 797  
 798                  //keep track of the current pattern field in use.

 799                  var patternField, wholeWordChkField;
 800  
 801                  //Ignore initial page select on dialog show

 802                  var isUserSelect = false;
 803                  this.on('hide', function()
 804                          {
 805                              isUserSelect = false;
 806                          } );
 807                  this.on('show', function()
 808                          {
 809                              isUserSelect = true;
 810                          } );
 811  
 812                  this.selectPage = CKEDITOR.tools.override( this.selectPage, function( originalFunc )
 813                      {
 814                          return function( pageId )
 815                          {
 816                              originalFunc.call( dialog, pageId );
 817  
 818                              var currPage = dialog._.tabs[ pageId ];
 819                              var patternFieldInput, patternFieldId, wholeWordChkFieldId;
 820                              patternFieldId = pageId === 'find' ? 'txtFindFind' : 'txtFindReplace';
 821                              wholeWordChkFieldId = pageId === 'find' ? 'txtFindWordChk' : 'txtReplaceWordChk';
 822  
 823                              patternField = dialog.getContentElement( pageId,
 824                                  patternFieldId );
 825                              wholeWordChkField = dialog.getContentElement( pageId,
 826                                  wholeWordChkFieldId );
 827  
 828                              // prepare for check pattern text filed 'keyup' event

 829                              if ( !currPage.initialized )
 830                              {
 831                                  patternFieldInput = CKEDITOR.document
 832                                      .getById( patternField._.inputId );
 833                                  currPage.initialized = true;
 834                              }
 835  
 836                              if ( isUserSelect )
 837                                  // synchronize fields on tab switch.

 838                                  syncFieldsBetweenTabs.call( this, pageId );
 839                          };
 840                      } );
 841  
 842              },
 843              onShow : function()
 844              {
 845                  // Establish initial searching start position.

 846                  finder.searchRange = getSearchRange();
 847  
 848                  this.selectPage( startupPage );
 849              },
 850              onHide : function()
 851              {
 852                  var range;
 853                  if ( finder.matchRange && finder.matchRange.isMatched() )
 854                  {
 855                      finder.matchRange.removeHighlight();
 856                      editor.focus();
 857  
 858                      range = finder.matchRange.toDomRange();
 859                      if ( range )
 860                          editor.getSelection().selectRanges( [ range ] );
 861                  }
 862  
 863                  // Clear current session before dialog close

 864                  delete finder.matchRange;
 865              },
 866              onFocus : function()
 867              {
 868                  if ( startupPage == 'replace' )
 869                      return this.getContentElement( 'replace', 'txtFindReplace' );
 870                  else
 871                      return this.getContentElement( 'find', 'txtFindFind' );
 872              }
 873          };
 874      };
 875  
 876      CKEDITOR.dialog.add( 'find', function( editor )
 877          {
 878              return findDialog( editor, 'find' );
 879          });
 880  
 881      CKEDITOR.dialog.add( 'replace', function( editor )
 882          {
 883              return findDialog( editor, 'replace' );
 884          });
 885  })();


Generated: Thu Mar 24 11:18:33 2011 Cross-referenced by PHPXref 0.7