/**
* 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 <amix@amix.dk>
* @author Aleksander Machniak - <alec [at] alec.pl>
*/
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,"<").replace(/>/g,">"):""};this.createXMLReq=function(a){return'<?xml version="1.0" encoding="utf-8" ?><spellrequest textalreadyclipped="0" ignoredups="0" ignoredigits="1" ignoreallcaps="1"><text>'+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(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='<?xml version="1.0" encoding="utf-8" ?><learnword><text>'+a+"</text></learnword>";$.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[^>]*>[^<]*<\/c>/g);var d=[];if(null==a)return d;for(var e=0,f=a.length;e<f;e++){var l=[];this.errorFound();l.attrs=[];for(var h,g,k=a[e].match(b),m=0;m<k.length;m++)h=k[m].split(/=/),g=h[1].replace(/"/g,""),l.attrs[h[0]]="true"!=g?parseInt(g):g;l.suggestions=[];h=a[e].replace(/<[^>]*>/g,"").split(c);for(g=0;g<h.length;g++)""!=h[g]&&l.suggestions.push(h[g]);d.push(l)}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")};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(){return $("<li>").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=$("<a>").text(this.lang_learn_word).addClass("googie_add_to_dict active");
$("<li>").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<h;k++)g=$("<a>").html(f[k]).addClass("active"),$("<li>").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=$("<a>").addClass("googie_list_revert active").html(this.lang_revert+
" "+m);$("<li>").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?$("<img>").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);0<this.extra_menu_items.length&&e.appendChild(this.createListSeparator());var r=function(n){if(n<c.extra_menu_items.length){var q=c.extra_menu_items[n];if(!q[2]||q[2](a,c)){var v=document.createElement("tr"),w=document.createElement("td");$(w).html(q[0]).mouseover(c.item_onmouseover).mouseout(c.item_onmouseout).click(function(){return q[1](a,c)});v.appendChild(w);e.appendChild(v)}r(n+1)}};
r(0);r=null;this.use_close_btn&&e.appendChild(this.createCloseButton(this.hideErrorWindow));this.error_window.appendChild(e);rcmail.triggerEvent("googiespell_create",{obj:this.error_window});g=$(this.error_window).height();f=$(this.error_window).width();k=$(document).height();h=$(document).width();g=d.top+g+20<k?d.top+20:d.top-g;d=d.left+f<h?d.left:d.left-f;0>d&&(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=$("<iframe>").css({position:"absolute","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()?$(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(d){if("googie_link"!=d.target.className&&!c.isErrorWindowShown()){c.resumeEditing();var e=function(){$(c.text_area).focus();e=null};window.setTimeout(e,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");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(f){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};this.createPart=function(a){if(" "==a)return document.createTextNode(" ");a=this.escapeSpecial(a);a=a.replace(/\n/g,"<br>");a=a.replace(/ /g," ");a=a.replace(/^ /g," ");a=a.replace(/ $/g," ");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 f=c[d].attrs.o,l=c[d].attrs.l,h=this.orginal_text.substring(b,f);h=this.createPart(h);
a.appendChild(h);b+=f-b;f=this.createErrorLink(this.orginal_text.substr(f,l),d);this.error_links.push(f);a.appendChild(f);b+=l}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 g=this;this.custom_item_evaulator&&$.map(this.error_links,function(k){g.custom_item_evaulator(g,k)});$(this.edit_layer).append(a);$(this.text_area).hide();$(this.edit_layer).insertBefore(this.text_area);this.use_focus&&
(this.focus_link_t=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.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.createSpellDiv=function(){var a=document.createElement("span");$(a).addClass("googie_check_spelling_link").text(this.lang_chck_spell);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=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)}};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=document.createElement("span");a=this.createSpellDiv();var b=this;this.custom_spellcheck_starter?$(a).click(function(c){b.custom_spellcheck_starter()}):$(a).click(function(c){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=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");
if(b){var f=document.createElement("span");$(f).addClass(b).html(a)}else f=document.createTextNode(a);$(e).click(c).mouseover(this.item_onmouseover).mouseout(this.item_onmouseout);e.appendChild(f);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"!=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"}};
|