Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1688 Rev 1921
Line 17... Line 17...
17
	this.popUpUrl = 'fck_spellerpages/spellerpages/spellchecker.html';		// by FredCK
17
	this.popUpUrl = 'fck_spellerpages/spellerpages/spellchecker.html';		// by FredCK
18
	this.popUpName = 'spellchecker';
18
	this.popUpName = 'spellchecker';
19
//	this.popUpProps = "menu=no,width=440,height=350,top=70,left=120,resizable=yes,status=yes";	// by FredCK
19
//	this.popUpProps = "menu=no,width=440,height=350,top=70,left=120,resizable=yes,status=yes";	// by FredCK
20
	this.popUpProps = null ;																	// by FredCK
20
	this.popUpProps = null ;																	// by FredCK
21
//	this.spellCheckScript = '/speller/server-scripts/spellchecker.php';		// by FredCK
21
//	this.spellCheckScript = '/speller/server-scripts/spellchecker.php';		// by FredCK
22
	this.spellCheckScript = 'server-scripts/spellchecker.php';				// by FredCK
-
 
23
	//this.spellCheckScript = '/cgi-bin/spellchecker.pl';
22
	//this.spellCheckScript = '/cgi-bin/spellchecker.pl';
Line 24... Line 23...
24
 
23
 
25
	// values used to keep track of what happened to a word
24
	// values used to keep track of what happened to a word
26
	this.replWordFlag = "R";	// single replace
25
	this.replWordFlag = "R";	// single replace
Line 35... Line 34...
35
	this.currentWordIndex = 0;
34
	this.currentWordIndex = 0;
36
	this.spellCheckerWin = null;
35
	this.spellCheckerWin = null;
37
	this.controlWin = null;
36
	this.controlWin = null;
38
	this.wordWin = null;
37
	this.wordWin = null;
39
	this.textArea = textObject;	// deprecated
38
	this.textArea = textObject;	// deprecated
40
	this.textInputs = arguments; 
39
	this.textInputs = arguments;
Line 41... Line 40...
41
 
40
 
42
	// private methods
41
	// private methods
43
	this._spellcheck = _spellcheck;
42
	this._spellcheck = _spellcheck;
44
	this._getSuggestions = _getSuggestions;
43
	this._getSuggestions = _getSuggestions;
Line 95... Line 94...
95
function startCheck( wordWindowObj, controlWindowObj ) {
94
function startCheck( wordWindowObj, controlWindowObj ) {
Line 96... Line 95...
96
 
95
 
97
	// set properties from args
96
	// set properties from args
98
	this.wordWin = wordWindowObj;
97
	this.wordWin = wordWindowObj;
99
	this.controlWin = controlWindowObj;
98
	this.controlWin = controlWindowObj;
100
	
99
 
101
	// reset properties
100
	// reset properties
102
	this.wordWin.resetForm();
101
	this.wordWin.resetForm();
103
	this.controlWin.resetForm();
102
	this.controlWin.resetForm();
104
	this.currentTextIndex = 0;
103
	this.currentTextIndex = 0;
Line 110... Line 109...
110
		this.wordFlags[i] = [];
109
		this.wordFlags[i] = [];
111
	}
110
	}
Line 112... Line 111...
112
 
111
 
113
	// start
112
	// start
114
	this._spellcheck();
113
	this._spellcheck();
115
	
114
 
116
	return true;
115
	return true;
Line 117... Line 116...
117
}
116
}
118
 
117
 
Line 130... Line 129...
130
	// set as ignored
129
	// set as ignored
131
	if( this._setAsIgnored( ti, wi, this.ignrWordFlag )) {
130
	if( this._setAsIgnored( ti, wi, this.ignrWordFlag )) {
132
		this.currentWordIndex++;
131
		this.currentWordIndex++;
133
		this._spellcheck();
132
		this._spellcheck();
134
	}
133
	}
-
 
134
	return true;
135
}
135
}
Line 136... Line 136...
136
 
136
 
