📄 spellchecker.js
字号:
/*
======================================================================
Copyright © 2007 by Francisco Burzi
http://phpnuke.org
AntiSlaed CMS based on:
RNuke (http://rusnuke.com)
EdogsNuke (http://edogs.ru)
XNuke (http://xnuke.info)
phpBB (http://phpbb.com)
Code modifications by AntiSlaed Team, June 2008
http://antislaedcms.ru
Please contact us, if you have any questions about AntiSlaedCMS
mailto: admin@antislaedcms.ru
AntiSlaed CMS is free software. You can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License.
======================================================================
*/
////////////////////////////////////////////////////
// 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++ ) {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -