1 | /*************************************************************
|
---|
2 | * AJAX Spell Checker - Version 2.8
|
---|
3 | * (C) 2005 - Garrison Locke
|
---|
4 | *
|
---|
5 | * This spell checker is built in the style of the Gmail spell
|
---|
6 | * checker. It uses AJAX to communicate with the backend without
|
---|
7 | * requiring the page be reloaded. If you use this code, please
|
---|
8 | * give me credit and a link to my site would be nice.
|
---|
9 | * http://www.broken-notebook.com.
|
---|
10 | *
|
---|
11 | * Copyright (c) 2005, Garrison Locke
|
---|
12 | * All rights reserved.
|
---|
13 | *
|
---|
14 | * Redistribution and use in source and binary forms, with or without
|
---|
15 | * modification, are permitted provided that the following conditions are met:
|
---|
16 | *
|
---|
17 | * * Redistributions of source code must retain the above copyright notice,
|
---|
18 | * this list of conditions and the following disclaimer.
|
---|
19 | * * Redistributions in binary form must reproduce the above copyright notice,
|
---|
20 | * this list of conditions and the following disclaimer in the documentation
|
---|
21 | * and/or other materials provided with the distribution.
|
---|
22 | * * Neither the name of the http://www.broken-notebook.com nor the names of its
|
---|
23 | * contributors may be used to endorse or promote products derived from this
|
---|
24 | * software without specific prior written permission.
|
---|
25 | *
|
---|
26 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
|
---|
27 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
|
---|
28 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
|
---|
29 | * IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
|
---|
30 | * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
|
---|
31 | * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
|
---|
32 | * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
|
---|
33 | * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
|
---|
34 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
---|
35 | * OF SUCH DAMAGE.
|
---|
36 | *
|
---|
37 | *************************************************************/
|
---|
38 |
|
---|
39 | var cp;
|
---|
40 | var currObj; //the current spell checker being used
|
---|
41 | var spellingSuggestionsDiv;
|
---|
42 | var old_onclick
|
---|
43 | cp = new cpaint();
|
---|
44 | cp.set_transfer_mode('post');
|
---|
45 | cp.set_response_type('text');
|
---|
46 | function beginSpellCheck(){
|
---|
47 |
|
---|
48 | //var cp = new cpaint();
|
---|
49 | // alert("Seta globals");
|
---|
50 | //cp = new cpaint();
|
---|
51 | //cp.set_transfer_mode('post');
|
---|
52 | //cp.set_response_type('text');
|
---|
53 | //cp.set_debug(1);
|
---|
54 |
|
---|
55 | //var currObj; //the current spell checker being used
|
---|
56 | //var spellingSuggestionsDiv = null; // Auto-generated suggestions div
|
---|
57 |
|
---|
58 |
|
---|
59 | spellingSuggestionsDiv = null;
|
---|
60 |
|
---|
61 | //alert("Seta globals");
|
---|
62 |
|
---|
63 |
|
---|
64 | // If there are already any onclick handlers loaded in the page, we'll add
|
---|
65 | // our onclick handler first and then call the old one, rather than completely
|
---|
66 | // overriding it. The checkClickLocation is used to hide the suggestions div
|
---|
67 | // when the user clicks outside it.
|
---|
68 | /*if(document.onclick)
|
---|
69 | {
|
---|
70 | old_onclick = document.onclick;
|
---|
71 |
|
---|
72 | document.onclick = function(e)
|
---|
73 | {
|
---|
74 | checkClickLocation(e);
|
---|
75 | old_onclick(e);
|
---|
76 | }
|
---|
77 | }
|
---|
78 | else
|
---|
79 | {
|
---|
80 | //document.onclick = checkClickLocation;
|
---|
81 | }*/
|
---|
82 |
|
---|
83 | //alert("Inicio");
|
---|
84 | // If there are already any onload handlers loaded in the page, we'll add our onload
|
---|
85 | // handler first and then call the old one, rather than completely overriding it.
|
---|
86 | if(window.onload)
|
---|
87 | {
|
---|
88 | window.onload = new setupSpellCheckers();
|
---|
89 |
|
---|
90 | /*var old_onload = window.onload;
|
---|
91 | window.onload = function(e)
|
---|
92 | {
|
---|
93 | var test = new setupSpellCheckers(e);
|
---|
94 | old_onload(e);
|
---|
95 | }*/
|
---|
96 | }
|
---|
97 | else
|
---|
98 | {
|
---|
99 | window.onload = new setupSpellCheckers();
|
---|
100 | }
|
---|
101 |
|
---|
102 | //window.onload =new setupSpellCheckers();
|
---|
103 | //alert("Fim");
|
---|
104 | } // fecha funᅵᅵo
|
---|
105 |
|
---|
106 |
|
---|
107 |
|
---|
108 |
|
---|
109 |
|
---|
110 | /*************************************************************
|
---|
111 | * function setupSpellCheckers()
|
---|
112 | *
|
---|
113 | * This function goes through the page and finds all the
|
---|
114 | * textareas. It then checks the title attribute for either
|
---|
115 | * spellcheck or spellcheck_icons to determine whether or not
|
---|
116 | * it should add a spellchecker to that textarea.
|
---|
117 | *************************************************************/
|
---|
118 | function setupSpellCheckers()
|
---|
119 | {
|
---|
120 | var ifr = document.getElementsByTagName('iframe')[0];
|
---|
121 | var numSpellCheckers = 0;
|
---|
122 | var tempSpellCheckers = Array();
|
---|
123 | // alert("NOT OK");
|
---|
124 |
|
---|
125 | //novo
|
---|
126 | //if (textareas){
|
---|
127 | if(ifr.contentWindow)
|
---|
128 | ifr=ifr.contentWindow.document;
|
---|
129 | else
|
---|
130 | ifr=ifr.contentDocument;
|
---|
131 | // alert(ifr.body.innerHTML);
|
---|
132 | var texto = ifr.body.innerHTML;
|
---|
133 |
|
---|
134 | // alert("valor textarea");
|
---|
135 | // alert(texto);
|
---|
136 | // //tempSpellCheckers[numSpellCheckers] = textareas;
|
---|
137 | var tempWidth = "300";
|
---|
138 | var tempHeight = "300";
|
---|
139 |
|
---|
140 | // alert("Antes AjaxSpell");
|
---|
141 | eval('spellCheckers' + numSpellCheckers + '= new ajaxSpell("spellCheckers' + numSpellCheckers + '", tempWidth, tempHeight, "spell_checker/spell_checker.php", "body_position_1", "Nome", "body_1", "Titulo", texto);');
|
---|
142 |
|
---|
143 |
|
---|
144 | //new ajaxSpell('spellTexto', tempWidth, tempHeight, 'spell_checker.php' ,'body_position_1', 'Nome','body_1', 'Titulo', texto);
|
---|
145 |
|
---|
146 | //ajaxSpell("", "", "", "" ,"", "","", "", "");
|
---|
147 |
|
---|
148 | //}
|
---|
149 |
|
---|
150 | /*for(var i=0; i < textareas.length; i++)
|
---|
151 | {
|
---|
152 | alert("ok iframe");
|
---|
153 | if(textareas[i].getAttribute("title") == "spellcheck" || textareas[i].getAttribute("title") == "spellcheck_icons")
|
---|
154 | {
|
---|
155 | tempSpellCheckers[numSpellCheckers] = textareas[i];
|
---|
156 |
|
---|
157 | //create a new spellchecker for this textarea
|
---|
158 | var tempWidth = tempSpellCheckers[numSpellCheckers].offsetWidth + 'px';
|
---|
159 | var tempHeight = tempSpellCheckers[numSpellCheckers].offsetHeight + 'px';
|
---|
160 | eval('spellCheckers' + numSpellCheckers + '= new ajaxSpell("spellCheckers' + numSpellCheckers + '", tempWidth, tempHeight, tempSpellCheckers[' + numSpellCheckers + '].getAttribute("accesskey"), "spellCheckDiv' + numSpellCheckers + '", tempSpellCheckers[' + numSpellCheckers + '].getAttribute("name"), tempSpellCheckers[' + numSpellCheckers + '].id, tempSpellCheckers[' + numSpellCheckers + '].title, tempSpellCheckers[' + numSpellCheckers + '].value);');
|
---|
161 | numSpellCheckers++;
|
---|
162 | }
|
---|
163 | }*/
|
---|
164 |
|
---|
165 | }; // end setInit
|
---|
166 |
|
---|
167 |
|
---|
168 | /*************************************************************
|
---|
169 | * ajaxSpell(varName, width, height, spellUrl, divId, name, id)
|
---|
170 | *
|
---|
171 | * This is the constructor that creates a new ajaxSpell object.
|
---|
172 | * All of it is dynamically generated so the user doesn't have
|
---|
173 | * to add a bunch of crap to their site.
|
---|
174 | *
|
---|
175 | * @param varName The name of the variable that the object is
|
---|
176 | * assigned to (must be unique and the same as the variable)
|
---|
177 | * @param width The width of the spell checker
|
---|
178 | * @param height The height of the spell checker
|
---|
179 | * @param spellUrl The url of the spell_checker.php code
|
---|
180 | * @param divId The id of the div that the spell checker is
|
---|
181 | * contained in (must be unique)
|
---|
182 | * @param name The name of the textarea form element
|
---|
183 | * @param id The id of the spell checker textarea (must be unique)
|
---|
184 | *************************************************************/
|
---|
185 | function ajaxSpell(varName, width, height, spellUrl, divId, name, id, title, value)
|
---|
186 | {
|
---|
187 | //alert("ajaxSpell");
|
---|
188 |
|
---|
189 | currObj = this;
|
---|
190 |
|
---|
191 | currObj.config = new Array(); //the array of configuration options
|
---|
192 | currObj.config['varName'] = varName; //the name of the variable that this instance is stored in
|
---|
193 | currObj.config['width'] = width; //the width of the textarea
|
---|
194 | currObj.config['height'] = height; //the height of the textarea
|
---|
195 | currObj.config['spellUrl'] = spellUrl; //url to spell checker php code (spell_checker.php by default);
|
---|
196 | currObj.config['divId'] = divId; //the id of the div that the spell checker element is in
|
---|
197 | currObj.config['name'] = name; //what you want the form element's name to be
|
---|
198 | currObj.config['id'] = id; //the unique id of the spell_checker textarea
|
---|
199 | currObj.config['title'] = title; //the title (specifies whether to use icons or not);
|
---|
200 | currObj.config['value'] = value; //the value of the text box when the page was loaded
|
---|
201 |
|
---|
202 | currObj.config['value'] = currObj.config['value'].replace(/<br *\/?>/gi, "\n");
|
---|
203 |
|
---|
204 | currObj.config['useIcons'] = false;
|
---|
205 |
|
---|
206 | if(currObj.config['title'] == "spellcheck_icons")
|
---|
207 | {
|
---|
208 | currObj.config['useIcons'] = true;
|
---|
209 | }
|
---|
210 |
|
---|
211 | spellContainer = document.createElement('DIV');
|
---|
212 | spellContainer.id = currObj.config['divId'];
|
---|
213 | spellContainer.className = 'spell_container';
|
---|
214 | spellContainer.style.width = currObj.config['width'];
|
---|
215 |
|
---|
216 | oldElement = document.getElementById(currObj.config['id']);
|
---|
217 |
|
---|
218 | oldElement.parentNode.replaceChild(spellContainer, oldElement);
|
---|
219 |
|
---|
220 | //generate the div to hold the spell checker controls
|
---|
221 | currObj.controlPanelDiv = document.createElement('DIV');
|
---|
222 | currObj.controlPanelDiv.className = 'control_panel';
|
---|
223 | document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv);
|
---|
224 |
|
---|
225 | //the span that toggles between spell checking and editing
|
---|
226 | currObj.actionSpan = document.createElement('SPAN');
|
---|
227 | currObj.actionSpan.className = "action";
|
---|
228 | currObj.actionSpan.id = "action";
|
---|
229 | if(currObj.config['useIcons'])
|
---|
230 | {
|
---|
231 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\"><img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Check Spelling & Preview\" alt=\"Check Spelling & Preview\" border=\"0\" /></a>";
|
---|
232 | }
|
---|
233 | else
|
---|
234 | {
|
---|
235 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Check Spelling & Preview</a>";
|
---|
236 | }
|
---|
237 | currObj.controlPanelDiv.appendChild(currObj.actionSpan);
|
---|
238 |
|
---|
239 | //the span that lets the user know of the status of the spell checker
|
---|
240 | currObj.statusSpan = document.createElement('SPAN');
|
---|
241 | currObj.statusSpan.className = "status";
|
---|
242 | currObj.statusSpan.id = "status";
|
---|
243 | currObj.statusSpan.innerHTML = "";
|
---|
244 | currObj.controlPanelDiv.appendChild(currObj.statusSpan);
|
---|
245 |
|
---|
246 | //the textarea to be spell checked
|
---|
247 | oldElement.value = currObj.config['value'];
|
---|
248 | document.getElementById(currObj.config['divId']).appendChild(oldElement);
|
---|
249 |
|
---|
250 | currObj.objToCheck = document.getElementById(currObj.config['id']); //the actual object we're spell checking
|
---|
251 | currObj.spellingResultsDiv = null; // Auto-generated results div
|
---|
252 |
|
---|
253 | //prototypes for the ajaxSpell objects
|
---|
254 | ajaxSpell.prototype.spellCheck = spellCheck;
|
---|
255 | ajaxSpell.prototype.spellCheck_cb = spellCheck_cb;
|
---|
256 | ajaxSpell.prototype.showSuggestions = showSuggestions;
|
---|
257 | ajaxSpell.prototype.showSuggestions_cb = showSuggestions_cb;
|
---|
258 | ajaxSpell.prototype.replaceWord = replaceWord;
|
---|
259 | ajaxSpell.prototype.switchText = switchText;
|
---|
260 | ajaxSpell.prototype.switchText_cb = switchText_cb;
|
---|
261 | ajaxSpell.prototype.resumeEditing = resumeEditing;
|
---|
262 | ajaxSpell.prototype.resetSpellChecker = resetSpellChecker;
|
---|
263 | ajaxSpell.prototype.resetAction = resetAction;
|
---|
264 | }; // end ajaxSpell
|
---|
265 |
|
---|
266 |
|
---|
267 | /*************************************************************
|
---|
268 | * setCurrentObject
|
---|
269 | *
|
---|
270 | * This sets the current object to be the spell checker that
|
---|
271 | * the user is currently using.
|
---|
272 | *
|
---|
273 | * @param obj The spell checker currently being used
|
---|
274 | *************************************************************/
|
---|
275 | function setCurrentObject(obj)
|
---|
276 | {
|
---|
277 | currObj = obj;
|
---|
278 |
|
---|
279 | }; // end setCurrentObject
|
---|
280 |
|
---|
281 |
|
---|
282 | /*************************************************************
|
---|
283 | * spellCheck_cb
|
---|
284 | *
|
---|
285 | * This is the callback function that the spellCheck php function
|
---|
286 | * returns the spell checked data to. It sets the results div
|
---|
287 | * to contain the markedup misspelled data and changes the status
|
---|
288 | * message. It also sets the width and height of the results
|
---|
289 | * div to match the element that's being checked.
|
---|
290 | * If there are no misspellings then new_data is the empty
|
---|
291 | * string and the status is set to "No Misspellings Found".
|
---|
292 | *
|
---|
293 | * @param new_data The marked up misspelled data returned from php.
|
---|
294 | *************************************************************/
|
---|
295 | function spellCheck_cb(new_data)
|
---|
296 | {
|
---|
297 | with(currObj);
|
---|
298 | new_data = new_data.toString();
|
---|
299 | var isThereAMisspelling = new_data.charAt(0);
|
---|
300 | new_data = new_data.substring(1);
|
---|
301 |
|
---|
302 | if(currObj.spellingResultsDiv)
|
---|
303 | {
|
---|
304 | currObj.spellingResultsDiv.parentNode.removeChild(spellingResultsDiv);
|
---|
305 | }
|
---|
306 |
|
---|
307 | currObj.spellingResultsDiv = document.createElement('DIV');
|
---|
308 | currObj.spellingResultsDiv.className = 'edit_box';
|
---|
309 | currObj.spellingResultsDiv.style.width = currObj.objToCheck.style.width;
|
---|
310 | currObj.spellingResultsDiv.style.height = currObj.objToCheck.style.height;
|
---|
311 | currObj.spellingResultsDiv.innerHTML = new_data;
|
---|
312 |
|
---|
313 | currObj.objToCheck.style.display = "none";
|
---|
314 | currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv,currObj.objToCheck);
|
---|
315 | currObj.statusSpan.innerHTML = "";
|
---|
316 |
|
---|
317 | if(currObj.config['useIcons'])
|
---|
318 | {
|
---|
319 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".resumeEditing();\"><img src=\"images/page_white_edit.png\" width=\"16\" height=\"16\" title=\"Resume Editing\" alt=\"Resume Editing\" border=\"0\" /></a>";
|
---|
320 | }
|
---|
321 | else
|
---|
322 | {
|
---|
323 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".resumeEditing();\">Resume Editing</a>";
|
---|
324 | }
|
---|
325 |
|
---|
326 | if(isThereAMisspelling != "1")
|
---|
327 | {
|
---|
328 | if(currObj.config['useIcons'])
|
---|
329 | {
|
---|
330 | currObj.statusSpan.innerHTML = "<img src=\"images/accept.png\" width=\"16\" height=\"16\" title=\"No Misspellings Found\" alt=\"No Misspellings Found\" border=\"0\" />";
|
---|
331 | }
|
---|
332 | else
|
---|
333 | {
|
---|
334 | currObj.statusSpan.innerHTML = "No Misspellings Found";
|
---|
335 | }
|
---|
336 | currObj.objToCheck.disabled = false;
|
---|
337 | }
|
---|
338 | }; // end spellCheck_cb
|
---|
339 |
|
---|
340 |
|
---|
341 | /*************************************************************
|
---|
342 | * spellCheck()
|
---|
343 | *
|
---|
344 | * The spellCheck javascript function sends the text entered by
|
---|
345 | * the user in the text box to php to be spell checked. It also
|
---|
346 | * sets the status message to "Checking..." because it's currently
|
---|
347 | * checking the spelling.
|
---|
348 | *************************************************************/
|
---|
349 | function spellCheck() {
|
---|
350 | with(currObj);
|
---|
351 | var query;
|
---|
352 |
|
---|
353 | if(currObj.spellingResultsDiv)
|
---|
354 | {
|
---|
355 | currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
|
---|
356 | currObj.spellingResultsDiv = null;
|
---|
357 | }
|
---|
358 |
|
---|
359 | if(currObj.config['useIcons'])
|
---|
360 | {
|
---|
361 | currObj.actionSpan.innerHTML = "<img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Check Spelling & Preview\" alt=\"Check Spelling & Preview\" border=\"0\" />";
|
---|
362 | }
|
---|
363 | else
|
---|
364 | {
|
---|
365 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\">Check Spelling & Preview</a>";
|
---|
366 | }
|
---|
367 |
|
---|
368 | if(currObj.config['useIcons'])
|
---|
369 | {
|
---|
370 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Checking...\" alt=\"Checking...\" border=\"0\" />";
|
---|
371 | }
|
---|
372 | else
|
---|
373 | {
|
---|
374 | currObj.statusSpan.innerHTML = "Checking...";
|
---|
375 | }
|
---|
376 |
|
---|
377 |
|
---|
378 | //Adicionado por Nathalie
|
---|
379 | var ifr= currObj.objToCheck;
|
---|
380 | if(ifr.contentWindow)
|
---|
381 | ifr=ifr.contentWindow.document;
|
---|
382 | else
|
---|
383 | ifr=ifr.contentDocument;
|
---|
384 | alert(ifr.body.innerHTML);
|
---|
385 |
|
---|
386 | var texto = ifr.body.innerHTML;
|
---|
387 |
|
---|
388 |
|
---|
389 | query = texto;
|
---|
390 | //query = currObj.objToCheck.value;
|
---|
391 |
|
---|
392 | query = query.replace(/\r?\n/gi, "<br />");
|
---|
393 |
|
---|
394 | cp.call(currObj.config['spellUrl'], 'spellCheck', spellCheck_cb, query, currObj.config['varName']);
|
---|
395 | }; // end spellcheck
|
---|
396 |
|
---|
397 |
|
---|
398 |
|
---|
399 | /*************************************************************
|
---|
400 | * addWord
|
---|
401 | *
|
---|
402 | * The addWord function adds a word to the custom dictionary
|
---|
403 | * file.
|
---|
404 | *
|
---|
405 | * @param id The id of the span that contains the word to be added
|
---|
406 | *************************************************************/
|
---|
407 | function addWord(id)
|
---|
408 | {
|
---|
409 | var wordToAdd = document.getElementById(id).innerHTML;
|
---|
410 |
|
---|
411 | with(currObj);
|
---|
412 |
|
---|
413 | if(spellingSuggestionsDiv)
|
---|
414 | {
|
---|
415 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
416 | spellingSuggestionsDiv = null;
|
---|
417 | }
|
---|
418 |
|
---|
419 | if(currObj.config['useIcons'])
|
---|
420 | {
|
---|
421 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Adding Word...\" alt=\"Adding Word...\" border=\"0\" />";
|
---|
422 | }
|
---|
423 | else
|
---|
424 | {
|
---|
425 | currObj.statusSpan.innerHTML = "Adding Word...";
|
---|
426 | }
|
---|
427 |
|
---|
428 | cp.call(currObj.config['spellUrl'], 'addWord', addWord_cb, wordToAdd);
|
---|
429 |
|
---|
430 | }; // end addWord
|
---|
431 |
|
---|
432 | /*************************************************************
|
---|
433 | * addWord_cb
|
---|
434 | *
|
---|
435 | * The addWord_cb function is a callback function that
|
---|
436 | * PHP's addWord function returns to. It recieves the
|
---|
437 | * return status of the add to word to personal dictionary call.
|
---|
438 | * It hides the status item.
|
---|
439 | *
|
---|
440 | * @param returnedData The return code from PHP.
|
---|
441 | *************************************************************/
|
---|
442 | function addWord_cb(returnedData)
|
---|
443 | {
|
---|
444 | //alert(returnedData);
|
---|
445 | with(currObj);
|
---|
446 | currObj.statusSpan.innerHTML = "";
|
---|
447 | resumeEditing();
|
---|
448 | spellCheck();
|
---|
449 | }; // end addWord_cb
|
---|
450 |
|
---|
451 |
|
---|
452 |
|
---|
453 | /*************************************************************
|
---|
454 | * checkClickLocation(e)
|
---|
455 | *
|
---|
456 | * This function is called by the event listener when the user
|
---|
457 | * clicks on anything. It is used to close the suggestion div
|
---|
458 | * if the user clicks anywhere that's not inside the suggestion
|
---|
459 | * div. It just checks to see if the name of what the user clicks
|
---|
460 | * on is not "suggestions" then hides the div if it's not.
|
---|
461 | *
|
---|
462 | * @param e The event, in this case the user clicking somewhere on
|
---|
463 | * the page.
|
---|
464 | *************************************************************/
|
---|
465 | function checkClickLocation(e)
|
---|
466 | {
|
---|
467 |
|
---|
468 | // alert("checkClickLocation");
|
---|
469 | if(spellingSuggestionsDiv)
|
---|
470 | {
|
---|
471 | // Bah. There's got to be a better way to deal with this, but the click
|
---|
472 | // on a word to get suggestions starts up a race condition between
|
---|
473 | // showing and hiding the suggestion box, so we'll ignore the first
|
---|
474 | // click.
|
---|
475 | if(spellingSuggestionsDiv.ignoreNextClick){
|
---|
476 | spellingSuggestionsDiv.ignoreNextClick = false;
|
---|
477 | }
|
---|
478 | else
|
---|
479 | {
|
---|
480 | var theTarget = getTarget(e);
|
---|
481 |
|
---|
482 | if(theTarget != spellingSuggestionsDiv)
|
---|
483 | {
|
---|
484 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
485 | spellingSuggestionsDiv = null;
|
---|
486 | }
|
---|
487 | }
|
---|
488 | }
|
---|
489 |
|
---|
490 | return true; // Allow other handlers to continue.
|
---|
491 | }; //end checkClickLocation
|
---|
492 |
|
---|
493 |
|
---|
494 | /*************************************************************
|
---|
495 | * getTarget
|
---|
496 | *
|
---|
497 | * The get target function gets the correct target of the event.
|
---|
498 | * This function is required because IE handles the events in
|
---|
499 | * a different (wrong) manner than the rest of the browsers.
|
---|
500 | *
|
---|
501 | * @param e The target, in this case the user clicking somewhere on
|
---|
502 | * the page.
|
---|
503 | *
|
---|
504 | *************************************************************/
|
---|
505 | function getTarget(e)
|
---|
506 | {
|
---|
507 | var value;
|
---|
508 | if(checkBrowser() == "ie")
|
---|
509 | {
|
---|
510 | value = window.event.srcElement;
|
---|
511 | }
|
---|
512 | else
|
---|
513 | {
|
---|
514 | value = e.target;
|
---|
515 | }
|
---|
516 | return value;
|
---|
517 | }; //end getTarget
|
---|
518 |
|
---|
519 |
|
---|
520 | /*************************************************************
|
---|
521 | * checkBrowser()
|
---|
522 | *
|
---|
523 | * The checkBrowser function simply checks to see what browser
|
---|
524 | * the user is using and returns a string containing the browser
|
---|
525 | * type.
|
---|
526 | *
|
---|
527 | * @return string The browser type
|
---|
528 | *************************************************************/
|
---|
529 | function checkBrowser()
|
---|
530 | {
|
---|
531 | var theAgent = navigator.userAgent.toLowerCase();
|
---|
532 | if(theAgent.indexOf("msie") != -1)
|
---|
533 | {
|
---|
534 | if(theAgent.indexOf("opera") != -1)
|
---|
535 | {
|
---|
536 | return "opera";
|
---|
537 | }
|
---|
538 | else
|
---|
539 | {
|
---|
540 | return "ie";
|
---|
541 | }
|
---|
542 | }
|
---|
543 | else if(theAgent.indexOf("netscape") != -1)
|
---|
544 | {
|
---|
545 | return "netscape";
|
---|
546 | }
|
---|
547 | else if(theAgent.indexOf("firefox") != -1)
|
---|
548 | {
|
---|
549 | return "firefox";
|
---|
550 | }
|
---|
551 | else if(theAgent.indexOf("mozilla/5.0") != -1)
|
---|
552 | {
|
---|
553 | return "mozilla";
|
---|
554 | }
|
---|
555 | else if(theAgent.indexOf("\/") != -1)
|
---|
556 | {
|
---|
557 | if(theAgent.substr(0,theAgent.indexOf('\/')) != 'mozilla')
|
---|
558 | {
|
---|
559 | return navigator.userAgent.substr(0,theAgent.indexOf('\/'));
|
---|
560 | }
|
---|
561 | else
|
---|
562 | {
|
---|
563 | return "netscape";
|
---|
564 | }
|
---|
565 | }
|
---|
566 | else if(theAgent.indexOf(' ') != -1)
|
---|
567 | {
|
---|
568 | return navigator.userAgent.substr(0,theAgent.indexOf(' '));
|
---|
569 | }
|
---|
570 | else
|
---|
571 | {
|
---|
572 | return navigator.userAgent;
|
---|
573 | }
|
---|
574 | }; // end checkBrowser
|
---|
575 |
|
---|
576 |
|
---|
577 | /*************************************************************
|
---|
578 | * showSuggestions_cb
|
---|
579 | *
|
---|
580 | * The showSuggestions_cb function is a callback function that
|
---|
581 | * php's showSuggestions function returns to. It sets the
|
---|
582 | * suggestions table to contain the new data and then displays
|
---|
583 | * the suggestions div. It also clears the status message.
|
---|
584 | *
|
---|
585 | * @param new_data The suggestions table returned from php.
|
---|
586 | *************************************************************/
|
---|
587 | function showSuggestions_cb(new_data)
|
---|
588 | {
|
---|
589 | with(currObj);
|
---|
590 | spellingSuggestionsDiv.innerHTML = new_data;
|
---|
591 | spellingSuggestionsDiv.style.display = 'block';
|
---|
592 | currObj.statusSpan.innerHTML = "";
|
---|
593 | }; //end showSuggestions_cb
|
---|
594 |
|
---|
595 |
|
---|
596 | /*************************************************************
|
---|
597 | * showSuggestions
|
---|
598 | *
|
---|
599 | * The showSuggestions function calls the showSuggestions php
|
---|
600 | * function to get suggestions for the misspelled word that the
|
---|
601 | * user has clicked on. It sets the status to "Searching...",
|
---|
602 | * hides the suggestions div, finds the x and y position of the
|
---|
603 | * span containing the misspelled word that user clicked on so
|
---|
604 | * the div can be displayed in the correct location, and then
|
---|
605 | * calls the showSuggestions php function with the misspelled word
|
---|
606 | * and the id of the span containing it.
|
---|
607 | *
|
---|
608 | * @param word The misspelled word that the user clicked on
|
---|
609 | * @param id The id of the span that contains the misspelled word
|
---|
610 | *************************************************************/
|
---|
611 | function showSuggestions(word, id)
|
---|
612 | {
|
---|
613 | with(currObj);
|
---|
614 | if(currObj.config['useIcons'])
|
---|
615 | {
|
---|
616 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Searching...\" alt=\"Searching...\" border=\"0\" />";
|
---|
617 | }
|
---|
618 | else
|
---|
619 | {
|
---|
620 | currObj.statusSpan.innerHTML = "Searching...";
|
---|
621 | }
|
---|
622 | var x = findPosXById(id);
|
---|
623 | var y = findPosYById(id);
|
---|
624 |
|
---|
625 | var scrollPos = 0;
|
---|
626 | if(checkBrowser() != "ie")
|
---|
627 | {
|
---|
628 | scrollPos = currObj.spellingResultsDiv.scrollTop;
|
---|
629 | }
|
---|
630 |
|
---|
631 | if(spellingSuggestionsDiv)
|
---|
632 | {
|
---|
633 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
634 | }
|
---|
635 | spellingSuggestionsDiv = document.createElement('DIV');
|
---|
636 | spellingSuggestionsDiv.style.display = "none";
|
---|
637 | spellingSuggestionsDiv.className = 'suggestion_box';
|
---|
638 | spellingSuggestionsDiv.style.position = 'absolute';
|
---|
639 | spellingSuggestionsDiv.style.left = x + 'px';
|
---|
640 | spellingSuggestionsDiv.style.top = (y+16-scrollPos) + 'px';
|
---|
641 |
|
---|
642 | // Bah. There's got to be a better way to deal with this, but the click
|
---|
643 | // on a word to get suggestions starts up a race condition between
|
---|
644 | // showing and hiding the suggestion box, so we'll ignore the first
|
---|
645 | // click.
|
---|
646 | spellingSuggestionsDiv.ignoreNextClick = true;
|
---|
647 |
|
---|
648 | document.body.appendChild(spellingSuggestionsDiv);
|
---|
649 |
|
---|
650 | cp.call(currObj.config['spellUrl'], 'showSuggestions', showSuggestions_cb, word, id);
|
---|
651 | }; // end showSuggestions
|
---|
652 |
|
---|
653 |
|
---|
654 | /*************************************************************
|
---|
655 | * replaceWord
|
---|
656 | *
|
---|
657 | * The replaceWord function takes the id of the misspelled word
|
---|
658 | * that the user clicked on and replaces the innerHTML of that
|
---|
659 | * span with the new word that the user selects from the suggestion
|
---|
660 | * div. It hides the suggestions div and changes the color of
|
---|
661 | * the previously misspelled word to green to let the user know
|
---|
662 | * it has been changed. It then calls the switchText php function
|
---|
663 | * with the innerHTML of the div to update the text of the text box.
|
---|
664 | *
|
---|
665 | * @param id The id of the span that contains the word to be replaced
|
---|
666 | * @param newWord The word the user selected from the suggestions div
|
---|
667 | * to replace the misspelled word.
|
---|
668 | *************************************************************/
|
---|
669 | function replaceWord(id, newWord)
|
---|
670 | {
|
---|
671 | document.getElementById(id).innerHTML = trim(newWord);
|
---|
672 | if(spellingSuggestionsDiv)
|
---|
673 | {
|
---|
674 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
675 | spellingSuggestionsDiv = null;
|
---|
676 | }
|
---|
677 | document.getElementById(id).className = "corrected_word";
|
---|
678 | }; // end replaceWord
|
---|
679 |
|
---|
680 |
|
---|
681 | /*************************************************************
|
---|
682 | * switchText
|
---|
683 | *
|
---|
684 | * The switchText function is a funtion is called when the user
|
---|
685 | * clicks on resume editing (or submits the form). It calls the
|
---|
686 | * php function to switchText and uncomments the html and replaces
|
---|
687 | * breaks and everything. Here all the breaks that the user has
|
---|
688 | * typed are replaced with %u2026. Firefox does this goofy thing
|
---|
689 | * where it cleans up the display of your html, which adds in \n's
|
---|
690 | * where you don't want them. So I replace the user-entered returns
|
---|
691 | * with something unique so that I can rip out all the breaks that
|
---|
692 | * the browser might add and we don't want.
|
---|
693 | *************************************************************/
|
---|
694 | function switchText()
|
---|
695 | {
|
---|
696 | with(currObj);
|
---|
697 | var text = currObj.spellingResultsDiv.innerHTML;
|
---|
698 | text = text.replace(/<br *\/?>/gi, "~~~");
|
---|
699 | // Work around a cpaint/safari bug by prefixing an asterisk to the text so that the text is never completely empty
|
---|
700 | text = '*' + text;
|
---|
701 | cp.call(currObj.config['spellUrl'], 'switchText', switchText_cb, text);
|
---|
702 | }; // end switchText
|
---|
703 |
|
---|
704 |
|
---|
705 | /*************************************************************
|
---|
706 | * switchText_cb
|
---|
707 | *
|
---|
708 | * The switchText_cb function is a call back funtion that the
|
---|
709 | * switchText php function returns to. I replace all the %u2026's
|
---|
710 | * with returns. It then replaces the text in the text box with
|
---|
711 | * the corrected text fromt he div.
|
---|
712 | *
|
---|
713 | * @param new_string The corrected text from the div.
|
---|
714 | *
|
---|
715 | *************************************************************/
|
---|
716 | function switchText_cb(new_string)
|
---|
717 | {
|
---|
718 | with(currObj);
|
---|
719 | new_string = new_string.replace(/~~~/gi, "\n");
|
---|
720 |
|
---|
721 | // Remove the prefixed asterisk that was added in switchText().
|
---|
722 | new_string = new_string.substr(1);
|
---|
723 | currObj.objToCheck.style.display = "none";
|
---|
724 | var ifr= currObj.objToCheck;
|
---|
725 | if(ifr.contentWindow)
|
---|
726 | ifr=ifr.contentWindow.document;
|
---|
727 | else
|
---|
728 | ifr=ifr.contentDocument;
|
---|
729 | alert(ifr.body.innerHTML);
|
---|
730 | var texto = ifr.body.innerHTML;
|
---|
731 | ifr.body.innerHTML = new_string;
|
---|
732 | currObj.objToCheck.disabled = false;
|
---|
733 | if(currObj.spellingResultsDiv)
|
---|
734 | {
|
---|
735 | currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
|
---|
736 | currObj.spellingResultsDiv = null;
|
---|
737 | }
|
---|
738 | currObj.objToCheck.style.display = "block";
|
---|
739 | currObj.resetAction();
|
---|
740 | }; // end switchText_cb
|
---|
741 |
|
---|
742 |
|
---|
743 | /*************************************************************
|
---|
744 | * resumeEditing
|
---|
745 | *
|
---|
746 | * The resumeEditing function is called when the user is in the
|
---|
747 | * correction mode and wants to return to the editing mode. It
|
---|
748 | * hides the results div and the suggestions div, then enables
|
---|
749 | * the text box and unhides the text box. It also calls
|
---|
750 | * resetAction() to reset the status message.
|
---|
751 | *************************************************************/
|
---|
752 | function resumeEditing()
|
---|
753 | {
|
---|
754 | with(currObj);
|
---|
755 | if(currObj.config['useIcons'])
|
---|
756 | {
|
---|
757 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\"><img src=\"images/page_white_edit.png\" width=\"16\" height=\"16\" title=\"Resume Editing\" alt=\"Resume Editing\" border=\"0\" /></a>";
|
---|
758 | }
|
---|
759 | else
|
---|
760 | {
|
---|
761 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\">Resume Editing</a>";
|
---|
762 | }
|
---|
763 | if(currObj.config['useIcons'])
|
---|
764 | {
|
---|
765 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Working...\" alt=\"Working...\" border=\"0\" />";
|
---|
766 | }
|
---|
767 | else
|
---|
768 | {
|
---|
769 | currObj.statusSpan.innerHTML = "Working...";
|
---|
770 | }
|
---|
771 |
|
---|
772 | if(spellingSuggestionsDiv)
|
---|
773 | {
|
---|
774 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
775 | spellingSuggestionsDiv = null;
|
---|
776 | }
|
---|
777 |
|
---|
778 | currObj.switchText();
|
---|
779 | }; // end resumeEditing
|
---|
780 |
|
---|
781 |
|
---|
782 | /*************************************************************
|
---|
783 | * resetAction
|
---|
784 | *
|
---|
785 | * The resetAction function just resets the status message to
|
---|
786 | * the default action of "Check Spelling".
|
---|
787 | *************************************************************/
|
---|
788 | function resetAction()
|
---|
789 | {
|
---|
790 | with(currObj);
|
---|
791 | if(currObj.config['useIcons'])
|
---|
792 | {
|
---|
793 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\"><img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Check Spelling & Preview\" alt=\"Check Spelling & Preview\" border=\"0\" /></a>";
|
---|
794 | }
|
---|
795 | else
|
---|
796 | {
|
---|
797 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Check Spelling & Preview</a>";
|
---|
798 | }
|
---|
799 |
|
---|
800 | currObj.statusSpan.innerHTML = "";
|
---|
801 | }; // end resetAction
|
---|
802 |
|
---|
803 |
|
---|
804 | /*************************************************************
|
---|
805 | * resetSpellChecker
|
---|
806 | *
|
---|
807 | * The resetSpellChecker function resets the entire spell checker
|
---|
808 | * to the defaults.
|
---|
809 | *************************************************************/
|
---|
810 | function resetSpellChecker()
|
---|
811 | {
|
---|
812 | with(currObj);
|
---|
813 | currObj.resetAction();
|
---|
814 |
|
---|
815 | currObj.objToCheck.value = "";
|
---|
816 | currObj.objToCheck.style.display = "block";
|
---|
817 | currObj.objToCheck.disabled = false;
|
---|
818 |
|
---|
819 | if(currObj.spellingResultsDiv)
|
---|
820 | {
|
---|
821 | currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
|
---|
822 | currObj.spellingResultsDiv = null;
|
---|
823 | }
|
---|
824 | if(spellingSuggestionsDiv)
|
---|
825 | {
|
---|
826 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
827 | spellingSuggestionsDiv = null;
|
---|
828 | }
|
---|
829 | currObj.statusSpan.style.display = "none";
|
---|
830 |
|
---|
831 | }; // end resetSpellChecker
|
---|
832 |
|
---|
833 |
|
---|
834 | /*************************************************************
|
---|
835 | * findPosX
|
---|
836 | *
|
---|
837 | * The findPosX function just finds the X offset of the top left
|
---|
838 | * corner of the object id it's given.
|
---|
839 | *
|
---|
840 | * @param object The id of the object that you want to find the
|
---|
841 | * upper left X coordinate of.
|
---|
842 | * @return int The X coordinate of the object
|
---|
843 | *************************************************************/
|
---|
844 | function findPosXById(object)
|
---|
845 | {
|
---|
846 | var curleft = 0;
|
---|
847 | var obj = document.getElementById(object);
|
---|
848 | if(obj.offsetParent)
|
---|
849 | {
|
---|
850 | while(obj.offsetParent)
|
---|
851 | {
|
---|
852 | curleft += obj.offsetLeft - obj.scrollLeft;
|
---|
853 | obj = obj.offsetParent;
|
---|
854 | }
|
---|
855 | }
|
---|
856 | else if(obj.x)
|
---|
857 | {
|
---|
858 | curleft += obj.x;
|
---|
859 | }
|
---|
860 | return curleft;
|
---|
861 | }; // end findPosX
|
---|
862 |
|
---|
863 |
|
---|
864 | /*************************************************************
|
---|
865 | * findPosY
|
---|
866 | *
|
---|
867 | * The findPosY function just finds the Y offset of the top left
|
---|
868 | * corner of the object id it's given.
|
---|
869 | *
|
---|
870 | * @param object The id of the object that you want to find the
|
---|
871 | * upper left Y coordinate of.
|
---|
872 | * @return int The Y coordinate of the object
|
---|
873 | *************************************************************/
|
---|
874 | function findPosYById(object)
|
---|
875 | {
|
---|
876 | var curtop = 0;var curtop = 0;
|
---|
877 | var obj = document.getElementById(object);
|
---|
878 | if(obj.offsetParent)
|
---|
879 | {
|
---|
880 | while(obj.offsetParent)
|
---|
881 | {
|
---|
882 | curtop += obj.offsetTop - obj.scrollTop;
|
---|
883 | obj = obj.offsetParent;
|
---|
884 | }
|
---|
885 | }
|
---|
886 | else if(obj.y)
|
---|
887 | {
|
---|
888 | curtop += obj.y;
|
---|
889 | }
|
---|
890 | return curtop;
|
---|
891 | }; // end findPosY
|
---|
892 |
|
---|
893 |
|
---|
894 | /*************************************************************
|
---|
895 | * trim
|
---|
896 | *
|
---|
897 | * Trims white space from a string.
|
---|
898 | *
|
---|
899 | * @param s The string you want to trim.
|
---|
900 | * @return string The trimmed string.
|
---|
901 | *************************************************************/
|
---|
902 | function trim(s)
|
---|
903 | {
|
---|
904 | while(s.substring(0,1) == ' ')
|
---|
905 | {
|
---|
906 | s = s.substring(1,s.length);
|
---|
907 | }
|
---|
908 | while(s.substring(s.length-1,s.length) == ' ')
|
---|
909 | {
|
---|
910 | s = s.substring(0,s.length-1);
|
---|
911 | }
|
---|
912 | return s;
|
---|
913 | }; // end trim |
---|