137
function ignoreAll() {
137
function ignoreAll() {
138
	var wi = this.currentWordIndex;
138
	var wi = this.currentWordIndex;
Line 146... Line 146...
146
	if( !s_word_to_repl ) {
146
	if( !s_word_to_repl ) {
147
		alert( 'Error: "Not in dictionary" text is missing' );
147
		alert( 'Error: "Not in dictionary" text is missing' );
148
		return false;
148
		return false;
149
	}
149
	}
Line 150... Line 150...
150
 
150
 
151
	// set this word as an "ignore all" word. 
151
	// set this word as an "ignore all" word.
Line 152... Line 152...
152
	this._setAsIgnored( ti, wi, this.ignrAllFlag );
152
	this._setAsIgnored( ti, wi, this.ignrAllFlag );
153
 
153
 
154
	// loop through all the words after this word
154
	// loop through all the words after this word
155
	for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
155
	for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
156
		for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
156
		for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
157
			if(( i == ti && j > wi ) || i > ti ) {
157
			if(( i == ti && j > wi ) || i > ti ) {
158
				// future word: set as "from ignore all" if
158
				// future word: set as "from ignore all" if
159
				// 1) do not already have a flag and 
159
				// 1) do not already have a flag and
160
				// 2) have the same value as current word
160
				// 2) have the same value as current word
161
				if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
161
				if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
162
				&& ( !this.wordFlags[i][j] )) {
162
				&& ( !this.wordFlags[i][j] )) {
Line 167... Line 167...
167
	}
167
	}
Line 168... Line 168...
168
 
168
 
169
	// finally, move on
169
	// finally, move on
170
	this.currentWordIndex++;
170
	this.currentWordIndex++;
-
 
171
	this._spellcheck();
171
	this._spellcheck();
172
	return true;
Line 172... Line 173...
172
}
173
}
173
 
174
 
174
function replaceWord() {
175
function replaceWord() {
Line 181... Line 182...
181
	if( !this.wordWin.getTextVal( ti, wi )) {
182
	if( !this.wordWin.getTextVal( ti, wi )) {
182
		alert( 'Error: "Not in dictionary" text is missing' );
183
		alert( 'Error: "Not in dictionary" text is missing' );
183
		return false;
184
		return false;
184
	}
185
	}
185
	if( !this.controlWin.replacementText ) {
186
	if( !this.controlWin.replacementText ) {
186
		return;
187
		return false ;
187
	}
188
	}
188
	var txt = this.controlWin.replacementText;
189
	var txt = this.controlWin.replacementText;
189
	if( txt.value ) {
190
	if( txt.value ) {
190
		var newspell = new String( txt.value );
191
		var newspell = new String( txt.value );
191
		if( this._setWordText( ti, wi, newspell, this.replWordFlag )) {
192
		if( this._setWordText( ti, wi, newspell, this.replWordFlag )) {
192
			this.currentWordIndex++;
193
			this.currentWordIndex++;
193
			this._spellcheck();
194
			this._spellcheck();
194
		}
195
		}
195
	}
196
	}
-
 
197
	return true;
196
}
198
}
Line 197... Line 199...
197
 
199
 
198
function replaceAll() {
200
function replaceAll() {
199
	var ti = this.currentTextIndex;
201
	var ti = this.currentTextIndex;
Line 206... Line 208...
206
	if( !s_word_to_repl ) {
208
	if( !s_word_to_repl ) {
207
		alert( 'Error: "Not in dictionary" text is missing' );
209
		alert( 'Error: "Not in dictionary" text is missing' );
208
		return false;
210
		return false;
209
	}
211
	}
210
	var txt = this.controlWin.replacementText;
212
	var txt = this.controlWin.replacementText;
211
	if( !txt.value ) return;
213
	if( !txt.value ) return false;
212
	var newspell = new String( txt.value );
214
	var newspell = new String( txt.value );
Line 213... Line 215...
213
 
215
 
214
	// set this word as a "replace all" word. 
216
	// set this word as a "replace all" word.
Line 215... Line 217...
215
	this._setWordText( ti, wi, newspell, this.replAllFlag );
217
	this._setWordText( ti, wi, newspell, this.replAllFlag );
216
 
218
 
217
	// loop through all the words after this word
219
	// loop through all the words after this word
218
	for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
220
	for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
219
		for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
221
		for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
220
			if(( i == ti && j > wi ) || i > ti ) {
222
			if(( i == ti && j > wi ) || i > ti ) {
221
				// future word: set word text to s_word_to_repl if
223
				// future word: set word text to s_word_to_repl if
222
				// 1) do not already have a flag and 
224
				// 1) do not already have a flag and
223
				// 2) have the same value as s_word_to_repl
225
				// 2) have the same value as s_word_to_repl
224
				if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
226
				if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
225
				&& ( !this.wordFlags[i][j] )) {
227
				&& ( !this.wordFlags[i][j] )) {
226
					this._setWordText( i, j, newspell, this.fromReplAll );
228
					this._setWordText( i, j, newspell, this.fromReplAll );
227
				}
229
				}
228
			}
230
			}
229
		}
231
		}
230
	}
232
	}
231
	
233
 
232
	// finally, move on
234
	// finally, move on
-
 
235
	this.currentWordIndex++;
233
	this.currentWordIndex++;
236
	this._spellcheck();
Line 234... Line 237...
234
	this._spellcheck();
237
	return true;
235
}
238
}
236
 
239
 
