123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304 |
- var spell_formname, spell_fieldname;
- function spellCheck(formName, fieldName)
- {
-
- var spellform = document.forms.spell_form;
-
- spell_formname = formName;
- spell_fieldname = fieldName;
-
- var regexpWordMatch = /(?:<[^>]+>)|(?:\[[^ ][^\]]*\])|(?:&[^; ]+;)|(?:[^0-9\s\]\[{};:"\\|,<.>\/?`~!@#$%^&*()_+=]+)/g;
-
- var aWordCharacters = ['-', '\''];
- var aWords = new Array(), aResult = new Array();
- var sText = $('#' + fieldName).data("sceditor").getTextareaValue(false);
- var bInCode = false;
- var iOffset1, iOffset2;
-
- while ((aResult = regexpWordMatch.exec(sText)) && typeof(aResult) != 'undefined')
- {
- iOffset1 = 0;
- iOffset2 = aResult[0].length - 1;
-
- while (in_array(aResult[0].charAt(iOffset1), aWordCharacters) && iOffset1 < iOffset2)
- iOffset1++;
-
- while (in_array(aResult[0].charAt(iOffset2), aWordCharacters) && iOffset1 < iOffset2)
- iOffset2--;
-
- if (iOffset1 == iOffset2)
- continue;
-
- if (aResult[0].substr(0, 5).toLowerCase() == '[code')
- bInCode = true;
-
- else if (bInCode && aResult[0].substr(0, 7).toLowerCase() == '[/code]')
- bInCode = false;
-
- else if (!bInCode && !in_array(aResult[0].charAt(0), ['[', '<']) && aResult[0].toUpperCase() != aResult[0])
- aWords[aWords.length] = aResult[0].substr(iOffset1, iOffset2 - iOffset1 + 1) + '|' + (iOffset1 + sText.substr(0, aResult.index).length) + '|' + (iOffset2 + sText.substr(0, aResult.index).length);
- }
-
- openSpellWin(640, 480);
-
- spellform.spellstring.value = aWords.join('\n');
-
- spellform.submit();
- return true;
- }
- var wordindex = -1, offsetindex = 0;
- var ignoredWords = [];
- function misp(word, start, end, suggestions)
- {
-
- this.word = word;
- this.start = start;
- this.end = end;
- this.suggestions = suggestions;
- }
- function replaceWord()
- {
- var strstart = "";
- var strend;
-
-
- if (misps[wordindex].start != 0)
- strstart = mispstr.slice(0, misps[wordindex].start + offsetindex);
-
- strend = mispstr.slice(misps[wordindex].end + 1 + offsetindex);
-
- mispstr = strstart + document.forms.spellingForm.changeto.value + strend;
-
-
- offsetindex += document.forms.spellingForm.changeto.value.length - misps[wordindex].word.length;
-
- misps[wordindex].word = document.forms.spellingForm.changeto.value;
- nextWord(false);
- }
- function replaceAll()
- {
- var strend;
- var idx;
- var origword;
- var localoffsetindex = offsetindex;
- origword = misps[wordindex].word;
-
- for (idx = wordindex; idx < misps.length; idx++)
- {
- misps[idx].start += localoffsetindex;
- misps[idx].end += localoffsetindex;
- }
- localoffsetindex = 0;
- for (idx = 0; idx < misps.length; idx++)
- {
- if (misps[idx].word == origword)
- {
- var strstart = "";
- if (misps[idx].start != 0)
- strstart = mispstr.slice(0, misps[idx].start + localoffsetindex);
-
- strend = mispstr.slice(misps[idx].end + 1 + localoffsetindex);
-
- mispstr = strstart + document.forms.spellingForm.changeto.value + strend;
-
-
- localoffsetindex += document.forms.spellingForm.changeto.value.length - misps[idx].word.length;
- }
-
- misps[idx].start += localoffsetindex;
- misps[idx].end += localoffsetindex;
- }
-
- ignoredWords[origword] = true;
-
- offsetindex = 0;
- nextWord(false);
- }
- function highlightWord()
- {
- var strstart = "";
- var strend;
-
-
- if (misps[wordindex].start != 0)
- strstart = mispstr.slice(0, misps[wordindex].start + offsetindex);
-
- strend = mispstr.slice(misps[wordindex].end + 1 + offsetindex);
-
-
- var divptr, newValue;
- divptr = document.getElementById("spellview");
- newValue = htmlspecialchars(strstart) + '<span class="highlight" id="h1">' + misps[wordindex].word + '</span>' + htmlspecialchars(strend);
- setInnerHTML(divptr, newValue.replace(/_\|_/g, '<br />'));
-
- var spellview_height = typeof(document.getElementById("spellview").currentStyle) != "undefined" ? parseInt(document.getElementById("spellview").currentStyle.height) : document.getElementById("spellview").offsetHeight;
- var word_position = document.getElementById("h1").offsetTop;
- var current_position = document.getElementById("spellview").scrollTop;
-
- if (spellview_height <= (word_position + current_position))
- document.getElementById("spellview").scrollTop = word_position + current_position - spellview_height + 32;
- }
- function nextWord(ignoreall)
- {
-
- if (ignoreall)
- ignoredWords[misps[wordindex].word] = true;
-
-
- if (wordindex >= 0)
- {
- misps[wordindex].start += offsetindex;
- misps[wordindex].end += offsetindex;
- }
-
- wordindex++;
-
- if (misps.length <= wordindex)
- {
- var divptr;
- divptr = document.getElementById("spellview");
- setInnerHTML(divptr, htmlspecialchars(mispstr).replace(/_\|_/g, "<br />"));
- while (document.forms.spellingForm.suggestions.options.length > 0)
- document.forms.spellingForm.suggestions.options[0] = null;
- alert(txt['done']);
- document.forms.spellingForm.change.disabled = true;
- document.forms.spellingForm.changeall.disabled = true;
- document.forms.spellingForm.ignore.disabled = true;
- document.forms.spellingForm.ignoreall.disabled = true;
-
- mispstr = mispstr.replace(/_\|_/g, "\n");
-
- window.opener.spellCheckSetText(mispstr, spell_fieldname);
- window.close();
- return true;
- }
-
- if (typeof(ignoredWords[misps[wordindex].word]) != "undefined")
- {
- nextWord(false);
- return false;
- }
-
- while (document.forms.spellingForm.suggestions.options.length > 0)
- document.forms.spellingForm.suggestions.options[0] = null;
-
- if (misps[wordindex].suggestions.length)
- {
- for (var sugidx = 0; sugidx < misps[wordindex].suggestions.length; sugidx++)
- {
- var newopt = new Option(misps[wordindex].suggestions[sugidx], misps[wordindex].suggestions[sugidx]);
- document.forms.spellingForm.suggestions.options[sugidx] = newopt;
- if (sugidx == 0)
- {
- newopt.selected = true;
- document.forms.spellingForm.changeto.value = newopt.value;
- document.forms.spellingForm.changeto.select();
- }
- }
- }
- if (document.forms.spellingForm.suggestions.options.length == 0)
- document.forms.spellingForm.changeto.value = "";
- highlightWord();
- return false;
- }
- function htmlspecialchars(thetext)
- {
- thetext = thetext.replace(/\</g, "<");
- thetext = thetext.replace(/\>/g, ">");
- thetext = thetext.replace(/\n/g, "<br />");
- thetext = thetext.replace(/\ \ /g, " ");
- return thetext;
- }
- function openSpellWin(width, height)
- {
- window.open("", "spellWindow", "toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes,resizable=no,width=" + width + ",height=" + height);
- }
- function spellCheckGetText(editorID)
- {
- return $("#" + editorID).data("sceditor").getTextareaValue(false);
- }
- function spellCheckSetText(text, editorID)
- {
- $("#" + editorID).data("sceditor").InsertText(text, true);
- if (!$("#" + editorID).data("sceditor").wasSource)
- $("#" + editorID).data("sceditor").toggleTextMode();
- }
|