1 var SPELL_CUR_LANG=null;
2 var GOOGIE_DEFAULT_LANG="en";
3 function GoogieSpell(_1,_2){
5 this.array_keys=function(_4){
12 var _7=getCookie("language");
13 GOOGIE_CUR_LANG=_7!=null?_7:GOOGIE_DEFAULT_LANG;
16 this.org_lang_to_word={"da":"Dansk","de":"Deutsch","en":"English","es":"Español","fr":"Français","it":"Italiano","nl":"Nederlands","pl":"Polski","pt":"Português","fi":"Suomi","sv":"Svenska"};
17 this.lang_to_word=this.org_lang_to_word;
18 this.langlist_codes=this.array_keys(this.lang_to_word);
19 this.show_change_lang_pic=true;
20 this.change_lang_pic_placement="right";
21 this.report_state_change=true;
24 this.lang_chck_spell="Check spelling";
25 this.lang_revert="Revert to";
26 this.lang_close="Close";
27 this.lang_rsm_edt="Resume editing";
28 this.lang_no_error_found="No spelling errors found";
29 this.lang_no_suggestions="No suggestions";
30 this.show_spell_img=false;
32 this.use_close_btn=true;
33 this.edit_layer_dbl_click=true;
34 this.report_ta_not_found=true;
35 this.custom_ajax_error=null;
36 this.custom_no_spelling_error=null;
37 this.custom_menu_builder=[];
38 this.custom_item_evaulator=null;
39 this.extra_menu_items=[];
40 this.custom_spellcheck_starter=null;
41 this.main_controller=true;
42 this.lang_state_observer=null;
43 this.spelling_state_observer=null;
44 this.show_menu_observer=null;
45 this.all_errors_fixed_observer=null;
47 this.focus_link_t=null;
48 this.focus_link_b=null;
50 this.cnt_errors_fixed=0;
51 $(document).bind("click",function(e){
52 if($(e.target).attr("googie_action_btn")!="1"&&_3.isLangWindowShown()){
55 if($(e.target).attr("googie_action_btn")!="1"&&_3.isErrorWindowShown()){
59 this.decorateTextarea=function(id){
60 this.text_area=typeof (id)=="string"?document.getElementById(id):id;
62 if(!this.spell_container&&this.decoration){
63 var _a=document.createElement("table");
64 var _b=document.createElement("tbody");
65 var tr=document.createElement("tr");
66 var _d=document.createElement("td");
67 var _e=this.isDefined(this.force_width)?this.force_width:this.text_area.offsetWidth;
68 var _f=this.isDefined(this.force_height)?this.force_height:16;
71 $(_a).append(_b).insertBefore(this.text_area).width("100%").height(_f);
72 $(_d).height(_f).width(_e).css("text-align","right");
73 this.spell_container=_d;
75 this.checkSpellingState();
77 if(this.report_ta_not_found){
78 alert("Text area not found");
82 this.setSpellContainer=function(id){
83 this.spell_container=typeof (id)=="string"?document.getElementById(id):id;
85 this.setLanguages=function(_11){
86 this.lang_to_word=_11;
87 this.langlist_codes=this.array_keys(_11);
89 this.setCurrentLanguage=function(_12){
92 now.setTime(now.getTime()+365*24*60*60*1000);
93 setCookie("language",_12,now);
95 this.setForceWidthHeight=function(_14,_15){
97 this.force_height=_15;
99 this.setDecoration=function(_16){
102 this.dontUseCloseButtons=function(){
103 this.use_close_btn=false;
105 this.appendNewMenuItem=function(_17,_18,_19){
106 this.extra_menu_items.push([_17,_18,_19]);
108 this.appendCustomMenuBuilder=function(_1a,_1b){
109 this.custom_menu_builder.push([_1a,_1b]);
111 this.setFocus=function(){
113 this.focus_link_b.focus();
114 this.focus_link_t.focus();
121 this.setStateChanged=function(_1c){
123 if(this.spelling_state_observer!=null&&this.report_state_change){
124 this.spelling_state_observer(_1c,this);
127 this.setReportStateChange=function(_1d){
128 this.report_state_change=_1d;
130 this.getUrl=function(){
131 return this.server_url+GOOGIE_CUR_LANG;
133 this.escapeSpecial=function(val){
134 return val.replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">");
136 this.createXMLReq=function(_1f){
137 return "<?xml version=\"1.0\" encoding=\"utf-8\" ?>"+"<spellrequest textalreadyclipped=\"0\" ignoredups=\"0\" ignoredigits=\"1\" ignoreallcaps=\"1\">"+"<text>"+_1f+"</text></spellrequest>";
139 this.spellCheck=function(_20){
140 this.cnt_errors_fixed=0;
142 this.setStateChanged("checking_spell");
143 if(this.main_controller){
144 this.appendIndicator(this.spell_span);
147 this.ta_scroll_top=this.text_area.scrollTop;
149 this.hideLangWindow();
150 if($(this.text_area).val()==""||_20){
151 if(!this.custom_no_spelling_error){
152 this.flashNoSpellingErrorState();
154 this.custom_no_spelling_error(this);
156 this.removeIndicator();
159 this.createEditLayer(this.text_area.offsetWidth,this.text_area.offsetHeight);
160 this.createErrorWindow();
161 $("body").append(this.error_window);
163 netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead");
167 if(this.main_controller){
168 $(this.spell_span).unbind("click");
170 this.orginal_text=$(this.text_area).val();
171 var _21=this.escapeSpecial(this.orginal_text);
173 $.ajax({type:"POST",url:this.getUrl(),data:this.createXMLReq(_21),dataType:"text",error:function(o){
174 if(ref.custom_ajax_error){
175 ref.custom_ajax_error(ref);
177 alert("An error was encountered on the server. Please try again later.");
179 if(ref.main_controller){
180 $(ref.spell_span).remove();
181 ref.removeIndicator();
183 ref.checkSpellingState();
184 },success:function(_24){
186 ref.results=ref.parseResult(_25);
187 if(_25.match(/<c.*>/)!=null){
188 ref.showErrorsInIframe();
189 ref.resumeEditingState();
191 if(!ref.custom_no_spelling_error){
192 ref.flashNoSpellingErrorState();
194 ref.custom_no_spelling_error(ref);
197 ref.removeIndicator();
200 this.parseResult=function(_26){
201 var _27=/\w+="(\d+|true)"/g;
203 var _29=_26.match(/<c[^>]*>[^<]*<\/c>/g);
208 for(var i=0;i<_29.length;i++){
211 _2c["attrs"]=new Array();
212 var _2d=_29[i].match(_27);
213 for(var j=0;j<_2d.length;j++){
214 var _2f=_2d[j].split(/=/);
215 var val=_2f[1].replace(/"/g,"");
216 _2c["attrs"][_2f[0]]=val!="true"?parseInt(val):val;
218 _2c["suggestions"]=new Array();
219 var _31=_29[i].replace(/<[^>]*>/g,"");
220 var _32=_31.split(_28);
221 for(var k=0;k<_32.length;k++){
223 _2c["suggestions"].push(_32[k]);
230 this.createErrorWindow=function(){
231 this.error_window=document.createElement("div");
232 $(this.error_window).addClass("googie_window").attr("googie_action_btn","1");
234 this.isErrorWindowShown=function(){
235 return $(this.error_window).is(":visible");
237 this.hideErrorWindow=function(){
238 $(this.error_window).css("visibility","hidden");
239 $(this.error_window_iframe).css("visibility","hidden");
241 this.updateOrginalText=function(_34,_35,_36,id){
242 var _38=this.orginal_text.substring(0,_34);
243 var _39=this.orginal_text.substring(_34+_35.length);
244 this.orginal_text=_38+_36+_39;
245 $(this.text_area).val(this.orginal_text);
246 var _3a=_36.length-_35.length;
247 for(var j=0;j<this.results.length;j++){
249 this.results[j]["attrs"]["o"]+=_3a;
253 this.saveOldValue=function(elm,_3d){
257 this.createListSeparator=function(){
258 var td=document.createElement("td");
259 var tr=document.createElement("tr");
260 $(td).html(" ").attr("googie_action_btn","1").css({"cursor":"default","font-size":"3px","border-top":"1px solid #ccc","padding-top":"3px"});
264 this.correctError=function(id,elm,_42,_43){
265 var _44=elm.innerHTML;
266 var _45=_42.nodeType==3?_42.nodeValue:_42.innerHTML;
267 var _46=this.results[id]["attrs"]["o"];
269 var _47=elm.previousSibling.innerHTML;
270 elm.previousSibling.innerHTML=_47.slice(0,_47.length-1);
274 this.hideErrorWindow();
275 this.updateOrginalText(_46,_44,_45,id);
276 $(elm).html(_45).css("color","green").attr("is_corrected",true);
277 this.results[id]["attrs"]["l"]=_45.length;
278 if(!this.isDefined(elm.old_value)){
279 this.saveOldValue(elm,_44);
283 this.showErrorWindow=function(elm,id){
284 if(this.show_menu_observer){
285 this.show_menu_observer(this);
288 var pos=$(elm).offset();
289 pos.top-=this.edit_layer.scrollTop;
290 $(this.error_window).css({"visibility":"visible","top":(pos.top+20)+"px","left":(pos.left)+"px"}).html("");
291 var _4c=document.createElement("table");
292 var _4d=document.createElement("tbody");
293 $(_4c).addClass("googie_list").attr("googie_action_btn","1");
295 if(this.custom_menu_builder!=[]){
296 for(var k=0;k<this.custom_menu_builder.length;k++){
297 var eb=this.custom_menu_builder[k];
298 if(eb[0]((this.results[id]))){
299 _4e=eb[1](this,_4d,elm);
305 var _51=this.results[id]["suggestions"];
306 var _52=this.results[id]["attrs"]["o"];
307 var len=this.results[id]["attrs"]["l"];
309 var row=document.createElement("tr");
310 var _55=document.createElement("td");
311 var _56=document.createElement("span");
312 $(_56).text(this.lang_no_suggestions);
313 $(_55).attr("googie_action_btn","1").css("cursor","default");
314 _55.appendChild(_56);
315 row.appendChild(_55);
316 _4d.appendChild(row);
318 for(i=0;i<_51.length;i++){
319 var row=document.createElement("tr");
320 var _55=document.createElement("td");
321 var _56=document.createElement("span");
323 $(_55).bind("mouseover",this.item_onmouseover).bind("mouseout",this.item_onmouseout).bind("click",function(e){
324 ref.correctError(id,elm,e.target.firstChild);
326 _55.appendChild(_56);
327 row.appendChild(_55);
328 _4d.appendChild(row);
330 if(elm.is_changed&&elm.innerHTML!=elm.old_value){
331 var _58=elm.old_value;
332 var _59=document.createElement("tr");
333 var _5a=document.createElement("td");
334 var _5b=document.createElement("span");
335 $(_5b).addClass("googie_list_revert").html(this.lang_revert+" "+_58);
336 $(_5a).bind("mouseover",this.item_onmouseover).bind("mouseout",this.item_onmouseout).bind("click",function(e){
337 ref.updateOrginalText(_52,elm.innerHTML,_58,id);
338 $(elm).attr("is_corrected",true).css("color","#b91414").html(_58);
339 ref.hideErrorWindow();
341 _5a.appendChild(_5b);
342 _59.appendChild(_5a);
343 _4d.appendChild(_59);
345 var _5d=document.createElement("tr");
346 var _5e=document.createElement("td");
347 var _5f=document.createElement("input");
348 var _60=document.createElement("img");
349 var _61=document.createElement("form");
352 if(!ref.isDefined(elm.old_value)){
353 ref.saveOldValue(elm,elm.innerHTML);
355 ref.updateOrginalText(_52,elm.innerHTML,_5f.value,id);
356 $(elm).attr("is_corrected",true).css("color","green").html(_5f.value);
357 ref.hideErrorWindow();
361 $(_5f).width(120).css({"margin":0,"padding":0});
362 $(_5f).val(elm.innerHTML).attr("googie_action_btn","1");
363 $(_5e).css("cursor","default").attr("googie_action_btn","1");
364 $(_60).attr("src",this.img_dir+"ok.gif").width(32).height(16).css({"cursor":"pointer","margin-left":"2px","margin-right":"2px"}).bind("click",_62);
365 $(_61).attr("googie_action_btn","1").css({"margin":0,"padding":0,"cursor":"default","white-space":"nowrap"}).bind("submit",_62);
366 _61.appendChild(_5f);
367 _61.appendChild(_60);
368 _5e.appendChild(_61);
369 _5d.appendChild(_5e);
370 _4d.appendChild(_5d);
371 if(this.extra_menu_items.length>0){
372 _4d.appendChild(this.createListSeparator());
375 if(i<ref.extra_menu_items.length){
376 var _65=ref.extra_menu_items[i];
377 if(!_65[2]||_65[2](elm,ref)){
378 var _66=document.createElement("tr");
379 var _67=document.createElement("td");
380 $(_67).html(_65[0]).bind("mouseover",ref.item_onmouseover).bind("mouseout",ref.item_onmouseout).bind("click",function(){
381 return _65[1](elm,ref);
383 _66.appendChild(_67);
384 _4d.appendChild(_66);
391 if(this.use_close_btn){
392 _4d.appendChild(this.createCloseButton(this.hideErrorWindow));
395 _4c.appendChild(_4d);
396 this.error_window.appendChild(_4c);
398 if(!this.error_window_iframe){
399 var _68=$("<iframe>").css("position","absolute").css("z-index",0);
400 $("body").append(_68);
401 this.error_window_iframe=_68;
403 $(this.error_window_iframe).css({"visibility":"visible","top":this.error_window.offsetTop,"left":this.error_window.offsetLeft,"width":this.error_window.offsetWidth,"height":this.error_window.offsetHeight});
406 this.createEditLayer=function(_69,_6a){
407 this.edit_layer=document.createElement("div");
408 $(this.edit_layer).addClass("googie_edit_layer").width(_69-10).height(_6a);
409 if(this.text_area.nodeName.toLowerCase()!="input"||$(this.text_area).val()==""){
410 $(this.edit_layer).css("overflow","auto").height(_6a-4);
412 $(this.edit_layer).css("overflow","hidden");
415 if(this.edit_layer_dbl_click){
416 $(this.edit_layer).bind("click",function(e){
417 if(e.target.className!="googie_link"&&!ref.isErrorWindowShown()){
420 $(ref.text_area).focus();
423 window.setTimeout(fn1,10);
429 this.resumeEditing=function(){
430 this.setStateChanged("ready");
432 this.el_scroll_top=this.edit_layer.scrollTop;
434 this.hideErrorWindow();
435 if(this.main_controller){
436 $(this.spell_span).removeClass().addClass("googie_no_style");
440 $(this.focus_link_t).remove();
441 $(this.focus_link_b).remove();
443 $(this.edit_layer).remove();
444 $(this.text_area).show();
445 if(this.el_scroll_top!=undefined){
446 this.text_area.scrollTop=this.el_scroll_top;
449 this.checkSpellingState(false);
451 this.createErrorLink=function(_6e,id){
452 var elm=document.createElement("span");
455 ref.showErrorWindow(elm,id);
459 $(elm).html(_6e).addClass("googie_link").bind("click",d).attr({"googie_action_btn":"1","g_id":id,"is_corrected":false});
462 this.createPart=function(_74){
464 return document.createTextNode(" ");
466 _74=this.escapeSpecial(_74);
467 _74=_74.replace(/\n/g,"<br>");
468 _74=_74.replace(/ /g," ");
469 _74=_74.replace(/^ /g," ");
470 _74=_74.replace(/ $/g," ");
471 var _75=document.createElement("span");
475 this.showErrorsInIframe=function(){
476 var _76=document.createElement("div");
478 var _78=this.results;
480 for(var i=0;i<_78.length;i++){
481 var _7a=_78[i]["attrs"]["o"];
482 var len=_78[i]["attrs"]["l"];
483 var _7c=this.orginal_text.substring(_77,_7a);
484 var _7d=this.createPart(_7c);
485 _76.appendChild(_7d);
487 var _7e=this.createErrorLink(this.orginal_text.substr(_7a,len),i);
488 this.error_links.push(_7e);
489 _76.appendChild(_7e);
492 var _7f=this.orginal_text.substr(_77,this.orginal_text.length);
493 var _80=this.createPart(_7f);
494 _76.appendChild(_80);
496 _76.innerHTML=this.orginal_text;
498 $(_76).css("text-align","left");
500 if(this.custom_item_evaulator){
501 $.map(this.error_links,function(elm){
502 me.custom_item_evaulator(me,elm);
505 $(this.edit_layer).append(_76);
506 $(this.text_area).hide();
507 $(this.edit_layer).insertBefore(this.text_area);
509 this.focus_link_t=this.createFocusLink("focus_t");
510 this.focus_link_b=this.createFocusLink("focus_b");
511 $(this.focus_link_t).insertBefore(this.edit_layer);
512 $(this.focus_link_b).insertAfter(this.edit_layer);
515 this.createLangWindow=function(){
516 this.language_window=document.createElement("div");
517 $(this.language_window).addClass("googie_window").width(100).attr("googie_action_btn","1");
518 var _83=document.createElement("table");
519 var _84=document.createElement("tbody");
521 $(_83).addClass("googie_list").width("100%");
522 this.lang_elms=new Array();
523 for(i=0;i<this.langlist_codes.length;i++){
524 var row=document.createElement("tr");
525 var _87=document.createElement("td");
526 var _88=document.createElement("span");
527 $(_88).text(this.lang_to_word[this.langlist_codes[i]]);
528 this.lang_elms.push(_87);
529 $(_87).attr("googieId",this.langlist_codes[i]).bind("click",function(e){
530 ref.deHighlightCurSel();
531 ref.setCurrentLanguage($(this).attr("googieId"));
532 if(ref.lang_state_observer!=null){
533 ref.lang_state_observer();
535 ref.highlightCurSel();
536 ref.hideLangWindow();
537 }).bind("mouseover",function(e){
538 if(this.className!="googie_list_selected"){
539 this.className="googie_list_onhover";
541 }).bind("mouseout",function(e){
542 if(this.className!="googie_list_selected"){
543 this.className="googie_list_onout";
546 _87.appendChild(_88);
547 row.appendChild(_87);
548 _84.appendChild(row);
550 if(this.use_close_btn){
551 _84.appendChild(this.createCloseButton(function(){
552 ref.hideLangWindow.apply(ref);
555 this.highlightCurSel();
556 _83.appendChild(_84);
557 this.language_window.appendChild(_83);
559 this.isLangWindowShown=function(){
560 return $(this.language_window).is(":hidden");
562 this.hideLangWindow=function(){
563 $(this.language_window).css("visibility","hidden");
564 $(this.switch_lan_pic).removeClass().addClass("googie_lang_3d_on");
566 this.deHighlightCurSel=function(){
567 $(this.lang_cur_elm).removeClass().addClass("googie_list_onout");
569 this.highlightCurSel=function(){
570 if(GOOGIE_CUR_LANG==null){
571 GOOGIE_CUR_LANG=GOOGIE_DEFAULT_LANG;
573 for(var i=0;i<this.lang_elms.length;i++){
574 if($(this.lang_elms[i]).attr("googieId")==GOOGIE_CUR_LANG){
575 this.lang_elms[i].className="googie_list_selected";
576 this.lang_cur_elm=this.lang_elms[i];
578 this.lang_elms[i].className="googie_list_onout";
582 this.showLangWindow=function(elm){
583 if(this.show_menu_observer){
584 this.show_menu_observer(this);
586 this.createLangWindow();
587 $("body").append(this.language_window);
588 var pos=$(elm).offset();
589 var top=pos.top+$(elm).height();
590 var _90=this.change_lang_pic_placement=="right"?pos.left-100+$(elm).width():pos.left+$(elm).width();
591 $(this.language_window).css({"visibility":"visible","top":top+"px","left":_90+"px"});
592 this.highlightCurSel();
594 this.createChangeLangPic=function(){
595 var img=$("<img>").attr({src:this.img_dir+"change_lang.gif","alt":"Change language","googie_action_btn":"1"});
596 var _92=document.createElement("span");
598 $(_92).addClass("googie_lang_3d_on").append(img).bind("click",function(e){
599 var elm=this.tagName.toLowerCase()=="img"?this.parentNode:this;
600 if($(elm).hasClass("googie_lang_3d_click")){
601 elm.className="googie_lang_3d_on";
602 ref.hideLangWindow();
604 elm.className="googie_lang_3d_click";
605 ref.showLangWindow(elm);
610 this.createSpellDiv=function(){
611 var _96=document.createElement("span");
612 $(_96).addClass("googie_check_spelling_link").text(this.lang_chck_spell);
613 if(this.show_spell_img){
614 $(_96).append(" ").append($("<img>").attr("src",this.img_dir+"spellc.gif"));
618 this.flashNoSpellingErrorState=function(_97){
619 this.setStateChanged("no_error_found");
621 if(this.main_controller){
626 ref.checkSpellingState();
631 ref.checkSpellingState();
634 var rsm=$("<span>").text(this.lang_no_error_found);
635 $(this.switch_lan_pic).hide();
636 $(this.spell_span).empty().append(rsm).removeClass().addClass("googie_check_spelling_ok");
637 window.setTimeout(_99,1000);
640 this.resumeEditingState=function(){
641 this.setStateChanged("resume_editing");
642 if(this.main_controller){
643 var rsm=$("<span>").text(this.lang_rsm_edt);
645 $(this.switch_lan_pic).hide();
646 $(this.spell_span).empty().unbind().append(rsm).bind("click",function(){
648 }).removeClass().addClass("googie_resume_editing");
651 this.edit_layer.scrollTop=this.ta_scroll_top;
656 this.checkSpellingState=function(_9e){
658 this.setStateChanged("ready");
660 if(this.show_change_lang_pic){
661 this.switch_lan_pic=this.createChangeLangPic();
663 this.switch_lan_pic=document.createElement("span");
665 var _9f=this.createSpellDiv();
667 if(this.custom_spellcheck_starter){
668 $(_9f).bind("click",function(e){
669 ref.custom_spellcheck_starter();
672 $(_9f).bind("click",function(e){
676 if(this.main_controller){
677 if(this.change_lang_pic_placement=="left"){
678 $(this.spell_container).empty().append(this.switch_lan_pic).append(" ").append(_9f);
680 $(this.spell_container).empty().append(_9f).append(" ").append(this.switch_lan_pic);
685 this.isDefined=function(o){
686 return (o!="undefined"&&o!=null);
688 this.errorFixed=function(){
689 this.cnt_errors_fixed++;
690 if(this.all_errors_fixed_observer){
691 if(this.cnt_errors_fixed==this.cnt_errors){
692 this.hideErrorWindow();
693 this.all_errors_fixed_observer();
697 this.errorFound=function(){
700 this.createCloseButton=function(_a4){
701 return this.createButton(this.lang_close,"googie_list_close",_a4);
703 this.createButton=function(_a5,_a6,_a7){
704 var _a8=document.createElement("tr");
705 var btn=document.createElement("td");
708 _aa=document.createElement("span");
709 $(_aa).addClass(_a6).html(_a5);
711 _aa=document.createTextNode(_a5);
713 $(btn).bind("click",_a7).bind("mouseover",this.item_onmouseover).bind("mouseout",this.item_onmouseout);
714 btn.appendChild(_aa);
715 _a8.appendChild(btn);
718 this.removeIndicator=function(elm){
720 rcmail.set_busy(false);
723 this.appendIndicator=function(elm){
725 rcmail.set_busy(true,"checking");
728 this.createFocusLink=function(_ad){
729 var _ae=document.createElement("a");
730 $(_ae).attr({"href":"javascript:;","name":_ad});
733 this.item_onmouseover=function(e){
734 if(this.className!="googie_list_revert"&&this.className!="googie_list_close"){
735 this.className="googie_list_onhover";
737 this.parentNode.className="googie_list_onhover";
740 this.item_onmouseout=function(e){
741 if(this.className!="googie_list_revert"&&this.className!="googie_list_close"){
742 this.className="googie_list_onout";
744 this.parentNode.className="googie_list_onout";