Changeset 2486 for sandbox/expressoMail1_2/corretor_ortografico
- Timestamp:
- 04/12/10 14:42:40 (14 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
sandbox/expressoMail1_2/corretor_ortografico/spell_checker/js/spell_checker.js
r2477 r2486 48 48 cp.set_transfer_mode('post'); 49 49 cp.set_response_type('text'); 50 50 51 function beginSpellCheck(){ 51 52 if(!blockSpellCheck){ … … 53 54 area = "body_" + currentTab; 54 55 aba = currentTab; 56 55 57 //var cp = new cpaint(); 56 58 // alert("Seta globals"); … … 94 96 // If there are already any onload handlers loaded in the page, we'll add our onload 95 97 // handler first and then call the old one, rather than completely overriding it. 96 if(window.onload)97 {98 window.onload = new setupSpellCheckers();99 100 /*var old_onload = window.onload;101 102 103 104 105 106 }107 else108 {109 110 }98 if(window.onload) 99 { 100 window.onload = new setupSpellCheckers(); 101 102 /*var old_onload = window.onload; 103 window.onload = function(e) 104 { 105 var test = new setupSpellCheckers(e); 106 old_onload(e); 107 }*/ 108 } 109 else 110 { 111 window.onload = new setupSpellCheckers(); 112 } 111 113 112 114 //window.onload =new setupSpellCheckers(); … … 135 137 136 138 if(ifr.contentWindow) 137 ifr=ifr.contentWindow.document;139 ifr=ifr.contentWindow.document; 138 140 else 139 ifr=ifr.contentDocument;141 ifr=ifr.contentDocument; 140 142 var texto = ifr.body.innerHTML; 141 143 … … 148 150 149 151 function setupSpellChecker(){ 150 151 152 152 153 currObj = this; … … 171 172 currObj.controlPanelDiv.className = 'control_panel'; 172 173 currObj.controlPanelDiv.id = 'control_panel_' + currentTab; 173 document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv); 174 document.getElementById(currObj.config['divId']).appendChild(currObj.controlPanelDiv); 175 176 177 174 178 175 179 //the span that toggles between spell checking and editing … … 223 227 function ajaxSpell(varName, width, height, spellUrl, divId, name, id, title, value) 224 228 { 225 226 currObj = this; 229 230 currObj = this; 231 227 232 228 233 currObj.config = new Array(); //the array of configuration options … … 307 312 ajaxSpell.prototype.resetSpellChecker = resetSpellChecker; 308 313 ajaxSpell.prototype.resetAction = resetAction; 314 315 309 316 310 317 … … 327 334 328 335 }; // end setCurrentObject 336 337 338 /************************************************************* 339 * showMenu 340 * 341 * This function is associated with the click event 342 * of all the tags span with correctd_word class. 343 * 344 *************************************************************/ 345 function showMenu(){ 346 var evento = this.onclick.toString(); 347 evento = evento.replace("function onclick(event) {", ""); 348 evento = evento.replace("}", ""); 349 var array_func = evento.split(";"); 350 eval(array_func[0]); 351 eval(array_func[1]); 352 return false; 353 } 354 355 /************************************************************* 356 * showMenu 357 * 358 * This function is associated with the click event 359 * of all the tags div with suggestion class. 360 * 361 *************************************************************/ 362 function replaceMenu(){ 363 var evento = this.onclick.toString(); 364 if(spellingSuggestionsDiv) 365 { 366 367 spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); 368 spellingSuggestionsDiv = null; 369 } 370 evento = evento.replace("function onclick(event) {", ""); 371 evento = evento.replace("}", ""); 372 var array_func = evento.split(";"); 373 eval(array_func[0]); 374 return false; 375 } 376 329 377 330 378 … … 344 392 function spellCheck_cb(new_data) 345 393 { 394 //adicionado nathalie 395 var ifr= currObj.objToCheck; 396 if(ifr.contentWindow) 397 ifr=ifr.contentWindow.document; 398 else 399 ifr=ifr.contentDocument; 400 346 401 347 402 with(currObj); 403 348 404 new_data = new_data.toString(); 349 405 var isThereAMisspelling = new_data.charAt(0); … … 353 409 { 354 410 355 currObj.spellingResultsDiv.parentNode.removeChild(spellingResultsDiv); 356 } 357 411 ifr.removeChild(currObj.spellingResultsDiv.id); 412 413 } 414 415 416 /*currObj.spellingResultsDiv = document.createElement('DIV'); 417 currObj.spellingResultsDiv.className = 'edit_box'; 418 currObj.spellingResultsDiv.id = 'edit_box'; //Added the id property - By Nathalie 419 currObj.spellingResultsDiv.style.width = "99%";//the width of the textarea 420 currObj.spellingResultsDiv.style.height = 300; // = height; //currObj.objToCheck.style.height; 421 currObj.spellingResultsDiv.innerHTML = new_data; 422 currObj.objToCheck.style.display = "none"; 423 currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv,currObj.objToCheck); 424 currObj.statusSpan.innerHTML = ""; */ 425 426 //Testes nathalie - substituido 358 427 currObj.spellingResultsDiv = document.createElement('DIV'); 359 428 currObj.spellingResultsDiv.className = 'edit_box'; … … 361 430 currObj.spellingResultsDiv.style.width = "99%";//the width of the textarea 362 431 currObj.spellingResultsDiv.style.height = 300; // = height; //currObj.objToCheck.style.height; 363 currObj.spellingResultsDiv.innerHTML = new_data; 364 365 currObj.objToCheck.style.display = "none"; 432 currObj.spellingResultsDiv.innerHTML = new_data; 433 currObj.spellingResultsDiv.border = 0; 434 //currObj.spellingResultsDiv.style.display = "none"; 435 //currObj.objToCheck.style.display = "none"; 436 currObj.statusSpan.innerHTML = ""; 437 438 // Teste de iFrame - Nathalie 439 var ifr= currObj.objToCheck; 440 if(ifr.contentWindow) 441 ifr=ifr.contentWindow.document; 442 else 443 ifr=ifr.contentDocument; 444 ifr.body.innerHTML = ""; 445 var cssLink = document.createElement("link") 446 cssLink.href = "spell_checker/css/spell_checker.css"; 447 cssLink .rel = "stylesheet"; 448 cssLink .type = "text/css"; 449 ifr.body.appendChild(cssLink); 450 ifr.body.appendChild(currObj.spellingResultsDiv); 451 452 453 // Obtain all the span tags which have highlight className 454 // and add the eventListener for the click - This event shows the suggestions menu 455 var nodeArray = ifr.getElementsByTagName("span"); 456 var totArray = nodeArray.length; 457 for (var i = 0 ; i < totArray ; i++) { 458 var node = nodeArray[i]; 459 if (node.className == "highlight") { 460 ifr.getElementsByTagName("span")[i].addEventListener("click", showMenu , true); 461 462 } 463 } 464 465 466 //adicionado Paula 467 // currObj.objToCheck.style.display = "none"; //Paula 366 468 //currObj.objToCheck.parentNode. 367 469 //currObj.objToCheck.parentNode.appendChild(currObj.spellingResultsDiv,currObj.objToCheck); 368 currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab)); 470 // currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab)); //Paula 369 471 currObj.statusSpan.innerHTML = ""; 370 371 472 473 372 474 if(currObj.config['useIcons']) 373 475 { … … 406 508 *************************************************************/ 407 509 function spellCheck() { 408 510 // adicionado nathalie 511 /* with(currObj); 512 var query; 513 514 if(currObj.spellingResultsDiv) 515 { 516 currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv); 517 currObj.spellingResultsDiv = null; 518 } 519 520 if(currObj.config['useIcons']) 521 { 522 currObj.actionSpan.innerHTML = "<img src=\"images/spellcheck.png\" width=\"16\" height=\"16\" title=\"Verificar Ortografia\" alt=\"Verificar Ortografia\" border=\"0\" />"; 523 } 524 else 525 { 526 currObj.actionSpan.innerHTML = "<a class=\"check_spelling\">Verificar Ortografia</a>"; 527 } 528 529 if(currObj.config['useIcons']) 530 { 531 currObj.statusSpan.innerHTML = "<img src=\"images/working.gif\" width=\"16\" height=\"16\" title=\"Verificando Ortografia...\" alt=\"Verificando Ortografia...\" border=\"0\" />"; 532 } 533 else 534 { 535 currObj.statusSpan.innerHTML = "Verificando Ortografia..."; 536 } 537 538 // Obtain the HTML content from iframe (edit area) 539 var ifr= currObj.objToCheck; 540 if(ifr.contentWindow) 541 ifr=ifr.contentWindow.document; 542 else 543 ifr=ifr.contentDocument; 544 var texto = ifr.body.innerHTML; 545 546 547 query = texto; 548 //query = currObj.objToCheck.value; 549 550 //query = query.replace(/\r?\n/gi, "<br />"); // Commented from the original by Nathalie 551 query = query.replace(/\r?\n/gi, " "); // replace \n with " " - By Nathalie 552 553 554 cp.call(currObj.config['spellUrl'], 'spellCheck', spellCheck_cb, query, currObj.config['varName']); 555 */ 556 //adicionado Paula 409 557 if(!blockSpellCheck) { 410 558 blockSpellCheck = true; … … 472 620 function addWord(id) 473 621 { 474 622 var wordToAdd = document.getElementById(id).innerHTML; 475 623 476 624 with(currObj); … … 509 657 function addWord_cb(returnedData) 510 658 { 511 with(currObj); 659 660 with(currObj); 512 661 currObj.statusSpan.innerHTML = ""; 513 662 resumeEditing(); … … 570 719 function getTarget(e) 571 720 { 721 572 722 var value; 573 723 if(checkBrowser() == "ie") … … 594 744 function checkBrowser() 595 745 { 596 597 var theAgent = navigator.userAgent.toLowerCase(); 746 var theAgent = navigator.userAgent.toLowerCase(); 598 747 if(theAgent.indexOf("msie") != -1) 599 748 { … … 658 807 spellingSuggestionsDiv.style.display = 'block'; 659 808 currObj.statusSpan.innerHTML = ""; 809 810 //adicionado os listener - nathalie 811 var ifr= currObj.objToCheck; 812 if(ifr.contentWindow) 813 ifr=ifr.contentWindow.document; 814 else 815 ifr=ifr.contentDocument; 816 817 var nodeArray = ifr.getElementsByTagName("div"); 818 var totArray = nodeArray.length; 819 for (var i = 0 ; i < totArray ; i++) { 820 var node = nodeArray[i]; 821 if (node.className == "suggestion" || node.className == "ignore" ) { 822 ifr.getElementsByTagName("div")[i].addEventListener("click", replaceMenu , true); 823 824 } 825 } 826 827 660 828 }; //end showSuggestions_cb 661 829 … … 678 846 function showSuggestions(word, id) 679 847 { 848 849 //adicionado nathalie 850 var ifr= currObj.objToCheck; 851 if(ifr.contentWindow) 852 ifr=ifr.contentWindow.document; 853 else 854 ifr=ifr.contentDocument; 855 856 //alterado - colocar ifr 680 857 language = document.getElementById("selectLanguage"); 681 858 language = language[document.getElementById("selectLanguage").selectedIndex].value; 682 859 860 683 861 with(currObj); 684 862 if(currObj.config['useIcons']) … … 690 868 currObj.statusSpan.innerHTML = "Procurando..."; 691 869 } 870 692 871 var x = findPosXById(id); 693 var y = findPosYById(id); 694 695 872 var y = findPosYById(id); 873 874 var scrollPos = 0; 696 875 if(checkBrowser() != "ie") 697 876 { 698 scrollPos = currObj.spellingResultsDiv.scrollTop; 877 878 //scrollPos = currObj.spellingResultsDiv.scrollTop; 879 scrollPos = ifr.getElementById(currObj.spellingResultsDiv.id).scrollTop; 880 699 881 } 700 882 … … 709 891 spellingSuggestionsDiv.style.left = x + 'px'; 710 892 spellingSuggestionsDiv.style.top = (y+16-scrollPos) + 'px'; 893 894 895 711 896 712 897 // Bah. There's got to be a better way to deal with this, but the click … … 714 899 // showing and hiding the suggestion box, so we'll ignore the first 715 900 // click. 716 spellingSuggestionsDiv.ignoreNextClick = true; 717 718 document.body.appendChild(spellingSuggestionsDiv); 719 901 //spellingSuggestionsDiv.ignoreNextClick = true; // comentado Nathalie 902 903 904 //document.body.appendChild(spellingSuggestionsDiv); 905 ifr.body.appendChild(spellingSuggestionsDiv); //alterado nathalie 906 907 908 909 910 720 911 cp.call(currObj.config['spellUrl'], 'showSuggestions', showSuggestions_cb, word, id, language); 721 912 }; // end showSuggestions 722 913 723 914 915 724 916 /************************************************************* 725 917 * replaceWord 726 918 * 727 * The replaceWord function takes the id of the misspelled word 728 * that the user clicked on and replaces the innerHTML of that 729 * span with the new word that the user selects from the suggestion 730 * div. It hides the suggestions div and changes the color of 919 * The replaceWord function replaces the innerHTML of all the span tags 920 * that contains the old word with the new word that the user selects 921 * from the suggestion div. It hides the suggestions div and changes the color of 731 922 * the previously misspelled word to green to let the user know 732 923 * it has been changed. It then calls the switchText php function 733 924 * with the innerHTML of the div to update the text of the text box. 734 925 * 735 * @param id The id of the span that contains the word to be replaced736 * @param new Word The word the user selected from the suggestions div926 * @param id The id of the element to be checked 927 * @param newword The word the user selected from the suggestions div 737 928 * to replace the misspelled word. 738 929 *************************************************************/ 739 930 function replaceWord(id, newWord) 740 931 { 741 742 document.getElementById(id).innerHTML = trim(newWord); 743 if(spellingSuggestionsDiv) 744 { 932 933 934 var ifr= currObj.objToCheck; 935 if(ifr.contentWindow) 936 ifr=ifr.contentWindow.document; 937 else 938 ifr=ifr.contentDocument; 939 940 var valorNo = trim(ifr.getElementById(id).innerHTML); 941 942 943 if(spellingSuggestionsDiv) 944 { 945 spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); 946 spellingSuggestionsDiv = null; 947 } 948 949 950 // Obtain all span tags which have highlight className and contais the old word 951 var nodeArray = ifr.getElementsByTagName("span"); 952 var totArray = nodeArray.length; 953 var nodeRemove = new Array(totArray); 954 var j = -1; 955 for (var i = 0 ; i < totArray ; i++) { 956 var node = nodeArray[i]; 957 if (node.className == "highlight" && trim(node.innerHTML) == valorNo ) { 958 j++; 959 nodeRemove[j] = node.id; 960 } 961 } 962 963 //Replace the class of the span tags with highlight and the innerHTML with the new_word 964 for (var i = 0 ; i <= j ; i++) { 965 ifr.getElementById(nodeRemove[i]).innerHTML = newWord; 966 ifr.getElementById(nodeRemove[i]).className = "corrected_word"; 967 } 968 969 970 return false; 971 972 973 // FIMMMMMMMMMMMMMMMMMMMMMMMMMMMMM 974 975 //Função antiga - substitui apenas uma palavra 976 /* var ifr= currObj.objToCheck; 977 if(ifr.contentWindow) 978 ifr=ifr.contentWindow.document; 979 else 980 ifr=ifr.contentDocument; 981 982 var valorNo = trim(newWord); 983 if(spellingSuggestionsDiv) 984 { 985 986 spellingSuggestionsDiv.style.display = 'none'; 745 987 spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); 746 988 spellingSuggestionsDiv = null; 747 989 } 748 document.getElementById(id).className = "corrected_word"; 990 991 var fake = document.createTextNode(valorNo); 992 993 var parent = ifr.getElementById(id).parentNode; 994 995 996 parent.replaceChild(fake, ifr.getElementById(id)); 997 998 return false;*/ 999 1000 1001 1002 749 1003 }; // end replaceWord 750 1004 … … 765 1019 function switchText() 766 1020 { 767 1021 768 1022 with(currObj); 769 1023 //By Nathalie - The Element means that this div belongs to the current tab 770 var parentElement = Element(currObj.spellingResultsDiv.id); 1024 //var parentElement = Element(currObj.spellingResultsDiv.id); //alterado nathalie 1025 var ifr= currObj.objToCheck; 1026 if(ifr.contentWindow) 1027 ifr=ifr.contentWindow.document; 1028 else 1029 ifr=ifr.contentDocument; 1030 var parentElement =ifr.getElementById(currObj.spellingResultsDiv.id); //alterado nathalie 771 1031 // Obtain all span tags which have highlight className or corrected_word className 772 var nodeArray = parentElement.getElementsByTagName("span");1032 var nodeArray = ifr.getElementsByTagName("span"); 773 1033 var totArray = nodeArray.length; 774 1034 var nodeRemove = new Array(totArray); … … 787 1047 //Remove span tags which have highlight className or corrected_word className 788 1048 for (var i = 0 ; i <= j ; i++) { 789 var valorNo = document.getElementById(nodeRemove[i]).innerHTML;1049 var valorNo = ifr.getElementById(nodeRemove[i]).innerHTML; 790 1050 var fake = document.createTextNode(valorNo); 791 var parent = document.getElementById(nodeRemove[i]).parentNode;792 parent.replaceChild(fake, document.getElementById(nodeRemove[i]));1051 var parent = ifr.getElementById(nodeRemove[i]).parentNode; 1052 parent.replaceChild(fake, ifr.getElementById(nodeRemove[i])); 793 1053 } 794 1054 795 var text = currObj.spellingResultsDiv.innerHTML;1055 var text = ifr.getElementById(currObj.spellingResultsDiv.id).innerHTML; 796 1056 797 1057 text = text.replace(/ /gi, " %u2026 "); // Replace with the code %u2026 … … 816 1076 function switchText_cb(new_string) 817 1077 { 818 819 with(currObj); 1078 1079 1080 //adicionado Paula 1081 with(currObj); 820 1082 821 1083 new_string = new_string.replace(/ %u2026/gi, " "); // Replace the code %u2026 with … … 834 1096 ifr=ifr.contentDocument; 835 1097 var texto = ifr.body.innerHTML; 836 1098 1099 ifr.body.innerHTM = ""; //adicionado nathalie 837 1100 ifr.body.innerHTML = new_string; 1101 currObj.spellingResultsDiv = null; //adicionado nathalie 1102 1103 1104 838 1105 currObj.objToCheck.disabled = false; 839 1106 840 if(currObj.spellingResultsDiv) 841 { 842 currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv); 1107 //Removido Nathalie 1108 /*if(currObj.spellingResultsDiv) 1109 { 1110 ifr.removeChild(currObj.spellingResultsDiv); //Alterado nathalie 843 1111 currObj.spellingResultsDiv = null; 844 } 1112 }*/ 845 1113 currObj.objToCheck.style.display = "block"; 846 1114 currObj.resetAction(); … … 884 1152 { 885 1153 886 spellingSuggestionsDiv. id.parentNode.removeChild(spellingSuggestionsDiv);1154 spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); 887 1155 spellingSuggestionsDiv = null; 888 1156 } … … 900 1168 function resetAction() 901 1169 { 1170 1171 //adicionado Paula 902 1172 with(currObj); 903 1173 /*if(currObj.config['useIcons']) … … 925 1195 function resetSpellChecker() 926 1196 { 927 928 with(currObj); 1197 1198 //adicionado nathalie 1199 var ifr= currObj.objToCheck; 1200 if(ifr.contentWindow) 1201 ifr=ifr.contentWindow.document; 1202 else 1203 ifr=ifr.contentDocument; 1204 1205 1206 with(currObj); 929 1207 currObj.resetAction(); 930 1208 … … 935 1213 if(currObj.spellingResultsDiv) 936 1214 { 937 currObj.spellingResultsDiv.parentNode.removeChild(currObj.spellingResultsDiv);1215 ifr.removeChild(currObj.spellingResultsDiv); //alterado nathalie 938 1216 currObj.spellingResultsDiv = null; 939 1217 } … … 958 1236 * @return int The X coordinate of the object 959 1237 *************************************************************/ 960 function findPosXById(object) 961 { 962 1238 function findPosXById(object) 1239 { 1240 1241 //adicionado Nathalie 1242 var ifr= currObj.objToCheck; 1243 if(ifr.contentWindow) 1244 ifr=ifr.contentWindow.document; 1245 else 1246 ifr=ifr.contentDocument; 1247 var obj = ifr.getElementById(object); 1248 1249 963 1250 var curleft = 0; 964 var obj = document.getElementById(object); 1251 //var obj = document.getElementById(object); //removido nathalie 1252 1253 965 1254 if(obj.offsetParent) 966 1255 { … … 991 1280 function findPosYById(object) 992 1281 { 1282 1283 //adicionado Nathalie 1284 var ifr= currObj.objToCheck; 1285 if(ifr.contentWindow) 1286 ifr=ifr.contentWindow.document; 1287 else 1288 ifr=ifr.contentDocument; 1289 var obj = ifr.getElementById(object); //removido Nathalie 1290 993 1291 994 1292 var curtop = 0;var curtop = 0; 995 var obj = document.getElementById(object);1293 //var obj = document.getElementById(object); //removido Nathalie 996 1294 if(obj.offsetParent) 997 1295 {
Note: See TracChangeset
for help on using the changeset viewer.