Line 284... Line 287...
284
}
287
}
Line 285... Line 288...
285
 
288
 
286
function undo() {
289
function undo() {
287
	// skip if this is the first word!
290
	// skip if this is the first word!
288
	var ti = this.currentTextIndex;
291
	var ti = this.currentTextIndex;
289
	var wi = this.currentWordIndex
292
	var wi = this.currentWordIndex;
290
	
293
 
291
	if( this.wordWin.totalPreviousWords( ti, wi ) > 0 ) {
294
	if( this.wordWin.totalPreviousWords( ti, wi ) > 0 ) {
Line 292... Line 295...
292
		this.wordWin.removeFocus( ti, wi );
295
		this.wordWin.removeFocus( ti, wi );
293
 
296
 
294
		// go back to the last word index that was acted upon 
297
		// go back to the last word index that was acted upon
295
		do {
298
		do {
296
			// if the current word index is zero then reset the seed
299
			// if the current word index is zero then reset the seed
297
			if( this.currentWordIndex == 0 && this.currentTextIndex > 0 ) {
300
			if( this.currentWordIndex == 0 && this.currentTextIndex > 0 ) {
Line 301... Line 304...
301
			} else {
304
			} else {
302
				if( this.currentWordIndex > 0 ) {
305
				if( this.currentWordIndex > 0 ) {
303
					this.currentWordIndex--;
306
					this.currentWordIndex--;
304
				}
307
				}
305
			}
308
			}
306
		} while ( 
309
		} while (
307
			this.wordWin.totalWords( this.currentTextIndex ) == 0
310
			this.wordWin.totalWords( this.currentTextIndex ) == 0
308
			|| this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromIgnrAll
311
			|| this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromIgnrAll
309
			|| this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromReplAll
312
			|| this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromReplAll
310
		); 
313
		);
Line 311... Line 314...
311
 
314
 
312
		var text_idx = this.currentTextIndex;
315
		var text_idx = this.currentTextIndex;
313
		var idx = this.currentWordIndex;
316
		var idx = this.currentWordIndex;
314
		var preReplSpell = this.wordWin.originalSpellings[text_idx][idx];
317
		var preReplSpell = this.wordWin.originalSpellings[text_idx][idx];
315
		
318
 
316
		// if we got back to the first word then set the Undo button back to disabled
319
		// if we got back to the first word then set the Undo button back to disabled
317
		if( this.wordWin.totalPreviousWords( text_idx, idx ) == 0 ) {
320
		if( this.wordWin.totalPreviousWords( text_idx, idx ) == 0 ) {
318
			this.controlWin.disableUndo();
321
			this.controlWin.disableUndo();
319
		}
322
		}
-
 
323
 
320
	
324
		var i, j, origSpell ;
321
		// examine what happened to this current word.
325
		// examine what happened to this current word.
322
		switch( this.wordFlags[text_idx][idx] ) {
326
		switch( this.wordFlags[text_idx][idx] ) {
323
			// replace all: go through this and all the future occurances of the word 
327
			// replace all: go through this and all the future occurances of the word
324
			// and revert them all to the original spelling and clear their flags
328
			// and revert them all to the original spelling and clear their flags
325
			case this.replAllFlag :
329
			case this.replAllFlag :
326
				for( var i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
330
				for( i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
327
					for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
331
					for( j = 0; j < this.wordWin.totalWords( i ); j++ ) {
328
						if(( i == text_idx && j >= idx ) || i > text_idx ) {
332
						if(( i == text_idx && j >= idx ) || i > text_idx ) {
329
							var origSpell = this.wordWin.originalSpellings[i][j];
333
							origSpell = this.wordWin.originalSpellings[i][j];
330
							if( origSpell == preReplSpell ) {
334
							if( origSpell == preReplSpell ) {
331
								this._setWordText ( i, j, origSpell, undefined );
335
								this._setWordText ( i, j, origSpell, undefined );
332
							}
336
							}
333
						}
337
						}
334
					}
338
					}
335
				}
339
				}
336
				break;
340
				break;
337
				
341
 
338
			// ignore all: go through all the future occurances of the word 
342
			// ignore all: go through all the future occurances of the word
339
			// and clear their flags
343
			// and clear their flags
340
			case this.ignrAllFlag :
344
			case this.ignrAllFlag :
341
				for( var i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
345
				for( i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
342
					for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
346
					for( j = 0; j < this.wordWin.totalWords( i ); j++ ) {
343
						if(( i == text_idx && j >= idx ) || i > text_idx ) {
347
						if(( i == text_idx && j >= idx ) || i > text_idx ) {
344
							var origSpell = this.wordWin.originalSpellings[i][j];
348
							origSpell = this.wordWin.originalSpellings[i][j];
345
							if( origSpell == preReplSpell ) {
349
							if( origSpell == preReplSpell ) {
346
								this.wordFlags[i][j] = undefined; 
350
								this.wordFlags[i][j] = undefined;
347
							}
351
							}
348
						}
352
						}
349
					}
353
					}
350
				}
354
				}
351
				break;
355
				break;
352
				
356
 
353
			// replace: revert the word to its original spelling
357
			// replace: revert the word to its original spelling
354
			case this.replWordFlag :
358
			case this.replWordFlag :
355
				this._setWordText ( text_idx, idx, preReplSpell, undefined );
359
				this._setWordText ( text_idx, idx, preReplSpell, undefined );
356
				break;
360
				break;
Line 357... Line 361...
357
		}
361
		}
358
 
362
 
359
		// For all four cases, clear the wordFlag of this word. re-start the process
363
		// For all four cases, clear the wordFlag of this word. re-start the process
360
		this.wordFlags[text_idx][idx] = undefined; 
364
		this.wordFlags[text_idx][idx] = undefined;
361
		this._spellcheck();
365
		this._spellcheck();
Line 362... Line 366...
362
	}
366
	}
