[otrs-cvs] otrs/var/httpd/htdocs/js/thirdparty/ckeditor-3.6.6/plugins/aspell/spellerpages controlWindow.js, NONE, 1.1.2.1 spellchecker.html, NONE, 1.1.2.1 blank.html, NONE, 1.1.2.1 spellerStyle.css, NONE, 1.1.2.1 spellChecker.js, NONE, 1.1.2.1 wordWindow.js, NONE, 1.1.2.1 controls.html, NONE, 1.1.2.1

"CVS commits notifications of OTRS.org" <[email protected]>
Newsgroups gmane.comp.otrs.cvs
Message-ID <[email protected]>
Comments:
Update of /home/cvs/otrs/var/httpd/htdocs/js/thirdparty/ckeditor-3.6.6/plugins/aspell/spellerpages
In directory lancelot:/tmp/cvs-serv18213/var/httpd/htdocs/js/thirdparty/ckeditor-3.6.6/plugins/aspell/spellerpages

Added Files:
      Tag: rel-3_1
	controlWindow.js spellchecker.html blank.html spellerStyle.css 
	spellChecker.js wordWindow.js controls.html 
Log Message:
Updated CKEditor to version 3.6.6.

Author: mn

--- NEW FILE: controlWindow.js ---
////////////////////////////////////////////////////
// controlWindow object
////////////////////////////////////////////////////
function controlWindow( controlForm ) {
	// private properties
	this._form = controlForm;

	// public properties
	this.windowType = "controlWindow";
	this.noSuggestionSelection = "- No suggestions -";
	// set up the properties for elements of the given control form
	this.suggestionList  = this._form.sugg;
	this.evaluatedText   = this._form.misword;
	this.replacementText = this._form.txtsugg;
	this.undoButton      = this._form.btnUndo;

	// public methods
	this.addSuggestion = addSuggestion;
	this.clearSuggestions = clearSuggestions;
	this.selectDefaultSuggestion = selectDefaultSuggestion;
	this.resetForm = resetForm;
	this.setSuggestedText = setSuggestedText;
	this.enableUndo = enableUndo;
	this.disableUndo = disableUndo;
}

function resetForm() {
	if( this._form ) {
		this._form.reset();
	}
}

function setSuggestedText() {
	var slct = this.suggestionList;
	var txt = this.replacementText;
	var str = "";
	if( (slct.options[0].text) && slct.options[0].text != this.noSuggestionSelection ) {
		str = slct.options[slct.selectedIndex].text;
	}
	txt.value = str;
}

function selectDefaultSuggestion() {
	var slct = this.suggestionList;
	var txt = this.replacementText;
	if( slct.options.length == 0 ) {
		this.addSuggestion( this.noSuggestionSelection );
	} else {
		slct.options[0].selected = true;
	}
	this.setSuggestedText();
}

function addSuggestion( sugg_text ) {
	var slct = this.suggestionList;
	if( sugg_text ) {
		var i = slct.options.length;
		var newOption = new Option( sugg_text, 'sugg_text'+i );
		slct.options[i] = newOption;
	 }
}

function clearSuggestions() {
	var slct = this.suggestionList;
	for( var j = slct.length - 1; j > -1; j-- ) {
		if( slct.options[j] ) {
			slct.options[j] = null;
		}
	}
}

function enableUndo() {
	if( this.undoButton ) {
		if( this.undoButton.disabled == true ) {
			this.undoButton.disabled = false;
		}
	}
}

function disableUndo() {
	if( this.undoButton ) {
		if( this.undoButton.disabled == false ) {
			this.undoButton.disabled = true;
		}
	}
}

Author: mn

--- NEW FILE: spellchecker.html ---

<script>

var wordWindow = null;
var controlWindow = null;

function init_spell( spellerWindow ) {

	if( spellerWindow ) {
		if( spellerWindow.windowType == "wordWindow" ) {
			wordWindow = spellerWindow;
		} else if ( spellerWindow.windowType == "controlWindow" ) {
			controlWindow = spellerWindow;
		}
	}

	if( controlWindow && wordWindow ) {
		// populate the speller object and start it off!
		var speller = opener.speller;
		wordWindow.speller = speller;
		speller.startCheck( wordWindow, controlWindow );
	}
}

