Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

googiespell.min.js 20KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. /**
  2. * Roundcube SpellCheck script
  3. *
  4. * jQuery'fied spell checker based on GoogieSpell 4.0
  5. * (which was published under GPL "version 2 or any later version")
  6. *
  7. * @licstart The following is the entire license notice for the
  8. * JavaScript code in this file.
  9. *
  10. * Copyright (C) 2006 Amir Salihefendic
  11. * Copyright (C) 2009 The Roundcube Dev Team
  12. * Copyright (C) 2011 Kolab Systems AG
  13. *
  14. * The JavaScript code in this page is free software: you can
  15. * redistribute it and/or modify it under the terms of the GNU
  16. * General Public License (GNU GPL) as published by the Free Software
  17. * Foundation, either version 3 of the License, or (at your option)
  18. * any later version. The code is distributed WITHOUT ANY WARRANTY;
  19. * without even the implied warranty of MERCHANTABILITY or FITNESS
  20. * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
  21. *
  22. * As additional permission under GNU GPL version 3 section 7, you
  23. * may distribute non-source (e.g., minimized or compacted) forms of
  24. * that code without the copy of the GNU GPL normally required by
  25. * section 4, provided you include this license notice and a URL
  26. * through which recipients can access the Corresponding Source.
  27. *
  28. * @licend The above is the entire license notice
  29. * for the JavaScript code in this file.
  30. *
  31. * @author 4mir Salihefendic <amix@amix.dk>
  32. * @author Aleksander Machniak - <alec [at] alec.pl>
  33. */
  34. var GOOGIE_CUR_LANG,GOOGIE_DEFAULT_LANG="en";
  35. function GoogieSpell(u,v,w){var m=this,t=rcmail.get_cookie("language");GOOGIE_CUR_LANG=null!=t?t:GOOGIE_DEFAULT_LANG;this.array_keys=function(a){var b=[],c;for(c in a)b.push([c]);return b};this.img_dir=u;this.server_url=v;this.lang_to_word=this.org_lang_to_word={da:"Dansk",de:"Deutsch",en:"English",es:"Espa\u00f1ol",fr:"Fran\u00e7ais",it:"Italiano",nl:"Nederlands",pl:"Polski",pt:"Portugu\u00eas",ru:"\u0420\u0443\u0441\u0441\u043a\u0438\u0439",fi:"Suomi",sv:"Svenska"};this.langlist_codes=this.array_keys(this.lang_to_word);
  36. this.show_change_lang_pic=!0;this.change_lang_pic_placement="right";this.report_state_change=!0;this.el_scroll_top=this.ta_scroll_top=0;this.lang_chck_spell="Check spelling";this.lang_revert="Revert to";this.lang_close="Close";this.lang_rsm_edt="Resume editing";this.lang_no_error_found="No spelling errors found";this.lang_no_suggestions="No suggestions";this.lang_learn_word="Add to dictionary";this.show_spell_img=!1;this.decoration=!0;this.use_close_btn=!1;this.report_ta_not_found=this.edit_layer_dbl_click=
  37. !0;this.custom_no_spelling_error=this.custom_ajax_error=null;this.custom_menu_builder=[];this.custom_item_evaulator=null;this.extra_menu_items=[];this.custom_spellcheck_starter=null;this.main_controller=!0;this.has_dictionary=w;this.all_errors_fixed_observer=this.show_menu_observer=this.spelling_state_observer=this.lang_state_observer=null;this.use_focus=!1;this.focus_link_b=this.focus_link_t=null;this.cnt_errors_fixed=this.cnt_errors=0;$(document).click(function(a){a=$(a.target);"1"!=a.attr("googie_action_btn")&&
  38. m.isLangWindowShown()&&m.hideLangWindow();"1"!=a.attr("googie_action_btn")&&m.isErrorWindowShown()&&m.hideErrorWindow()});this.decorateTextarea=function(a){if(this.text_area="string"===typeof a?document.getElementById(a):a){if(!this.spell_container&&this.decoration){a=document.createElement("table");var b=document.createElement("tbody"),c=document.createElement("tr"),d=document.createElement("td"),e=this.isDefined(this.force_width)?this.force_width:this.text_area.offsetWidth,g=this.isDefined(this.force_height)?
  39. this.force_height:16;c.appendChild(d);b.appendChild(c);$(a).append(b).insertBefore(this.text_area).width("100%").height(g);$(d).height(g).width(e).css("text-align","right");this.spell_container=d}this.checkSpellingState()}else this.report_ta_not_found&&alert("Text area not found")};this.setSpellContainer=function(a){this.spell_container="string"===typeof a?document.getElementById(a):a};this.setLanguages=function(a){this.lang_to_word=a;this.langlist_codes=this.array_keys(a)};this.setCurrentLanguage=
  40. function(a){GOOGIE_CUR_LANG=a;var b=new Date;b.setTime(b.getTime()+31536E6);rcmail.set_cookie("language",a,b)};this.setForceWidthHeight=function(a,b){this.force_width=a;this.force_height=b};this.setDecoration=function(a){this.decoration=a};this.dontUseCloseButtons=function(){this.use_close_btn=!1};this.appendNewMenuItem=function(a,b,c){this.extra_menu_items.push([a,b,c])};this.appendCustomMenuBuilder=function(a,b){this.custom_menu_builder.push([a,b])};this.setFocus=function(){try{return this.focus_link_b.focus(),
  41. this.focus_link_t.focus(),!0}catch(a){return!1}};this.setStateChanged=function(a){this.state=a;null!=this.spelling_state_observer&&this.report_state_change&&this.spelling_state_observer(a,this)};this.setReportStateChange=function(a){this.report_state_change=a};this.getUrl=function(){return this.server_url+GOOGIE_CUR_LANG};this.escapeSpecial=function(a){return a?a.replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;"):""};this.createXMLReq=function(a){return'<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>'+
  42. a+"</text></spellrequest>"};this.spellCheck=function(a){this.prepare(a);a=this.escapeSpecial(this.orginal_text);var b=this;$.ajax({type:"POST",url:this.getUrl(),data:this.createXMLReq(a),dataType:"text",error:function(a){b.custom_ajax_error?b.custom_ajax_error(b):alert("An error was encountered on the server. Please try again later.");b.main_controller&&($(b.spell_span).remove(),b.removeIndicator());b.checkSpellingState()},success:function(a){b.processData(a);b.results.length||(b.custom_no_spelling_error?
  43. b.custom_no_spelling_error(b):b.flashNoSpellingErrorState());b.removeIndicator()}})};this.learnWord=function(a,b){a=this.escapeSpecial(a.innerHTML);var c=this,d='<?xml version="1.0" encoding="utf-8" ?><learnword><text>'+a+"</text></learnword>";$.ajax({type:"POST",url:this.getUrl(),data:d,dataType:"text",error:function(a){c.custom_ajax_error?c.custom_ajax_error(c):alert("An error was encountered on the server. Please try again later.")},success:function(a){}})};this.prepare=function(a,b){this.cnt_errors=
  44. this.cnt_errors_fixed=0;this.setStateChanged("checking_spell");this.orginal_text="";!b&&this.main_controller&&this.appendIndicator(this.spell_span);this.error_links=[];this.ta_scroll_top=this.text_area.scrollTop;this.ignore=a;this.hideLangWindow();var c=$(this.text_area);if(""==c.val()||a)this.custom_no_spelling_error?this.custom_no_spelling_error(this):this.flashNoSpellingErrorState(),this.removeIndicator();else{this.createEditLayer(c.width(),c.height());this.createErrorWindow();$("body").append(this.error_window);
  45. try{netscape.security.PrivilegeManager.enablePrivilege("UniversalBrowserRead")}catch(d){}this.main_controller&&$(this.spell_span).off("click");this.orginal_text=c.val()}};this.parseResult=function(a){var b=/\w+="(\d+|true)"/g,c=/\t/g;a=a.match(/<c[^>]*>[^<]*<\/c>/g);var d=[];if(null==a)return d;for(var e=0,g=a.length;e<g;e++){var k=[];this.errorFound();k.attrs=[];for(var f,h,m=a[e].match(b),l=0;l<m.length;l++)f=m[l].split(/=/),h=f[1].replace(/"/g,""),k.attrs[f[0]]="true"!=h?parseInt(h):h;k.suggestions=
  46. [];f=a[e].replace(/<[^>]*>/g,"").split(c);for(h=0;h<f.length;h++)""!=f[h]&&k.suggestions.push(f[h]);d.push(k)}return d};this.processData=function(a){this.results=this.parseResult(a);this.results.length&&(this.showErrorsInIframe(),this.resumeEditingState())};this.createErrorWindow=function(){this.error_window=document.createElement("div");$(this.error_window).addClass("googie_window popupmenu").attr("googie_action_btn","1")};this.isErrorWindowShown=function(){return $(this.error_window).is(":visible")};
  47. this.hideErrorWindow=function(){$(this.error_window).hide();$(this.error_window_iframe).hide()};this.updateOrginalText=function(a,b,c,d){var e=this.orginal_text.substring(0,a);a=this.orginal_text.substring(a+b.length);b=c.length-b.length;this.orginal_text=e+c+a;$(this.text_area).val(this.orginal_text);c=0;for(e=this.results.length;c<e;c++)c!=d&&c>d&&(this.results[c].attrs.o+=b)};this.saveOldValue=function(a,b){a.is_changed=!0;a.old_value=b};this.createListSeparator=function(){var a=document.createElement("td"),
  48. b=document.createElement("tr");$(a).html(" ").attr("googie_action_btn","1").css({cursor:"default","font-size":"3px","border-top":"1px solid #ccc","padding-top":"3px"});b.appendChild(a);return b};this.correctError=function(a,b,c,d){var e=b.innerHTML;c=3==c.nodeType?c.nodeValue:c.innerHTML;var g=this.results[a].attrs.o;d&&(d=b.previousSibling.innerHTML,b.previousSibling.innerHTML=d.slice(0,d.length-1),e=" "+e,g--);this.hideErrorWindow();this.updateOrginalText(g,e,c,a);$(b).html(c).css("color","green").attr("is_corrected",
  49. !0);this.results[a].attrs.l=c.length;this.isDefined(b.old_value)||this.saveOldValue(b,e);this.errorFixed()};this.ignoreError=function(a,b){$(a).removeAttr("class").css("color","").off();this.hideErrorWindow()};this.showErrorWindow=function(a,b){this.show_menu_observer&&this.show_menu_observer(this);var c=this,d=$(a).offset(),e=document.createElement("table"),g=document.createElement("tbody");$(this.error_window).html("");$(e).addClass("googie_list").attr("googie_action_btn","1");for(var k=!1,f=0;f<
  50. this.custom_menu_builder.length;f++){var h=this.custom_menu_builder[f];if(h[0](this.results[b])){k=h[1](this,g,a);break}}if(!k){var k=this.results[b].suggestions,m=this.results[b].attrs.o,f=this.results[b].attrs.l,l,n;this.has_dictionary&&!$(a).attr("is_corrected")&&(h=document.createElement("tr"),l=document.createElement("td"),n=document.createElement("span"),$(n).text(this.lang_learn_word),$(l).attr("googie_action_btn","1").css("cursor","default").mouseover(c.item_onmouseover).mouseout(c.item_onmouseout).click(function(d){c.learnWord(a,
  51. b);c.ignoreError(a,b)}),l.appendChild(n),h.appendChild(l),g.appendChild(h));for(var q=0,f=k.length;q<f;q++)h=document.createElement("tr"),l=document.createElement("td"),n=document.createElement("span"),$(n).html(k[q]),$(l).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout).click(function(d){c.correctError(b,a,d.target.firstChild)}),l.appendChild(n),h.appendChild(l),g.appendChild(h);if(a.is_changed&&a.innerHTML!=a.old_value){var r=a.old_value,k=document.createElement("tr"),f=document.createElement("td"),
  52. h=document.createElement("span");$(h).addClass("googie_list_revert").html(this.lang_revert+" "+r);$(f).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout).click(function(d){c.updateOrginalText(m,a.innerHTML,r,b);$(a).removeAttr("is_corrected").css("color","#b91414").html(r);c.hideErrorWindow()});f.appendChild(h);k.appendChild(f);g.appendChild(k)}var k=document.createElement("tr"),f=document.createElement("td"),p=document.createElement("input"),h=document.createElement("img");l=document.createElement("form");
  53. n=function(){""!=p.value&&(c.isDefined(a.old_value)||c.saveOldValue(a,a.innerHTML),c.updateOrginalText(m,a.innerHTML,p.value,b),$(a).attr("is_corrected",!0).css("color","green").text(p.value),c.hideErrorWindow());return!1};$(p).width(120).css({margin:0,padding:0}).val($(a).text()).attr("googie_action_btn","1");$(f).css("cursor","default").attr("googie_action_btn","1");$(h).attr("src",this.img_dir+"ok.gif").width(32).height(16).css({cursor:"pointer","margin-left":"2px","margin-right":"2px"}).click(n);
  54. $(l).attr("googie_action_btn","1").css({margin:0,padding:0,cursor:"default","white-space":"nowrap"}).submit(n);l.appendChild(p);l.appendChild(h);f.appendChild(l);k.appendChild(f);g.appendChild(k);0<this.extra_menu_items.length&&g.appendChild(this.createListSeparator());var s=function(b){if(b<c.extra_menu_items.length){var d=c.extra_menu_items[b];if(!d[2]||d[2](a,c)){var e=document.createElement("tr"),f=document.createElement("td");$(f).html(d[0]).mouseover(c.item_onmouseover).mouseout(c.item_onmouseout).click(function(){return d[1](a,
  55. c)});e.appendChild(f);g.appendChild(e)}s(b+1)}};s(0);s=null;this.use_close_btn&&g.appendChild(this.createCloseButton(this.hideErrorWindow))}e.appendChild(g);this.error_window.appendChild(e);f=$(this.error_window).height();e=$(this.error_window).width();h=$(document).height();k=$(document).width();f=d.top+f+20<h?d.top+20:d.top-f;d=d.left+e<k?d.left:d.left-e;$(this.error_window).css({top:f+"px",left:d+"px"}).show();document.all&&!window.opera&&(this.error_window_iframe||(d=$("<iframe>").css({position:"absolute",
  56. "z-index":-1}),$("body").append(d),this.error_window_iframe=d),$(this.error_window_iframe).css({top:this.error_window.offsetTop,left:this.error_window.offsetLeft,width:this.error_window.offsetWidth,height:this.error_window.offsetHeight}).show())};this.createEditLayer=function(a,b){this.edit_layer=document.createElement("div");$(this.edit_layer).addClass("googie_edit_layer").attr("id","googie_edit_layer").width(a).height(b);"input"!=this.text_area.nodeName.toLowerCase()||""==$(this.text_area).val()?
  57. $(this.edit_layer).css("overflow","auto"):$(this.edit_layer).css("overflow","hidden");var c=this;this.edit_layer_dbl_click&&$(this.edit_layer).dblclick(function(a){if("googie_link"!=a.target.className&&!c.isErrorWindowShown()){c.resumeEditing();var b=function(){$(c.text_area).focus();b=null};window.setTimeout(b,10)}return!1})};this.resumeEditing=function(){this.setStateChanged("ready");this.edit_layer&&(this.el_scroll_top=this.edit_layer.scrollTop);this.hideErrorWindow();this.main_controller&&$(this.spell_span).removeClass().addClass("googie_no_style");
  58. this.ignore||(this.use_focus&&($(this.focus_link_t).remove(),$(this.focus_link_b).remove()),$(this.edit_layer).remove(),$(this.text_area).show(),void 0!=this.el_scroll_top&&(this.text_area.scrollTop=this.el_scroll_top));this.checkSpellingState(!1)};this.createErrorLink=function(a,b){var c=document.createElement("span"),d=this,e=function(a){d.showErrorWindow(c,b);e=null;return!1};$(c).html(a).addClass("googie_link").click(e).removeAttr("is_corrected").attr({googie_action_btn:"1",g_id:b});return c};
  59. this.createPart=function(a){if(" "==a)return document.createTextNode(" ");a=this.escapeSpecial(a);a=a.replace(/\n/g,"<br>");a=a.replace(/ /g," &nbsp;");a=a.replace(/^ /g,"&nbsp;");a=a.replace(/ $/g,"&nbsp;");var b=document.createElement("span");$(b).html(a);return b};this.showErrorsInIframe=function(){var a=document.createElement("div"),b=0,c=this.results;if(0<c.length){for(var d=0,e=c.length;d<e;d++){var g=c[d].attrs.o,k=c[d].attrs.l,f=this.orginal_text.substring(b,g),f=this.createPart(f);a.appendChild(f);
  60. b+=g-b;g=this.createErrorLink(this.orginal_text.substr(g,k),d);this.error_links.push(g);a.appendChild(g);b+=k}b=this.orginal_text.substr(b,this.orginal_text.length);b=this.createPart(b);a.appendChild(b)}else a.innerHTML=this.orginal_text;$(a).css("text-align","left");var h=this;this.custom_item_evaulator&&$.map(this.error_links,function(a){h.custom_item_evaulator(h,a)});$(this.edit_layer).append(a);$(this.text_area).hide();$(this.edit_layer).insertBefore(this.text_area);this.use_focus&&(this.focus_link_t=
  61. this.createFocusLink("focus_t"),this.focus_link_b=this.createFocusLink("focus_b"),$(this.focus_link_t).insertBefore(this.edit_layer),$(this.focus_link_b).insertAfter(this.edit_layer))};this.createLangWindow=function(){this.language_window=document.createElement("div");$(this.language_window).addClass("googie_window popupmenu").width(100).attr("googie_action_btn","1");var a=document.createElement("table"),b=document.createElement("tbody"),c=this,d,e,g;$(a).addClass("googie_list").width("100%");this.lang_elms=
  62. [];for(i=0;i<this.langlist_codes.length;i++)d=document.createElement("tr"),e=document.createElement("td"),g=document.createElement("span"),$(g).text(this.lang_to_word[this.langlist_codes[i]]),this.lang_elms.push(e),$(e).attr("googieId",this.langlist_codes[i]).click(function(a){c.deHighlightCurSel();c.setCurrentLanguage($(this).attr("googieId"));null!=c.lang_state_observer&&c.lang_state_observer();c.highlightCurSel();c.hideLangWindow()}).mouseover(function(a){"googie_list_selected"!=this.className&&
  63. (this.className="googie_list_onhover")}).mouseout(function(a){"googie_list_selected"!=this.className&&(this.className="googie_list_onout")}),e.appendChild(g),d.appendChild(e),b.appendChild(d);this.use_close_btn&&b.appendChild(this.createCloseButton(function(){c.hideLangWindow.apply(c)}));this.highlightCurSel();a.appendChild(b);this.language_window.appendChild(a)};this.isLangWindowShown=function(){return $(this.language_window).is(":visible")};this.hideLangWindow=function(){$(this.language_window).hide();
  64. $(this.switch_lan_pic).removeClass().addClass("googie_lang_3d_on")};this.showLangWindow=function(a){this.show_menu_observer&&this.show_menu_observer(this);this.createLangWindow();$("body").append(this.language_window);var b=$(a).offset(),c=$(a).height(),d=$(a).width();a=$(this.language_window).height();var e=$(document).height(),d="right"==this.change_lang_pic_placement?b.left-100+d:b.left+d,b=b.top+a<e?b.top+c:b.top-a-4;$(this.language_window).css({top:b+"px",left:d+"px"}).show();this.highlightCurSel()};
  65. this.deHighlightCurSel=function(){$(this.lang_cur_elm).removeClass().addClass("googie_list_onout")};this.highlightCurSel=function(){null==GOOGIE_CUR_LANG&&(GOOGIE_CUR_LANG=GOOGIE_DEFAULT_LANG);for(var a=0;a<this.lang_elms.length;a++)$(this.lang_elms[a]).attr("googieId")==GOOGIE_CUR_LANG?(this.lang_elms[a].className="googie_list_selected",this.lang_cur_elm=this.lang_elms[a]):this.lang_elms[a].className="googie_list_onout"};this.createChangeLangPic=function(){var a=$("<img>").attr({src:this.img_dir+
  66. "change_lang.gif",alt:"Change language",googie_action_btn:"1"}),b=document.createElement("span");m=this;$(b).addClass("googie_lang_3d_on").append(a).click(function(a){a="img"==this.tagName.toLowerCase()?this.parentNode:this;$(a).hasClass("googie_lang_3d_click")?(a.className="googie_lang_3d_on",m.hideLangWindow()):(a.className="googie_lang_3d_click",m.showLangWindow(a))});return b};this.createSpellDiv=function(){var a=document.createElement("span");$(a).addClass("googie_check_spelling_link").text(this.lang_chck_spell);
  67. this.show_spell_img&&$(a).append(" ").append($("<img>").attr("src",this.img_dir+"spellc.gif"));return a};this.flashNoSpellingErrorState=function(a){this.setStateChanged("no_error_found");var b=this;if(this.main_controller){var c;c=a?function(){a();b.checkSpellingState()}:function(){b.checkSpellingState()};var d=$("<span>").text(this.lang_no_error_found);$(this.switch_lan_pic).hide();$(this.spell_span).empty().append(d).removeClass().addClass("googie_check_spelling_ok");window.setTimeout(c,1E3)}};
  68. this.resumeEditingState=function(){this.setStateChanged("resume_editing");if(this.main_controller){var a=$("<span>").text(this.lang_rsm_edt),b=this;$(this.switch_lan_pic).hide();$(this.spell_span).empty().off().append(a).click(function(){b.resumeEditing()}).removeClass().addClass("googie_resume_editing")}try{this.edit_layer.scrollTop=this.ta_scroll_top}catch(c){}};this.checkSpellingState=function(a){a&&this.setStateChanged("ready");this.switch_lan_pic=this.show_change_lang_pic?this.createChangeLangPic():
  69. document.createElement("span");a=this.createSpellDiv();var b=this;this.custom_spellcheck_starter?$(a).click(function(a){b.custom_spellcheck_starter()}):$(a).click(function(a){b.spellCheck()});this.main_controller&&("left"==this.change_lang_pic_placement?$(this.spell_container).empty().append(this.switch_lan_pic).append(" ").append(a):$(this.spell_container).empty().append(a).append(" ").append(this.switch_lan_pic));this.spell_span=a};this.isDefined=function(a){return void 0!==a&&null!==a};this.errorFixed=
  70. function(){this.cnt_errors_fixed++;this.all_errors_fixed_observer&&this.cnt_errors_fixed==this.cnt_errors&&(this.hideErrorWindow(),this.all_errors_fixed_observer())};this.errorFound=function(){this.cnt_errors++};this.createCloseButton=function(a){return this.createButton(this.lang_close,"googie_list_close",a)};this.createButton=function(a,b,c){var d=document.createElement("tr"),e=document.createElement("td"),g;b?(g=document.createElement("span"),$(g).addClass(b).html(a)):g=document.createTextNode(a);
  71. $(e).click(c).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout);e.appendChild(g);d.appendChild(e);return d};this.removeIndicator=function(a){window.rcmail&&rcmail.set_busy(!1,null,this.rc_msg_id)};this.appendIndicator=function(a){window.rcmail&&(this.rc_msg_id=rcmail.set_busy(!0,"checking"))};this.createFocusLink=function(a){var b=document.createElement("a");$(b).attr({href:"javascript:;",name:a});return b};this.item_onmouseover=function(a){"googie_list_revert"!=this.className&&"googie_list_close"!=
  72. this.className?this.className="googie_list_onhover":this.parentNode.className="googie_list_onhover"};this.item_onmouseout=function(a){"googie_list_revert"!=this.className&&"googie_list_close"!=this.className?this.className="googie_list_onout":this.parentNode.className="googie_list_onout"}};