Subversion Repositories Applications.papyrus

Rev

Rev 1688 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1688 Rev 1921
1
////////////////////////////////////////////////////
1
////////////////////////////////////////////////////
2
// spellChecker.js
2
// spellChecker.js
3
//
3
//
4
// spellChecker object
4
// spellChecker object
5
//
5
//
6
// This file is sourced on web pages that have a textarea object to evaluate
6
// This file is sourced on web pages that have a textarea object to evaluate
7
// for spelling. It includes the implementation for the spellCheckObject.
7
// for spelling. It includes the implementation for the spellCheckObject.
8
//
8
//
9
////////////////////////////////////////////////////
9
////////////////////////////////////////////////////
10
 
10
 
11
 
11
 
12
// constructor
12
// constructor
13
function spellChecker( textObject ) {
13
function spellChecker( textObject ) {
14
 
14
 
15
	// public properties - configurable
15
	// public properties - configurable
16
//	this.popUpUrl = '/speller/spellchecker.html';							// by FredCK
16
//	this.popUpUrl = '/speller/spellchecker.html';							// by FredCK
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';
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
27
	this.ignrWordFlag = "I";	// single ignore
26
	this.ignrWordFlag = "I";	// single ignore
28
	this.replAllFlag = "RA";	// replace all occurances
27
	this.replAllFlag = "RA";	// replace all occurances
29
	this.ignrAllFlag = "IA";	// ignore all occurances
28
	this.ignrAllFlag = "IA";	// ignore all occurances
30
	this.fromReplAll = "~RA";	// an occurance of a "replace all" word
29
	this.fromReplAll = "~RA";	// an occurance of a "replace all" word
31
	this.fromIgnrAll = "~IA";	// an occurance of a "ignore all" word
30
	this.fromIgnrAll = "~IA";	// an occurance of a "ignore all" word
32
	// properties set at run time
31
	// properties set at run time
33
	this.wordFlags = new Array();
32
	this.wordFlags = new Array();
34
	this.currentTextIndex = 0;
33
	this.currentTextIndex = 0;
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;
41
 
40
 
42
	// private methods
41
	// private methods
43
	this._spellcheck = _spellcheck;
42
	this._spellcheck = _spellcheck;
44
	this._getSuggestions = _getSuggestions;
43
	this._getSuggestions = _getSuggestions;
45
	this._setAsIgnored = _setAsIgnored;
44
	this._setAsIgnored = _setAsIgnored;
46
	this._getTotalReplaced = _getTotalReplaced;
45
	this._getTotalReplaced = _getTotalReplaced;
47
	this._setWordText = _setWordText;
46
	this._setWordText = _setWordText;
48
	this._getFormInputs = _getFormInputs;
47
	this._getFormInputs = _getFormInputs;
49
 
48
 
50
	// public methods
49
	// public methods
51
	this.openChecker = openChecker;
50
	this.openChecker = openChecker;
52
	this.startCheck = startCheck;
51
	this.startCheck = startCheck;
53
	this.checkTextBoxes = checkTextBoxes;
52
	this.checkTextBoxes = checkTextBoxes;
54
	this.checkTextAreas = checkTextAreas;
53
	this.checkTextAreas = checkTextAreas;
55
	this.spellCheckAll = spellCheckAll;
54
	this.spellCheckAll = spellCheckAll;
56
	this.ignoreWord = ignoreWord;
55
	this.ignoreWord = ignoreWord;
57
	this.ignoreAll = ignoreAll;
56
	this.ignoreAll = ignoreAll;
58
	this.replaceWord = replaceWord;
57
	this.replaceWord = replaceWord;
59
	this.replaceAll = replaceAll;
58
	this.replaceAll = replaceAll;
60
	this.terminateSpell = terminateSpell;
59
	this.terminateSpell = terminateSpell;
61
	this.undo = undo;
60
	this.undo = undo;
62
 
61
 
63
	// set the current window's "speller" property to the instance of this class.
62
	// set the current window's "speller" property to the instance of this class.
64
	// this object can now be referenced by child windows/frames.
63
	// this object can now be referenced by child windows/frames.
65
	window.speller = this;
64
	window.speller = this;
66
}
65
}
67
 
66
 
68
// call this method to check all text boxes (and only text boxes) in the HTML document
67
// call this method to check all text boxes (and only text boxes) in the HTML document
69
function checkTextBoxes() {
68
function checkTextBoxes() {
70
	this.textInputs = this._getFormInputs( "^text$" );
69
	this.textInputs = this._getFormInputs( "^text$" );
71
	this.openChecker();
70
	this.openChecker();
72
}
71
}
73
 
72
 
