//////////////////////////////////////////////////// // wordWindow object //////////////////////////////////////////////////// function wordWindow() { // private properties this._forms = []; // private methods this._getWordObject = _getWordObject; //this._getSpellerObject = _getSpellerObject; this._wordInputStr = _wordInputStr; this._adjustIndexes = _adjustIndexes; this._isWordChar = _isWordChar; this._lastPos = _lastPos; // public properties this.wordChar = /[a-zA-Z]/; this.windowType = "wordWindow"; this.originalSpellings = new Array(); this.suggestions = new Array(); this.checkWordBgColor = "pink"; this.normWordBgColor = "white"; this.text = ""; this.textInputs = new Array(); this.indexes = new Array(); //this.speller = this._getSpellerObject(); // public methods this.resetForm = resetForm; this.totalMisspellings = totalMisspellings; this.totalWords = totalWords; this.totalPreviousWords = totalPreviousWords; //this.getTextObjectArray = getTextObjectArray; this.getTextVal = getTextVal; this.setFocus = setFocus; this.removeFocus = removeFocus; this.setText = setText; //this.getTotalWords = getTotalWords; this.writeBody = writeBody; this.printForHtml = printForHtml; } function resetForm() { if( this._forms ) { for( var i = 0; i < this._forms.length; i++ ) { this._forms[i].reset(); } } return true; } function totalMisspellings() { var total_words = 0; for( var i = 0; i < this.textInputs.length; i++ ) { total_words += this.totalWords( i ); } return total_words; } function totalWords( textIndex ) { return this.originalSpellings[textIndex].length; } function totalPreviousWords( textIndex, wordIndex ) { var total_words = 0; for( var i = 0; i <= textIndex; i++ ) { for( var j = 0; j < this.totalWords( i ); j++ ) { if( i == textIndex && j == wordIndex ) { break; } else { total_words++; } } } return total_words; } //function getTextObjectArray() { // return this._form.elements; //} function getTextVal( textIndex, wordIndex ) { var word = this._getWordObject( textIndex, wordIndex ); if( word ) { return word.value; } } function setFocus( textIndex, wordIndex ) { var word = this._getWordObject( textIndex, wordIndex ); if( word ) { if( word.type == "text" ) { word.focus(); word.style.backgroundColor = this.checkWordBgColor; } } } function removeFocus( textIndex, wordIndex ) { var word = this._getWordObject( textIndex, wordIndex ); if( word ) { if( word.type == "text" ) { word.blur(); word.style.backgroundColor = this.normWordBgColor; } } } function setText( textIndex, wordIndex, newText ) { var word = this._getWordObject( textIndex, wordIndex ); var beginStr; var endStr; if( word ) { var pos = this.indexes[textIndex][wordIndex]; var oldText = word.value; // update the text given the index of the string beginStr = this.textInputs[textIndex].substring( 0, pos ); endStr = this.textInputs[textIndex].substring( pos + oldText.length, this.textInputs[textIndex].length ); this.textInputs[textIndex] = beginStr + newText + endStr; // adjust the indexes on the stack given the differences in // length between the new word and old word. var lengthDiff = newText.length - oldText.length; this._adjustIndexes( textIndex, wordIndex, lengthDiff ); word.size = newText.length; word.value = newText; this.removeFocus( textIndex, wordIndex ); } } /* This should be more robust for extracting words from HTML. * Many repercussions = project for another time; possibly * make it a server side project with return of everything * already done where only client side change (other than deleting * the way we're processing) would be insertion of corrections into * possible html markup within original spellings OR do it ALL * here and give the server nothing but plain text words - MWB * (Either way, give only plain text to spell checker) */ // redesigned to handle plain text search failure to find words // returned by server function writeBody() { var d = window.document; d.open(); // iterate through each text input. for( var txtid = 0; txtid < this.textInputs.length; txtid++ ) { d.writeln( '