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 10... Line 10...
10
	//this._getSpellerObject = _getSpellerObject;
10
	//this._getSpellerObject = _getSpellerObject;
11
	this._wordInputStr = _wordInputStr;
11
	this._wordInputStr = _wordInputStr;
12
	this._adjustIndexes = _adjustIndexes;
12
	this._adjustIndexes = _adjustIndexes;
13
	this._isWordChar = _isWordChar;
13
	this._isWordChar = _isWordChar;
14
	this._lastPos = _lastPos;
14
	this._lastPos = _lastPos;
15
	
15
 
16
	// public properties
16
	// public properties
17
	this.wordChar = /[a-zA-Z]/;
17
	this.wordChar = /[a-zA-Z]/;
18
	this.windowType = "wordWindow";
18
	this.windowType = "wordWindow";
19
	this.originalSpellings = new Array();
19
	this.originalSpellings = new Array();
20
	this.suggestions = new Array();
20
	this.suggestions = new Array();
Line 67... Line 67...
67
		for( var j = 0; j < this.totalWords( i ); j++ ) {
67
		for( var j = 0; j < this.totalWords( i ); j++ ) {
68
			if( i == textIndex && j == wordIndex ) {
68
			if( i == textIndex && j == wordIndex ) {
69
				break;
69
				break;
70
			} else {
70
			} else {
71
				total_words++;
71
				total_words++;
72
			}	
72
			}
73
		}
73
		}
74
	}
74
	}
75
	return total_words;
75
	return total_words;
76
}
76
}
Line 113... Line 113...
113
	if( word ) {
113
	if( word ) {
114
		var pos = this.indexes[textIndex][wordIndex];
114
		var pos = this.indexes[textIndex][wordIndex];
115
		var oldText = word.value;
115
		var oldText = word.value;
116
		// update the text given the index of the string
116
		// update the text given the index of the string
117
		beginStr = this.textInputs[textIndex].substring( 0, pos );
117
		beginStr = this.textInputs[textIndex].substring( 0, pos );
118
		endStr = this.textInputs[textIndex].substring( 
118
		endStr = this.textInputs[textIndex].substring(
119
			pos + oldText.length, 
119
			pos + oldText.length,
120
			this.textInputs[textIndex].length 
120
			this.textInputs[textIndex].length
121
		);
121
		);
122
		this.textInputs[textIndex] = beginStr + newText + endStr;
122
		this.textInputs[textIndex] = beginStr + newText + endStr;
123
		
123
 
124
		// adjust the indexes on the stack given the differences in 
124
		// adjust the indexes on the stack given the differences in
125
		// length between the new word and old word. 
125
		// length between the new word and old word.
126
		var lengthDiff = newText.length - oldText.length;
126
		var lengthDiff = newText.length - oldText.length;
127
		this._adjustIndexes( textIndex, wordIndex, lengthDiff );
127
		this._adjustIndexes( textIndex, wordIndex, lengthDiff );
128
		
128
 
129
		word.size = newText.length;
129
		word.size = newText.length;
130
		word.value = newText;
130
		word.value = newText;
131
		this.removeFocus( textIndex, wordIndex );
131
		this.removeFocus( textIndex, wordIndex );
132
	}
132
	}
133
}
133
}
Line 138... Line 138...
138
	var is_html = false;
138
	var is_html = false;
Line 139... Line 139...
139
 
139
 
Line 140... Line 140...
140
	d.open();
140
	d.open();
141
 
141
 
142
	// iterate through each text input.
142
	// iterate through each text input.
