//>>built
define("dojox/editor/plugins/SpellCheck",["dijit","dojo","dojox","dojo/i18n!dojox/editor/plugins/nls/SpellCheck","dojo/require!dijit/_base/popup,dijit/_Widget,dijit/_Templated,dijit/form/TextBox,dijit/form/DropDownButton,dijit/TooltipDialog,dijit/form/MultiSelect,dojo/io/script,dijit/Menu"],function(_1,_2,_3){
_2.provide("dojox.editor.plugins.SpellCheck");
_2.require("dijit._base.popup");
_2.require("dijit._Widget");
_2.require("dijit._Templated");
_2.require("dijit.form.TextBox");
_2.require("dijit.form.DropDownButton");
_2.require("dijit.TooltipDialog");
_2.require("dijit.form.MultiSelect");
_2.require("dojo.io.script");
_2.require("dijit.Menu");
_2.requireLocalization("dojox.editor.plugins","SpellCheck");
_2.experimental("dojox.editor.plugins.SpellCheck");
_2.declare("dojox.editor.plugins._spellCheckControl",[_1._Widget,_1._Templated],{widgetsInTemplate:true,templateString:"
",constructor:function(){
this.ignoreChange=false;
this.isChanged=false;
this.isOpen=false;
this.closable=true;
},postMixInProperties:function(){
this.id=_1.getUniqueId(this.declaredClass.replace(/\./g,"_"));
this.textId=this.id+"_textBox";
this.selectId=this.id+"_select";
},postCreate:function(){
var _4=this.suggestionSelect;
_2.removeAttr(_4.domNode,"multiple");
_4.addItems=function(_5){
var _6=this;
var o=null;
if(_5&&_5.length>0){
_2.forEach(_5,function(_7,i){
o=_2.create("option",{innerHTML:_7,value:_7},_6.domNode);
if(i==0){
o.selected=true;
}
});
}
};
_4.removeItems=function(){
_2.empty(this.domNode);
};
_4.deselectAll=function(){
this.containerNode.selectedIndex=-1;
};
this.connect(this,"onKeyPress","_cancel");
this.connect(this.unfoundTextBox,"onKeyPress","_enter");
this.connect(this.unfoundTextBox,"onChange","_unfoundTextBoxChange");
this.connect(this.suggestionSelect,"onKeyPress","_enter");
this.connect(this.skipButton,"onClick","onSkip");
this.connect(this.skipAllButton,"onClick","onSkipAll");
this.connect(this.toDicButton,"onClick","onAddToDic");
this.connect(this.replaceButton,"onClick","onReplace");
this.connect(this.replaceAllButton,"onClick","onReplaceAll");
this.connect(this.cancelButton,"onClick","onCancel");
},onSkip:function(){
},onSkipAll:function(){
},onAddToDic:function(){
},onReplace:function(){
},onReplaceAll:function(){
},onCancel:function(){
},onEnter:function(){
},focus:function(){
this.unfoundTextBox.focus();
},_cancel:function(_8){
if(_8.keyCode==_2.keys.ESCAPE){
this.onCancel();
_2.stopEvent(_8);
}
},_enter:function(_9){
if(_9.keyCode==_2.keys.ENTER){
this.onEnter();
_2.stopEvent(_9);
}
},_unfoundTextBoxChange:function(){
var id=this.textId+"_label";
if(!this.ignoreChange){
_2.byId(id).innerHTML=this["replaceWith"];
this.isChanged=true;
this.suggestionSelect.deselectAll();
}else{
_2.byId(id).innerHTML=this["unfound"];
}
},_setUnfoundWordAttr:function(_a){
_a=_a||"";
this.unfoundTextBox.set("value",_a);
},_getUnfoundWordAttr:function(){
return this.unfoundTextBox.get("value");
},_setSuggestionListAttr:function(_b){
var _c=this.suggestionSelect;
_b=_b||[];
_c.removeItems();
_c.addItems(_b);
},_getSelectedWordAttr:function(){
var _d=this.suggestionSelect.getSelected();
if(_d&&_d.length>0){
return _d[0].value;
}else{
return this.unfoundTextBox.get("value");
}
},_setDisabledAttr:function(_e){
this.skipButton.set("disabled",_e);
this.skipAllButton.set("disabled",_e);
this.toDicButton.set("disabled",_e);
this.replaceButton.set("disabled",_e);
this.replaceAllButton.set("disabled",_e);
},_setInProgressAttr:function(_f){
var id=this.id+"_progressIcon",cmd=_f?"removeClass":"addClass";
_2[cmd](id,"hidden");
}});
_2.declare("dojox.editor.plugins._SpellCheckScriptMultiPart",null,{ACTION_QUERY:"query",ACTION_UPDATE:"update",callbackHandle:"callback",maxBufferLength:100,delimiter:" ",label:"response",_timeout:30000,SEC:1000,constructor:function(){
this.serviceEndPoint="";
this._queue=[];
this.isWorking=false;
this.exArgs=null;
this._counter=0;
},send:function(_10,_11){
var _12=this,dt=this.delimiter,mbl=this.maxBufferLength,_13=this.label,_14=this.serviceEndPoint,_15=this.callbackHandle,_16=this.exArgs,_17=this._timeout,l=0,r=0;
if(!this._result){
this._result=[];
}
_11=_11||this.ACTION_QUERY;
var _18=function(){
var _19=[];
var _1a=0;
if(_10&&_10.length>0){
_12.isWorking=true;
var len=_10.length;
do{
l=r+1;
if((r+=mbl)>len){
r=len;
}else{
while(dt&&_10.charAt(r)!=dt&&r<=len){
r++;
}
}
_19.push({l:l,r:r});
_1a++;
}while(r0){
(_12._queue.shift())();
}
}
}};
_1d.content=_16?_2.mixin(_16,{action:_11,content:_10.substring(_1b.l-1,_1b.r)}):{action:_11,content:_10.substring(_1b.l-1,_1b.r)};
_1d.size=_1a;
_1d.number=_1c;
_1d.offset=_1b.l-1;
_2.io.script.get(_1d);
});
}
};
if(!_12.isWorking){
_18();
}else{
_12._queue.push(_18);
}
},_finalizeCollection:function(_22){
var _23=this._result,len=_23.length;
for(var i=0;i",_cursorSelector:"cursorPlaceHolder",_incorrectWordsSpan:"${text}",_ignoredIncorrectStyle:{"cursor":"inherit","borderBottom":"none","backgroundColor":"transparent"},_normalIncorrectStyle:{"cursor":"pointer","borderBottom":"1px dotted red","backgroundColor":"yellow"},_highlightedIncorrectStyle:{"borderBottom":"1px dotted red","backgroundColor":"#b3b3ff"},_selector:"incorrectWordPlaceHolder",_maxItemNumber:3,constructor:function(){
this._spanList=[];
this._cache={};
this._enabled=true;
this._iterator=0;
},setEditor:function(_27){
this._editor=_27;
this._initButton();
this._setNetwork();
this._connectUp();
},_initButton:function(){
var _28=this,_29=(this._strings=_2.i18n.getLocalization("dojox.editor.plugins","SpellCheck")),_2a=(this._dialog=new _1.TooltipDialog());
_2a.set("content",(this._dialogContent=new _3.editor.plugins._spellCheckControl({unfound:_29["unfound"],skip:_29["skip"],skipAll:_29["skipAll"],toDic:_29["toDic"],suggestions:_29["suggestions"],replaceWith:_29["replaceWith"],replace:_29["replace"],replaceAll:_29["replaceAll"],cancel:_29["cancel"]})));
this.button=new _1.form.DropDownButton({label:_29["widgetLabel"],showLabel:false,iconClass:"dijitEditorSpellCheckIcon",dropDown:_2a,id:_1.getUniqueId(this.declaredClass.replace(/\./g,"_"))+"_dialogPane",closeDropDown:function(_2b){
if(_28._dialogContent.closable){
_28._dialogContent.isOpen=false;
if(_2.isIE){
var pos=_28._iterator,_2c=_28._spanList;
if(pos<_2c.length&&pos>=0){
_2.style(_2c[pos],_28._normalIncorrectStyle);
}
}
if(this._opened){
_1.popup.close(this.dropDown);
if(_2b){
this.focus();
}
this._opened=false;
this.state="";
}
}
}});
_28._dialogContent.isOpen=false;
_2a.domNode.setAttribute("aria-label",this._strings["widgetLabel"]);
},_setNetwork:function(){
var _2d=this.exArgs;
if(!this._service){
var _2e=(this._service=new _3.editor.plugins._SpellCheckScriptMultiPart());
_2e.serviceEndPoint=this.url;
_2e.maxBufferLength=this.bufferLength;
_2e.setWaitingTime(this.timeout);
if(_2d){
delete _2d.name;
delete _2d.url;
delete _2d.interactive;
delete _2d.timeout;
_2e.exArgs=_2d;
}
}
},_connectUp:function(){
var _2f=this._editor,_30=this._dialogContent;
this.connect(this.button,"set","_disabled");
this.connect(this._service,"onLoad","_loadData");
this.connect(this._dialog,"onOpen","_openDialog");
this.connect(_2f,"onKeyPress","_keyPress");
this.connect(_2f,"onLoad","_submitContent");
this.connect(_30,"onSkip","_skip");
this.connect(_30,"onSkipAll","_skipAll");
this.connect(_30,"onAddToDic","_add");
this.connect(_30,"onReplace","_replace");
this.connect(_30,"onReplaceAll","_replaceAll");
this.connect(_30,"onCancel","_cancel");
this.connect(_30,"onEnter","_enter");
_2f.contentPostFilters.push(this._spellCheckFilter);
_2.publish(_1._scopeName+".Editor.plugin.SpellCheck.getParser",[this]);
if(!this.parser){
console.error("Can not get the word parser!");
}
},_disabled:function(_31,_32){
if(_31=="disabled"){
if(_32){
this._iterator=0;
this._spanList=[];
}else{
if(this.interactive&&!_32&&this._service){
this._submitContent(true);
}
}
this._enabled=!_32;
}
},_keyPress:function(evt){
if(this.interactive){
var v=118,V=86,cc=evt.charCode;
if(!evt.altKey&&cc==_2.keys.SPACE){
this._submitContent();
}else{
if((evt.ctrlKey&&(cc==v||cc==V))||(!evt.ctrlKey&&evt.charCode)){
this._submitContent(true);
}
}
}
},_loadData:function(_33){
var _34=this._cache,_35=this._editor.get("value"),_36=this._dialogContent;
this._iterator=0;
_2.forEach(_33,function(d){
_34[d.text]=d.suggestion;
_34[d.text].correct=false;
});
if(this._enabled){
_36.closable=false;
this._markIncorrectWords(_35,_34);
_36.closable=true;
if(this._dialogContent.isOpen){
this._iterator=-1;
this._skip();
}
}
},_openDialog:function(){
var _37=this._dialogContent;
_37.ignoreChange=true;
_37.set("unfoundWord","");
_37.set("suggestionList",null);
_37.set("disabled",true);
_37.set("inProgress",true);
_37.isOpen=true;
_37.closable=false;
this._submitContent();
_37.closable=true;
},_skip:function(evt,_38){
var _39=this._dialogContent,_3a=this._spanList||[],len=_3a.length,_3b=this._iterator;
_39.closable=false;
_39.isChanged=false;
_39.ignoreChange=true;
if(!_38&&_3b>=0&&_3b0){
_46.send(_49.join(" "));
}else{
if(!_46.isWorking){
this._loadData([]);
}
}
},_html2Text:function(_4b){
var _4c=[],_4d=false,len=_4b?_4b.length:0;
for(var i=0;i"){
_4d=false;
}
}
return _4c.join("");
},_getBookmark:function(_4e){
var ed=this._editor,cp=this._cursorSpan;
ed.execCommand("inserthtml",cp);
var nv=ed.get("value"),_4f=nv.indexOf(cp),i=-1;
while(++i<_4f&&_4e.charAt(i)==nv.charAt(i)){
}
return i;
},_moveToBookmark:function(){
var ed=this._editor,cps=_2.query("."+this._cursorSelector,ed.document),_50=cps&&cps[0];
if(_50){
ed._sCall("selectElement",[_50]);
ed._sCall("collapse",[true]);
var _51=_50.parentNode;
if(_51){
_51.removeChild(_50);
}
}
},_submitContent:function(_52){
if(_52){
var _53=this,_54=3000;
if(this._delayHandler){
clearTimeout(this._delayHandler);
this._delayHandler=null;
}
setTimeout(function(){
_53._query(_53._editor.get("value"));
},_54);
}else{
this._query(this._editor.get("value"));
}
},_populateDialog:function(_55){
var _56=this._spanList,_57=this._cache,_58=this._dialogContent;
_58.set("disabled",false);
if(_55<_56.length&&_56.length>0){
var _59=_56[_55].innerHTML;
_58.set("unfoundWord",_59);
_58.set("suggestionList",_57[_59.toLowerCase()]);
_58.set("inProgress",false);
}
},_markIncorrectWords:function(_5a,_5b){
var _5c=this,_5d=this.parser,_5e=this._editor,_5f=this._incorrectWordsSpan,_60=this._normalIncorrectStyle,_61=this._selector,_62=_5d.parseIntoWords(this._html2Text(_5a).toLowerCase()),_63=_5d.getIndices(),_64=this._cursorSpan,_65=this._getBookmark(_5a),_66="".length,_67=false,_68=_5a.split(""),_69=null;
for(var i=_62.length-1;i>=0;i--){
var _6a=_62[i];
if(_5b[_6a]&&!_5b[_6a].correct){
var _6b=_63[i],len=_62[i].length,end=_6b+len;
if(end<=_65&&!_67){
_68.splice(_65,0,_64);
_67=true;
}
_68.splice(_6b,len,_2.string.substitute(_5f,{text:_5a.substring(_6b,end)}));
if(_6b<_65&&_650){
ed._sCall("selectElement",[_78[_77]]);
ed._sCall("collapse",[true]);
this._findText(_78[_77].innerHTML,false,false);
if(_2.isIE){
_2.style(_78[_77],this._highlightedIncorrectStyle);
}
}
},_replaceWord:function(_79,_7a){
var _7b=this._spanList;
_7b[_79].innerHTML=_7a;
_2.style(_7b[_79],this._ignoredIncorrectStyle);
_7b[_79].edited=true;
},_skipWord:function(_7c){
var _7d=this._spanList;
_2.style(_7d[_7c],this._ignoredIncorrectStyle);
this._cache[_7d[_7c].innerHTML.toLowerCase()].correct=true;
_7d[_7c].edited=true;
},_skipWordAll:function(_7e,_7f){
var _80=this._spanList,len=_80.length;
_7f=_7f||_80[_7e].innerHTML.toLowerCase();
for(var i=0;i(.*?)<\/span>/g;
return _8a.replace(_8b,"$1");
}});
_2.subscribe(_1._scopeName+".Editor.getPlugin",null,function(o){
if(o.plugin){
return;
}
var _8c=o.args.name.toLowerCase();
if(_8c==="spellcheck"){
o.plugin=new _3.editor.plugins.SpellCheck({url:("url" in o.args)?o.args.url:"",interactive:("interactive" in o.args)?o.args.interactive:false,bufferLength:("bufferLength" in o.args)?o.args.bufferLength:100,timeout:("timeout" in o.args)?o.args.timeout:30,exArgs:o.args});
}
});
});