// encodeForPost
function encodeForPost( str ) {
	var s = new String( str );
	s = encodeURIComponent( s );
	// additionally encode single quotes to evade any PHP
	// magic_quotes_gpc setting (it inserts escape characters and
	// therefore skews the btye positions of misspelled words)
	return s.replace( /\'/g, '%27' );
}

// post the text area data to the script that populates the speller
function postWords() {
	var bodyDoc = window.frames[0].document;
	opener = opener || window.parent;
	bodyDoc.open();
	bodyDoc.write('<html>');
	bodyDoc.write('<meta http-equiv="Content-Type" content="text/html; charset=utf-8">');
	bodyDoc.write('<link rel="stylesheet" type="text/css" href="spellerStyle.css"/>');
	
	if (opener) {
		var speller = opener.speller;
		bodyDoc.write('<body class="normalText" onLoad="document.forms[0].submit();">');
		bodyDoc.write('<p>' + window.parent.FCKLang.DlgSpellProgress + '<\/p>');		// by FredCK
		bodyDoc.write('<form action="'+speller.spellCheckScript+'" method="post">');
// ---
// OTRS
		bodyDoc.write('<input type="hidden" name="Action" value="SpellingInline">');
		bodyDoc.write('<input type="hidden" name="Subaction" value="Inline">');
// ---
		for( var i = 0; i < speller.textInputs.length; i++ ) {
			bodyDoc.write('<input type="hidden" name="textinputs[]" value="'+encodeForPost(speller.textInputs[i].value)+'">');
		}
		bodyDoc.write('<\/form>');
		bodyDoc.write('<\/body>');
	} else {
		bodyDoc.write('<body class="normalText">');
		bodyDoc.write('<p><b>This page cannot be displayed<\/b><\/p><p>The window was not opened from another window.<\/p>');
		bodyDoc.write('<\/body>');
	}
	bodyDoc.write('<\/html>');
	bodyDoc.close();
}
</script>

<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
<title>Speller Pages</title>
</head>
<frameset rows="*,201" onLoad="postWords();">
<frame src="blank.html">
<frame src="controls.html">
</frameset>
</html>

Author: mn

--- NEW FILE: blank.html ---

Author: mn

--- NEW FILE: spellerStyle.css ---
.blend {
	font-family: courier new;
	font-size: 10pt;
	border: 0;
	margin-bottom:-1;
}
.normalLabel {
	font-size:8pt;
}
.normalText {
	font-family:arial, helvetica, sans-serif;
	font-size:10pt;
	color:000000;
	background-color:FFFFFF;
}
.plainText {
	font-family: courier new, courier, monospace;
	font-size: 10pt;
	color:000000;
	background-color:FFFFFF;
}
.controlWindowBody {
	font-family:arial, helvetica, sans-serif;
	font-size:8pt;
	padding-top: 7px;		/* by FredCK */
	margin: 0px;		/* by FredCK */
	color:000000;
	background-color:DADADA;
}
.readonlyInput {
	background-color:DADADA;
	color:000000;
	font-size:8pt;
	width:392px;
}
.textDefault {
	font-size:8pt;
	width: 200px;
}
.buttonDefault {
	width:90px;
	height:22px;
	font-size:8pt;
}
.suggSlct {
	width:200px;
	margin-top:2;
	font-size:8pt;
}

Author: mn

--- NEW FILE: spellChecker.js ---
////////////////////////////////////////////////////
// spellChecker.js
//
// spellChecker object
//
// This file is sourced on web pages that have a textarea object to evaluate
// for spelling. It includes the implementation for the spellCheckObject.
//
////////////////////////////////////////////////////


// constructor
function spellChecker( textObject ) {

	// public properties - configurable
//	this.popUpUrl = '/speller/spellchecker.html';							// by FredCK
//	this.popUpUrl = 'fck_spellerpages/spellerpages/spellchecker.html';		// by FredCK
	this.popUpName = 'spellchecker';
//	this.popUpProps = "menu=no,width=440,height=350,top=70,left=120,resizable=yes,status=yes";	// by FredCK
	this.popUpProps = null ;																	// by FredCK
//	this.spellCheckScript = '/speller/server-scripts/spellchecker.php';		// by FredCK
//  this.spellCheckScript = '/cgi-bin/spellchecker.pl';

	// values used to keep track of what happened to a word
	this.replWordFlag = "R";	// single replace
	this.ignrWordFlag = "I";	// single ignore
	this.replAllFlag = "RA";	// replace all occurances
	this.ignrAllFlag = "IA";	// ignore all occurances
	this.fromReplAll = "~RA";	// an occurance of a "replace all" word
	this.fromIgnrAll = "~IA";	// an occurance of a "ignore all" word
	// properties set at run time
	this.wordFlags = new Array();
	this.currentTextIndex = 0;
	this.currentWordIndex = 0;
	this.spellCheckerWin = null;
	this.controlWin = null;
	this.wordWin = null;
	this.textArea = textObject;	// deprecated
	this.textInputs = arguments;

	// private methods
	this._spellcheck = _spellcheck;
	this._getSuggestions = _getSuggestions;
	this._setAsIgnored = _setAsIgnored;
	this._getTotalReplaced = _getTotalReplaced;
	this._setWordText = _setWordText;
	this._getFormInputs = _getFormInputs;

	// public methods
	this.openChecker = openChecker;
	this.startCheck = startCheck;
	this.checkTextBoxes = checkTextBoxes;
	this.checkTextAreas = checkTextAreas;
	this.spellCheckAll = spellCheckAll;
	this.ignoreWord = ignoreWord;
	this.ignoreAll = ignoreAll;
	this.replaceWord = replaceWord;
	this.replaceAll = replaceAll;
	this.terminateSpell = terminateSpell;
	this.undo = undo;

	// set the current window's "speller" property to the instance of this class.
	// this object can now be referenced by child windows/frames.
	window.speller = this;
}

// call this method to check all text boxes (and only text boxes) in the HTML document
function checkTextBoxes() {
	this.textInputs = this._getFormInputs( "^text$" );
	this.openChecker();
}

// call this method to check all textareas (and only textareas ) in the HTML document
function checkTextAreas() {
	this.textInputs = this._getFormInputs( "^textarea$" );
	this.openChecker();
}

// call this method to check all text boxes and textareas in the HTML document
function spellCheckAll() {
	this.textInputs = this._getFormInputs( "^text(area)?$" );
	this.openChecker();
}

// call this method to check text boxe(s) and/or textarea(s) that were passed in to the
// object's constructor or to the textInputs property
function openChecker() {
	this.spellCheckerWin = window.open( this.popUpUrl, this.popUpName, this.popUpProps );
	if( !this.spellCheckerWin.opener ) {
		this.spellCheckerWin.opener = window;
	}
}

function startCheck( wordWindowObj, controlWindowObj ) {

	// set properties from args
	this.wordWin = wordWindowObj;
	this.controlWin = controlWindowObj;

	// reset properties
	this.wordWin.resetForm();
	this.controlWin.resetForm();
	this.currentTextIndex = 0;
	this.currentWordIndex = 0;
	// initialize the flags to an array - one element for each text input
	this.wordFlags = new Array( this.wordWin.textInputs.length );
	// each element will be an array that keeps track of each word in the text
	for( var i=0; i<this.wordFlags.length; i++ ) {
		this.wordFlags[i] = [];
	}

	// start
	this._spellcheck();

	return true;
}

function ignoreWord() {
	var wi = this.currentWordIndex;
	var ti = this.currentTextIndex;
	if( !this.wordWin ) {
		alert( 'Error: Word frame not available.' );
		return false;
	}
	if( !this.wordWin.getTextVal( ti, wi )) {
		alert( 'Error: "Not in dictionary" text is missing.' );
		return false;
	}
	// set as ignored
	if( this._setAsIgnored( ti, wi, this.ignrWordFlag )) {
		this.currentWordIndex++;
		this._spellcheck();
	}
	return true;
}

function ignoreAll() {
	var wi = this.currentWordIndex;
	var ti = this.currentTextIndex;
	if( !this.wordWin ) {
		alert( 'Error: Word frame not available.' );
		return false;
	}
	// get the word that is currently being evaluated.
	var s_word_to_repl = this.wordWin.getTextVal( ti, wi );
	if( !s_word_to_repl ) {
		alert( 'Error: "Not in dictionary" text is missing' );
		return false;
	}

	// set this word as an "ignore all" word.
	this._setAsIgnored( ti, wi, this.ignrAllFlag );

	// loop through all the words after this word
	for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
		for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
			if(( i == ti && j > wi ) || i > ti ) {
				// future word: set as "from ignore all" if
				// 1) do not already have a flag and
				// 2) have the same value as current word
				if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
				&& ( !this.wordFlags[i][j] )) {
					this._setAsIgnored( i, j, this.fromIgnrAll );
				}
			}
		}
	}

	// finally, move on
	this.currentWordIndex++;
	this._spellcheck();
	return true;
}

function replaceWord() {
	var wi = this.currentWordIndex;
	var ti = this.currentTextIndex;
	if( !this.wordWin ) {
		alert( 'Error: Word frame not available.' );
		return false;
	}
	if( !this.wordWin.getTextVal( ti, wi )) {
		alert( 'Error: "Not in dictionary" text is missing' );
		return false;
	}
	if( !this.controlWin.replacementText ) {
		return false ;
	}
	var txt = this.controlWin.replacementText;
	if( txt.value ) {
		var newspell = new String( txt.value );
		if( this._setWordText( ti, wi, newspell, this.replWordFlag )) {
			this.currentWordIndex++;
			this._spellcheck();
		}
	}
	return true;
}

function replaceAll() {
	var ti = this.currentTextIndex;
	var wi = this.currentWordIndex;
	if( !this.wordWin ) {
		alert( 'Error: Word frame not available.' );
		return false;
	}
	var s_word_to_repl = this.wordWin.getTextVal( ti, wi );
	if( !s_word_to_repl ) {
		alert( 'Error: "Not in dictionary" text is missing' );
		return false;
	}
	var txt = this.controlWin.replacementText;
	if( !txt.value ) return false;
	var newspell = new String( txt.value );

	// set this word as a "replace all" word.
	this._setWordText( ti, wi, newspell, this.replAllFlag );

	// loop through all the words after this word
	for( var i = ti; i < this.wordWin.textInputs.length; i++ ) {
		for( var j = 0; j < this.wordWin.totalWords( i ); j++ ) {
			if(( i == ti && j > wi ) || i > ti ) {
				// future word: set word text to s_word_to_repl if
				// 1) do not already have a flag and
				// 2) have the same value as s_word_to_repl
				if(( this.wordWin.getTextVal( i, j ) == s_word_to_repl )
				&& ( !this.wordFlags[i][j] )) {
					this._setWordText( i, j, newspell, this.fromReplAll );
				}
			}
		}
	}

	// finally, move on
	this.currentWordIndex++;
	this._spellcheck();
	return true;
}

