var EXPORTED_SYMBOLS=['AtDCore'];function AtDCore(){this.ignore_types=['Bias Language','Cliches','Complex Expression','Diacritical Marks','Double Negatives','Hidden Verbs','Jargon Language','Passive voice','Phrases to Avoid','Redundant Expression'];this.ignore_strings={};this.i18n={};};AtDCore.prototype.getLang=function(key,defaultk){if(this.i18n[key]==undefined) return defaultk;return this.i18n[key];};AtDCore.prototype.addI18n=function(localizations){this.i18n=localizations;};AtDCore.prototype.setIgnoreStrings=function(string){var parent=this;this.map(string.split(/,\s*/g),function(string){parent.ignore_strings[string]=1;});};AtDCore.prototype.showTypes=function(string){var show_types=string.split(/,\s*/g);var types={};types["Double Negatives"]=1;types["Hidden Verbs"]=1;types["Passive voice"]=1;types["Bias Language"]=1;types["Cliches"]=1;types["Complex Expression"]=1;types["Diacritical Marks"]=1;types["Jargon Language"]=1;types["Phrases to Avoid"]=1;types["Redundant Expression"]=1;var ignore_types=[];this.map(show_types,function(string){types[string]=undefined;});this.map(this.ignore_types,function(string){if(types[string]!=undefined) ignore_types.push(string);});this.ignore_types=ignore_types;};AtDCore.prototype.makeError=function(error_s,tokens,type,seps,pre){var struct=new Object();struct.type=type;struct.string=error_s;struct.tokens=tokens;if(new RegExp("\\b"+error_s+"\\b").test(error_s)){struct.regexp=new RegExp("(?!"+error_s+"<)\\b"+error_s.replace(/\s+/g,seps)+"\\b");} else if(new RegExp(error_s+"\\b").test(error_s)){struct.regexp=new RegExp("(?!"+error_s+"<)"+error_s.replace(/\s+/g,seps)+"\\b");} else if(new RegExp("\\b"+error_s).test(error_s)){struct.regexp=new RegExp("(?!"+error_s+"<)\\b"+error_s.replace(/\s+/g,seps));} else{struct.regexp=new RegExp("(?!"+error_s+"<)"+error_s.replace(/\s+/g,seps));} struct.used=false;return struct;};AtDCore.prototype.addToErrorStructure=function(errors,list,type,seps){var parent=this;this.map(list,function(error){var tokens=error["word"].split(/\s+/);var pre=error["pre"];var first=tokens[0];if(errors['__'+first]==undefined){errors['__'+first]=new Object();errors['__'+first].pretoks={};errors['__'+first].defaults=new Array();} if(pre==""){errors['__'+first].defaults.push(parent.makeError(error["word"],tokens,type,seps,pre));}else{if(errors['__'+first].pretoks['__'+pre]==undefined) errors['__'+first].pretoks['__'+pre]=new Array();errors['__'+first].pretoks['__'+pre].push(parent.makeError(error["word"],tokens,type,seps,pre));}});};AtDCore.prototype.buildErrorStructure=function(spellingList,enrichmentList,grammarList){var seps=this._getSeparators();var errors={};this.addToErrorStructure(errors,spellingList,"hiddenSpellError",seps);this.addToErrorStructure(errors,grammarList,"hiddenGrammarError",seps);this.addToErrorStructure(errors,enrichmentList,"hiddenSuggestion",seps);return errors;};AtDCore.prototype._getSeparators=function(){var re='',i;var str='"s!#$%&()*+,./:;<=>?@[\]^_{|}';for(i=0;i0) errorStruct=this.buildErrorStructure(spellingErrors,enrichment,grammarErrors);else errorStruct=undefined;return{errors:errorStruct,count:ecount,suggestions:this.suggestions};};AtDCore.prototype.findSuggestion=function(element){var text=element.innerHTML;var context=(this.getAttrib(element,'pre')+"").replace(/[\\,!\\?\\."\s]/g,'');if(this.getAttrib(element,'pre')==undefined) {alert(element.innerHTML);} var errorDescription=undefined;var len=this.suggestions.length;for(var i=0;i$&']);error.used=true;done=true;}};var foundStrings={};if(current!=undefined){previous=previous+' ';parent.map(current,checkErrors);} if(!done){previous='';parent.map(defaults,checkErrors);}} previous=token;} if(doReplaces.length>0){newNode=n;for(var x=0;x0&&node.nodeValue.substr(0,1)==' ') return parent.create(' '+node.nodeValue.substr(1,node.nodeValue.length-1).replace(regexp,result),false);else return parent.create(node.nodeValue.replace(regexp,result),false);} else{var contents=parent.contents(node);for(var y=0;y0&&contents[y].nodeValue.substr(0,1)==' ') nnode=parent.create(' '+contents[y].nodeValue.substr(1,contents[y].nodeValue.length-1).replace(regexp,result),true);else nnode=parent.create(contents[y].nodeValue.replace(regexp,result),true);parent.replaceWith(contents[y],nnode);parent.removeParent(nnode);ecount++;return node;}} return node;}};newNode=bringTheHurt(newNode);} parent.replaceWith(n,newNode);}}});return ecount;};AtDCore.prototype._walk=function(elements,f){var i;for(i=0;i2000&&navigator.appName=='Microsoft Internet Explorer')||text.length>7800){if(callback_f!=undefined&&callback_f.error!=undefined) callback_f.error("Maximum text length for this browser exceeded");return;} CSSHttpRequest.get(AtD.rpc_css+text+"&lang="+AtD.rpc_css_lang+"&nocache="+(new Date().getTime()),function(response){var xml;if(navigator.appName=='Microsoft Internet Explorer'){xml=new ActiveXObject("Microsoft.XMLDOM");xml.async=false;xml.loadXML(response);} else{xml=(new DOMParser()).parseFromString(response,'text/xml');} if(AtD.core.hasErrorMessage(xml)){if(AtD.callback_f!=undefined&&AtD.callback_f.error!=undefined) AtD.callback_f.error(AtD.core.getErrorMessage(xml));return;} AtD.container=container_id;var count=AtD.processXML(container_id,xml);if(AtD.callback_f!=undefined&&AtD.callback_f.ready!=undefined) AtD.callback_f.ready(count);if(count==0&&AtD.callback_f!=undefined&&AtD.callback_f.success!=undefined) AtD.callback_f.success(count);AtD.counter=count;AtD.count=count;});};AtD.check=function(container_id,callback_f){if(typeof AtD_proofread_click_count!="undefined") AtD_proofread_click_count++;AtD.callback_f=callback_f;AtD.remove(container_id);var container=jQuery('#'+container_id);var html=container.html();text=jQuery.trim(container.html());text=encodeURIComponent(text);jQuery.ajax({type:"POST",url:AtD.rpc+'/checkDocument',data:'key='+AtD.api_key+'&data='+text,format:'raw',dataType:(jQuery.browser.msie)?"text":"xml",error:function(XHR,status,error){if(AtD.callback_f!=undefined&&AtD.callback_f.error!=undefined) AtD.callback_f.error(status+": "+error);},success:function(data){var xml;if(typeof data=="string"){xml=new ActiveXObject("Microsoft.XMLDOM");xml.async=false;xml.loadXML(data);} else{xml=data;} if(AtD.core.hasErrorMessage(xml)){if(AtD.callback_f!=undefined&&AtD.callback_f.error!=undefined) AtD.callback_f.error(AtD.core.getErrorMessage(xml));return;} AtD.container=container_id;var count=AtD.processXML(container_id,xml);if(AtD.callback_f!=undefined&&AtD.callback_f.ready!=undefined) AtD.callback_f.ready(count);if(count==0&&AtD.callback_f!=undefined&&AtD.callback_f.success!=undefined) AtD.callback_f.success(count);AtD.counter=count;AtD.count=count;}});};AtD.remove=function(container_id){AtD._removeWords(container_id,null);};AtD.clickListener=function(event){if(AtD.core.isMarkedNode(event.target)) AtD.suggest(event.target);};AtD.processXML=function(container_id,responseXML){var results=AtD.core.processXML(responseXML);if(results.count>0) results.count=AtD.core.markMyWords(jQuery('#'+container_id).contents(),results.errors);jQuery('#'+container_id).unbind('click',AtD.clickListener);jQuery('#'+container_id).click(AtD.clickListener);return results.count;};AtD.useSuggestion=function(word){this.core.applySuggestion(AtD.errorElement,word);AtD.counter--;if(AtD.counter==0&&AtD.callback_f!=undefined&&AtD.callback_f.success!=undefined) AtD.callback_f.success(AtD.count);};AtD.editSelection=function(){var parent=AtD.errorElement.parent();if(AtD.callback_f!=undefined&&AtD.callback_f.editSelection!=undefined) AtD.callback_f.editSelection(AtD.errorElement);if(AtD.errorElement.parent()!=parent){AtD.counter--;if(AtD.counter==0&&AtD.callback_f!=undefined&&AtD.callback_f.success!=undefined) AtD.callback_f.success(AtD.count);}};AtD.ignoreSuggestion=function(){AtD.core.removeParent(AtD.errorElement);AtD.counter--;if(AtD.counter==0&&AtD.callback_f!=undefined&&AtD.callback_f.success!=undefined) AtD.callback_f.success(AtD.count);};AtD.ignoreAll=function(container_id){var target=AtD.errorElement.text();var removed=AtD._removeWords(container_id,target);AtD.counter-=removed;if(AtD.counter==0&&AtD.callback_f!=undefined&&AtD.callback_f.success!=undefined) AtD.callback_f.success(AtD.count);if(AtD.callback_f!=undefined&&AtD.callback_f.ignore!=undefined){AtD.callback_f.ignore(target);AtD.core.setIgnoreStrings(target);}};AtD.explainError=function(){if(AtD.callback_f!=undefined&&AtD.callback_f.explain!=undefined) AtD.callback_f.explain(AtD.explainURL);};AtD.suggest=function(element){if(jQuery('#suggestmenu').length==0){var suggest=jQuery('
');suggest.prependTo('body');} else{var suggest=jQuery('#suggestmenu');suggest.hide();} errorDescription=AtD.core.findSuggestion(element);AtD.errorElement=jQuery(element);suggest.empty();if(errorDescription==undefined){suggest.append(''+AtD.getLang('menu_title_no_suggestions','No suggestions')+'');} else if(errorDescription["suggestions"].length==0){suggest.append(''+errorDescription['description']+'');} else{suggest.append(''+errorDescription['description']+'');for(var i=0;i'+sugg+'');})(errorDescription["suggestions"][i]);}} if(AtD.callback_f!=undefined&&AtD.callback_f.explain!=undefined&&errorDescription['moreinfo']!=undefined){suggest.append(''+AtD.getLang('menu_option_explain','Explain...')+'');AtD.explainURL=errorDescription['moreinfo'];} suggest.append(''+AtD.getLang('menu_option_ignore_once','Ignore suggestion')+'');if(AtD.callback_f!=undefined&&AtD.callback_f.editSelection!=undefined){if(AtD.callback_f!=undefined&&AtD.callback_f.ignore!=undefined) suggest.append(''+AtD.getLang('menu_option_ignore_always','Ignore always')+'');else suggest.append(''+AtD.getLang('menu_option_ignore_all','Ignore all')+'');suggest.append(''+AtD.getLang('menu_option_edit_selection','Edit Selection...')+'');} else{if(AtD.callback_f!=undefined&&AtD.callback_f.ignore!=undefined) suggest.append(''+AtD.getLang('menu_option_ignore_always','Ignore always')+'');else suggest.append(''+AtD.getLang('menu_option_ignore_all','Ignore all')+'');} var pos=jQuery(element).offset();var width=jQuery(element).width();jQuery(suggest).css({left:(pos.left+width)+'px',top:pos.top+'px'});jQuery(suggest).fadeIn(200);AtD.suggestShow=true;setTimeout(function(){jQuery("body").bind("click",function(){if(!AtD.suggestShow) jQuery('#suggestmenu').fadeOut(200);});},1);setTimeout(function(){AtD.suggestShow=false;},2);};AtD._removeWords=function(container_id,w){return this.core.removeWords(jQuery('#'+container_id),w);};AtD.initCoreModule=function(){var core=new AtDCore();core.hasClass=function(node,className){return jQuery(node).hasClass(className);};core.map=jQuery.map;core.contents=function(node){return jQuery(node).contents();};core.replaceWith=function(old_node,new_node){return jQuery(old_node).replaceWith(new_node);};core.findSpans=function(parent){return jQuery.makeArray(parent.find('span'));};core.create=function(node_html,isTextNode){return jQuery(''+node_html+'');};core.remove=function(node){return jQuery(node).remove();};core.removeParent=function(node){if(jQuery(node).unwrap) return jQuery(node).contents().unwrap();else return jQuery(node).replaceWith(jQuery(node).html());};core.getAttrib=function(node,name){return jQuery(node).attr(name);};return core;};AtD.core=AtD.initCoreModule();AtD.textareas={};AtD.restoreTextArea=function(id){var options=AtD.textareas[id];if(options==undefined||options['before']==options['link'].html()) return;AtD.remove(id);jQuery('#AtD_sync_').remove();var content;if(navigator.appName=='Microsoft Internet Explorer') content=jQuery('#'+id).html().replace(//gi,"\n");else content=jQuery('#'+id).html();jQuery('#'+id).replaceWith(options['node']);jQuery('#'+id).val(content.replace(/\<\;/g,'<').replace(/\>\;/,'>').replace(/\&/g,'&'));jQuery('#'+id).height(options['height']);options['link'].html(options['before']);};AtD.checkTextAreaCrossAJAX=function(id,linkId,after){AtD._checkTextArea(id,AtD.checkCrossAJAX,linkId,after);} AtD.checkTextArea=function(id,linkId,after){if(AtD.api_key==undefined||AtD.rpc==undefined) alert("You need to set AtD.api_key and AtD.rpc to use AtD.checkTextArea()");else AtD._checkTextArea(id,AtD.check,linkId,after);} AtD._checkTextArea=function(id,commChannel,linkId,after){var container=jQuery('#'+id);if(AtD.textareas[id]==undefined){var properties={};var saveProperty=function(key,node){if(node.css(key)!="") properties[key]=node.css(key);} var saveme=['background-color','color','font-size','font-family','border-top-width','border-bottom-width','border-left-width','border-right-width','border-top-style','border-bottom-style','border-left-style','border-right-style','border-top-color','border-bottom-color','border-left-color','border-right-color','text-align','margin-top','margin-bottom','margin-left','margin-right','width','line-height','letter-spacing','left','right','top','bottom','position','padding-left','padding-right','padding-top','padding-bottom'];for(var x=0,node=container;x