Changeset 2546


Ignore:
Timestamp:
04/15/10 11:15:13 (14 years ago)
Author:
nathalie.silva
Message:

Ticket #891 - adicionado - clicar fora da lista de sugestões para esconder a lista- Nathalie

File:
1 edited

Legend:

Unmodified
Added
Removed
  • sandbox/expressoMail1_2/corretor_ortografico/spell_checker/js/spell_checker.js

    r2543 r2546  
    5050 
    5151function beginSpellCheck(){ 
    52 if(!blockSpellCheck){ 
    53     position = "body_position_" + currentTab; 
    54     area = "body_" + currentTab; 
    55     aba = currentTab; 
    56  
    57     //var cp = new cpaint(); 
    58     // alert("Seta globals"); 
    59     //cp = new cpaint(); 
    60     //cp.set_transfer_mode('post'); 
    61     //cp.set_response_type('text'); 
    62     //cp.set_debug(1); 
    63  
    64     //var currObj; //the current spell checker being used 
    65     //var spellingSuggestionsDiv = null;  // Auto-generated suggestions div 
    66  
    67     spellingSuggestionsDiv = null; 
    68     positionEditor = position; 
    69     areaEditor = area; 
    70     abaEditor = aba;  
    71      
    72  
    73     //alert("Seta globals"); 
    74  
    75  
    76 // If there are already any onclick handlers loaded in the page, we'll add 
    77 // our onclick handler first and then call the old one, rather than completely 
    78 // overriding it.  The checkClickLocation is used to hide the suggestions div 
    79 // when the user clicks outside it. 
    80     /*if(document.onclick) 
    81     { 
    82         old_onclick = document.onclick; 
    83         
    84         document.onclick = function(e) 
    85         { 
    86                 checkClickLocation(e); 
    87                 old_onclick(e); 
    88         } 
    89 } 
    90 else 
    91 { 
    92         //document.onclick = checkClickLocation; 
    93 }*/ 
    94  
    95 //alert("Inicio"); 
    96 // If there are already any onload handlers loaded in the page, we'll add our onload 
    97 // handler first and then call the old one, rather than completely overriding it. 
    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             }*/ 
     52    if(!blockSpellCheck){ 
     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    } else { 
     72        alert("O corretor esta executando") 
    10873    } 
    109     else 
    110     { 
    111             window.onload = new setupSpellCheckers(); 
    112     } 
    113  
    114 //window.onload =new setupSpellCheckers(); 
    115 //alert("Fim"); 
    116 } else { 
    117     alert("O corretor ja esta rodando.") 
    118 } 
    119 } // fecha funᅵᅵo 
    120  
     74} // close BeginSpellCheck 
    12175 
    12276 
     
    12680 * function setupSpellCheckers() 
    12781 * 
    128  * This function goes through the page and finds all the  
    129  * textareas.  It then checks the title attribute for either 
    130  * spellcheck or spellcheck_icons to determine whether or not 
    131  * it should add a spellchecker to that textarea. 
     82 * This function obtain the iframe of the page (that is the area editor) 
     83 * and then adds a spellchecker to the iframe. 
    13284 *************************************************************/ 
    13385function setupSpellCheckers() 
    13486{ 
    13587    var ifr = document.getElementsByTagName('iframe')[0]; 
     88    //alert(area); 
     89    //var ifr = document.getElementById(area); 
    13690    var numSpellCheckers = abaEditor; 
    13791 
     
    14094    else 
    14195        ifr=ifr.contentDocument; 
     96 
     97     if (document.addEventListener) { 
     98        ifr.addEventListener("click", checkClickLocation , true); //add the click event 
     99     }    
     100     else { 
     101        ifr.attachEvent("onclick", checkClickLocation); //add the click event 
     102         
     103     } 
     104     
     105 
    142106    var texto = ifr.body.innerHTML; 
    143107 
     
    342306 
    343307         
    344  
    345  
    346308       
    347309         
     
    369331 * 
    370332 * This function is associated with the click event 
    371  *  of all the tags span with correctd_word class. 
     333 *  of all the span tags with correctd_word class. 
    372334 * 
    373335 *************************************************************/ 
     
    382344    var browser = checkBrowser(); 
    383345    if (browser == "ie"){ 
    384         //iframe.body.contentEditable="false" ; 
     346         
    385347        iframe.body.contentEditable="true" ; 
     348        var ifr= currObj.objToCheck; 
     349        if(!e){var e = ifr.contentWindow.event;} 
     350        if(!e.target){e.target = e.srcElement;} 
     351        var evento = e.target.onclick.toString(); 
     352 
    386353    } 
    387354    else { 
    388355        iframe.designMode = "off"; 
    389356        iframe.designMode = "on"; 
    390     } 
    391      
    392     var browser = checkBrowser(); 
    393     if (browser == "ie"){ 
    394          var ifr= currObj.objToCheck; 
    395          if(!e){var e = ifr.contentWindow.event;} 
    396             if(!e.target){e.target = e.srcElement;} 
    397  
    398             if(ifr.contentWindow) 
    399             ifr=ifr.contentWindow.document; 
    400         else 
    401             ifr=ifr.contentDocument; 
    402         var evento = ifr.getElementById(e.target.id).onclick.toString(); 
    403     } 
    404     else { 
    405357        var evento = this.onclick.toString(); 
    406     } 
    407  
     358    }   
    408359    evento = evento.replace("function onclick(event) {", ""); 
    409360    evento = evento.replace("}", ""); 
    410361    var array_func = evento.split(";"); 
    411362    eval(array_func[0]); 
    412    eval(array_func[1]); 
     363    eval(array_func[1]); 
    413364    return false;    
    414      
    415  
    416      
     365        
    417366   
    418367// 
     
    420369 
    421370/************************************************************* 
    422  * showMenu 
     371 * replaceMenu 
    423372 * 
    424373 * This function is associated with the click event 
    425  *  of all the tags div with suggestion class. 
    426  * 
    427  *************************************************************/ 
    428 function replaceMenu(){ 
    429       //adicionado nathalie 
    430  
     374 *  of all the div tags with suggestion class. 
     375 * 
     376 *************************************************************/ 
     377function replaceMenu(){      
    431378    var iframe= currObj.objToCheck; 
    432379    if(iframe.contentWindow) 
     
    434381    else 
    435382        iframe=iframe.contentDocument; 
    436  
    437383    var browser = checkBrowser(); 
    438384    if (browser == "ie"){ 
    439385        iframe.body.contentEditable="false" ; 
    440         //iframe.body.contentEditable="true" ; 
     386        var ifr= currObj.objToCheck; 
     387        if(!e){var e = ifr.contentWindow.event;} 
     388        if(!e.target){e.target = e.srcElement;} 
     389        var evento = e.target.onclick.toString(); 
    441390    } 
    442391    else { 
    443392        iframe.designMode = "off"; 
    444393        iframe.designMode = "on"; 
    445     } 
    446  
    447  
    448      
    449     var browser = checkBrowser(); 
    450     if (browser == "ie"){ 
    451          var ifr= currObj.objToCheck; 
    452          if(!e){var e = ifr.contentWindow.event;} 
    453          if(!e.target){e.target = e.srcElement;}         
    454          var evento = e.target.onclick.toString(); 
    455     } 
    456     else { 
    457394        var evento = this.onclick.toString(); 
    458395    } 
    459  
    460396    evento = evento.replace("function onclick(event) {", ""); 
    461397    evento = evento.replace("}", ""); 
     
    482418function spellCheck_cb(new_data) 
    483419{ 
    484          //adicionado nathalie 
     420          
    485421        var ifr= currObj.objToCheck; 
    486422        if(ifr.contentWindow) 
     
    503439        } 
    504440 
    505          
    506         /*currObj.spellingResultsDiv =  document.createElement('DIV'); 
    507         currObj.spellingResultsDiv.className = 'edit_box'; 
    508         currObj.spellingResultsDiv.id = 'edit_box'; //Added the id property - By Nathalie 
    509         currObj.spellingResultsDiv.style.width =  "99%";//the width of the textarea 
    510         currObj.spellingResultsDiv.style.height = 300;  //   = height; //currObj.objToCheck.style.height; 
    511         currObj.spellingResultsDiv.innerHTML = new_data;        
    512         currObj.objToCheck.style.display = "none"; 
    513         currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv,currObj.objToCheck); 
    514         currObj.statusSpan.innerHTML = ""; */ 
    515  
    516  
    517  
    518  
    519         // Teste de iFrame - Nathalie 
     441 
    520442         var ifr= currObj.objToCheck; 
    521443         if(ifr.contentWindow) 
     
    568490 
    569491 
    570 //adicionado Paula 
    571 //    currObj.objToCheck.style.display = "none"; //Paula 
    572         //currObj.objToCheck.parentNode. 
    573         //currObj.objToCheck.parentNode.appendChild(currObj.spellingResultsDiv,currObj.objToCheck); 
    574 //      currObj.objToCheck.parentNode.insertBefore(currObj.spellingResultsDiv, document.getElementById("viewsource_rt_checkbox_" + currentTab)); //Paula 
    575         currObj.statusSpan.innerHTML = "";     
     492        currObj.statusSpan.innerHTML = ""; 
    576493 
    577494         
     
    694611            }*/ 
    695612 
     613 
    696614            // Obtain the HTML content from iframe (edit area) 
    697615             var ifr= currObj.objToCheck; 
     
    783701function checkClickLocation(e) 
    784702{ 
    785     
     703 
     704    var browser = checkBrowser(); 
    786705    if(spellingSuggestionsDiv) 
    787706        { 
     
    789708                // on a word to get suggestions starts up a race condition between 
    790709                // showing and hiding the suggestion box, so we'll ignore the first 
    791                 // click. 
    792                 if(spellingSuggestionsDiv.ignoreNextClick){ 
     710                // click. Problem with IE browser                 
     711                if(spellingSuggestionsDiv.ignoreNextClick && browser == "ie"){ 
    793712                        spellingSuggestionsDiv.ignoreNextClick = false; 
    794713                } 
     
    801720                                spellingSuggestionsDiv.parentNode.removeChild(spellingSuggestionsDiv); 
    802721                                spellingSuggestionsDiv = null; 
    803                         } 
    804                 } 
     722                                
     723                                if (browser == "ie"){ 
     724                                     var iframe= currObj.objToCheck; 
     725                                    if(iframe.contentWindow) 
     726                                        iframe=iframe.contentWindow.document; 
     727                                    else 
     728                                        iframe=iframe.contentDocument; 
     729                                    iframe.body.contentEditable="false" ; 
     730                                } 
     731                         } 
     732                } 
    805733        } 
    806734         
     
    826754        if(checkBrowser() == "ie") 
    827755        { 
    828                 value = window.event.srcElement; 
     756            if(!e){var e = ifr.contentWindow.event;} 
     757            if(!e.target){value = e.srcElement;} 
     758             
    829759        } 
    830760        else 
    831761        { 
    832                 value = e.target; 
     762            value = e.target; 
    833763        } 
    834764        return value; 
     
    899829 * php's showSuggestions function returns to.  It sets the  
    900830 * suggestions table to contain the new data and then displays 
    901  * the suggestions div.  It also clears the status message. 
     831 * the suggestions div.  It also adds the event listener - click - 
     832 * for all the suggestions tags and sets te property to be not editable. 
    902833 * 
    903834 * @param new_data The suggestions table returned from php. 
     
    911842        currObj.statusSpan.innerHTML = ""; 
    912843 
    913         //adicionado os listener - nathalie 
    914          var ifr= currObj.objToCheck; 
    915          if(ifr.contentWindow) 
    916             ifr=ifr.contentWindow.document; 
    917          else 
    918             ifr=ifr.contentDocument; 
     844        var ifr= currObj.objToCheck; 
     845        if(ifr.contentWindow) 
     846           ifr=ifr.contentWindow.document; 
     847        else 
     848           ifr=ifr.contentDocument; 
    919849 
    920850        var nodeArray = ifr.getElementsByTagName("div"); 
     
    927857                    ifr.getElementsByTagName("div")[i].contentEditable="false" ; 
    928858                 } 
    929                 else { 
     859                 else { 
    930860                    ifr.getElementsByTagName("div")[i].attachEvent("onclick", replaceMenu); 
    931861                    ifr.getElementsByTagName("div")[i].contentEditable="false" ; 
    932                 } 
    933                      
    934  
    935  
    936  
    937                  
     862                 } 
     863                  
    938864 
    939865            } 
     
    955881 * calls the showSuggestions php function with the misspelled word 
    956882 * and the id of the span containing it. 
     883 * This function is only executed when the word is in red (the word id misspelled). 
    957884 * 
    958885 * @param word The misspelled word that the user clicked on 
     
    961888function showSuggestions(word, id) 
    962889{ 
    963          
    964         //adicionado nathalie 
     890                 
    965891         var ifr= currObj.objToCheck; 
    966892         if(ifr.contentWindow) 
     
    969895            ifr=ifr.contentDocument; 
    970896 
    971          if (ifr.getElementById(id).className == "highlight"){ //show the suggestion box only when the words are in red  
    972  
    973     //alterado - colocar ifr 
     897         if (ifr.getElementById(id).className == "highlight"){ //show the suggestion box only if the words are in red 
     898 
     899    
    974900            languageId =  document.getElementById("selectLanguage"); 
    975901            languageId = languageId[document.getElementById("selectLanguage").selectedIndex].value; 
     
    1009935            spellingSuggestionsDiv.style.left = x + 'px'; 
    1010936            spellingSuggestionsDiv.style.top = (y+16-scrollPos) + 'px'; 
    1011             spellingSuggestionsDiv.id = 'suggestion_box'; //Adicionado Nathalie 
     937            spellingSuggestionsDiv.id = 'suggestion_box';  
    1012938            spellingSuggestionsDiv.contentEditable="false" ; 
    1013  
    1014  
    1015  
    1016  
    1017  
    1018  
    1019939 
    1020940 
     
    1023943            // showing and hiding the suggestion box, so we'll ignore the first 
    1024944            // click. 
    1025             //spellingSuggestionsDiv.ignoreNextClick = true; // comentado Nathalie 
     945            spellingSuggestionsDiv.ignoreNextClick = true;  
    1026946 
    1027947 
    1028948            //document.body.appendChild(spellingSuggestionsDiv); 
    1029             ifr.body.appendChild(spellingSuggestionsDiv); //alterado nathalie 
    1030  
    1031  
    1032  
     949            ifr.body.appendChild(spellingSuggestionsDiv); 
    1033950 
    1034951 
    1035952            cp.call(currObj.config['spellUrl'], 'showSuggestions', showSuggestions_cb, word, id, languageId); 
    1036         } 
     953        } // end if - show the suggestion box only if the words are in red 
    1037954 
    1038955}; // end showSuggestions 
     
    11611078        
    11621079        with(currObj); 
    1163         //By Nathalie - The Element means that this div belongs to the current tab 
    1164         //var parentElement = Element(currObj.spellingResultsDiv.id); //alterado nathalie 
    11651080        var ifr= currObj.objToCheck; 
    11661081        if(ifr.contentWindow) 
     
    11681083        else 
    11691084            ifr=ifr.contentDocument; 
    1170          
    1171         //var parentElement =ifr.getElementById(currObj.spellingResultsDiv.id); //alterado nathalie 
    1172         // 
     1085      
    11731086        // Obtain all span tags which have highlight className or corrected_word className 
    11741087        var nodeArray = ifr.getElementsByTagName("div"); 
     
    11951108        } 
    11961109 
    1197         var text = ifr.body.innerHTML; //alterado result div 
     1110        var text = ifr.body.innerHTML;  
    11981111 
    11991112        text = text.replace(/ /gi, " %u2026 "); // Replace   with the code %u2026 
     
    12201133 
    12211134 
    1222 //adicionado Paula 
    12231135    with(currObj); 
    12241136 
    1225         new_string = new_string.replace(/ %u2026/gi, " "); // Replace the code %u2026 with   
    1226               
    1227         new_string = new_string.replace(/~~~/gi, "\n"); 
    1228         
    1229         // Remove the prefixed asterisk that was added in switchText(). 
    1230         new_string = new_string.substr(1); 
    1231  
    1232  
    1233          currObj.objToCheck.style.display = "none"; 
    1234          var ifr= currObj.objToCheck; 
    1235          if(ifr.contentWindow) 
    1236             ifr=ifr.contentWindow.document; 
    1237          else 
    1238             ifr=ifr.contentDocument; 
    1239          var texto = ifr.body.innerHTML; 
    1240  
    1241          ifr.body.innerHTM = ""; //adicionado nathalie 
    1242          ifr.body.innerHTML = new_string; 
    1243          currObj.spellingResultsDiv = null; //adicionado nathalie 
    1244  
    1245           
    1246  
    1247         currObj.objToCheck.disabled = false; 
    1248          
    1249         //Removido Nathalie 
    1250         /*if(currObj.spellingResultsDiv) 
    1251         { 
    1252                 ifr.removeChild(currObj.spellingResultsDiv); //Alterado nathalie 
    1253                 currObj.spellingResultsDiv = null; 
    1254         }*/ 
    1255         currObj.objToCheck.style.display = "block"; 
    1256         currObj.resetAction(); 
     1137    new_string = new_string.replace(/ %u2026/gi, " "); // Replace the code %u2026 with   
     1138 
     1139    new_string = new_string.replace(/~~~/gi, "\n"); 
     1140 
     1141    // Remove the prefixed asterisk that was added in switchText(). 
     1142    new_string = new_string.substr(1); 
     1143 
     1144 
     1145    currObj.objToCheck.style.display = "none"; 
     1146    var ifr= currObj.objToCheck; 
     1147    if(ifr.contentWindow) 
     1148        ifr=ifr.contentWindow.document; 
     1149    else 
     1150        ifr=ifr.contentDocument; 
     1151    var texto = ifr.body.innerHTML; 
     1152 
     1153    ifr.body.innerHTM = ""; 
     1154    ifr.body.innerHTML = new_string; 
     1155    currObj.spellingResultsDiv = null; 
     1156 
     1157    currObj.objToCheck.disabled = false; 
     1158 
     1159 
     1160    currObj.objToCheck.style.display = "block"; 
     1161    currObj.resetAction(); 
    12571162}; // end switchText_cb 
    12581163 
     
    13241229{ 
    13251230 
    1326 //adicionado Paula 
     1231 
    13271232        with(currObj); 
    13281233        /*if(currObj.config['useIcons']) 
     
    13511256{ 
    13521257         
    1353         //adicionado nathalie 
     1258         
    13541259        var ifr= currObj.objToCheck; 
    1355          if(ifr.contentWindow) 
     1260        if(ifr.contentWindow) 
    13561261            ifr=ifr.contentWindow.document; 
    1357          else 
     1262        else 
    13581263            ifr=ifr.contentDocument; 
    13591264 
     
    13681273        if(currObj.spellingResultsDiv) 
    13691274        { 
    1370                 ifr.removeChild(currObj.spellingResultsDiv); //alterado nathalie 
     1275                ifr.removeChild(currObj.spellingResultsDiv);  
    13711276                currObj.spellingResultsDiv = null; 
    13721277        } 
     
    13931298    function findPosXById(object) 
    13941299{ 
    1395          
    1396         //adicionado Nathalie 
     1300                 
    13971301        var ifr= currObj.objToCheck; 
    1398          if(ifr.contentWindow) 
     1302        if(ifr.contentWindow) 
    13991303            ifr=ifr.contentWindow.document; 
    1400          else 
     1304        else 
    14011305            ifr=ifr.contentDocument; 
    14021306        var obj = ifr.getElementById(object); 
     
    14041308 
    14051309        var curleft = 0; 
    1406         //var obj = document.getElementById(object); //removido nathalie 
    1407  
    1408  
     1310         
    14091311        if(obj.offsetParent) 
    14101312        { 
     
    14341336 *************************************************************/ 
    14351337function findPosYById(object) 
    1436 { 
    1437          
    1438         //adicionado Nathalie 
     1338{       
    14391339        var ifr= currObj.objToCheck; 
    1440          if(ifr.contentWindow) 
     1340        if(ifr.contentWindow) 
    14411341            ifr=ifr.contentWindow.document; 
    1442          else 
     1342        else 
    14431343            ifr=ifr.contentDocument; 
    1444         var obj = ifr.getElementById(object); //removido Nathalie 
    1445  
     1344        var obj = ifr.getElementById(object); 
    14461345     
    14471346        var curtop = 0;var curtop = 0; 
    1448         //var obj = document.getElementById(object); //removido Nathalie 
    14491347        if(obj.offsetParent) 
    14501348        { 
Note: See TracChangeset for help on using the changeset viewer.