function terminateSpell() {
	// called when we have reached the end of the spell checking.
	var msg = "";		// by FredCK
	var numrepl = this._getTotalReplaced();
	if( numrepl == 0 ) {
		// see if there were no misspellings to begin with
		if( !this.wordWin ) {
			msg = "";
		} else {
			if( this.wordWin.totalMisspellings() ) {
//				msg += "No words changed.";			// by FredCK
				msg += FCKLang.DlgSpellNoChanges ;	// by FredCK
			} else {
//				msg += "No misspellings found.";	// by FredCK
				msg += FCKLang.DlgSpellNoMispell ;	// by FredCK
			}
		}
	} else if( numrepl == 1 ) {
//		msg += "One word changed.";			// by FredCK
		msg += FCKLang.DlgSpellOneChange ;	// by FredCK
	} else {
//		msg += numrepl + " words changed.";	// by FredCK
		msg += FCKLang.DlgSpellManyChanges.replace( /%1/g, numrepl ) ;
	}
	if( msg ) {
//		msg += "\n";	// by FredCK
		alert( msg );
	}

	if( numrepl > 0 ) {
		// update the text field(s) on the opener window
		for( var i = 0; i < this.textInputs.length; i++ ) {
			// this.textArea.value = this.wordWin.text;
			if( this.wordWin ) {
				if( this.wordWin.textInputs[i] ) {
					this.textInputs[i].value = this.wordWin.textInputs[i];
				}
			}
		}
	}

	// return back to the calling window
//	this.spellCheckerWin.close();					// by FredCK
	if ( typeof( this.OnFinished ) == 'function' )	// by FredCK
		this.OnFinished(numrepl) ;					// by FredCK

	return true;
}

function undo() {
	// skip if this is the first word!
	var ti = this.currentTextIndex;
	var wi = this.currentWordIndex;

	if( this.wordWin.totalPreviousWords( ti, wi ) > 0 ) {
		this.wordWin.removeFocus( ti, wi );

		// go back to the last word index that was acted upon
		do {
			// if the current word index is zero then reset the seed
			if( this.currentWordIndex == 0 && this.currentTextIndex > 0 ) {
				this.currentTextIndex--;
				this.currentWordIndex = this.wordWin.totalWords( this.currentTextIndex )-1;
				if( this.currentWordIndex < 0 ) this.currentWordIndex = 0;
			} else {
				if( this.currentWordIndex > 0 ) {
					this.currentWordIndex--;
				}
			}
		} while (
			this.wordWin.totalWords( this.currentTextIndex ) == 0
			|| this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromIgnrAll
			|| this.wordFlags[this.currentTextIndex][this.currentWordIndex] == this.fromReplAll
		);

		var text_idx = this.currentTextIndex;
		var idx = this.currentWordIndex;
		var preReplSpell = this.wordWin.originalSpellings[text_idx][idx];

		// if we got back to the first word then set the Undo button back to disabled
		if( this.wordWin.totalPreviousWords( text_idx, idx ) == 0 ) {
			this.controlWin.disableUndo();
		}

		var i, j, origSpell ;
		// examine what happened to this current word.
		switch( this.wordFlags[text_idx][idx] ) {
			// replace all: go through this and all the future occurances of the word
			// and revert them all to the original spelling and clear their flags
			case this.replAllFlag :
				for( i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
					for( j = 0; j < this.wordWin.totalWords( i ); j++ ) {
						if(( i == text_idx && j >= idx ) || i > text_idx ) {
							origSpell = this.wordWin.originalSpellings[i][j];
							if( origSpell == preReplSpell ) {
								this._setWordText ( i, j, origSpell, undefined );
							}
						}
					}
				}
				break;

			// ignore all: go through all the future occurances of the word
			// and clear their flags
			case this.ignrAllFlag :
				for( i = text_idx; i < this.wordWin.textInputs.length; i++ ) {
					for( j = 0; j < this.wordWin.totalWords( i ); j++ ) {
						if(( i == text_idx && j >= idx ) || i > text_idx ) {
							origSpell = this.wordWin.originalSpellings[i][j];
							if( origSpell == preReplSpell ) {
								this.wordFlags[i][j] = undefined;
							}
						}
					}
				}
				break;

			// replace: revert the word to its original spelling
			case this.replWordFlag :
				this._setWordText ( text_idx, idx, preReplSpell, undefined );
				break;
		}

		// For all four cases, clear the wordFlag of this word. re-start the process
		this.wordFlags[text_idx][idx] = undefined;
		this._spellcheck();
	}
}

