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 | var positionEditor;
|
---|
44 | var areaEditor;
|
---|
45 | var abaEditor;
|
---|
46 |
|
---|
47 | cp = new cpaint();
|
---|
48 | cp.set_transfer_mode('post');
|
---|
49 | cp.set_response_type('text');
|
---|
50 |
|
---|
51 | function beginSpellCheck(){
|
---|
52 |
|
---|
53 | position = "body_position_" + currentTab;
|
---|
54 | area = "body_" + currentTab;
|
---|
55 | aba = currentTab;
|
---|
56 | spellingSuggestionsDiv = null;
|
---|
57 | positionEditor = position;
|
---|
58 | areaEditor = area;
|
---|
59 | abaEditor = aba;
|
---|
60 |
|
---|
61 | if(window.onload)
|
---|
62 | {
|
---|
63 | window.onload = new setupSpellCheckers();
|
---|
64 |
|
---|
65 | }
|
---|
66 | else
|
---|
67 | {
|
---|
68 | window.onload = new setupSpellCheckers();
|
---|
69 | }
|
---|
70 |
|
---|
71 | } // close BeginSpellCheck
|
---|
72 |
|
---|
73 |
|
---|
74 |
|
---|
75 |
|
---|
76 | /*************************************************************
|
---|
77 | * function setupSpellCheckers()
|
---|
78 | *
|
---|
79 | * This function obtain the iframe of the page (that is the area editor)
|
---|
80 | * and then adds a spellchecker to the iframe.
|
---|
81 | *************************************************************/
|
---|
82 | function setupSpellCheckers()
|
---|
83 | {
|
---|
84 | var ifr = document.getElementsByTagName('iframe')[0];
|
---|
85 | //alert(area);
|
---|
86 | //var ifr = document.getElementById(area);
|
---|
87 | var numSpellCheckers = abaEditor;
|
---|
88 |
|
---|
89 | if(ifr.contentWindow)
|
---|
90 | ifr=ifr.contentWindow.document;
|
---|
91 | else
|
---|
92 | ifr=ifr.contentDocument;
|
---|
93 |
|
---|
94 | if (document.addEventListener) {
|
---|
95 | ifr.addEventListener("click", checkClickLocation , true); //add the click event
|
---|
96 | }
|
---|
97 | else {
|
---|
98 | ifr.attachEvent("onclick", checkClickLocation); //add the click event
|
---|
99 |
|
---|
100 | }
|
---|
101 |
|
---|
102 |
|
---|
103 | var texto = ifr.body.innerHTML;
|
---|
104 |
|
---|
105 | var tempWidth = "99%";
|
---|
106 | var tempHeight = "300";
|
---|
107 |
|
---|
108 | eval('spellCheckers' + numSpellCheckers + '= new ajaxSpell("spellCheckers' + numSpellCheckers + '", tempWidth, tempHeight, "spell_checker/spell_checker.php", positionEditor, "Nome", areaEditor, "Titulo", texto);');
|
---|
109 |
|
---|
110 | }; // end setInit
|
---|
111 |
|
---|
112 | function setupSpellChecker(){
|
---|
113 |
|
---|
114 |
|
---|
115 | currObj = this;
|
---|
116 |
|
---|
117 | currObj.config = new Array();
|
---|
118 |
|
---|
119 | currObj.config['divId'] = "body_position_" + currentTab;
|
---|
120 | currObj.config['width'] = "99%";
|
---|
121 | currObj.config['id'] = "body_" + currentTab;
|
---|
122 |
|
---|
123 | spellContainer = document.createElement('DIV');
|
---|
124 | spellContainer.id = currObj.config['divId'];
|
---|
125 | spellContainer.className = 'spell_container';
|
---|
126 | spellContainer.style.width = currObj.config['width'];
|
---|
127 |
|
---|
128 | //oldElement = document.getElementById(currObj.config['id']);
|
---|
129 |
|
---|
130 | //oldElement.parentNode.replaceChild(spellContainer, oldElement);
|
---|
131 |
|
---|
132 | //generate the div to hold the spell checker controls
|
---|
133 | currObj.controlPanelDiv = document.createElement('DIV');
|
---|
134 | currObj.controlPanelDiv.className = 'control_panel';
|
---|
135 | currObj.controlPanelDiv.id = 'control_panel_' + currentTab;
|
---|
136 | document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv);
|
---|
137 |
|
---|
138 | //if (document.getElementById(currObj.config['id']))
|
---|
139 | // alert("OK");
|
---|
140 |
|
---|
141 | //document.getElementById(currObj.config['divId']).insertBefore(currObj.controlPanelDiv, document.getElementById(currObj.config['id']));
|
---|
142 | //currObj.controlPanelDiv.parentNode.insertBefore(currObj.controlPanelDiv, document.getElementById(currObj.config["id"]));
|
---|
143 |
|
---|
144 |
|
---|
145 |
|
---|
146 |
|
---|
147 |
|
---|
148 | //the span that toggles between spell checking and editing
|
---|
149 | currObj.actionSpan = document.createElement('SPAN');
|
---|
150 | currObj.actionSpan.className = "action";
|
---|
151 | currObj.actionSpan.id = "action";
|
---|
152 | /*if(currObj.config['useIcons'])
|
---|
153 | {
|
---|
154 | 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=\"Verificar Ortografia\" alt=\"Verificar Ortografia \" border=\"0\" /></a>";
|
---|
155 | }
|
---|
156 | else
|
---|
157 | {
|
---|
158 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Verificar Ortografia</a>";
|
---|
159 | }*/
|
---|
160 | currObj.controlPanelDiv.appendChild(currObj.actionSpan);
|
---|
161 |
|
---|
162 | //the span that lets the user know of the status of the spell checker
|
---|
163 | currObj.statusSpan = document.createElement('SPAN');
|
---|
164 | currObj.statusSpan.className = "status";
|
---|
165 | currObj.statusSpan.id = "status";
|
---|
166 | currObj.statusSpan.innerHTML = "";
|
---|
167 | currObj.controlPanelDiv.style.display = "none";
|
---|
168 | currObj.controlPanelDiv.appendChild(currObj.statusSpan);
|
---|
169 |
|
---|
170 |
|
---|
171 | //document.getElementById(currObj.config['divId']).insertBefore(currObj.controlPanelDiv, document.getElementById(currObj.config['id'])); //test
|
---|
172 |
|
---|
173 | //document.getElementById("body_position_" + currentTab).insertBefore(currObj.controlPanelDiv, document.getElementById("viewsource_rt_checkbox"));
|
---|
174 | //the textarea to be spell checked
|
---|
175 | //oldElement.value = currObj.config['value'];
|
---|
176 | //document.getElementById(currObj.config['divId']).appendChild(oldElement);
|
---|
177 | currObj.controlPanelDiv.parentNode.insertBefore(currObj.controlPanelDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab));
|
---|
178 | //currObj.controlPanelDiv.parentNode.insertBefore(currObj.controlPanelDiv, document.getElementById(currObj.config["id"]));
|
---|
179 |
|
---|
180 |
|
---|
181 | }
|
---|
182 |
|
---|
183 |
|
---|
184 | /*************************************************************
|
---|
185 | * ajaxSpell(varName, width, height, spellUrl, divId, name, id)
|
---|
186 | *
|
---|
187 | * This is the constructor that creates a new ajaxSpell object.
|
---|
188 | * All of it is dynamically generated so the user doesn't have
|
---|
189 | * to add a bunch of crap to their site.
|
---|
190 | *
|
---|
191 | * @param varName The name of the variable that the object is
|
---|
192 | * assigned to (must be unique and the same as the variable)
|
---|
193 | * @param width The width of the spell checker
|
---|
194 | * @param height The height of the spell checker
|
---|
195 | * @param spellUrl The url of the spell_checker.php code
|
---|
196 | * @param divId The id of the div that the spell checker is
|
---|
197 | * contained in (must be unique)
|
---|
198 | * @param name The name of the textarea form element
|
---|
199 | * @param id The id of the spell checker textarea (must be unique)
|
---|
200 | *************************************************************/
|
---|
201 | function ajaxSpell(varName, width, height, spellUrl, divId, name, id, title, value)
|
---|
202 | {
|
---|
203 |
|
---|
204 | currObj = this;
|
---|
205 |
|
---|
206 |
|
---|
207 | currObj.config = new Array(); //the array of configuration options
|
---|
208 | currObj.config['varName'] = varName; //the name of the variable that this instance is stored in
|
---|
209 | currObj.config['width'] = width; //the width of the textarea
|
---|
210 | currObj.config['height'] = height; //the height of the textarea
|
---|
211 | currObj.config['spellUrl'] = spellUrl; //url to spell checker php code (spell_checker.php by default);
|
---|
212 | currObj.config['divId'] = divId; //the id of the div that the spell checker element is in
|
---|
213 | currObj.config['name'] = name; //what you want the form element's name to be
|
---|
214 | currObj.config['id'] = id; //the unique id of the spell_checker textarea
|
---|
215 | currObj.config['title'] = title; //the title (specifies whether to use icons or not);
|
---|
216 | currObj.config['value'] = value; //the value of the text box when the page was loaded
|
---|
217 | currObj.config['aba'] = abaEditor;
|
---|
218 |
|
---|
219 | //currObj.config['value'] = currObj.config['value'].replace(/<br *\/?>/gi, "\n"); // Comment from the original by Nathalie
|
---|
220 |
|
---|
221 | currObj.config['useIcons'] = false;
|
---|
222 |
|
---|
223 | if(currObj.config['title'] == "spellcheck_icons")
|
---|
224 | {
|
---|
225 | currObj.config['useIcons'] = true;
|
---|
226 | }
|
---|
227 |
|
---|
228 | /*spellContainer = document.createElement('DIV');
|
---|
229 | spellContainer.id = currObj.config['divId'];
|
---|
230 | spellContainer.className = 'spell_container';
|
---|
231 | spellContainer.style.width = currObj.config['width'];
|
---|
232 |
|
---|
233 | oldElement = document.getElementById(currObj.config['id']);
|
---|
234 |
|
---|
235 | //oldElement.parentNode.replaceChild(spellContainer, oldElement);
|
---|
236 |
|
---|
237 | //generate the div to hold the spell checker controls
|
---|
238 | currObj.controlPanelDiv = document.createElement('DIV');
|
---|
239 | currObj.controlPanelDiv.className = 'control_panel';
|
---|
240 | document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv);
|
---|
241 |
|
---|
242 | //the span that toggles between spell checking and editing
|
---|
243 | currObj.actionSpan = document.createElement('SPAN');
|
---|
244 | currObj.actionSpan.className = "action";
|
---|
245 | currObj.actionSpan.id = "action";
|
---|
246 | /*if(currObj.config['useIcons'])
|
---|
247 | {
|
---|
248 | 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=\"Verificar Ortografia\" alt=\"Verificar Ortografia \" border=\"0\" /></a>";
|
---|
249 | }
|
---|
250 | else
|
---|
251 | {
|
---|
252 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Verificar Ortografia</a>";
|
---|
253 | }*/
|
---|
254 | /*currObj.controlPanelDiv.appendChild(currObj.actionSpan);
|
---|
255 |
|
---|
256 | //the span that lets the user know of the status of the spell checker
|
---|
257 | currObj.statusSpan = document.createElement('SPAN');
|
---|
258 | currObj.statusSpan.className = "status";
|
---|
259 | currObj.statusSpan.id = "status";
|
---|
260 | currObj.statusSpan.innerHTML = "";
|
---|
261 | currObj.controlPanelDiv.appendChild(currObj.statusSpan);
|
---|
262 |
|
---|
263 | //document.getElementById("body_position_" + currentTab).insertBefore(currObj.controlPanelDiv, document.getElementById("viewsource_rt_checkbox"));
|
---|
264 | //the textarea to be spell checked
|
---|
265 | oldElement.value = currObj.config['value'];
|
---|
266 | //document.getElementById(currObj.config['divId']).appendChild(oldElement);
|
---|
267 | currObj.controlPanelDiv.parentNode.insertBefore(currObj.controlPanelDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab));
|
---|
268 | */
|
---|
269 |
|
---|
270 | currObj.controlPanelDiv = document.getElementById('control_panel_' + currentTab);
|
---|
271 | currObj.statusSpan = currObj.controlPanelDiv.childNodes[1];
|
---|
272 | currObj.actionSpan = currObj.controlPanelDiv.childNodes[0] ;
|
---|
273 |
|
---|
274 | currObj.objToCheck = document.getElementById(currObj.config['id']); //the actual object we're spell checking
|
---|
275 | currObj.spellingResultsDiv = null; // Auto-generated results div
|
---|
276 |
|
---|
277 | //prototypes for the ajaxSpell objects
|
---|
278 | ajaxSpell.prototype.spellCheck = spellCheck;
|
---|
279 | ajaxSpell.prototype.spellCheck_cb = spellCheck_cb;
|
---|
280 | ajaxSpell.prototype.showSuggestions = showSuggestions;
|
---|
281 | ajaxSpell.prototype.showSuggestions_cb = showSuggestions_cb;
|
---|
282 | ajaxSpell.prototype.replaceWord = replaceWord;
|
---|
283 | ajaxSpell.prototype.switchText = switchText;
|
---|
284 | ajaxSpell.prototype.switchText_cb = switchText_cb;
|
---|
285 | ajaxSpell.prototype.resumeEditing = resumeEditing;
|
---|
286 | ajaxSpell.prototype.resetSpellChecker = resetSpellChecker;
|
---|
287 | ajaxSpell.prototype.resetAction = resetAction;
|
---|
288 | ajaxSpell.prototype.ignore = ignore;
|
---|
289 |
|
---|
290 |
|
---|
291 | //set the contentEditable to false for IE browsers
|
---|
292 | var iframe= currObj.objToCheck;
|
---|
293 | if(iframe.contentWindow)
|
---|
294 | iframe=iframe.contentWindow.document;
|
---|
295 | else
|
---|
296 | iframe=iframe.contentDocument;
|
---|
297 |
|
---|
298 | var browser = checkBrowser();
|
---|
299 | if (browser == "ie"){
|
---|
300 | iframe.body.contentEditable="false" ;
|
---|
301 |
|
---|
302 | }
|
---|
303 |
|
---|
304 |
|
---|
305 |
|
---|
306 |
|
---|
307 | }; // end ajaxSpell
|
---|
308 |
|
---|
309 |
|
---|
310 | /*************************************************************
|
---|
311 | * setCurrentObject
|
---|
312 | *
|
---|
313 | * This sets the current object to be the spell checker that
|
---|
314 | * the user is currently using.
|
---|
315 | *
|
---|
316 | * @param obj The spell checker currently being used
|
---|
317 | *************************************************************/
|
---|
318 | function setCurrentObject(obj)
|
---|
319 | {
|
---|
320 | currObj = obj;
|
---|
321 |
|
---|
322 |
|
---|
323 | }; // end setCurrentObject
|
---|
324 |
|
---|
325 |
|
---|
326 | /*************************************************************
|
---|
327 | * showMenu
|
---|
328 | *
|
---|
329 | * This function is associated with the click event
|
---|
330 | * of all the span tags with correctd_word class.
|
---|
331 | *
|
---|
332 | *************************************************************/
|
---|
333 | function showMenu(){
|
---|
334 | var iframe= currObj.objToCheck;
|
---|
335 | if(iframe.contentWindow)
|
---|
336 | iframe=iframe.contentWindow.document;
|
---|
337 | else
|
---|
338 | iframe=iframe.contentDocument;
|
---|
339 |
|
---|
340 | var browser = checkBrowser();
|
---|
341 | if (browser == "ie"){
|
---|
342 | iframe.body.contentEditable="true" ;
|
---|
343 | var ifr= currObj.objToCheck;
|
---|
344 | if(!e){var e = ifr.contentWindow.event;}
|
---|
345 | if(!e.target){e.target = e.srcElement;}
|
---|
346 | var evento = e.target.onclick.toString();
|
---|
347 | }
|
---|
348 | else {
|
---|
349 | iframe.designMode = "off";
|
---|
350 | iframe.designMode = "on";
|
---|
351 | var evento = this.onclick.toString();
|
---|
352 | }
|
---|
353 | evento = evento.replace("function onclick(event) {", "");
|
---|
354 | evento = evento.replace("}", "");
|
---|
355 | var array_func = evento.split(";");
|
---|
356 | eval(array_func[0]);
|
---|
357 | eval(array_func[1]);
|
---|
358 | return false;
|
---|
359 |
|
---|
360 |
|
---|
361 | //
|
---|
362 | }
|
---|
363 |
|
---|
364 | /*************************************************************
|
---|
365 | * replaceMenu
|
---|
366 | *
|
---|
367 | * This function is associated with the click event
|
---|
368 | * of all the div tags with suggestion class.
|
---|
369 | *
|
---|
370 | *************************************************************/
|
---|
371 | function replaceMenu(){
|
---|
372 | var iframe= currObj.objToCheck;
|
---|
373 | if(iframe.contentWindow)
|
---|
374 | iframe=iframe.contentWindow.document;
|
---|
375 | else
|
---|
376 | iframe=iframe.contentDocument;
|
---|
377 | var browser = checkBrowser();
|
---|
378 | if (browser == "ie"){
|
---|
379 | iframe.body.contentEditable="false" ;
|
---|
380 | var ifr= currObj.objToCheck;
|
---|
381 | if(!e){var e = ifr.contentWindow.event;}
|
---|
382 | if(!e.target){e.target = e.srcElement;}
|
---|
383 | var evento = e.target.onclick.toString();
|
---|
384 | }
|
---|
385 | else {
|
---|
386 | iframe.designMode = "off";
|
---|
387 | iframe.designMode = "on";
|
---|
388 | var evento = this.onclick.toString();
|
---|
389 | }
|
---|
390 | evento = evento.replace("function onclick(event) {", "");
|
---|
391 | evento = evento.replace("}", "");
|
---|
392 | var array_func = evento.split(";");
|
---|
393 | eval(array_func[0]);
|
---|
394 | return false;
|
---|
395 | }
|
---|
396 |
|
---|
397 |
|
---|
398 |
|
---|
399 | /*************************************************************
|
---|
400 | * spellCheck_cb
|
---|
401 | *
|
---|
402 | * This is the callback function that the spellCheck php function
|
---|
403 | * returns the spell checked data to. It sets the results div
|
---|
404 | * to contain the markedup misspelled data and changes the status
|
---|
405 | * message. It also sets the width and height of the results
|
---|
406 | * div to match the element that's being checked.
|
---|
407 | * If there are no misspellings then new_data is the empty
|
---|
408 | * string and the status is set to "No Misspellings Found".
|
---|
409 | *
|
---|
410 | * @param new_data The marked up misspelled data returned from php.
|
---|
411 | *************************************************************/
|
---|
412 | function spellCheck_cb(new_data)
|
---|
413 | {
|
---|
414 |
|
---|
415 | var ifr= currObj.objToCheck;
|
---|
416 | if(ifr.contentWindow)
|
---|
417 | ifr=ifr.contentWindow.document;
|
---|
418 | else
|
---|
419 | ifr=ifr.contentDocument;
|
---|
420 |
|
---|
421 |
|
---|
422 | with(currObj);
|
---|
423 |
|
---|
424 | new_data = new_data.toString();
|
---|
425 | var isThereAMisspelling = new_data.charAt(0);
|
---|
426 | new_data = new_data.substring(1);
|
---|
427 |
|
---|
428 |
|
---|
429 |
|
---|
430 | if(currObj.spellingResultsDiv)
|
---|
431 | {
|
---|
432 |
|
---|
433 | ifr.removeChild(currObj.spellingResultsDiv.id);
|
---|
434 |
|
---|
435 | }
|
---|
436 |
|
---|
437 |
|
---|
438 | var ifr= currObj.objToCheck;
|
---|
439 | if(ifr.contentWindow)
|
---|
440 | ifr=ifr.contentWindow.document;
|
---|
441 | else
|
---|
442 | ifr=ifr.contentDocument;
|
---|
443 | ifr.body.innerHTML = "";
|
---|
444 | var cssLink = ifr.createElement("link");
|
---|
445 | cssLink.href = "spell_checker/css/spell_checker.css";
|
---|
446 | cssLink .rel = "stylesheet";
|
---|
447 | cssLink .type = "text/css";
|
---|
448 | //Testes nathalie - substituido
|
---|
449 | currObj.spellingResultsDiv = ifr.createElement('span');
|
---|
450 | currObj.spellingResultsDiv.className = 'edit_box';
|
---|
451 | currObj.spellingResultsDiv.id = 'edit_box'; //Added the id property - By Nathalie
|
---|
452 | currObj.spellingResultsDiv.style.width = "99%";//the width of the textarea
|
---|
453 | currObj.spellingResultsDiv.style.height = 300; // = height; //currObj.objToCheck.style.height;
|
---|
454 | currObj.spellingResultsDiv.innerHTML = new_data;
|
---|
455 | currObj.spellingResultsDiv.border = 0;
|
---|
456 | //currObj.spellingResultsDiv.style.display = "none";
|
---|
457 | //currObj.objToCheck.style.display = "none";
|
---|
458 | currObj.statusSpan.innerHTML = "";
|
---|
459 |
|
---|
460 | //ifr.body.appendChild(currObj.spellingResultsDiv);
|
---|
461 | //alert(new_data);
|
---|
462 | ifr.body.innerHTML = "";
|
---|
463 | //alert(new_data);
|
---|
464 | //new_data = new_data.replace(/ </g ," <");
|
---|
465 | //alert(new_data);
|
---|
466 |
|
---|
467 | ifr.body.innerHTML = new_data;
|
---|
468 | //alert(ifr.body.innerHTML);
|
---|
469 | ifr.body.appendChild(cssLink);
|
---|
470 |
|
---|
471 |
|
---|
472 | // Obtain all the span tags which have highlight className
|
---|
473 | // and add the eventListener for the click - This event shows the suggestions menu
|
---|
474 | var nodeArray = ifr.getElementsByTagName("span");
|
---|
475 | var totArray = nodeArray.length;
|
---|
476 | for (var i = 0 ; i < totArray ; i++) {
|
---|
477 | var node = nodeArray[i];
|
---|
478 | if (node.className == "highlight") {
|
---|
479 | if (document.addEventListener) {
|
---|
480 | ifr.getElementsByTagName("span")[i].addEventListener("click", showMenu , true);
|
---|
481 | ifr.getElementsByTagName("span")[i].contentEditable="false" ;
|
---|
482 | }
|
---|
483 | else {
|
---|
484 | ifr.getElementsByTagName("span")[i].attachEvent("onclick", showMenu );
|
---|
485 | ifr.getElementsByTagName("span")[i].contentEditable="false" ;
|
---|
486 | }
|
---|
487 |
|
---|
488 | }
|
---|
489 | }
|
---|
490 |
|
---|
491 |
|
---|
492 | currObj.statusSpan.innerHTML = "";
|
---|
493 |
|
---|
494 |
|
---|
495 | if(currObj.config['useIcons'])
|
---|
496 | {
|
---|
497 | 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=\"Continuar Editando\" alt=\"Continuar Editando\" border=\"0\" /></a>";
|
---|
498 | }
|
---|
499 | else
|
---|
500 | {
|
---|
501 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".resumeEditing();\">Continuar Editando </a>";
|
---|
502 | }
|
---|
503 |
|
---|
504 | if(isThereAMisspelling != "1")
|
---|
505 | {
|
---|
506 | if(currObj.config['useIcons'])
|
---|
507 | {
|
---|
508 | currObj.statusSpan.innerHTML = "<img src=\"images/accept.png\" width=\"16\" height=\"16\" title=\"Nenhum Erro Encontrado\" alt=\"Nenhum Erro Encontrado\" border=\"0\" />";
|
---|
509 | }
|
---|
510 | else
|
---|
511 | {
|
---|
512 | currObj.statusSpan.innerHTML = "Nenhum Erro Encontrado";
|
---|
513 | }
|
---|
514 | currObj.objToCheck.disabled = false;
|
---|
515 | }
|
---|
516 |
|
---|
517 | currObj.controlPanelDiv.style.display = "block";
|
---|
518 |
|
---|
519 | }; // end spellCheck_cb
|
---|
520 |
|
---|
521 |
|
---|
522 | /*************************************************************
|
---|
523 | * spellCheck()
|
---|
524 | *
|
---|
525 | * The spellCheck javascript function sends the text entered by
|
---|
526 | * the user in the text box to php to be spell checked. It also
|
---|
527 | * sets the status message to "Checking..." because it's currently
|
---|
528 | * checking the spelling.
|
---|
529 | *************************************************************/
|
---|
530 | function spellCheck() {
|
---|
531 | // adicionado nathalie
|
---|
532 | /* with(currObj);
|
---|
533 | var query;
|
---|
534 |
|
---|
535 | if(currObj.spellingResultsDiv)
|
---|
536 | {
|
---|
537 | currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
|
---|
538 | currObj.spellingResultsDiv = null;
|
---|
539 | }
|
---|
540 |
|
---|
541 | if(currObj.config['useIcons'])
|
---|
542 | {
|
---|
543 | currObj.actionSpan.innerHTML = "<img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Verificar Ortografia\" alt=\"Verificar Ortografia\" border=\"0\" />";
|
---|
544 | }
|
---|
545 | else
|
---|
546 | {
|
---|
547 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\">Verificar Ortografia</a>";
|
---|
548 | }
|
---|
549 |
|
---|
550 | if(currObj.config['useIcons'])
|
---|
551 | {
|
---|
552 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Verificando Ortografia...\" alt=\"Verificando Ortografia...\" border=\"0\" />";
|
---|
553 | }
|
---|
554 | else
|
---|
555 | {
|
---|
556 | currObj.statusSpan.innerHTML = "Verificando Ortografia...";
|
---|
557 | }
|
---|
558 |
|
---|
559 | // Obtain the HTML content from iframe (edit area)
|
---|
560 | var ifr= currObj.objToCheck;
|
---|
561 | if(ifr.contentWindow)
|
---|
562 | ifr=ifr.contentWindow.document;
|
---|
563 | else
|
---|
564 | ifr=ifr.contentDocument;
|
---|
565 | var texto = ifr.body.innerHTML;
|
---|
566 |
|
---|
567 |
|
---|
568 | query = texto;
|
---|
569 | //query = currObj.objToCheck.value;
|
---|
570 |
|
---|
571 | //query = query.replace(/\r?\n/gi, "<br />"); // Commented from the original by Nathalie
|
---|
572 | query = query.replace(/\r?\n/gi, " "); // replace \n with " " - By Nathalie
|
---|
573 |
|
---|
574 |
|
---|
575 | cp.call(currObj.config['spellUrl'], 'spellCheck', spellCheck_cb, query, currObj.config['varName']);
|
---|
576 | */
|
---|
577 | //adicionado Paula
|
---|
578 | languageId = document.getElementById("selectLanguage");
|
---|
579 | languageId = languageId[document.getElementById("selectLanguage").selectedIndex].value;
|
---|
580 |
|
---|
581 | with(currObj);
|
---|
582 | var query;
|
---|
583 |
|
---|
584 | currObj.controlPanelDiv.style.display = "block";
|
---|
585 |
|
---|
586 | if(currObj.spellingResultsDiv)
|
---|
587 | {
|
---|
588 | currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);
|
---|
589 | currObj.spellingResultsDiv = null;
|
---|
590 | }
|
---|
591 |
|
---|
592 | /*if(currObj.config['useIcons'])
|
---|
593 | {
|
---|
594 | currObj.actionSpan.innerHTML = "<img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Verificar Ortografia\" alt=\"Verificar Ortografia\" border=\"0\" />";
|
---|
595 | }
|
---|
596 | else
|
---|
597 | {
|
---|
598 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\">Verificar Ortografia</a>";
|
---|
599 | }*/
|
---|
600 |
|
---|
601 | /*if(currObj.config['useIcons'])
|
---|
602 | {
|
---|
603 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Verificando Ortografia...\" alt=\"Verificando Ortografia...\" border=\"0\" />";
|
---|
604 | }
|
---|
605 | else
|
---|
606 | {
|
---|
607 | currObj.statusSpan.innerHTML = "Verificando Ortografia...";
|
---|
608 | }*/
|
---|
609 |
|
---|
610 |
|
---|
611 | // Obtain the HTML content from iframe (edit area)
|
---|
612 | var ifr= currObj.objToCheck;
|
---|
613 | if(ifr.contentWindow)
|
---|
614 | ifr=ifr.contentWindow.document;
|
---|
615 | else
|
---|
616 | ifr=ifr.contentDocument;
|
---|
617 | var texto = ifr.body.innerHTML;
|
---|
618 |
|
---|
619 | query = texto;
|
---|
620 | //query = currObj.objToCheck.value;
|
---|
621 |
|
---|
622 | //query = query.replace(/\r?\n/gi, "<br />"); // Commented from the original by Nathalie
|
---|
623 | query = query.replace(/\r?\n/gi, " "); // replace \n with " " - By Nathalie
|
---|
624 |
|
---|
625 | cp.call(currObj.config['spellUrl'], 'spellCheck', spellCheck_cb, query, currObj.config['varName'], languageId);
|
---|
626 |
|
---|
627 | }; // end spellcheck
|
---|
628 |
|
---|
629 |
|
---|
630 |
|
---|
631 | /*************************************************************
|
---|
632 | * addWord
|
---|
633 | *
|
---|
634 | * The addWord function adds a word to the custom dictionary
|
---|
635 | * file.
|
---|
636 | *
|
---|
637 | * @param id The id of the span that contains the word to be added
|
---|
638 | *************************************************************/
|
---|
639 | function addWord(id)
|
---|
640 | {
|
---|
641 | var wordToAdd = document.getElementById(id).innerHTML;
|
---|
642 |
|
---|
643 | with(currObj);
|
---|
644 |
|
---|
645 | if(spellingSuggestionsDiv)
|
---|
646 | {
|
---|
647 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
648 | spellingSuggestionsDiv = null;
|
---|
649 | }
|
---|
650 |
|
---|
651 | currObj.controlPanelDiv.style.display = "block";
|
---|
652 |
|
---|
653 | if(currObj.config['useIcons'])
|
---|
654 | {
|
---|
655 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Adding Word...\" alt=\"Adding Word...\" border=\"0\" />";
|
---|
656 | }
|
---|
657 | else
|
---|
658 | {
|
---|
659 | currObj.statusSpan.innerHTML = "Adding Word...";
|
---|
660 | }
|
---|
661 |
|
---|
662 | cp.call(currObj.config['spellUrl'], 'addWord', addWord_cb, wordToAdd);
|
---|
663 |
|
---|
664 | }; // end addWord
|
---|
665 |
|
---|
666 | /*************************************************************
|
---|
667 | * addWord_cb
|
---|
668 | *
|
---|
669 | * The addWord_cb function is a callback function that
|
---|
670 | * PHP's addWord function returns to. It recieves the
|
---|
671 | * return status of the add to word to personal dictionary call.
|
---|
672 | * It hides the status item.
|
---|
673 | *
|
---|
674 | * @param returnedData The return code from PHP.
|
---|
675 | *************************************************************/
|
---|
676 | function addWord_cb(returnedData)
|
---|
677 | {
|
---|
678 | with(currObj);
|
---|
679 | currObj.statusSpan.innerHTML = "";
|
---|
680 | resumeEditing();
|
---|
681 | spellCheck();
|
---|
682 | }; // end addWord_cb
|
---|
683 |
|
---|
684 |
|
---|
685 |
|
---|
686 | /*************************************************************
|
---|
687 | * checkClickLocation(e)
|
---|
688 | *
|
---|
689 | * This function is called by the event listener when the user
|
---|
690 | * clicks on anything. It is used to close the suggestion div
|
---|
691 | * if the user clicks anywhere that's not inside the suggestion
|
---|
692 | * div. It just checks to see if the name of what the user clicks
|
---|
693 | * on is not "suggestions" then hides the div if it's not.
|
---|
694 | *
|
---|
695 | * @param e The event, in this case the user clicking somewhere on
|
---|
696 | * the page.
|
---|
697 | *************************************************************/
|
---|
698 | function checkClickLocation(e)
|
---|
699 | {
|
---|
700 |
|
---|
701 | var browser = checkBrowser();
|
---|
702 | if(spellingSuggestionsDiv)
|
---|
703 | {
|
---|
704 | // Bah. There's got to be a better way to deal with this, but the click
|
---|
705 | // on a word to get suggestions starts up a race condition between
|
---|
706 | // showing and hiding the suggestion box, so we'll ignore the first
|
---|
707 | // click. Problem with IE browser
|
---|
708 | if(spellingSuggestionsDiv.ignoreNextClick && browser == "ie"){
|
---|
709 | spellingSuggestionsDiv.ignoreNextClick = false;
|
---|
710 | }
|
---|
711 | else
|
---|
712 | {
|
---|
713 | var theTarget = getTarget(e);
|
---|
714 |
|
---|
715 | if(theTarget != spellingSuggestionsDiv)
|
---|
716 | {
|
---|
717 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
718 | spellingSuggestionsDiv = null;
|
---|
719 |
|
---|
720 | if (browser == "ie"){
|
---|
721 | var iframe= currObj.objToCheck;
|
---|
722 | if(iframe.contentWindow)
|
---|
723 | iframe=iframe.contentWindow.document;
|
---|
724 | else
|
---|
725 | iframe=iframe.contentDocument;
|
---|
726 | iframe.body.contentEditable="false" ;
|
---|
727 | }
|
---|
728 | }
|
---|
729 | }
|
---|
730 | }
|
---|
731 |
|
---|
732 | return true; // Allow other handlers to continue.
|
---|
733 | }; //end checkClickLocation
|
---|
734 |
|
---|
735 |
|
---|
736 | /*************************************************************
|
---|
737 | * getTarget
|
---|
738 | *
|
---|
739 | * The get target function gets the correct target of the event.
|
---|
740 | * This function is required because IE handles the events in
|
---|
741 | * a different (wrong) manner than the rest of the browsers.
|
---|
742 | *
|
---|
743 | * @param e The target, in this case the user clicking somewhere on
|
---|
744 | * the page.
|
---|
745 | *
|
---|
746 | *************************************************************/
|
---|
747 | function getTarget(e)
|
---|
748 | {
|
---|
749 |
|
---|
750 | var value;
|
---|
751 | if(checkBrowser() == "ie")
|
---|
752 | {
|
---|
753 | if(!e){var e = ifr.contentWindow.event;}
|
---|
754 | if(!e.target){value = e.srcElement;}
|
---|
755 |
|
---|
756 | }
|
---|
757 | else
|
---|
758 | {
|
---|
759 | value = e.target;
|
---|
760 | }
|
---|
761 | return value;
|
---|
762 | }; //end getTarget
|
---|
763 |
|
---|
764 |
|
---|
765 | /*************************************************************
|
---|
766 | * checkBrowser()
|
---|
767 | *
|
---|
768 | * The checkBrowser function simply checks to see what browser
|
---|
769 | * the user is using and returns a string containing the browser
|
---|
770 | * type.
|
---|
771 | *
|
---|
772 | * @return string The browser type
|
---|
773 | *************************************************************/
|
---|
774 | function checkBrowser()
|
---|
775 | {
|
---|
776 | var theAgent = navigator.userAgent.toLowerCase();
|
---|
777 | if(theAgent.indexOf("msie") != -1)
|
---|
778 | {
|
---|
779 | if(theAgent.indexOf("opera") != -1)
|
---|
780 | {
|
---|
781 | return "opera";
|
---|
782 | }
|
---|
783 | else
|
---|
784 | {
|
---|
785 | return "ie";
|
---|
786 | }
|
---|
787 | }
|
---|
788 | else if(theAgent.indexOf("netscape") != -1)
|
---|
789 | {
|
---|
790 | return "netscape";
|
---|
791 | }
|
---|
792 | else if(theAgent.indexOf("firefox") != -1)
|
---|
793 | {
|
---|
794 | return "firefox";
|
---|
795 | }
|
---|
796 | else if(theAgent.indexOf("mozilla/5.0") != -1)
|
---|
797 | {
|
---|
798 | return "mozilla";
|
---|
799 | }
|
---|
800 | else if(theAgent.indexOf("\/") != -1)
|
---|
801 | {
|
---|
802 | if(theAgent.substr(0,theAgent.indexOf('\/')) != 'mozilla')
|
---|
803 | {
|
---|
804 | return navigator.userAgent.substr(0,theAgent.indexOf('\/'));
|
---|
805 | }
|
---|
806 | else
|
---|
807 | {
|
---|
808 | return "netscape";
|
---|
809 | }
|
---|
810 | }
|
---|
811 | else if(theAgent.indexOf(' ') != -1)
|
---|
812 | {
|
---|
813 | return navigator.userAgent.substr(0,theAgent.indexOf(' '));
|
---|
814 | }
|
---|
815 | else
|
---|
816 | {
|
---|
817 | return navigator.userAgent;
|
---|
818 | }
|
---|
819 | }; // end checkBrowser
|
---|
820 |
|
---|
821 |
|
---|
822 | /*************************************************************
|
---|
823 | * showSuggestions_cb
|
---|
824 | *
|
---|
825 | * The showSuggestions_cb function is a callback function that
|
---|
826 | * php's showSuggestions function returns to. It sets the
|
---|
827 | * suggestions table to contain the new data and then displays
|
---|
828 | * the suggestions div. It also adds the event listener - click -
|
---|
829 | * for all the suggestions tags and sets te property to be not editable.
|
---|
830 | *
|
---|
831 | * @param new_data The suggestions table returned from php.
|
---|
832 | *************************************************************/
|
---|
833 | function showSuggestions_cb(new_data)
|
---|
834 | {
|
---|
835 |
|
---|
836 | with(currObj);
|
---|
837 | spellingSuggestionsDiv.innerHTML = new_data;
|
---|
838 | spellingSuggestionsDiv.style.display = 'block';
|
---|
839 | currObj.statusSpan.innerHTML = "";
|
---|
840 |
|
---|
841 | var ifr= currObj.objToCheck;
|
---|
842 | if(ifr.contentWindow)
|
---|
843 | ifr=ifr.contentWindow.document;
|
---|
844 | else
|
---|
845 | ifr=ifr.contentDocument;
|
---|
846 |
|
---|
847 | var nodeArray = ifr.getElementsByTagName("div");
|
---|
848 | var totArray = nodeArray.length;
|
---|
849 | for (var i = 0 ; i < totArray ; i++) {
|
---|
850 | var node = nodeArray[i];
|
---|
851 | if (node.className == "suggestion" || node.className == "ignore" ) {
|
---|
852 | if (document.addEventListener){
|
---|
853 | ifr.getElementsByTagName("div")[i].addEventListener("click", replaceMenu , true);
|
---|
854 | ifr.getElementsByTagName("div")[i].contentEditable="false" ;
|
---|
855 | }
|
---|
856 | else {
|
---|
857 | ifr.getElementsByTagName("div")[i].attachEvent("onclick", replaceMenu);
|
---|
858 | ifr.getElementsByTagName("div")[i].contentEditable="false" ;
|
---|
859 | }
|
---|
860 |
|
---|
861 |
|
---|
862 | }
|
---|
863 | }
|
---|
864 |
|
---|
865 |
|
---|
866 | }; //end showSuggestions_cb
|
---|
867 |
|
---|
868 |
|
---|
869 | /*************************************************************
|
---|
870 | * showSuggestions
|
---|
871 | *
|
---|
872 | * The showSuggestions function calls the showSuggestions php
|
---|
873 | * function to get suggestions for the misspelled word that the
|
---|
874 | * user has clicked on. It sets the status to "Searching...",
|
---|
875 | * hides the suggestions div, finds the x and y position of the
|
---|
876 | * span containing the misspelled word that user clicked on so
|
---|
877 | * the div can be displayed in the correct location, and then
|
---|
878 | * calls the showSuggestions php function with the misspelled word
|
---|
879 | * and the id of the span containing it.
|
---|
880 | * This function is only executed when the word is in red (the word id misspelled).
|
---|
881 | *
|
---|
882 | * @param word The misspelled word that the user clicked on
|
---|
883 | * @param id The id of the span that contains the misspelled word
|
---|
884 | *************************************************************/
|
---|
885 | function showSuggestions(word, id)
|
---|
886 | {
|
---|
887 |
|
---|
888 | var ifr= currObj.objToCheck;
|
---|
889 | if(ifr.contentWindow)
|
---|
890 | ifr=ifr.contentWindow.document;
|
---|
891 | else
|
---|
892 | ifr=ifr.contentDocument;
|
---|
893 |
|
---|
894 | if (ifr.getElementById(id).className == "highlight"){ //show the suggestion box only if the words are in red
|
---|
895 |
|
---|
896 |
|
---|
897 | languageId = document.getElementById("selectLanguage");
|
---|
898 | languageId = languageId[document.getElementById("selectLanguage").selectedIndex].value;
|
---|
899 |
|
---|
900 |
|
---|
901 | with(currObj);
|
---|
902 | if(currObj.config['useIcons'])
|
---|
903 | {
|
---|
904 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Procurando...\" alt=\"Procurando...\" border=\"0\" />";
|
---|
905 | }
|
---|
906 | else
|
---|
907 | {
|
---|
908 | currObj.statusSpan.innerHTML = "Procurando...";
|
---|
909 | }
|
---|
910 |
|
---|
911 | var x = findPosXById(id);
|
---|
912 | var y = findPosYById(id);
|
---|
913 |
|
---|
914 | var scrollPos = 0;
|
---|
915 | if(checkBrowser() != "ie")
|
---|
916 | {
|
---|
917 |
|
---|
918 |
|
---|
919 | //scrollPos = ifr.getElementById(currObj.spellingResultsDiv.id).scrollTop;
|
---|
920 | scrollPos = ifr.getElementsByTagName("body")[0].scrollTop;
|
---|
921 |
|
---|
922 | }
|
---|
923 |
|
---|
924 | if(spellingSuggestionsDiv)
|
---|
925 | {
|
---|
926 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
927 | }
|
---|
928 | spellingSuggestionsDiv = ifr.createElement('div');
|
---|
929 | spellingSuggestionsDiv.style.display = "none";
|
---|
930 | spellingSuggestionsDiv.className = 'suggestion_box';
|
---|
931 | spellingSuggestionsDiv.style.position = 'absolute';
|
---|
932 | spellingSuggestionsDiv.style.left = x + 'px';
|
---|
933 | spellingSuggestionsDiv.style.top = (y+16-scrollPos) + 'px';
|
---|
934 | spellingSuggestionsDiv.id = 'suggestion_box';
|
---|
935 | spellingSuggestionsDiv.contentEditable="false" ;
|
---|
936 |
|
---|
937 |
|
---|
938 | // Bah. There's got to be a better way to deal with this, but the click
|
---|
939 | // on a word to get suggestions starts up a race condition between
|
---|
940 | // showing and hiding the suggestion box, so we'll ignore the first
|
---|
941 | // click.
|
---|
942 | spellingSuggestionsDiv.ignoreNextClick = true;
|
---|
943 |
|
---|
944 |
|
---|
945 | //document.body.appendChild(spellingSuggestionsDiv);
|
---|
946 | ifr.body.appendChild(spellingSuggestionsDiv);
|
---|
947 |
|
---|
948 |
|
---|
949 | cp.call(currObj.config['spellUrl'], 'showSuggestions', showSuggestions_cb, word, id, languageId);
|
---|
950 | } // end if - show the suggestion box only if the words are in red
|
---|
951 |
|
---|
952 | }; // end showSuggestions
|
---|
953 |
|
---|
954 |
|
---|
955 |
|
---|
956 | /*************************************************************
|
---|
957 | * replaceWord
|
---|
958 | *
|
---|
959 | * The replaceWord function replaces the innerHTML of all the span tags
|
---|
960 | * that contains the old word with the new word that the user selects
|
---|
961 | * from the suggestion div. It hides the suggestions div and changes the color of
|
---|
962 | * the previously misspelled word to green to let the user know
|
---|
963 | * it has been changed. It then calls the switchText php function
|
---|
964 | * with the innerHTML of the div to update the text of the text box.
|
---|
965 | *
|
---|
966 | * @param id The id of the element to be checked
|
---|
967 | * @param newword The word the user selected from the suggestions div
|
---|
968 | * to replace the misspelled word.
|
---|
969 | *************************************************************/
|
---|
970 | function replaceWord(id, newWord)
|
---|
971 | {
|
---|
972 |
|
---|
973 |
|
---|
974 | var ifr= currObj.objToCheck;
|
---|
975 | if(ifr.contentWindow)
|
---|
976 | ifr=ifr.contentWindow.document;
|
---|
977 | else
|
---|
978 | ifr=ifr.contentDocument;
|
---|
979 |
|
---|
980 | var valorNo = trim(ifr.getElementById(id).innerHTML);
|
---|
981 |
|
---|
982 |
|
---|
983 | // Obtain all span tags which have highlight className and contais the old word
|
---|
984 | var nodeArray = ifr.getElementsByTagName("span");
|
---|
985 | var totArray = nodeArray.length;
|
---|
986 | var nodeRemove = new Array(totArray);
|
---|
987 | var j = -1;
|
---|
988 | for (var i = 0 ; i < totArray ; i++) {
|
---|
989 | var node = nodeArray[i];
|
---|
990 | if (node.className == "highlight" && trim(node.innerHTML) == valorNo ) {
|
---|
991 | j++;
|
---|
992 | nodeRemove[j] = node.id;
|
---|
993 | }
|
---|
994 | }
|
---|
995 |
|
---|
996 | //Replace the class of the span tags with highlight and the innerHTML with the new_word
|
---|
997 | for (var i = 0 ; i <= j ; i++) {
|
---|
998 | ifr.getElementById(nodeRemove[i]).innerHTML = newWord;
|
---|
999 | ifr.getElementById(nodeRemove[i]).className = "corrected_word";
|
---|
1000 | }
|
---|
1001 |
|
---|
1002 |
|
---|
1003 | if(spellingSuggestionsDiv)
|
---|
1004 | {
|
---|
1005 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
1006 | spellingSuggestionsDiv = null;
|
---|
1007 | }
|
---|
1008 |
|
---|
1009 | return false;
|
---|
1010 |
|
---|
1011 |
|
---|
1012 | }; // end replaceWord
|
---|
1013 |
|
---|
1014 |
|
---|
1015 | /*************************************************************
|
---|
1016 | * ignore
|
---|
1017 | *
|
---|
1018 | * The ignore function removes the span tags and mantain
|
---|
1019 | * the original word. So, the word comes back to the original, without
|
---|
1020 | * css.
|
---|
1021 | *
|
---|
1022 | * @param id The id of the element to be checked
|
---|
1023 | * @param word The original word.
|
---|
1024 | *************************************************************/
|
---|
1025 |
|
---|
1026 | function ignore(id, word){
|
---|
1027 |
|
---|
1028 |
|
---|
1029 | var ifr= currObj.objToCheck;
|
---|
1030 | if(ifr.contentWindow)
|
---|
1031 | ifr=ifr.contentWindow.document;
|
---|
1032 | else
|
---|
1033 | ifr=ifr.contentDocument;
|
---|
1034 |
|
---|
1035 | var valorNo = trim(word);
|
---|
1036 | if(spellingSuggestionsDiv)
|
---|
1037 | {
|
---|
1038 |
|
---|
1039 | spellingSuggestionsDiv.style.display = 'none';
|
---|
1040 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
1041 | spellingSuggestionsDiv = null;
|
---|
1042 | }
|
---|
1043 |
|
---|
1044 | var fake = ifr.createTextNode(valorNo);
|
---|
1045 |
|
---|
1046 | var parent = ifr.getElementById(id).parentNode;
|
---|
1047 |
|
---|
1048 |
|
---|
1049 | parent.replaceChild(fake, ifr.getElementById(id));
|
---|
1050 |
|
---|
1051 | return false;
|
---|
1052 |
|
---|
1053 |
|
---|
1054 |
|
---|
1055 | };
|
---|
1056 |
|
---|
1057 |
|
---|
1058 |
|
---|
1059 |
|
---|
1060 | /*************************************************************
|
---|
1061 | * switchText
|
---|
1062 | *
|
---|
1063 | * The switchText function is a funtion is called when the user
|
---|
1064 | * clicks on resume editing (or submits the form). It calls the
|
---|
1065 | * php function to switchText and uncomments the html and replaces
|
---|
1066 | * breaks and everything. Here all the breaks that the user has
|
---|
1067 | * typed are replaced with %u2026. Firefox does this goofy thing
|
---|
1068 | * where it cleans up the display of your html, which adds in \n's
|
---|
1069 | * where you don't want them. So I replace the user-entered returns
|
---|
1070 | * with something unique so that I can rip out all the breaks that
|
---|
1071 | * the browser might add and we don't want.
|
---|
1072 | *************************************************************/
|
---|
1073 | function switchText()
|
---|
1074 | {
|
---|
1075 |
|
---|
1076 | with(currObj);
|
---|
1077 | var ifr= currObj.objToCheck;
|
---|
1078 | if(ifr.contentWindow)
|
---|
1079 | ifr=ifr.contentWindow.document;
|
---|
1080 | else
|
---|
1081 | ifr=ifr.contentDocument;
|
---|
1082 |
|
---|
1083 | // Obtain all span tags which have highlight className or corrected_word className
|
---|
1084 | var nodeArray = ifr.getElementsByTagName("span");
|
---|
1085 | var totArray = nodeArray.length;
|
---|
1086 | var nodeRemove = new Array(totArray);
|
---|
1087 | var j = -1;
|
---|
1088 |
|
---|
1089 | for (var i = 0 ; i < totArray ; i++) {
|
---|
1090 | var node = nodeArray[i];
|
---|
1091 | if (node.className == "highlight" || node.className == "corrected_word") {
|
---|
1092 | j++;
|
---|
1093 | nodeRemove[j] = node.id;
|
---|
1094 |
|
---|
1095 |
|
---|
1096 | }
|
---|
1097 | }
|
---|
1098 |
|
---|
1099 | //Remove span tags which have highlight className or corrected_word className
|
---|
1100 | for (var i = 0 ; i <= j ; i++) {
|
---|
1101 | var valorNo = ifr.getElementById(nodeRemove[i]).innerHTML;
|
---|
1102 | var fake = ifr.createTextNode(valorNo);
|
---|
1103 | var parent = ifr.getElementById(nodeRemove[i]).parentNode;
|
---|
1104 | parent.replaceChild(fake, ifr.getElementById(nodeRemove[i]));
|
---|
1105 | }
|
---|
1106 |
|
---|
1107 | var text = ifr.body.innerHTML;
|
---|
1108 |
|
---|
1109 | text = text.replace(/ /gi, " %u2026 "); // Replace with the code %u2026
|
---|
1110 | text = '*' + text;
|
---|
1111 |
|
---|
1112 | cp.call(currObj.config['spellUrl'], 'switchText', switchText_cb, text);
|
---|
1113 |
|
---|
1114 | }; // end switchText
|
---|
1115 |
|
---|
1116 |
|
---|
1117 | /*************************************************************
|
---|
1118 | * switchText_cb
|
---|
1119 | *
|
---|
1120 | * The switchText_cb function is a call back funtion that the
|
---|
1121 | * switchText php function returns to. I replace all the %u2026's
|
---|
1122 | * with returns. It then replaces the text in the text box with
|
---|
1123 | * the corrected text fromt he div.
|
---|
1124 | *
|
---|
1125 | * @param new_string The corrected text from the div.
|
---|
1126 | *
|
---|
1127 | *************************************************************/
|
---|
1128 | function switchText_cb(new_string)
|
---|
1129 | {
|
---|
1130 |
|
---|
1131 |
|
---|
1132 | with(currObj);
|
---|
1133 |
|
---|
1134 | new_string = new_string.replace(/ %u2026/gi, " "); // Replace the code %u2026 with
|
---|
1135 |
|
---|
1136 | new_string = new_string.replace(/~~~/gi, "\n");
|
---|
1137 |
|
---|
1138 | // Remove the prefixed asterisk that was added in switchText().
|
---|
1139 | new_string = new_string.substr(1);
|
---|
1140 |
|
---|
1141 |
|
---|
1142 | currObj.objToCheck.style.display = "none";
|
---|
1143 | var ifr= currObj.objToCheck;
|
---|
1144 | if(ifr.contentWindow)
|
---|
1145 | ifr=ifr.contentWindow.document;
|
---|
1146 | else
|
---|
1147 | ifr=ifr.contentDocument;
|
---|
1148 | var texto = ifr.body.innerHTML;
|
---|
1149 |
|
---|
1150 | ifr.body.innerHTM = "";
|
---|
1151 | ifr.body.innerHTML = new_string;
|
---|
1152 | currObj.spellingResultsDiv = null;
|
---|
1153 |
|
---|
1154 | currObj.objToCheck.disabled = false;
|
---|
1155 |
|
---|
1156 |
|
---|
1157 | currObj.objToCheck.style.display = "block";
|
---|
1158 | currObj.resetAction();
|
---|
1159 | }; // end switchText_cb
|
---|
1160 |
|
---|
1161 |
|
---|
1162 | /*************************************************************
|
---|
1163 | * resumeEditing
|
---|
1164 | *
|
---|
1165 | * The resumeEditing function is called when the user is in the
|
---|
1166 | * correction mode and wants to return to the editing mode. It
|
---|
1167 | * hides the results div and the suggestions div, then enables
|
---|
1168 | * the text box and unhides the text box. It also calls
|
---|
1169 | * resetAction() to reset the status message.
|
---|
1170 | *************************************************************/
|
---|
1171 | function resumeEditing()
|
---|
1172 | {
|
---|
1173 |
|
---|
1174 | with(currObj);
|
---|
1175 |
|
---|
1176 | currObj.controlPanelDiv.style.display = "block";
|
---|
1177 | if(currObj.config['useIcons'])
|
---|
1178 | {
|
---|
1179 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\"><img src=\"images/page_white_edit.png\" width=\"16\" height=\"16\" title=\"Continuar Editando\" alt=\"Continuar Editando\" border=\"0\" /></a>";
|
---|
1180 | }
|
---|
1181 | else
|
---|
1182 | {
|
---|
1183 | currObj.actionSpan.innerHTML = "<a class=\"resume_editing\">Continuar Editando</a>";
|
---|
1184 | }
|
---|
1185 | if(currObj.config['useIcons'])
|
---|
1186 | {
|
---|
1187 | currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Carregando...\" alt=\"Carregando...\" border=\"0\" />";
|
---|
1188 | }
|
---|
1189 | else
|
---|
1190 | {
|
---|
1191 | currObj.statusSpan.innerHTML = "Carregando...";
|
---|
1192 | }
|
---|
1193 |
|
---|
1194 |
|
---|
1195 | if(spellingSuggestionsDiv)
|
---|
1196 | {
|
---|
1197 |
|
---|
1198 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
1199 | spellingSuggestionsDiv = null;
|
---|
1200 | }
|
---|
1201 |
|
---|
1202 | //set the contentEditable to true for IE browsers to continue editing
|
---|
1203 | var iframe= currObj.objToCheck;
|
---|
1204 | if(iframe.contentWindow)
|
---|
1205 | iframe=iframe.contentWindow.document;
|
---|
1206 | else
|
---|
1207 | iframe=iframe.contentDocument;
|
---|
1208 |
|
---|
1209 | var browser = checkBrowser();
|
---|
1210 | if (browser == "ie"){
|
---|
1211 | iframe.body.contentEditable="true" ;
|
---|
1212 |
|
---|
1213 | }
|
---|
1214 |
|
---|
1215 | currObj.switchText();
|
---|
1216 | }; // end resumeEditing
|
---|
1217 |
|
---|
1218 |
|
---|
1219 | /*************************************************************
|
---|
1220 | * resetAction
|
---|
1221 | *
|
---|
1222 | * The resetAction function just resets the status message to
|
---|
1223 | * the default action of "Check Spelling".
|
---|
1224 | *************************************************************/
|
---|
1225 | function resetAction()
|
---|
1226 | {
|
---|
1227 |
|
---|
1228 |
|
---|
1229 | with(currObj);
|
---|
1230 | /*if(currObj.config['useIcons'])
|
---|
1231 | {
|
---|
1232 | 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=\"Verificar Ortografia\" alt=\"Verificar Ortografia\" border=\"0\" /></a>";
|
---|
1233 | }
|
---|
1234 | else
|
---|
1235 | {
|
---|
1236 | currObj.actionSpan.innerHTML = "<a class=\"check_spelling\" onclick=\"setCurrentObject(" + currObj.config['varName'] + "); " + currObj.config['varName'] + ".spellCheck();\">Verificar Ortografia</a>";
|
---|
1237 | }*/
|
---|
1238 |
|
---|
1239 | currObj.actionSpan.innerHTML = "";
|
---|
1240 | currObj.statusSpan.innerHTML = "";
|
---|
1241 | currObj.controlPanelDiv.style.display = "none";
|
---|
1242 |
|
---|
1243 | }; // end resetAction
|
---|
1244 |
|
---|
1245 |
|
---|
1246 | /*************************************************************
|
---|
1247 | * resetSpellChecker
|
---|
1248 | *
|
---|
1249 | * The resetSpellChecker function resets the entire spell checker
|
---|
1250 | * to the defaults.
|
---|
1251 | *************************************************************/
|
---|
1252 | function resetSpellChecker()
|
---|
1253 | {
|
---|
1254 |
|
---|
1255 |
|
---|
1256 | var ifr= currObj.objToCheck;
|
---|
1257 | if(ifr.contentWindow)
|
---|
1258 | ifr=ifr.contentWindow.document;
|
---|
1259 | else
|
---|
1260 | ifr=ifr.contentDocument;
|
---|
1261 |
|
---|
1262 |
|
---|
1263 | with(currObj);
|
---|
1264 | currObj.resetAction();
|
---|
1265 |
|
---|
1266 | currObj.objToCheck.value = "";
|
---|
1267 | currObj.objToCheck.style.display = "block";
|
---|
1268 | currObj.objToCheck.disabled = false;
|
---|
1269 |
|
---|
1270 | if(currObj.spellingResultsDiv)
|
---|
1271 | {
|
---|
1272 | ifr.removeChild(currObj.spellingResultsDiv);
|
---|
1273 | currObj.spellingResultsDiv = null;
|
---|
1274 | }
|
---|
1275 | if(spellingSuggestionsDiv)
|
---|
1276 | {
|
---|
1277 | spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv);
|
---|
1278 | spellingSuggestionsDiv = null;
|
---|
1279 | }
|
---|
1280 | currObj.statusSpan.style.display = "none";
|
---|
1281 |
|
---|
1282 | }; // end resetSpellChecker
|
---|
1283 |
|
---|
1284 |
|
---|
1285 | /*************************************************************
|
---|
1286 | * findPosX
|
---|
1287 | *
|
---|
1288 | * The findPosX function just finds the X offset of the top left
|
---|
1289 | * corner of the object id it's given.
|
---|
1290 | *
|
---|
1291 | * @param object The id of the object that you want to find the
|
---|
1292 | * upper left X coordinate of.
|
---|
1293 | * @return int The X coordinate of the object
|
---|
1294 | *************************************************************/
|
---|
1295 | function findPosXById(object)
|
---|
1296 | {
|
---|
1297 |
|
---|
1298 | var ifr= currObj.objToCheck;
|
---|
1299 | if(ifr.contentWindow)
|
---|
1300 | ifr=ifr.contentWindow.document;
|
---|
1301 | else
|
---|
1302 | ifr=ifr.contentDocument;
|
---|
1303 | var obj = ifr.getElementById(object);
|
---|
1304 |
|
---|
1305 |
|
---|
1306 | var curleft = 0;
|
---|
1307 |
|
---|
1308 | if(obj.offsetParent)
|
---|
1309 | {
|
---|
1310 | while(obj.offsetParent)
|
---|
1311 | {
|
---|
1312 | curleft += obj.offsetLeft - obj.scrollLeft;
|
---|
1313 | obj = obj.offsetParent;
|
---|
1314 | }
|
---|
1315 | }
|
---|
1316 | else if(obj.x)
|
---|
1317 | {
|
---|
1318 | curleft += obj.x;
|
---|
1319 | }
|
---|
1320 | return curleft;
|
---|
1321 | }; // end findPosX
|
---|
1322 |
|
---|
1323 |
|
---|
1324 | /*************************************************************
|
---|
1325 | * findPosY
|
---|
1326 | *
|
---|
1327 | * The findPosY function just finds the Y offset of the top left
|
---|
1328 | * corner of the object id it's given.
|
---|
1329 | *
|
---|
1330 | * @param object The id of the object that you want to find the
|
---|
1331 | * upper left Y coordinate of.
|
---|
1332 | * @return int The Y coordinate of the object
|
---|
1333 | *************************************************************/
|
---|
1334 | function findPosYById(object)
|
---|
1335 | {
|
---|
1336 | var ifr= currObj.objToCheck;
|
---|
1337 | if(ifr.contentWindow)
|
---|
1338 | ifr=ifr.contentWindow.document;
|
---|
1339 | else
|
---|
1340 | ifr=ifr.contentDocument;
|
---|
1341 | var obj = ifr.getElementById(object);
|
---|
1342 |
|
---|
1343 | var curtop = 0;var curtop = 0;
|
---|
1344 | if(obj.offsetParent)
|
---|
1345 | {
|
---|
1346 | while(obj.offsetParent)
|
---|
1347 | {
|
---|
1348 | curtop += obj.offsetTop - obj.scrollTop;
|
---|
1349 | obj = obj.offsetParent;
|
---|
1350 | }
|
---|
1351 | }
|
---|
1352 | else if(obj.y)
|
---|
1353 | {
|
---|
1354 | curtop += obj.y;
|
---|
1355 | }
|
---|
1356 | return curtop;
|
---|
1357 | }; // end findPosY
|
---|
1358 |
|
---|
1359 |
|
---|
1360 | /*************************************************************
|
---|
1361 | * trim
|
---|
1362 | *
|
---|
1363 | * Trims white space from a string.
|
---|
1364 | *
|
---|
1365 | * @param s The string you want to trim.
|
---|
1366 | * @return string The trimmed string.
|
---|
1367 | *************************************************************/
|
---|
1368 | function trim(s)
|
---|
1369 | {
|
---|
1370 |
|
---|
1371 | while(s.substring(0,1) == ' ')
|
---|
1372 | {
|
---|
1373 | s = s.substring(1,s.length);
|
---|
1374 | }
|
---|
1375 | while(s.substring(s.length-1,s.length) == ' ')
|
---|
1376 | {
|
---|
1377 | s = s.substring(0,s.length-1);
|
---|
1378 | }
|
---|
1379 | return s;
|
---|
1380 | }; // end trim |
---|