74
// call this method to check all textareas (and only textareas ) in the HTML document
73
// call this method to check all textareas (and only textareas ) in the HTML document
75
function checkTextAreas() {
74
function checkTextAreas() {
76
	this.textInputs = this._getFormInputs( "^textarea$" );
75
	this.textInputs = this._getFormInputs( "^textarea$" );
77
	this.openChecker();
76
	this.openChecker();
78
}
77
}
79
 
78
 
80
// call this method to check all text boxes and textareas in the HTML document
79
// call this method to check all text boxes and textareas in the HTML document
81
function spellCheckAll() {
80
function spellCheckAll() {
82
	this.textInputs = this._getFormInputs( "^text(area)?$" );
81
	this.textInputs = this._getFormInputs( "^text(area)?$" );
83
	this.openChecker();
82
	this.openChecker();
84
}
83
}
85
 
84
 
86
// call this method to check text boxe(s) and/or textarea(s) that were passed in to the
85
// call this method to check text boxe(s) and/or textarea(s) that were passed in to the
87
// object's constructor or to the textInputs property
86
// object's constructor or to the textInputs property
88
function openChecker() {
87
function openChecker() {
89
	this.spellCheckerWin = window.open( this.popUpUrl, this.popUpName, this.popUpProps );
88
	this.spellCheckerWin = window.open( this.popUpUrl, this.popUpName, this.popUpProps );
90
	if( !this.spellCheckerWin.opener ) {
89
	if( !this.spellCheckerWin.opener ) {
91
		this.spellCheckerWin.opener = window;
90
		this.spellCheckerWin.opener = window;
92
	}
91
	}
93
}
92
}
94
 
93
 
95
function startCheck( wordWindowObj, controlWindowObj ) {
94
function startCheck( wordWindowObj, controlWindowObj ) {
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;
105
	this.currentWordIndex = 0;
104
	this.currentWordIndex = 0;
106
	// initialize the flags to an array - one element for each text input
105
	// initialize the flags to an array - one element for each text input
107
	this.wordFlags = new Array( this.wordWin.textInputs.length );
106
	this.wordFlags = new Array( this.wordWin.textInputs.length );
108
	// each element will be an array that keeps track of each word in the text
107
	// each element will be an array that keeps track of each word in the text
109
	for( var i=0; i<this.wordFlags.length; i++ ) {
108
	for( var i=0; i<this.wordFlags.length; i++ ) {
110
		this.wordFlags[i] = [];
109
		this.wordFlags[i] = [];
111
	}
110
	}
112
 
111
 
113
	// start
112
	// start
114
	this._spellcheck();
113
	this._spellcheck();
115
	
114
 
116
	return true;
115
	return true;
117
}
116
}
118
 
117
 
119
function ignoreWord() {
118
function ignoreWord() {
120
	var wi = this.currentWordIndex;
119
	var wi = this.currentWordIndex;
121
	var ti = this.currentTextIndex;
120
	var ti = this.currentTextIndex;
122
	if( !this.wordWin ) {
121
	if( !this.wordWin ) {
123
		alert( 'Error: Word frame not available.' );
122
		alert( 'Error: Word frame not available.' );
124
		return false;
123
		return false;
125
	}
124
	}
126
	if( !this.wordWin.getTextVal( ti, wi )) {
125
	if( !this.wordWin.getTextVal( ti, wi )) {
127
		alert( 'Error: "Not in dictionary" text is missing.' );
126
		alert( 'Error: "Not in dictionary" text is missing.' );
128
		return false;
127
		return false;
129
	}
128
	}
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
}
136
 
136
 
137
function ignoreAll() {
137
function ignoreAll() {
138
	var wi = this.currentWordIndex;
138
	var wi = this.currentWordIndex;
139
	var ti = this.currentTextIndex;
139
	var ti = this.currentTextIndex;
140
	if( !this.wordWin ) {
140
	if( !this.wordWin ) {
141
		alert( 'Error: Word frame not available.' );
141
		alert( 'Error: Word frame not available.' );
142
		return false;
142
		return false;
143
	}
143
	}
144
	// get the word that is currently being evaluated.
144
	// get the word that is currently being evaluated.
145
	var s_word_to_repl = this.wordWin.getTextVal( ti, wi );
145
	var s_word_to_repl = this.wordWin.getTextVal( ti, wi );
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
	}
150
 
150
 
151
	// set this word as an "ignore all" word. 
151
	// set this word as an "ignore all" word.
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] )) {
163
					this._setAsIgnored( i, j, this.fromIgnrAll );
163
					this._setAsIgnored( i, j, this.fromIgnrAll );
164
				}
164
				}
165
			}
165
			}
166
		}
166
		}
167
	}
167
	}
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;
172
}
173
}
173
 
174
 