function _spellcheck() {
	var ww = this.wordWin;

	// check if this is the last word in the current text element
	if( this.currentWordIndex == ww.totalWords( this.currentTextIndex) ) {
		this.currentTextIndex++;
		this.currentWordIndex = 0;
		// keep going if we're not yet past the last text element
		if( this.currentTextIndex < this.wordWin.textInputs.length ) {
			this._spellcheck();
			return;
		} else {
			this.terminateSpell();
			return;
		}
	}

	// if this is after the first one make sure the Undo button is enabled
	if( this.currentWordIndex > 0 ) {
		this.controlWin.enableUndo();
	}

	// skip the current word if it has already been worked on
	if( this.wordFlags[this.currentTextIndex][this.currentWordIndex] ) {
		// increment the global current word index and move on.
		this.currentWordIndex++;
		this._spellcheck();
	} else {
		var evalText = ww.getTextVal( this.currentTextIndex, this.currentWordIndex );
		if( evalText ) {
			this.controlWin.evaluatedText.value = evalText;
			ww.setFocus( this.currentTextIndex, this.currentWordIndex );
			this._getSuggestions( this.currentTextIndex, this.currentWordIndex );
		}
	}
}

function _getSuggestions( text_num, word_num ) {
	this.controlWin.clearSuggestions();
	// add suggestion in list for each suggested word.
	// get the array of suggested words out of the
	// three-dimensional array containing all suggestions.
	var a_suggests = this.wordWin.suggestions[text_num][word_num];
	if( a_suggests ) {
		// got an array of suggestions.
		for( var ii = 0; ii < a_suggests.length; ii++ ) {
			this.controlWin.addSuggestion( a_suggests[ii] );
		}
	}
	this.controlWin.selectDefaultSuggestion();
}

function _setAsIgnored( text_num, word_num, flag ) {
	// set the UI
	this.wordWin.removeFocus( text_num, word_num );
	// do the bookkeeping
	this.wordFlags[text_num][word_num] = flag;
	return true;
}

function _getTotalReplaced() {
	var i_replaced = 0;
	for( var i = 0; i < this.wordFlags.length; i++ ) {
		for( var j = 0; j < this.wordFlags[i].length; j++ ) {
			if(( this.wordFlags[i][j] == this.replWordFlag )
			|| ( this.wordFlags[i][j] == this.replAllFlag )
			|| ( this.wordFlags[i][j] == this.fromReplAll )) {
				i_replaced++;
			}
		}
	}
	return i_replaced;
}

function _setWordText( text_num, word_num, newText, flag ) {
	// set the UI and form inputs
	this.wordWin.setText( text_num, word_num, newText );
	// keep track of what happened to this word:
	this.wordFlags[text_num][word_num] = flag;
	return true;
}

function _getFormInputs( inputPattern ) {
	var inputs = new Array();
	for( var i = 0; i < document.forms.length; i++ ) {
		for( var j = 0; j < document.forms[i].elements.length; j++ ) {
			if( document.forms[i].elements[j].type.match( inputPattern )) {
				inputs[inputs.length] = document.forms[i].elements[j];
			}
		}
	}
	return inputs;
}

Author: mn