143
	for( var txtid = 0; txtid < this.textInputs.length; txtid++ ) {	
143
	for( var txtid = 0; txtid < this.textInputs.length; txtid++ ) {
144
		var end_idx = 0;
144
		var end_idx = 0;
145
		var begin_idx = 0;	
145
		var begin_idx = 0;
146
		d.writeln( '<form name="textInput'+txtid+'">' );
146
		d.writeln( '<form name="textInput'+txtid+'">' );
Line 147... Line 147...
147
		var wordtxt = this.textInputs[txtid];
147
		var wordtxt = this.textInputs[txtid];
148
		this.indexes[txtid] = [];
148
		this.indexes[txtid] = [];
149
 
149
 
Line 150... Line 150...
150
		if( wordtxt ) {			
150
		if( wordtxt ) {
151
			var orig = this.originalSpellings[txtid];
151
			var orig = this.originalSpellings[txtid];
152
			if( !orig ) break;
152
			if( !orig ) break;
153
 
153
 
154
			//!!! plain text, or HTML mode?
154
			//!!! plain text, or HTML mode?
155
			d.writeln( '<div class="plainText">' );
155
			d.writeln( '<div class="plainText">' );
156
			// iterate through each occurrence of a misspelled word. 
156
			// iterate through each occurrence of a misspelled word.
157
			for( var i = 0; i < orig.length; i++ ) {
157
			for( var i = 0; i < orig.length; i++ ) {
158
				// find the position of the current misspelled word,
158
				// find the position of the current misspelled word,
159
				// starting at the last misspelled word. 
159
				// starting at the last misspelled word.
160
				// and keep looking if it's a substring of another word
160
				// and keep looking if it's a substring of another word
161
				do {
161
				do {
162
					begin_idx = wordtxt.indexOf( orig[i], end_idx );
162
					begin_idx = wordtxt.indexOf( orig[i], end_idx );
163
					end_idx = begin_idx + orig[i].length;
163
					end_idx = begin_idx + orig[i].length;
164
					// word not found? messed up!
164
					// word not found? messed up!
165
					if( begin_idx == -1 ) break; 
165
					if( begin_idx == -1 ) break;
166
					// look at the characters immediately before and after 
166
					// look at the characters immediately before and after
167
					// the word. If they are word characters we'll keep looking.
167
					// the word. If they are word characters we'll keep looking.
168
					var before_char = wordtxt.charAt( begin_idx - 1 );
168
					var before_char = wordtxt.charAt( begin_idx - 1 );
169
					var after_char = wordtxt.charAt( end_idx );
169
					var after_char = wordtxt.charAt( end_idx );
Line 170... Line 170...
170
				} while ( 
170
				} while (
171
					this._isWordChar( before_char ) 
171
					this._isWordChar( before_char )
Line 172... Line 172...
172
					|| this._isWordChar( after_char )
172
					|| this._isWordChar( after_char )
173
				);
173
				);
174
 
174
 
175
				// keep track of its position in the original text. 
175
				// keep track of its position in the original text.
176
				this.indexes[txtid][i] = begin_idx;
176
				this.indexes[txtid][i] = begin_idx;
Line 177... Line 177...
177
 
177
 
178
				// write out the characters before the current misspelled word
178
				// write out the characters before the current misspelled word
Line 179... Line 179...
179
				for( var j = this._lastPos( txtid, i ); j < begin_idx; j++ ) {
179
				for( var j = this._lastPos( txtid, i ); j < begin_idx; j++ ) {
180
					// !!! html mode? make it html compatible
180
					// !!! html mode? make it html compatible
181
					d.write( this.printForHtml( wordtxt.charAt( j )));
181
					d.write( this.printForHtml( wordtxt.charAt( j )));
182
				}
182
				}
183
 
183
 
Line 184... Line 184...
184
				// write out the misspelled word. 
184
				// write out the misspelled word.
185
				d.write( this._wordInputStr( orig[i] ));
185
				d.write( this._wordInputStr( orig[i] ));
186
 
186
 
187
				// if it's the last word, write out the rest of the text
187
				// if it's the last word, write out the rest of the text
188
				if( i == orig.length-1 ){
188
				if( i == orig.length-1 ){
189
					d.write( printForHtml( wordtxt.substr( end_idx )));
189
					d.write( printForHtml( wordtxt.substr( end_idx )));
190
				}			
190
				}
191
			}
191
			}
192
 
192
 
193
			d.writeln( '</div>' );
193
			d.writeln( '</div>' );
194
			
194
 
195
		}
195
		}
196
		d.writeln( '</form>' );
196
		d.writeln( '</form>' );
197
	}
197
	}
198
	//for ( var j = 0; j < d.forms.length; j++ ) {
198
	//for ( var j = 0; j < d.forms.length; j++ ) {
199
	//	alert( d.forms[j].name );
199
	//	alert( d.forms[j].name );
Line 215... Line 215...
215
		return 0;
215
		return 0;
216
}
216
}
Line 217... Line 217...
217
 
217
 
218
function printForHtml( n ) {
218
function printForHtml( n ) {
219
	return n ;		// by FredCK
219
	return n ;		// by FredCK
220
	
220
/*
221
	var htmlstr = n;
221
	var htmlstr = n;
222
	if( htmlstr.length == 1 ) {
222
	if( htmlstr.length == 1 ) {
223
		// do simple case statement if it's just one character
223
		// do simple case statement if it's just one character
224
		switch ( n ) {
224
		switch ( n ) {
Line 237... Line 237...
237
		htmlstr = htmlstr.replace( /</g, '&lt' );
237
		htmlstr = htmlstr.replace( /</g, '&lt' );
238
		htmlstr = htmlstr.replace( />/g, '&gt' );
238
		htmlstr = htmlstr.replace( />/g, '&gt' );
239
		htmlstr = htmlstr.replace( /\n/g, '<br/>' );
239
		htmlstr = htmlstr.replace( /\n/g, '<br/>' );
240
		return htmlstr;
240
		return htmlstr;
241
	}
241
	}
-
 
242
*/
242
}
243
}
Line 243... Line 244...
243
 
244
 
244
function _isWordChar( letter ) {
245
function _isWordChar( letter ) {
245
	if( letter.search( this.wordChar ) == -1 ) {
246
	if( letter.search( this.wordChar ) == -1 ) {