174
function replaceWord() {
175
function replaceWord() {
175
	var wi = this.currentWordIndex;
176
	var wi = this.currentWordIndex;
176
	var ti = this.currentTextIndex;
177
	var ti = this.currentTextIndex;
177
	if( !this.wordWin ) {
178
	if( !this.wordWin ) {
178
		alert( 'Error: Word frame not available.' );
179
		alert( 'Error: Word frame not available.' );
179
		return false;
180
		return false;
180
	}
181
	}
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
}
197
 
199
 
198
function replaceAll() {
200
function replaceAll() {
199
	var ti = this.currentTextIndex;
201
	var ti = this.currentTextIndex;
200
	var wi = this.currentWordIndex;
202
	var wi = this.currentWordIndex;
201
	if( !this.wordWin ) {
203
	if( !this.wordWin ) {
202
		alert( 'Error: Word frame not available.' );
204
		alert( 'Error: Word frame not available.' );
203
		return false;
205
		return false;
204
	}
206
	}
205
	var s_word_to_repl = this.wordWin.getTextVal( ti, wi );
207
	var s_word_to_repl = this.wordWin.getTextVal( ti, wi );
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 );
213
 
215
 
214
	// set this word as a "replace all" word. 
216
	// set this word as a "replace all" word.
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
233
	this.currentWordIndex++;
235
	this.currentWordIndex++;
234
	this._spellcheck();
236
	this._spellcheck();
-
 
237
	return true;
235
}
238
}
236
 
239
 
237
function terminateSpell() {
240
function terminateSpell() {
238
	// called when we have reached the end of the spell checking.
241
	// called when we have reached the end of the spell checking.
239
	var msg = "";		// by FredCK
242
	var msg = "";		// by FredCK
240
	var numrepl = this._getTotalReplaced();
243
	var numrepl = this._getTotalReplaced();
241
	if( numrepl == 0 ) {
244
	if( numrepl == 0 ) {
242
		// see if there were no misspellings to begin with
245
		// see if there were no misspellings to begin with
243
		if( !this.wordWin ) {
246
		if( !this.wordWin ) {
244
			msg = "";
247
			msg = "";
245
		} else {
248
		} else {
246
			if( this.wordWin.totalMisspellings() ) {
249
			if( this.wordWin.totalMisspellings() ) {
247
//				msg += "No words changed.";			// by FredCK
250
//				msg += "No words changed.";			// by FredCK
248
				msg += FCKLang.DlgSpellNoChanges ;	// by FredCK
251
				msg += FCKLang.DlgSpellNoChanges ;	// by FredCK
249
			} else {
252
			} else {
250
//				msg += "No misspellings found.";	// by FredCK
253
//				msg += "No misspellings found.";	// by FredCK
251
				msg += FCKLang.DlgSpellNoMispell ;	// by FredCK
254
				msg += FCKLang.DlgSpellNoMispell ;	// by FredCK
252
			}
255
			}
253
		}
256
		}
254
	} else if( numrepl == 1 ) {
257
	} else if( numrepl == 1 ) {
255
//		msg += "One word changed.";			// by FredCK
258
//		msg += "One word changed.";			// by FredCK
256
		msg += FCKLang.DlgSpellOneChange ;	// by FredCK
259
		msg += FCKLang.DlgSpellOneChange ;	// by FredCK
257
	} else {
260
	} else {
258
//		msg += numrepl + " words changed.";	// by FredCK
261
//		msg += numrepl + " words changed.";	// by FredCK
259
		msg += FCKLang.DlgSpellManyChanges.replace( /%1/g, numrepl ) ;
262
		msg += FCKLang.DlgSpellManyChanges.replace( /%1/g, numrepl ) ;
260
	}
263
	}
261
	if( msg ) {
264
	if( msg ) {
262
//		msg += "\n";	// by FredCK
265
//		msg += "\n";	// by FredCK
263
		alert( msg );
266
		alert( msg );
264
	}
267
	}
265
 
268
 
266
	if( numrepl > 0 ) {
269
	if( numrepl > 0 ) {
267
		// update the text field(s) on the opener window
270
		// update the text field(s) on the opener window
268
		for( var i = 0; i < this.textInputs.length; i++ ) {
271
		for( var i = 0; i < this.textInputs.length; i++ ) {
269
			// this.textArea.value = this.wordWin.text;
272
			// this.textArea.value = this.wordWin.text;
270
			if( this.wordWin ) {
273
			if( this.wordWin ) {
271
				if( this.wordWin.textInputs[i] ) {
274
				if( this.wordWin.textInputs[i] ) {
272
					this.textInputs[i].value = this.wordWin.textInputs[i];
275
					this.textInputs[i].value = this.wordWin.textInputs[i];
273
				}
276
				}
274
			}
277
			}
275
		}
278
		}
276
	}
279
	}
277
 
280
 
278
	// return back to the calling window
281
	// return back to the calling window
279
//	this.spellCheckerWin.close();					// by FredCK
282
//	this.spellCheckerWin.close();					// by FredCK
280
	if ( typeof( this.OnFinished ) == 'function' )	// by FredCK
283
	if ( typeof( this.OnFinished ) == 'function' )	// by FredCK
281
		this.OnFinished(numrepl) ;					// by FredCK
284
		this.OnFinished(numrepl) ;					// by FredCK
282
 
285
 
283
	return true;
286
	return true;
284
}
287
}
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 ) {
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 ) {
298
				this.currentTextIndex--;
301
				this.currentTextIndex--;
299
				this.currentWordIndex = this.wordWin.totalWords( this.currentTextIndex )-1;
302
				this.currentWordIndex = this.wordWin.totalWords( this.currentTextIndex )-1;
300
				if( this.currentWordIndex < 0 ) this.currentWordIndex = 0;
303
				if( this.currentWordIndex < 0 ) this.currentWordIndex = 0;
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
		);
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
		}