--- NEW FILE: wordWindow.js ---
////////////////////////////////////////////////////
// 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( '<form name="textInput'+txtid+'">' );
        var wordtxt = this.textInputs[txtid];
        //this.indexes[txtid] = []; // we'll copy after this is known
        if( wordtxt ) {
            var orig = this.originalSpellings[txtid];
            if( !orig ) break;

/* Create array of word locations
 *
 * Following logic is based on four assumptions:
 * 1. Server always returns misspelled words in doc sequence
 * 2. We'll never find a misspell occurrence the server didn't find.
 *    (but handle the exception if it happens)
 * 3. Our plain text method of locating words the server found can fail
 * 4. HTML is always valid
 *
 * We end up with arrays of only those words with their locations we could find
 * using plain text search method.
 */
            var i,j,k;

            // initialize our locations working structure:
            //    serverTotal/dupFlag, totalFound/dupRef, positionArray/position
            var locations = new Array(orig.length);
            for(i=0;i<locations.length;i++) locations[i] = new Array(1,0,null);

            // now mark multiple misspell occurrences the server found
            for(i=0;i<locations.length;i++) {
                if(locations[i][0] == -1) continue; // already dup of a previous word
                    for(j=i+1;j<locations.length;j++) {
                    if(orig[j]==orig[i]) {
                            locations[i][0]++;    // add up number server found
                        locations[j][0] = -1; // mark as dup reference
                        locations[j][1] = i;  // reference to first occurrence
                    }
                    }
            }

            // find all misspell locations we can with verbatim text search for each unique
            // word and only search between tags.
            // end up with locations[i][2] == Array of all positions we found word
            var keepLooking;
            var end_idx;
            var begin_idx;
            var tagNextStart;
            for(i=0;i<locations.length;i++) {
                if(locations[i][0] == -1) continue; // dup, we've already done this word
                locations[i][2] = new Array();
                keepLooking = true;
                end_idx = 0;
                tagNextStart = wordtxt.indexOf("<"); // we only look between tags
                if(tagNextStart == -1) tagNextStart = wordtxt.length; // no tags
                do {
                    begin_idx = wordtxt.indexOf( orig[i], end_idx );
                    if(begin_idx == -1) keepLooking = false;
                    else if(tagNextStart<begin_idx) { // prevents getting a FUBAR doc
                        end_idx=wordtxt.indexOf(">",tagNextStart+1)+1; // always found if valid html
                        tagNextStart=wordtxt.indexOf("<",end_idx);
                        if(tagNextStart == -1) tagNextStart=wordtxt.length; // no more tags
                    }
                    else if( !this._isWordChar(wordtxt.charAt(begin_idx+orig[i].length)) &&
                             !this._isWordChar(wordtxt.charAt(begin_idx-1)) ) {
                        locations[i][2].push(begin_idx);
                        end_idx = begin_idx + orig[i].length + 1;
                    }
                    else end_idx = begin_idx + orig[i].length + 1;
                } while(keepLooking);
                locations[i][1] = locations[i][2].length;
                // Enforce one of our assumptions. This 'should' never happen, but if
                // we found more occurances of any word than the server found,
                // prevent mess up by getting rid of em
                if(locations[i][1]>locations[i][0]) locations[i][1]=0;
            }

            // Define all locations that have only one possibility.
            // Those for which server and we found the same number of
            // misspell occurrences for given misspelling of a word.
            for(i=0;i<locations.length;i++) {
                if(locations[i][0]==locations[i][1] && typeof(locations[i][2])=="object") {
                    locations[i][0]=1;
                    locations[i][1]=1;
                    var foundarray=locations[i][2];
                    locations[i][2]=foundarray.shift();
                    for(j=i+1;j<locations.length && foundarray.length>0;j++) {
                        if(locations[j][0] == -1 && locations[j][1]==i) {
                            locations[j][0]=1; // total 1
                            locations[j][1]=1; // found 1
                            locations[j][2]=foundarray.shift(); // the location
                        }
                    }
                }
            }

            // now reduce multiple possibilities (never a known case when using Aspell)
            //
            // Extract array of referenced words of which we've found
            // at least one that have more locations in the original
            // sequence than we could find
            var multiwords = new Array(); // each item = [ref, docPosition]
            for(i=0;i<locations.length;i++) {
                if(locations[i][0]>locations[i][1] && locations[i][1]>0) {
                    for(j=0;j<locations[i][2].length;j++) {
                        multiwords.push(new Array(i,locations[i][2][j]));
                    }
                        locations[i][0] = -1; // mark as referenced after we've extracted info
                    locations[i][1] = i;
                }
            }

            // now sort this array by sequence we found in doc (presumably like server)
            multiwords.sort(new Function("a","b","return a[1]-b[1]"));

            // Shift each location of this array to the location
            // they fit in original server sequence
            var keepLooking = true;
            var maxcheck = true;
            var minIdx = 0;
            var minLoc = 0;
            for(j=0;j<multiwords.length;j++) {
                // check each position for this word in doc order; look for
                // word location to pass minimum criteria, then look for upper
                // criteria. if it doesn't fit, go to the next occurrence
                for(keepLooking=true,i=minIdx;i<locations.length && keepLooking;i++) {
                    if(locations[i][0]==-1 && locations[i][1]==multiwords[j][0]) { // if a ref
                        if(multiwords[j][1]>minLoc) { // if beyond last word
                            for(maxcheck=true,k=i+1;k<locations.length && maxcheck;k++) {
                                if(locations[k][0] != -1 && locations[k][1]>0) {
                                    if(locations[k][2]>multiwords[j][1]) { // and if before next word
                                        locations[i][0] = 1;
                                        locations[i][1] = 1;
                                        locations[i][2] = multiwords[j][1];
                                        minIdx = i+1; // no point starting next word search before here
                                        keepLooking=false; 
                                    }
                                    maxcheck=false;
                                }
                            }
                            if(maxcheck) { //nothing is after this location
                                locations[i][0] = 1;
                                locations[i][1] = 1;
                                locations[i][2] = multiwords[j][1];
                                minIdx = i+1; 
                                keepLooking=false;
                            }
                        }
                    }
                    else if(locations[i][0] != -1) {
                        minLoc=locations[i][2];
                        minIdx=i+1; // where to start next word search
                    }
                }
            }

            // splice arrays to get rid of unfound words and their suggestions
            // (should only omit words that plain text search can't find)
            for(i=locations.length-1;i>=0;i--) { // reverse is simpler
                if(locations[i][0] == -1 || locations[i][1]==0) { // unfound ref OR none found
                    locations.splice(i,1);
                    this.originalSpellings[txtid].splice(i,1);
                    this.suggestions[txtid].splice(i,1);
                }
            }

            // finally, write out the doc and word locations
            this.indexes[txtid]= new Array(locations.length);
            d.writeln('<div class="plainText">');
            for(minLoc=0,i=0;i<locations.length;i++) {
                this.indexes[txtid][i] = locations[i][2];
                d.write(wordtxt.substring(minLoc,locations[i][2])); // before word
                d.write( this._wordInputStr(this.originalSpellings[txtid][i],txtid,i)); // the word
                minLoc = locations[i][2]+this.originalSpellings[txtid][i].length; // where to write from next
            }
            d.write(wordtxt.substring(minLoc)); // end of doc
            d.writeln('</div>');
            d.writeln('</form>');
        }
    }
    d.close();

    // set the _forms property
    this._forms = d.forms;

    // Replace all hyperlinks with spans without the href's that look like links.
    // This prevents being able to break it by navigating the wordWindow with links.
    var find = /<a(\s[^\>]*)href=\"[^\"]*\"(.*?)\<\/a\>/gi;
    var repl = '<span style="color:blue;text-decoration:underline"$1$2</span>';
    // memory leak for IE?
    //d.body.innerHTML = d.body.innerHTML.replace(find,repl);   
    var doc = d.body.innerHTML.replace(find,repl);
    d.body.innerHTML = doc;
}

