/** * Roundcube SpellCheck script * * jQuery'fied spell checker based on GoogieSpell 4.0 * (which was published under GPL "version 2 or any later version") * * @licstart The following is the entire license notice for the * JavaScript code in this file. * * Copyright (C) 2006 Amir Salihefendic * Copyright (C) The Roundcube Dev Team * Copyright (C) Kolab Systems AG * * The JavaScript code in this page is free software: you can * redistribute it and/or modify it under the terms of the GNU * General Public License (GNU GPL) as published by the Free Software * Foundation, either version 3 of the License, or (at your option) * any later version. The code is distributed WITHOUT ANY WARRANTY; * without even the implied warranty of MERCHANTABILITY or FITNESS * FOR A PARTICULAR PURPOSE. See the GNU GPL for more details. * * As additional permission under GNU GPL version 3 section 7, you * may distribute non-source (e.g., minimized or compacted) forms of * that code without the copy of the GNU GPL normally required by * section 4, provided you include this license notice and a URL * through which recipients can access the Corresponding Source. * * @licend The above is the entire license notice * for the JavaScript code in this file. * * @author 4mir Salihefendic * @author Aleksander Machniak - */ var GOOGIE_CUR_LANG,GOOGIE_DEFAULT_LANG="en"; function GoogieSpell(x,y,z){var t=this,u=rcmail.get_cookie("language");GOOGIE_CUR_LANG=null!=u?u:GOOGIE_DEFAULT_LANG;this.array_keys=function(a){var b=[],c;for(c in a)b.push([c]);return b};this.img_dir=x;this.server_url=y;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); this.show_change_lang_pic=!1;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=this.use_ok_pic=!1;this.decoration=!0;this.use_close_btn=!1;this.report_ta_not_found= this.edit_layer_dbl_click=!0;this.custom_no_spelling_error=this.custom_ajax_error=null;this.extra_menu_items=[];this.custom_spellcheck_starter=null;this.main_controller=!0;this.has_dictionary=z;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){"1"!=$(a.target).attr("googie_action_btn")&&t.isErrorWindowShown()&& t.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,f=this.isDefined(this.force_height)?this.force_height:16;c.appendChild(d);b.appendChild(c);$(a).append(b).insertBefore(this.text_area).width("100%").height(f); $(d).height(f).width(e).css("text-align","right");this.spell_container=d}this.checkSpellingState()}else this.report_ta_not_found&&rcmail.alert_dialog("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=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.setFocus=function(){try{return this.focus_link_b.focus(),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,"&").replace(//g,">"):""};this.createXMLReq=function(a){return''+a+""};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(c){b.custom_ajax_error?b.custom_ajax_error(b):rcmail.alert_dialog("An error was encountered on the server. Please try again later.");b.main_controller&&($(b.spell_span).remove(),b.removeIndicator());b.checkSpellingState()},success:function(c){b.processData(c);b.results.length||(b.custom_no_spelling_error?b.custom_no_spelling_error(b):b.flashNoSpellingErrorState());b.removeIndicator()}})};this.learnWord= function(a,b){a=this.escapeSpecial(a.innerHTML);var c=this;a=''+a+"";$.ajax({type:"POST",url:this.getUrl(),data:a,dataType:"text",error:function(d){c.custom_ajax_error?c.custom_ajax_error(c):rcmail.alert_dialog("An error was encountered on the server. Please try again later.")},success:function(d){}})};this.prepare=function(a,b){this.cnt_errors=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;b=$(this.text_area);""==b.val()||a?(this.custom_no_spelling_error?this.custom_no_spelling_error(this):this.flashNoSpellingErrorState(),this.removeIndicator()):(a="border-box"==$(b).css("box-sizing")?this.text_area.offsetHeight:$(b).height(),this.createEditLayer(b.width(),a),this.createErrorWindow(),$("body").append(this.error_window),this.main_controller&& $(this.spell_span).off("click"),this.orginal_text=b.val())};this.parseResult=function(a){var b=/\w+="(\d+|true)"/g,c=/\t/g;a=a.match(/]*>[^<]*<\/c>/g);var d=[];if(null==a)return d;for(var e=0,f=a.length;e]*>/g,"").split(c);for(g=0;gd&&(this.results[c].attrs.o+=b)};this.saveOldValue=function(a,b){a.is_changed=!0;a.old_value=b};this.createListSeparator=function(){return $("
  • ").html(" ").attr("googie_action_btn","1").css({cursor:"default","font-size":"3px","border-top":"1px solid #ccc","padding-top":"3px"}).get(0)}; this.correctError=function(a,b,c,d){var e=b.innerHTML;c=3==c.nodeType?c.nodeValue:c.innerHTML;var f=this.results[a].attrs.o;d&&(d=b.previousSibling.innerHTML,b.previousSibling.innerHTML=d.slice(0,d.length-1),e=" "+e,f--);this.hideErrorWindow();this.updateOrginalText(f,e,c,a);$(b).html(c).css("color","green").attr("is_corrected",!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("ul");$(this.error_window).html("");$(e).addClass("googie_list toolbarmenu").attr("googie_action_btn","1");var f=this.results[b].suggestions,l=this.results[b].attrs.o,h=this.results[b].attrs.l;if(this.has_dictionary&&!$(a).attr("is_corrected")){var g=$("").text(this.lang_learn_word).addClass("googie_add_to_dict active"); $("
  • ").attr("googie_action_btn","1").css("cursor","default").mouseover(c.item_onmouseover).mouseout(c.item_onmouseout).click(function(n){c.learnWord(a,b);c.ignoreError(a,b)}).append(g).appendTo(e)}var k=0;for(h=f.length;k").html(f[k]).addClass("active"),$("
  • ").mouseover(this.item_onmouseover).mouseout(this.item_onmouseout).click(function(n){c.correctError(b,a,n.target.firstChild)}).append(g).appendTo(e);if(a.is_changed&&a.innerHTML!=a.old_value){var m=a.old_value;g=$("").addClass("googie_list_revert active").html(this.lang_revert+ " "+m);$("
  • ").mouseover(this.item_onmouseover).mouseout(this.item_onmouseout).click(function(n){c.updateOrginalText(l,a.innerHTML,m,b);$(a).removeAttr("is_corrected").css("color","#b91414").html(m);c.hideErrorWindow()}).append(g).appendTo(e)}f=document.createElement("li");var p=document.createElement("input");h=document.createElement("button");g=document.createElement("form");k=function(){""!=p.value&&(c.isDefined(a.old_value)||c.saveOldValue(a,a.innerHTML),c.updateOrginalText(l,a.innerHTML,p.value, b),$(a).attr("is_corrected",!0).css("color","green").text(p.value),c.hideErrorWindow());return!1};$(p).width(120).val($(a).text()).attr("googie_action_btn","1");$(f).css("cursor","default").attr("googie_action_btn","1").on("click",function(){return!1});this.use_ok_pic?$("").attr("src",this.img_dir+"ok.gif").width(32).height(16).css({cursor:"pointer","margin-left":"2px","margin-right":"2px"}).appendTo(h):$(h).text("OK");$(h).addClass("mainaction save googie_ok_button btn-sm").click(k);$(g).attr("googie_action_btn", "1").css({cursor:"default","white-space":"nowrap"}).submit(k).append(p).append(h).appendTo(f);e.appendChild(f);0d&&(d=0);0>g&&(g=0);$(this.error_window).css({top:g+"px",left:d+"px",position:"absolute"}).show();document.all&&!window.opera&&(this.error_window_iframe|| (d=$("