320
	
323
 
-
 
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;
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();
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
383
	if( this.currentWordIndex > 0 ) {
387
	if( this.currentWordIndex > 0 ) {
384
		this.controlWin.enableUndo();
388
		this.controlWin.enableUndo();
385
	}
389
	}
386
 
390
 
387
	// skip the current word if it has already been worked on
391
	// skip the current word if it has already been worked on
388
	if( this.wordFlags[this.currentTextIndex][this.currentWordIndex] ) {
392
	if( this.wordFlags[this.currentTextIndex][this.currentWordIndex] ) {
389
		// increment the global current word index and move on.
393
		// increment the global current word index and move on.
390
		this.currentWordIndex++;
394
		this.currentWordIndex++;
391
		this._spellcheck();
395
		this._spellcheck();
392
	} else {
396
	} else {
393
		var evalText = ww.getTextVal( this.currentTextIndex, this.currentWordIndex );
397
		var evalText = ww.getTextVal( this.currentTextIndex, this.currentWordIndex );
394
		if( evalText ) {
398
		if( evalText ) {
395
			this.controlWin.evaluatedText.value = evalText;
399
			this.controlWin.evaluatedText.value = evalText;
396
			ww.setFocus( this.currentTextIndex, this.currentWordIndex );
400
			ww.setFocus( this.currentTextIndex, this.currentWordIndex );
397
			this._getSuggestions( this.currentTextIndex, this.currentWordIndex );
401
			this._getSuggestions( this.currentTextIndex, this.currentWordIndex );
398
		}
402
		}
399
	}
403
	}
400
}
404
}
401
 
405
 
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
}
416
 
420
 
417
function _setAsIgnored( text_num, word_num, flag ) {
421
function _setAsIgnored( text_num, word_num, flag ) {
418
	// set the UI
422
	// set the UI
419
	this.wordWin.removeFocus( text_num, word_num );
423
	this.wordWin.removeFocus( text_num, word_num );
420
	// do the bookkeeping
424
	// do the bookkeeping
421
	this.wordFlags[text_num][word_num] = flag;
425
	this.wordFlags[text_num][word_num] = flag;
422
	return true;
426
	return true;
423
}
427
}
424
 
428
 
425
function _getTotalReplaced() {
429
function _getTotalReplaced() {
426
	var i_replaced = 0;
430
	var i_replaced = 0;
427
	for( var i = 0; i < this.wordFlags.length; i++ ) {
431
	for( var i = 0; i < this.wordFlags.length; i++ ) {
428
		for( var j = 0; j < this.wordFlags[i].length; j++ ) {
432
		for( var j = 0; j < this.wordFlags[i].length; j++ ) {
429
			if(( this.wordFlags[i][j] == this.replWordFlag )
433
			if(( this.wordFlags[i][j] == this.replWordFlag )
430
			|| ( this.wordFlags[i][j] == this.replAllFlag )
434
			|| ( this.wordFlags[i][j] == this.replAllFlag )
431
			|| ( this.wordFlags[i][j] == this.fromReplAll )) {
435
			|| ( this.wordFlags[i][j] == this.fromReplAll )) {
432
				i_replaced++;
436
				i_replaced++;
433
			}
437
			}
434
		}
438
		}
435
	}
439
	}
436
	return i_replaced;
440
	return i_replaced;
437
}
441
}
438
 
442
 
439
function _setWordText( text_num, word_num, newText, flag ) {
443
function _setWordText( text_num, word_num, newText, flag ) {
440
	// set the UI and form inputs
444
	// set the UI and form inputs
441
	this.wordWin.setText( text_num, word_num, newText );
445
	this.wordWin.setText( text_num, word_num, newText );
442
	// keep track of what happened to this word:
446
	// keep track of what happened to this word:
443
	this.wordFlags[text_num][word_num] = flag;
447
	this.wordFlags[text_num][word_num] = flag;
444
	return true;
448
	return true;
445
}
449
}
446
 
450
 
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
 
-