// return the character index in the full text after the last word we evaluated
function _lastPos( txtid, idx ) {
	if( idx > 0 )
		return this.indexes[txtid][idx-1] + this.originalSpellings[txtid][idx-1].length;
	else
		return 0;
}

function printForHtml( n ) {
	return n ;		// by FredCK
/*
	var htmlstr = n;
	if( htmlstr.length == 1 ) {
		// do simple case statement if it's just one character
		switch ( n ) {
			case "\n":
				htmlstr = '<br/>';
				break;
			case "<":
				htmlstr = '&lt;';
				break;
			case ">":
				htmlstr = '&gt;';
				break;
		}
		return htmlstr;
	} else {
		htmlstr = htmlstr.replace( /</g, '&lt' );
		htmlstr = htmlstr.replace( />/g, '&gt' );
		htmlstr = htmlstr.replace( /\n/g, '<br/>' );
		return htmlstr;
	}
*/
}

function _isWordChar( letter ) {
	if( letter.search( this.wordChar ) == -1 ) {
		return false;
	} else {
		return true;
	}
}

function _getWordObject( textIndex, wordIndex ) {
	if( this._forms[textIndex] ) {
		if( this._forms[textIndex].elements[wordIndex] ) {
			return this._forms[textIndex].elements[wordIndex];
		}
	}
	return null;
}

function _wordInputStr( word ) {
	var str = '<input readonly ';
	str += 'class="blend" type="text" value="' + word + '" size="' + word.length + '">';
	return str;
}

function _adjustIndexes( textIndex, wordIndex, lengthDiff ) {
	for( var i = wordIndex + 1; i < this.originalSpellings[textIndex].length; i++ ) {
		this.indexes[textIndex][i] = this.indexes[textIndex][i] + lengthDiff;
	}
}

Author: mn

--- NEW FILE: controls.html ---
<html>
	<head>
		<link rel="stylesheet" type="text/css" href="spellerStyle.css" />
		<script type="text/javascript" src="controlWindow.js"></script>
		<script type="text/javascript">
