f30374bdad1d9a9e6eb2d8e63557a40a41ba5a3b.svn-base
23.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
/*
Copyright (c) 2003-2012, CKSource - Frederico Knabben. All rights reserved.
For licensing, see LICENSE.html or http://ckeditor.com/license
*/
(function()
{
var isReplace;
function findEvaluator( node )
{
return node.type == CKEDITOR.NODE_TEXT && node.getLength() > 0 && ( !isReplace || !node.isReadOnly() );
}
/**
* Elements which break characters been considered as sequence.
*/
function nonCharactersBoundary( node )
{
return !( node.type == CKEDITOR.NODE_ELEMENT && node.isBlockBoundary(
CKEDITOR.tools.extend( {}, CKEDITOR.dtd.$empty, CKEDITOR.dtd.$nonEditable ) ) );
}
/**
* Get the cursor object which represent both current character and it's dom
* position thing.
*/
var cursorStep = function()
{
return {
textNode : this.textNode,
offset : this.offset,
character : this.textNode ?
this.textNode.getText().charAt( this.offset ) : null,
hitMatchBoundary : this._.matchBoundary
};
};
var pages = [ 'find', 'replace' ],
fieldsMapping = [
[ 'txtFindFind', 'txtFindReplace' ],
[ 'txtFindCaseChk', 'txtReplaceCaseChk' ],
[ 'txtFindWordChk', 'txtReplaceWordChk' ],
[ 'txtFindCyclic', 'txtReplaceCyclic' ] ];
/**
* Synchronize corresponding filed values between 'replace' and 'find' pages.
* @param {String} currentPageId The page id which receive values.
*/
function syncFieldsBetweenTabs( currentPageId )
{
var sourceIndex, targetIndex,
sourceField, targetField;
sourceIndex = currentPageId === 'find' ? 1 : 0;
targetIndex = 1 - sourceIndex;
var i, l = fieldsMapping.length;
for ( i = 0 ; i < l ; i++ )
{
sourceField = this.getContentElement( pages[ sourceIndex ],
fieldsMapping[ i ][ sourceIndex ] );
targetField = this.getContentElement( pages[ targetIndex ],
fieldsMapping[ i ][ targetIndex ] );
targetField.setValue( sourceField.getValue() );
}
}
var findDialog = function( editor, startupPage )
{
// Style object for highlights: (#5018)
// 1. Defined as full match style to avoid compromising ordinary text color styles.
// 2. Must be apply onto inner-most text to avoid conflicting with ordinary text color styles visually.
var highlightStyle = new CKEDITOR.style(
CKEDITOR.tools.extend( { attributes : { 'data-cke-highlight': 1 }, fullMatch : 1, ignoreReadonly : 1, childRule : function(){ return 0; } },
editor.config.find_highlight, true ) );
/**
* Iterator which walk through the specified range char by char. By
* default the walking will not stop at the character boundaries, until
* the end of the range is encountered.
* @param { CKEDITOR.dom.range } range
* @param {Boolean} matchWord Whether the walking will stop at character boundary.
*/
var characterWalker = function( range , matchWord )
{
var self = this;
var walker =
new CKEDITOR.dom.walker( range );
walker.guard = matchWord ? nonCharactersBoundary : function( node )
{
!nonCharactersBoundary( node ) && ( self._.matchBoundary = true );
};
walker[ 'evaluator' ] = findEvaluator;
walker.breakOnFalse = 1;
if ( range.startContainer.type == CKEDITOR.NODE_TEXT )
{
this.textNode = range.startContainer;
this.offset = range.startOffset - 1;
}
this._ = {
matchWord : matchWord,
walker : walker,
matchBoundary : false
};
};
characterWalker.prototype = {
next : function()
{
return this.move();
},
back : function()
{
return this.move( true );
},
move : function( rtl )
{
var currentTextNode = this.textNode;
// Already at the end of document, no more character available.
if ( currentTextNode === null )
return cursorStep.call( this );
this._.matchBoundary = false;
// There are more characters in the text node, step forward.
if ( currentTextNode
&& rtl
&& this.offset > 0 )
{
this.offset--;
return cursorStep.call( this );
}
else if ( currentTextNode
&& this.offset < currentTextNode.getLength() - 1 )
{
this.offset++;
return cursorStep.call( this );
}
else
{
currentTextNode = null;
// At the end of the text node, walking foward for the next.
while ( !currentTextNode )
{
currentTextNode =
this._.walker[ rtl ? 'previous' : 'next' ].call( this._.walker );
// Stop searching if we're need full word match OR
// already reach document end.
if ( this._.matchWord && !currentTextNode
|| this._.walker._.end )
break;
}
// Found a fresh text node.
this.textNode = currentTextNode;
if ( currentTextNode )
this.offset = rtl ? currentTextNode.getLength() - 1 : 0;
else
this.offset = 0;
}
return cursorStep.call( this );
}
};
/**
* A range of cursors which represent a trunk of characters which try to
* match, it has the same length as the pattern string.
*/
var characterRange = function( characterWalker, rangeLength )
{
this._ = {
walker : characterWalker,
cursors : [],
rangeLength : rangeLength,
highlightRange : null,
isMatched : 0
};
};
characterRange.prototype = {
/**
* Translate this range to {@link CKEDITOR.dom.range}
*/
toDomRange : function()
{
var range = new CKEDITOR.dom.range( editor.document );
var cursors = this._.cursors;
if ( cursors.length < 1 )
{
var textNode = this._.walker.textNode;
if ( textNode )
range.setStartAfter( textNode );
else
return null;
}
else
{
var first = cursors[0],
last = cursors[ cursors.length - 1 ];
range.setStart( first.textNode, first.offset );
range.setEnd( last.textNode, last.offset + 1 );
}
return range;
},
/**
* Reflect the latest changes from dom range.
*/
updateFromDomRange : function( domRange )
{
var cursor,
walker = new characterWalker( domRange );
this._.cursors = [];
do
{
cursor = walker.next();
if ( cursor.character )
this._.cursors.push( cursor );
}
while ( cursor.character );
this._.rangeLength = this._.cursors.length;
},
setMatched : function()
{
this._.isMatched = true;
},
clearMatched : function()
{
this._.isMatched = false;
},
isMatched : function()
{
return this._.isMatched;
},
/**
* Hightlight the current matched chunk of text.
*/
highlight : function()
{
// Do not apply if nothing is found.
if ( this._.cursors.length < 1 )
return;
// Remove the previous highlight if there's one.
if ( this._.highlightRange )
this.removeHighlight();
// Apply the highlight.
var range = this.toDomRange(),
bookmark = range.createBookmark();
highlightStyle.applyToRange( range );
range.moveToBookmark( bookmark );
this._.highlightRange = range;
// Scroll the editor to the highlighted area.
var element = range.startContainer;
if ( element.type != CKEDITOR.NODE_ELEMENT )
element = element.getParent();
element.scrollIntoView();
// Update the character cursors.
this.updateFromDomRange( range );
},
/**
* Remove highlighted find result.
*/
removeHighlight : function()
{
if ( !this._.highlightRange )
return;
var bookmark = this._.highlightRange.createBookmark();
highlightStyle.removeFromRange( this._.highlightRange );
this._.highlightRange.moveToBookmark( bookmark );
this.updateFromDomRange( this._.highlightRange );
this._.highlightRange = null;
},
isReadOnly : function()
{
if ( !this._.highlightRange )
return 0;
return this._.highlightRange.startContainer.isReadOnly();
},
moveBack : function()
{
var retval = this._.walker.back(),
cursors = this._.cursors;
if ( retval.hitMatchBoundary )
this._.cursors = cursors = [];
cursors.unshift( retval );
if ( cursors.length > this._.rangeLength )
cursors.pop();
return retval;
},
moveNext : function()
{
var retval = this._.walker.next(),
cursors = this._.cursors;
// Clear the cursors queue if we've crossed a match boundary.
if ( retval.hitMatchBoundary )
this._.cursors = cursors = [];
cursors.push( retval );
if ( cursors.length > this._.rangeLength )
cursors.shift();
return retval;
},
getEndCharacter : function()
{
var cursors = this._.cursors;
if ( cursors.length < 1 )
return null;
return cursors[ cursors.length - 1 ].character;
},
getNextCharacterRange : function( maxLength )
{
var lastCursor,
nextRangeWalker,
cursors = this._.cursors;
if ( ( lastCursor = cursors[ cursors.length - 1 ] ) && lastCursor.textNode )
nextRangeWalker = new characterWalker( getRangeAfterCursor( lastCursor ) );
// In case it's an empty range (no cursors), figure out next range from walker (#4951).
else
nextRangeWalker = this._.walker;
return new characterRange( nextRangeWalker, maxLength );
},
getCursors : function()
{
return this._.cursors;
}
};
// The remaining document range after the character cursor.
function getRangeAfterCursor( cursor , inclusive )
{
var range = new CKEDITOR.dom.range();
range.setStart( cursor.textNode,
( inclusive ? cursor.offset : cursor.offset + 1 ) );
range.setEndAt( editor.document.getBody(),
CKEDITOR.POSITION_BEFORE_END );
return range;
}
// The document range before the character cursor.
function getRangeBeforeCursor( cursor )
{
var range = new CKEDITOR.dom.range();
range.setStartAt( editor.document.getBody(),
CKEDITOR.POSITION_AFTER_START );
range.setEnd( cursor.textNode, cursor.offset );
return range;
}
var KMP_NOMATCH = 0,
KMP_ADVANCED = 1,
KMP_MATCHED = 2;
/**
* Examination the occurrence of a word which implement KMP algorithm.
*/
var kmpMatcher = function( pattern, ignoreCase )
{
var overlap = [ -1 ];
if ( ignoreCase )
pattern = pattern.toLowerCase();
for ( var i = 0 ; i < pattern.length ; i++ )
{
overlap.push( overlap[i] + 1 );
while ( overlap[ i + 1 ] > 0
&& pattern.charAt( i ) != pattern
.charAt( overlap[ i + 1 ] - 1 ) )
overlap[ i + 1 ] = overlap[ overlap[ i + 1 ] - 1 ] + 1;
}
this._ = {
overlap : overlap,
state : 0,
ignoreCase : !!ignoreCase,
pattern : pattern
};
};
kmpMatcher.prototype =
{
feedCharacter : function( c )
{
if ( this._.ignoreCase )
c = c.toLowerCase();
while ( true )
{
if ( c == this._.pattern.charAt( this._.state ) )
{
this._.state++;
if ( this._.state == this._.pattern.length )
{
this._.state = 0;
return KMP_MATCHED;
}
return KMP_ADVANCED;
}
else if ( !this._.state )
return KMP_NOMATCH;
else
this._.state = this._.overlap[ this._.state ];
}
return null;
},
reset : function()
{
this._.state = 0;
}
};
var wordSeparatorRegex =
/[.,"'?!;: \u0085\u00a0\u1680\u280e\u2028\u2029\u202f\u205f\u3000]/;
var isWordSeparator = function( c )
{
if ( !c )
return true;
var code = c.charCodeAt( 0 );
return ( code >= 9 && code <= 0xd )
|| ( code >= 0x2000 && code <= 0x200a )
|| wordSeparatorRegex.test( c );
};
var finder = {
searchRange : null,
matchRange : null,
find : function( pattern, matchCase, matchWord, matchCyclic, highlightMatched, cyclicRerun )
{
if ( !this.matchRange )
this.matchRange =
new characterRange(
new characterWalker( this.searchRange ),
pattern.length );
else
{
this.matchRange.removeHighlight();
this.matchRange = this.matchRange.getNextCharacterRange( pattern.length );
}
var matcher = new kmpMatcher( pattern, !matchCase ),
matchState = KMP_NOMATCH,
character = '%';
while ( character !== null )
{
this.matchRange.moveNext();
while ( ( character = this.matchRange.getEndCharacter() ) )
{
matchState = matcher.feedCharacter( character );
if ( matchState == KMP_MATCHED )
break;
if ( this.matchRange.moveNext().hitMatchBoundary )
matcher.reset();
}
if ( matchState == KMP_MATCHED )
{
if ( matchWord )
{
var cursors = this.matchRange.getCursors(),
tail = cursors[ cursors.length - 1 ],
head = cursors[ 0 ];
var rangeBefore = getRangeBeforeCursor( head ),
rangeAfter = getRangeAfterCursor( tail );
// The word boundary checks requires to trim the text nodes. (#9036)
rangeBefore.trim();
rangeAfter.trim();
var headWalker = new characterWalker( rangeBefore, true ),
tailWalker = new characterWalker( rangeAfter, true );
if ( ! ( isWordSeparator( headWalker.back().character )
&& isWordSeparator( tailWalker.next().character ) ) )
continue;
}
this.matchRange.setMatched();
if ( highlightMatched !== false )
this.matchRange.highlight();
return true;
}
}
this.matchRange.clearMatched();
this.matchRange.removeHighlight();
// Clear current session and restart with the default search
// range.
// Re-run the finding once for cyclic.(#3517)
if ( matchCyclic && !cyclicRerun )
{
this.searchRange = getSearchRange( 1 );
this.matchRange = null;
return arguments.callee.apply( this,
Array.prototype.slice.call( arguments ).concat( [ true ] ) );
}
return false;
},
/**
* Record how much replacement occurred toward one replacing.
*/
replaceCounter : 0,
replace : function( dialog, pattern, newString, matchCase, matchWord,
matchCyclic , isReplaceAll )
{
isReplace = 1;
// Successiveness of current replace/find.
var result = 0;
// 1. Perform the replace when there's already a match here.
// 2. Otherwise perform the find but don't replace it immediately.
if ( this.matchRange && this.matchRange.isMatched()
&& !this.matchRange._.isReplaced && !this.matchRange.isReadOnly() )
{
// Turn off highlight for a while when saving snapshots.
this.matchRange.removeHighlight();
var domRange = this.matchRange.toDomRange();
var text = editor.document.createText( newString );
if ( !isReplaceAll )
{
// Save undo snaps before and after the replacement.
var selection = editor.getSelection();
selection.selectRanges( [ domRange ] );
editor.fire( 'saveSnapshot' );
}
domRange.deleteContents();
domRange.insertNode( text );
if ( !isReplaceAll )
{
selection.selectRanges( [ domRange ] );
editor.fire( 'saveSnapshot' );
}
this.matchRange.updateFromDomRange( domRange );
if ( !isReplaceAll )
this.matchRange.highlight();
this.matchRange._.isReplaced = true;
this.replaceCounter++;
result = 1;
}
else
result = this.find( pattern, matchCase, matchWord, matchCyclic, !isReplaceAll );
isReplace = 0;
return result;
}
};
/**
* The range in which find/replace happened, receive from user
* selection prior.
*/
function getSearchRange( isDefault )
{
var searchRange,
sel = editor.getSelection(),
body = editor.document.getBody();
if ( sel && !isDefault )
{
searchRange = sel.getRanges()[ 0 ].clone();
searchRange.collapse( true );
}
else
{
searchRange = new CKEDITOR.dom.range();
searchRange.setStartAt( body, CKEDITOR.POSITION_AFTER_START );
}
searchRange.setEndAt( body, CKEDITOR.POSITION_BEFORE_END );
return searchRange;
}
var lang = editor.lang.findAndReplace;
return {
title : lang.title,
resizable : CKEDITOR.DIALOG_RESIZE_NONE,
minWidth : 350,
minHeight : 170,
buttons : [ CKEDITOR.dialog.cancelButton ], // Cancel button only.
contents : [
{
id : 'find',
label : lang.find,
title : lang.find,
accessKey : '',
elements : [
{
type : 'hbox',
widths : [ '230px', '90px' ],
children :
[
{
type : 'text',
id : 'txtFindFind',
label : lang.findWhat,
isChanged : false,
labelLayout : 'horizontal',
accessKey : 'F'
},
{
type : 'button',
id : 'btnFind',
align : 'left',
style : 'width:100%',
label : lang.find,
onClick : function()
{
var dialog = this.getDialog();
if ( !finder.find( dialog.getValueOf( 'find', 'txtFindFind' ),
dialog.getValueOf( 'find', 'txtFindCaseChk' ),
dialog.getValueOf( 'find', 'txtFindWordChk' ),
dialog.getValueOf( 'find', 'txtFindCyclic' ) ) )
alert( lang
.notFoundMsg );
}
}
]
},
{
type : 'fieldset',
label : CKEDITOR.tools.htmlEncode( lang.findOptions ),
style : 'margin-top:29px',
children :
[
{
type : 'vbox',
padding : 0,
children :
[
{
type : 'checkbox',
id : 'txtFindCaseChk',
isChanged : false,
label : lang.matchCase
},
{
type : 'checkbox',
id : 'txtFindWordChk',
isChanged : false,
label : lang.matchWord
},
{
type : 'checkbox',
id : 'txtFindCyclic',
isChanged : false,
'default' : true,
label : lang.matchCyclic
}
]
}
]
}
]
},
{
id : 'replace',
label : lang.replace,
accessKey : 'M',
elements : [
{
type : 'hbox',
widths : [ '230px', '90px' ],
children :
[
{
type : 'text',
id : 'txtFindReplace',
label : lang.findWhat,
isChanged : false,
labelLayout : 'horizontal',
accessKey : 'F'
},
{
type : 'button',
id : 'btnFindReplace',
align : 'left',
style : 'width:100%',
label : lang.replace,
onClick : function()
{
var dialog = this.getDialog();
if ( !finder.replace( dialog,
dialog.getValueOf( 'replace', 'txtFindReplace' ),
dialog.getValueOf( 'replace', 'txtReplace' ),
dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ),
dialog.getValueOf( 'replace', 'txtReplaceWordChk' ),
dialog.getValueOf( 'replace', 'txtReplaceCyclic' ) ) )
alert( lang
.notFoundMsg );
}
}
]
},
{
type : 'hbox',
widths : [ '230px', '90px' ],
children :
[
{
type : 'text',
id : 'txtReplace',
label : lang.replaceWith,
isChanged : false,
labelLayout : 'horizontal',
accessKey : 'R'
},
{
type : 'button',
id : 'btnReplaceAll',
align : 'left',
style : 'width:100%',
label : lang.replaceAll,
isChanged : false,
onClick : function()
{
var dialog = this.getDialog();
var replaceNums;
finder.replaceCounter = 0;
// Scope to full document.
finder.searchRange = getSearchRange( 1 );
if ( finder.matchRange )
{
finder.matchRange.removeHighlight();
finder.matchRange = null;
}
editor.fire( 'saveSnapshot' );
while ( finder.replace( dialog,
dialog.getValueOf( 'replace', 'txtFindReplace' ),
dialog.getValueOf( 'replace', 'txtReplace' ),
dialog.getValueOf( 'replace', 'txtReplaceCaseChk' ),
dialog.getValueOf( 'replace', 'txtReplaceWordChk' ),
false, true ) )
{ /*jsl:pass*/ }
if ( finder.replaceCounter )
{
alert( lang.replaceSuccessMsg.replace( /%1/, finder.replaceCounter ) );
editor.fire( 'saveSnapshot' );
}
else
alert( lang.notFoundMsg );
}
}
]
},
{
type : 'fieldset',
label : CKEDITOR.tools.htmlEncode( lang.findOptions ),
children :
[
{
type : 'vbox',
padding : 0,
children :
[
{
type : 'checkbox',
id : 'txtReplaceCaseChk',
isChanged : false,
label : lang.matchCase
},
{
type : 'checkbox',
id : 'txtReplaceWordChk',
isChanged : false,
label : lang.matchWord
},
{
type : 'checkbox',
id : 'txtReplaceCyclic',
isChanged : false,
'default' : true,
label : lang.matchCyclic
}
]
}
]
}
]
}
],
onLoad : function()
{
var dialog = this;
// Keep track of the current pattern field in use.
var patternField, wholeWordChkField;
// Ignore initial page select on dialog show
var isUserSelect = 0;
this.on( 'hide', function()
{
isUserSelect = 0;
});
this.on( 'show', function()
{
isUserSelect = 1;
});
this.selectPage = CKEDITOR.tools.override( this.selectPage, function( originalFunc )
{
return function( pageId )
{
originalFunc.call( dialog, pageId );
var currPage = dialog._.tabs[ pageId ];
var patternFieldInput, patternFieldId, wholeWordChkFieldId;
patternFieldId = pageId === 'find' ? 'txtFindFind' : 'txtFindReplace';
wholeWordChkFieldId = pageId === 'find' ? 'txtFindWordChk' : 'txtReplaceWordChk';
patternField = dialog.getContentElement( pageId,
patternFieldId );
wholeWordChkField = dialog.getContentElement( pageId,
wholeWordChkFieldId );
// Prepare for check pattern text filed 'keyup' event
if ( !currPage.initialized )
{
patternFieldInput = CKEDITOR.document
.getById( patternField._.inputId );
currPage.initialized = true;
}
// Synchronize fields on tab switch.
if ( isUserSelect )
syncFieldsBetweenTabs.call( this, pageId );
};
} );
},
onShow : function()
{
// Establish initial searching start position.
finder.searchRange = getSearchRange();
// Fill in the find field with selected text.
var selectedText = this.getParentEditor().getSelection().getSelectedText(),
patternFieldId = ( startupPage == 'find' ? 'txtFindFind' : 'txtFindReplace' );
var field = this.getContentElement( startupPage, patternFieldId );
field.setValue( selectedText );
field.select();
this.selectPage( startupPage );
this[ ( startupPage == 'find' && this._.editor.readOnly? 'hide' : 'show' ) + 'Page' ]( 'replace');
},
onHide : function()
{
var range;
if ( finder.matchRange && finder.matchRange.isMatched() )
{
finder.matchRange.removeHighlight();
editor.focus();
range = finder.matchRange.toDomRange();
if ( range )
editor.getSelection().selectRanges( [ range ] );
}
// Clear current session before dialog close
delete finder.matchRange;
},
onFocus : function()
{
if ( startupPage == 'replace' )
return this.getContentElement( 'replace', 'txtFindReplace' );
else
return this.getContentElement( 'find', 'txtFindFind' );
}
};
};
CKEDITOR.dialog.add( 'find', function( editor )
{
return findDialog( editor, 'find' );
});
CKEDITOR.dialog.add( 'replace', function( editor )
{
return findDialog( editor, 'replace' );
});
})();