363
}
367
}
364
 
368
 
365
function _spellcheck() {
369
function _spellcheck() {
366
	var ww = this.wordWin;
370
	var ww = this.wordWin;
367
	
371
 
368
	// check if this is the last word in the current text element
372
	// check if this is the last word in the current text element
369
	if( this.currentWordIndex == ww.totalWords( this.currentTextIndex) ) {
373
	if( this.currentWordIndex == ww.totalWords( this.currentTextIndex) ) {
370
		this.currentTextIndex++;
374
		this.currentTextIndex++;
371
		this.currentWordIndex = 0;
375
		this.currentWordIndex = 0;
372
		// keep going if we're not yet past the last text element
376
		// keep going if we're not yet past the last text element
373
		if( this.currentTextIndex < this.wordWin.textInputs.length ) {	
377
		if( this.currentTextIndex < this.wordWin.textInputs.length ) {
374
			this._spellcheck();
378
			this._spellcheck();
375
			return;
379
			return;
376
		} else {
380
		} else {
377
			this.terminateSpell();
381
			this.terminateSpell();
378
			return;
382
			return;
379
		}
383
		}
380
	}
384
	}
381
	
385
 
382
	// if this is after the first one make sure the Undo button is enabled
386
	// if this is after the first one make sure the Undo button is enabled
Line 402... Line 406...
402
function _getSuggestions( text_num, word_num ) {
406
function _getSuggestions( text_num, word_num ) {
403
	this.controlWin.clearSuggestions();
407
	this.controlWin.clearSuggestions();
404
	// add suggestion in list for each suggested word.
408
	// add suggestion in list for each suggested word.
405
	// get the array of suggested words out of the
409
	// get the array of suggested words out of the
406
	// three-dimensional array containing all suggestions.
410
	// three-dimensional array containing all suggestions.
407
	var a_suggests = this.wordWin.suggestions[text_num][word_num];	
411
	var a_suggests = this.wordWin.suggestions[text_num][word_num];
408
	if( a_suggests ) {
412
	if( a_suggests ) {
409
		// got an array of suggestions.
413
		// got an array of suggestions.
410
		for( var ii = 0; ii < a_suggests.length; ii++ ) {	
414
		for( var ii = 0; ii < a_suggests.length; ii++ ) {
411
			this.controlWin.addSuggestion( a_suggests[ii] );
415
			this.controlWin.addSuggestion( a_suggests[ii] );
412
		}
416
		}
413
	}
417
	}
414
	this.controlWin.selectDefaultSuggestion();
418
	this.controlWin.selectDefaultSuggestion();
415
}
419
}
Line 447... Line 451...
447
function _getFormInputs( inputPattern ) {
451
function _getFormInputs( inputPattern ) {
448
	var inputs = new Array();
452
	var inputs = new Array();
449
	for( var i = 0; i < document.forms.length; i++ ) {
453
	for( var i = 0; i < document.forms.length; i++ ) {
450
		for( var j = 0; j < document.forms[i].elements.length; j++ ) {
454
		for( var j = 0; j < document.forms[i].elements.length; j++ ) {
451
			if( document.forms[i].elements[j].type.match( inputPattern )) {
455
			if( document.forms[i].elements[j].type.match( inputPattern )) {
452
				inputs[inputs.length] = document.forms[i].elements[j]; 
456
				inputs[inputs.length] = document.forms[i].elements[j];
453
			}	
457
			}
454
		}
458
		}
455
	}
459
	}
456
	return inputs;
460
	return inputs;
457
}
461
}
458
 
-