var spellerObject;
var controlWindowObj;

if( parent.opener ) {
	spellerObject = parent.opener.speller;
}
else if( parent.parent )
{
        spellerObject = parent.parent.speller;
}

function ignore_word() {
	if( spellerObject ) {
		spellerObject.ignoreWord();
	}
}

function ignore_all() {
	if( spellerObject ) {
		spellerObject.ignoreAll();
	}
}

function replace_word() {
	if( spellerObject ) {
		spellerObject.replaceWord();
	}
}

function replace_all() {
	if( spellerObject ) {
		spellerObject.replaceAll();
	}
}

function end_spell() {
	if( spellerObject ) {
		spellerObject.terminateSpell();
	}
}

function undo() {
	if( spellerObject ) {
		spellerObject.undo();
	}
}

function suggText() {
	if( controlWindowObj ) {
		controlWindowObj.setSuggestedText();
	}
}

function init_spell() {
	// By FredCK (fckLang attributes have been added to the HTML source of this page)
	window.parent.parent.OnSpellerControlsLoad(this);
	
	var controlForm = document.spellcheck;
	
	// create a new controlWindow object
 	controlWindowObj = new controlWindow( controlForm );
	// Let's take this out of the constructor, shall we?
	controlWindowObj.noSuggestionSelection = window.parent.parent.FCKLang.DlgSpellNoSuggestions; // By ChrisB

	// call the init_spell() function in the parent frameset
	if( parent.frames.length ) {
		parent.init_spell( controlWindowObj );
	} else {
		alert( 'This page was loaded outside of a frameset. It might not display properly' );
	}
}

</script>
	</head>
	<body class="controlWindowBody" onLoad="init_spell();" style="OVERFLOW: hidden" scroll="no">	<!-- by FredCK -->
		<form name="spellcheck">
			<table border="0" cellpadding="0" cellspacing="0" border="0" align="center">
				<tr>
					<td colspan="3" class="normalLabel"><span fckLang="DlgSpellNotInDic">Not in dictionary</span><span>:</span></td>
				</tr>
				<tr>
					<td colspan="3"><input class="readonlyInput" type="text" name="misword" readonly /></td>
				</tr>
				<tr>
					<td colspan="3" height="5"></td>
				</tr>
				<tr>
					<td class="normalLabel"><span fckLang="DlgSpellChangeTo">Change to</span>:</td>
				</tr>
				<tr valign="top">
					<td>
						<table border="0" cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td class="normalLabel">
									<input class="textDefault" type="text" name="txtsugg" />
								</td>
							</tr>
							<tr>
								<td>
									<select class="suggSlct" name="sugg" size="7" onChange="suggText();" onDblClick="replace_word();">
										<option></option>
									</select>
								</td>
							</tr>
						</table>
					</td>
					<td>&nbsp;&nbsp;</td>
					<td>
						<table border="0" cellpadding="0" cellspacing="0" border="0">
							<tr>
								<td>
									<input class="buttonDefault" type="button" fckLang="DlgSpellBtnIgnore" value="Ignore" onClick="ignore_word();">
								</td>
								<td>&nbsp;&nbsp;</td>
								<td>
									<input class="buttonDefault" type="button" fckLang="DlgSpellBtnIgnoreAll" value="Ignore All" onClick="ignore_all();">
								</td>
							</tr>
							<tr>
								<td colspan="3" height="5"></td>
							</tr>
							<tr>
								<td>
									<input class="buttonDefault" type="button" fckLang="DlgSpellBtnReplace" value="Replace" onClick="replace_word();">
								</td>
								<td>&nbsp;&nbsp;</td>
								<td>
									<input class="buttonDefault" type="button" fckLang="DlgSpellBtnReplaceAll" value="Replace All" onClick="replace_all();">
								</td>
							</tr>
							<tr>
								<td colspan="3" height="5"></td>
							</tr>
							<tr>
								<td>
									<input class="buttonDefault" type="button" name="btnUndo" fckLang="DlgSpellBtnUndo" value="Undo" onClick="undo();"
										disabled>
								</td>
								<td>&nbsp;&nbsp;</td>
								<td>
									<!-- by FredCK
									<input class="buttonDefault" type="button" value="Close" onClick="end_spell();">
									-->
								</td>
							</tr>
						</table>
					</td>
				</tr>
			</table>
		</form>
	</body>
</html>

---------------------------------------------------------------------
OTRS mailing list: cvs-log - Webpage: http://otrs.org/
Archive: http://lists.otrs.org/pipermail/cvs-log
To unsubscribe: http://lists.otrs.org/cgi-bin/listinfo/cvs-log
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.