var CookieManager={set:function(_1,_2){
var _3=new Date();
_3.setTime(_3.getTime()+(30*24*60*60*1000));
var _4="; expires="+_3.toGMTString();
document.cookie=_1+"="+escape(_2)+_4;
},get:function(_5){
var dc=document.cookie;
var _7=_5+"=";
var _8=dc.indexOf("; "+_7);
if(_8==-1){
_8=dc.indexOf(_7);
if(_8!==0){
return null;
}
}else{
_8+=2;
}
var _9=document.cookie.indexOf(";",_8);
if(_9==-1){
_9=dc.length;
}
return unescape(dc.substring(_8+_7.length,_9));
},erase:function(_a){
var _b=new Date(2000,1,1,19,30,30);
document.cookie=_a+"=; expires="+_b.toGMTString();
}};
CookieManager.setCookiePair=function(_c,_d,_e){
var _f,end;
var _11=CookieManager.get(_c);
var _12=[_d,"@",_e,"#"].join("");
function trimEntry(s){
var a=s.split(",");
return a.slice(3).join(",");
}
if(!_11){
CookieManager.set(_c,_12);
}else{
_f=_11.search(eval("/(^|#)"+_d+"@/"));
if(_f===-1){
_11+=_12;
}else{
if(_11.charAt(_f)==="#"){
_f+=1;
}
end=_11.indexOf("#",_f);
_11=_11.replace(_11.substring(_f,end+1),_12);
}
while(_11.length>600){
_11=trimEntry(_11);
}
CookieManager.set(_c,_11);
}
};
CookieManager.getCookiePair=function(_15,key){
var _17=CookieManager.get(_15);
if(!_17){
return null;
}
var _18=_17.search(eval("/(^|#)"+key+"@/"));
if(_18===-1){
return null;
}
var end=_17.indexOf("#",_18+1);
var s=_17.substring(_18,end);
return s.split("@")[1];
};
var QuillUtil={isValidEmailID:function(_1b){
var _1c=_1b.match(/^[0-9a-zA-Z_\.-]+@([0-9a-zA-Z_-]+\.)+[a-zA-Z0-9_-]+$/);
return (_1c!==null);
},isValidEmailIDGroup:function(_1d){
var _1e=_1d.split(/[\s\+,]+/);
var _1f;
if(_1e.length<1){
return false;
}
for(var i=0;i<_1e.length;++i){
_1f=_1e[i].match(/^[0-9a-zA-Z_\.-]+@([0-9a-zA-Z_-]+\.)+[a-zA-Z0-9_-]+$/);
if(_1f===null){
return false;
}
}
return true;
},getRandom:function(_21){
var _22=Math.random()-0.5;
_22=_22*Math.pow(2,32);
return Math.floor(_22);
},getBrowser:function(){
var ua=window.navigator.userAgent.toLowerCase();
var _24;
var _25;
var _26;
if(ua.indexOf("opera")!=-1){
return "opera";
}else{
if(ua.indexOf("safari")!=-1){
return "safari";
}else{
if(ua.indexOf("msie 6.0")!=-1||ua.indexOf("msie 7.0")!=-1){
return "ie";
}else{
if(ua.indexOf("mozilla")!=-1){
_25=ua.indexOf("gecko/");
if(_25==-1){
return "oldmoz";
}
_26=ua.indexOf(" ",_25);
if(_26==-1){
_26=ua.length;
}
_24=parseInt(ua.substring(_25+6,_26),10);
if(_24<20051107){
return "oldmoz";
}
return "moz";
}
}
}
}
return "unknown";
},isBlank:function(_27){
if(_27.match(/^\s*$/)){
return true;
}
return false;
},isValidURL:function(_28){
if(_28.match(/^http:\/\/.*$/)){
return true;
}
return false;
},isAlpha:function(_29){
if(_29.match(/^[a-zA-Z]$/)){
return true;
}
return false;
},getServerAddr:function(){
if(Quill.Config.client.scriptReq){
return Quill.Config.server.location;
}
if(document.domain){
return ("http://"+window.location.host);
}else{
return Quill.Config.server.location;
}
},getServerPath:function(){
var _2a=window.location.pathname.match(/.*\//g);
return ["http://",window.location.host,_2a].join("");
},isValidAlpha:function(_2b){
if(_2b.match(/[a-zA-Z]+/)){
return true;
}
return false;
},getMeta:function(){
var d=document.getElementsByTagName("meta");
var ret={};
var i;
if(!d||!d.length){
logger.error("Could not read meta tags.");
}else{
for(i=0;i<d.length;i++){
if(d[i].name){
ret[d[i].name]=d[i].content;
}
}
}
return ret;
},makeURL:function(_2f,req){
var _31="";
for(var i in req){
_31+=[i,"=",encodeURIComponent(req[i])].join("");
}
if(_31){
return [_2f,"?",_31].join("");
}else{
return _2f;
}
},setupLogging:function(){
try{
try{
if(console.log){
logger={log:console.log,debug:console.debug,info:console.info,warn:console.warn,error:console.error};
}
}
catch(e){
if(logDebug){
logger={log:log,debug:logDebug,info:logDebug,warn:logWarning,error:logError};
}
}
}
catch(e){
logger={log:function(){
},debug:function(){
},info:function(){
},warn:function(){
},error:function(){
}};
}
},setCharEncoding:function(_33){
if(document.defaultCharset){
document.defaultCharset=_33;
}else{
if(document.charset){
document.charset=_33;
}
}
},getNodeText:function(){
var n=MochiKit.DOM.SPAN();
if(typeof (n.textContent)!=="undefined"){
return function(_35){
return _35.textContent;
};
}else{
if(typeof (n.innerText)!=="undefined"){
return function(_36){
return _36.innerText;
};
}else{
return function(_37){
return _37.text;
};
}
}
}(),setNodeText:function(){
var n=MochiKit.DOM.SPAN();
if(typeof (n.textContent)!=="undefined"){
return function(_39,_3a){
_39.textContent=_3a;
};
}else{
if(typeof (n.innerText)!=="undefined"){
return function(_3b,_3c){
_3b.innerText=_3c;
};
}else{
return function(_3d,_3e){
_3d.text=_3e;
};
}
}
}(),addStyleSheet:function(doc,url){
var _41=doc.createElement("LINK");
_41.rel="stylesheet";
_41.type="text/css";
_41.href=url;
var _42=doc.getElementsByTagName("head")[0];
if(_42){
_42.appendChild(_41);
}else{
logger.error("addStyleSheet: document.head not found for",doc);
}
},enableLogPane:function(){
var _43=MochiKit.DOM.getElement("logpane");
logger.info=function(){
var s="";
for(var i=0;i<arguments.length;i++){
s+=arguments[i]+" ";
}
_43.appendChild(DIV(s));
if(_43.scrollHeight>_43.clientHeight){
_43.scrollTop=_43.scrollHeight-_43.clientHeight;
}
};
},getCursorPosition:function(_46){
var _47;
if(typeof (_46.selectionStart)!=="undefined"){
_47=_46.selectionEnd;
}else{
if(document.selection){
_46.focus();
var sel=document.selection.createRange();
var _49=sel.duplicate();
_49.collapse(true);
var _4a=_49.moveStart("character",-1000);
return -_4a;
}
}
return _47;
},setCursorPosition:function(_4b,pos){
if(typeof (_4b.selectionStart)!=="undefined"){
_4b.selectionStart=pos;
_4b.selectionEnd=pos;
}else{
if(document.selection){
_4b.focus();
var _4d=_4b.createTextRange();
_4d.collapse(true);
_4d.moveStart("character",pos);
_4d.moveEnd("character",pos);
_4d.select();
}
}
}};
if(typeof (Quill)==="undefined"){
Quill={};
}
Quill.doScriptRequest=function(url,req){
var d=new MochiKit.Async.Deferred();
var id=Quill.doScriptRequest.id;
var dom=MochiKit.DOM;
req.callback="Quill.cbk";
req.scid=id;
var qs=MochiKit.Base.queryString(req);
if(qs){
url+="?"+qs;
}
if(!Quill.doScriptRequest.head){
Quill.doScriptRequest.head=document.getElementsByTagName("head")[0];
}
var _54=dom.createDOM("SCRIPT",{"type":"text/javascript","src":url,"id":"scr"+id});
Quill.doScriptRequest.id+=1;
dom.appendChildNodes(Quill.doScriptRequest.head,_54);
Quill.doScriptRequest.reqmap[id]=d;
return d;
};
Quill.doScriptRequest.id=0;
Quill.doScriptRequest.reqmap={};
Quill.cbk=function(obj,id){
var _57=Quill.doScriptRequest.reqmap;
if(_57.hasOwnProperty(id)){
try{
_57[id].callback(obj);
MochiKit.DOM.removeElement("scr"+id);
}
catch(e){
logger.warn(e);
}
}else{
logger.warn("id",id,"not found");
}
};
Quill.doAsyncRequest=function(){
if(Quill.Config.client.scriptReq){
return Quill.doScriptRequest;
}else{
return MochiKit.Async.doSimpleXMLHttpRequest;
}
}();
WordMapping=function(_58,_59,_5a,_5b,_5c){
this.engWord=_58;
this.tWordList=_59;
this.preferred=_5a;
this.itrans=_5b;
this.optmap=_5c;
};
var WordMap=function WordMap(_5d){
this.localCache=_5d;
this.wordMap={};
for(var i in Quill.Config.supportedLanguages){
this.wordMap[i]={};
}
};
WordMap.prototype.responseFunc=function(_5f,_60,o,_62,r){
var a=[];
var val;
var i;
var itr=true;
var _68=false;
var _69;
var _6a;
try{
if(typeof (r.responseText)!=="undefined"){
val=eval("("+r.responseText+")");
}else{
val=r;
}
_69=CookieManager.getCookiePair(_5f+"_prefs",_60);
_6a=Quill.Config.client.maxWordOptions;
if(val.twords[0].options.length<_6a){
_6a=val.twords[0].options.length;
}
for(i=0;i<_6a;i++){
if(val.twords[0].options[i]===val.itrans){
itr=false;
}
a.push(val.twords[0].options[i]);
}
var _6b=val.twords[0].optmap;
if(!itr){
val.itrans=null;
}else{
a=a.splice(0,Quill.Config.client.maxWordOptions-1);
if(val.inString.slice(1).match(/[A-Z]+/)){
a.unshift(val.itrans);
}else{
a.push(val.itrans);
}
}
if(a.length<1){
logger.error("goofup in responseFunc, len(a) < 1");
return;
}
if(_69!=null){
for(i=0;i<a.length;i++){
if(a[i]===_69){
_68=true;
break;
}
}
}
if(!_68){
if(_60.match(/[\.\/~\^]/)){
o.wordMap[_5f][_60]=new WordMapping(_60,[val.itrans],val.itrans,val.itrans,_6b);
}else{
o.wordMap[_5f][_60]=new WordMapping(_60,a,a[0],val.itrans,_6b);
}
}else{
o.wordMap[_5f][_60]=new WordMapping(_60,a,_69,val.itrans,_6b);
}
var _6c=CookieManager.getCookiePair(_5f+"_userMaps",_60);
if(_6c){
_6c=_6c.split(",");
for(i=0;i<_6c.length;i++){
if(_6c[i]===_69){
o.wordMap[_5f][_60].preferred=_69;
break;
}
}
o.wordMap[_5f][_60].userMapping=_6c;
}
_62(o.getMapping(_5f,_60));
}
catch(e){
logger.error(e);
return;
}
};
WordMap.prototype.secondaryResp=function(_6d,_6e,o,_70,r){
try{
_70(o.getMapping(_6d,_6e));
}
catch(e){
logger.error(e);
return;
}
};
WordMap.prototype.getMapping=function(_72,_73){
if(_72=="english"){
return (new WordMapping(_73,[_73],_73));
}
var m=this.wordMap[_72][_73];
if(m&&m.engWord){
return m;
}else{
return null;
}
};
WordMap.prototype.getWordMapping=function(_75,_76,_77){
if(_75=="english"){
_77(new WordMapping(_76,[_76],_76));
return;
}
var _78=this.wordMap[_75][_76];
if(_78&&this.wordMap[_75].hasOwnProperty(_76)){
if(_78.def){
_78.def.addCallback(MochiKit.Base.partial(this.secondaryResp,_75,_76,this,_77));
}else{
_77(this.getMapping(_75,_76));
}
return;
}
var req={rand:QuillUtil.getRandom(),lang:_75,inString:_76};
var d=Quill.doAsyncRequest(QuillUtil.getServerAddr()+Quill.Config.server.processWord,req);
d.addCallbacks(MochiKit.Base.partial(this.responseFunc,_75,_76,this,_77),function(e){
logger.error("getWordMapping failed");
});
this.wordMap[_75][_76]={"def":d};
};
WordMap.prototype.setPreferredMapping=function(_7c,_7d,_7e){
if(_7c=="english"){
return;
}
var wm=this.wordMap[_7c][_7d];
wm.preferred=_7e;
CookieManager.setCookiePair(_7c+"_prefs",_7d,_7e);
};
WordMap.prototype.getAllOptions=function(_80,_81){
if(this.wordMap[_80][_81]){
return this.wordMap[_80][_81].tWordList;
}else{
return [];
}
};
WordMap.prototype.correctionRespFunc=function(_82,_83,_84,r){
var val;
var _87;
try{
val=eval("("+r.responseText+")");
_87=this.wordMap[_82][_83].optmap;
if(_87){
for(var i in val.optmap){
if(val.optmap.hasOwnProperty(i)){
if(!_87[i]){
_87[i]=val.optmap[i];
}
}
}
}
_84(val.options,val.optmap);
}
catch(e){
logger.error(e);
}
};
WordMap.prototype.getCorrections=function(_89,_8a,_8b,pos,_8d,loc){
req={rand:QuillUtil.getRandom(),lang:_89,currWord:_8a.toString(),userInput:_8b,pos:pos};
var d=Quill.doAsyncRequest(QuillUtil.getServerAddr()+Quill.Config.server.correctionPrefix+loc,req);
d.addCallbacks(MochiKit.Base.method(this,MochiKit.Base.partial(this.correctionRespFunc,_89,_8b,_8d)),function(e){
console.error("getCorrections failed");
});
};
WordMap.prototype.setUserMapping=function(_91,_92,_93){
var i;
var m=this.wordMap[_91][_92];
for(i=0;i<m.tWordList.length;i++){
if(m.tWordList[i]===_93){
return;
}
}
if(m.userMapping){
for(var i=0;i<m.userMapping.length;i++){
if(m.userMapping[i]===_93){
return;
}
}
m.userMapping.unshift(_93);
}else{
m.userMapping=[_93];
}
CookieManager.setCookiePair(_91+"_userMaps",_92,m.userMapping.toString());
};
WordMap.prototype.setUserMappingList=function(_96,_97,_98){
var m=this.wordMap[_96][_97];
m.userMapping=_98;
CookieManager.setCookiePair(_96+"_userMaps",_97,_98.toString());
};
MochiKit.Base.update(Quill,{isSpecial:function(c){
if(c=="."||c=="/"||c=="^"||c=="~"){
return true;
}
return false;
},splitSpecial:function(s){
var m=s.match(/((([a-zA-Z]+[\.\^~\/]*)*[a-zA-Z]+)|([^a-zA-Z])+)/g);
if(!m){
return [];
}
return m;
},diffStr:function(_9d,_9e){
function diff(o,n){
var ns={};
var os={};
var i;
try{
for(i=0;i<n.length;++i){
if(!ns.hasOwnProperty(n[i])){
ns[n[i]]={rows:[],o:null};
}
ns[n[i]].rows.push(i);
}
for(i=0;i<o.length;++i){
if(!os.hasOwnProperty(o[i])){
os[o[i]]={rows:[],n:null};
}
os[o[i]].rows.push(i);
}
for(i in ns){
if(ns[i].rows.length==1&&os.hasOwnProperty(i)&&os[i].rows.length==1){
n[ns[i].rows[0]]={text:n[ns[i].rows[0]],row:os[i].rows[0]};
o[os[i].rows[0]]={text:o[os[i].rows[0]],row:ns[i].rows[0]};
}
}
for(i=0;i<n.length-1;++i){
if(n[i].text&&!(n[i+1].text)&&(!(o[n[i].row+1])||!(o[n[i].row+1].text))&&n[i+1]==o[n[i].row+1]){
n[i+1]={text:n[i+1],row:n[i].row+1};
o[n[i].row+1]={text:o[n[i].row+1],row:i+1};
}
}
for(i=n.length-1;i>0;--i){
if(n[i].text&&!(n[i-1].text)&&(!(o[n[i].row-1])||!(o[n[i].row-1].text))&&n[i-1]==o[n[i].row-1]){
n[i-1]={text:n[i-1],row:n[i].row-1};
o[n[i].row-1]={text:o[n[i].row-1],row:i-1};
}
}
return {o:o,n:n};
}
catch(ex){
logger.error("diff(javascript) "+ex);
}
}
function diffArray(o,n){
try{
return diff(extend(["x"," "],splitSpecial(o)),extend(["x"," "],splitSpecial(n)));
}
catch(ex){
logger.error("diffArray(javascript) "+ex);
}
}
try{
return diffArray(_9d,_9e);
}
catch(e){
logger.error(e);
}
}});
var OptMgr=function(_a6,_a7,_a8){
var i;
this.mapping=_a6;
this.options=[];
var _aa;
try{
_aa=_a7?_a7:_a6.preferred;
this.lang=_a8;
MochiKit.Base.extend(this.options,_a6.tWordList);
MochiKit.Base.extend(this.options,_a6.userMapping);
}
catch(e){
_aa=null;
this.lang=_a8;
}
this.numOptions=this.options.length;
for(i=0;i<this.options.length;i++){
if(this.options[i]===_aa){
this.chosenOption=i+1;
break;
}
}
};
OptMgr.prototype.chooseOptionWord=function(_ab){
var i;
for(i=0;i<this.options.length;i++){
if(this.options[i]===_ab){
this.chooseOption(i+1);
break;
}
}
};
OptMgr.prototype.chooseOption=function(idx){
if(idx<1||idx>this.numOptions){
return;
}
if(idx===this.chosenOption){
return [idx,this.options[idx-1]];
}
this.chosenOption=idx;
this.mapping.preferred=this.options[idx-1];
wm.setPreferredMapping(this.lang,this.mapping.engWord,this.options[idx-1]);
return [idx,this.options[idx-1]];
};
OptMgr.prototype.chooseNext=function(){
if(this.chosenOption>=this.numOptions){
return this.chooseOption(1);
}else{
return this.chooseOption(this.chosenOption+1);
}
};
OptMgr.prototype.choosePrevious=function(){
if(this.chosenOption<=1){
return this.chooseOption(this.numOptions);
}else{
return this.chooseOption(this.chosenOption-1);
}
};
var OptMenu=function(_ae){
this.visible=false;
this.table=null;
this.textengine=_ae;
};
OptMenu.prototype={enabled:function(){
return this.visible;
},update:function(_af,_b0){
var dom=MochiKit.DOM;
var _b2=MochiKit.Base;
this.node=_af;
this.mgr=new OptMgr(_b0,null,dom.getNodeAttribute(_af,"lang"));
var _b3=this;
function makeTR(_b4,_b5,opt){
var td;
if(opt===_b3.mgr.mapping.preferred){
td=dom.TD({style:{background:_b4}},opt);
}else{
td=dom.TD({style:{background:_b5}},opt);
td.onmouseover=function(){
td.style.background=_b4;
};
td.onmouseout=function(){
td.style.background=_b5;
};
}
dom.setElementClass(td,"linkCursor");
return dom.TR(null,td);
}
if(!this.mgr.mapping){
return;
}
var trs=_b2.map(_b2.partial(makeTR,"#C0DAFF","#FFF"),this.mgr.mapping.tWordList);
if(this.mgr.mapping.userMapping){
_b2.extend(trs,_b2.map(_b2.partial(makeTR,"#FFBFC2","#FFFEF0"),this.mgr.mapping.userMapping));
}
this.table=dom.TABLE({cellspacing:"1",cellpadding:"2","class":"optsTable"},dom.TBODY(null,trs));
this.table.style.border="1px #C0DAFF solid";
this.table.style.background="white";
this.table.style.padding="1px";
this.table.style.fontSize=this.textengine.getFontSize()[0];
this.table.style.lineHeight=this.textengine.getFontSize()[1];
this.sig=MochiKit.Signal.connect(this.table,"onclick",this,this.onTblClick);
var pos=dom.withDocument(this.textengine.doc,_b2.partial(dom.elementPosition,_af));
var _ba=this.textengine.iframePos();
pos.x+=_ba.x;
pos.y+=_ba.y+22-this.textengine.displayArea.scrollTop;
this.table.style.position="absolute";
dom.setElementPosition(this.table,pos);
document.body.appendChild(this.table);
this.visible=true;
},onTblClick:function(evt){
var tgt=evt.target();
if(tgt!==this.table&&tgt.nodeName==="TD"){
QuillUtil.setNodeText(this.node,MochiKit.DOM.scrapeText(tgt));
this.mgr.chooseOptionWord(QuillUtil.getNodeText(tgt));
this.cleanup();
}
evt.stop();
},cleanup:function(){
MochiKit.Signal.disconnect(this.sig);
MochiKit.DOM.removeElement(this.table);
this.table=null;
this.visible=false;
}};
function ToolTip(_bd,_be,_bf,_c0,_c1){
var dom=MochiKit.DOM;
this.tdiv=dom.getElement(_bd);
this.textengine=_c1;
if(QuillUtil.getBrowser()==="moz"){
this.tdiv.style.position="fixed";
this.updatePos=function(_c3){
var pos=dom.withDocument(this.textengine.doc,MochiKit.Base.partial(dom.elementPosition,_c3));
var _c5=this.textengine.iframePos();
pos.x+=_c5.x;
pos.y+=_c5.y+24-this.textengine.doc.body.scrollTop;
this.pos=pos;
pos.x-=window.pageXOffset;
pos.y-=window.pageYOffset;
dom.setElementPosition(this.tdiv,pos);
};
window.onscroll=MochiKit.Base.method(this,function(){
var pos=this.pos;
if(!pos){
return;
}
MochiKit.DOM.setElementPosition(this.tdiv,{x:pos.x-window.pageXOffset,y:pos.y-window.pageYOffset});
});
}else{
this.tdiv.style.position="absolute";
}
this.wordSpan=dom.getElement(_be);
this.optSpan=dom.getElement(_bf);
this.editorInput=dom.getElement(_c0);
if(QuillUtil.getBrowser()==="ie"){
this.editorInput.onpaste=function(){
window.event.returnValue=false;
};
}else{
if(QuillUtil.getBrowser()==="moz"){
}
}
}
ToolTip.prototype={show:function(){
if(QuillUtil.getBrowser()==="moz"){
this.tdiv.style.display="table";
}else{
this.tdiv.style.display="block";
}
},hide:function(){
this.tdiv.style.display="none";
},updatePos:function(_c7){
var dom=MochiKit.DOM;
var pos=dom.withDocument(this.textengine.doc,MochiKit.Base.partial(dom.elementPosition,_c7));
var _ca=this.textengine.iframePos();
var _cb=dom.elementDimensions(_c7).h+4;
_cb=_cb<22?22:_cb;
pos.x+=_ca.x;
pos.y+=_ca.y+_cb-this.textengine.doc.body.scrollTop;
dom.setElementPosition(this.tdiv,pos);
},update:function(_cc,_cd){
this.node=_cc;
this.updatePos(_cc);
this.setWord(_cd);
QuillUtil.setNodeText(this.optSpan,"...");
this.mgr=null;
this.show();
},changeColor:function(){
this.optSpan.style.color="#F66";
},restoreColor:function(){
this.optSpan.style.color="#66F";
},setWord:function(_ce){
this.word=_ce;
QuillUtil.setNodeText(this.wordSpan,_ce);
},updateOpts:function(_cf,_d0){
QuillUtil.setNodeText(this.optSpan,_cf+"/"+_d0);
this.updatePos(this.node);
},getWord:function(){
return this.word;
},doneEditing:function(_d1){
clearInterval(this.timer);
MochiKit.Signal.disconnect(this.sig1);
MochiKit.Signal.disconnect(this.sig2);
MochiKit.Signal.disconnect(this.sig3);
this.editorInput.style.display="none";
if(QuillUtil.getBrowser()==="moz"){
this.wordSpan.style.display="table-cell";
}else{
this.wordSpan.style.display="inline";
}
this.hide();
this.restoreColor();
if(this.mode==="correction"){
logger.info("Setting user mapping",this.editorInput.value,this.mgr.mapping.preferred);
wm.setUserMapping(MochiKit.DOM.getNodeAttribute(this.node,"lang"),this.editorInput.value,this.mgr.mapping.preferred);
}
if(this.editorInput.value===""){
this.textengine.doneEditing(this.node,true);
}else{
this.textengine.doneEditing(this.node,false,_d1);
}
},editWord:function(_d2,_d3){
this.editorInput.style.display="inline";
this.wordSpan.style.display="none";
this.update(_d2,_d3);
this.oldText=_d3;
var _d4=MochiKit.DOM.getNodeAttribute(_d2,"lang");
this.mgr=new OptMgr(wm.getMapping(_d4,_d3),null,_d4);
this.mode="edit";
this.editorInput.focus();
this.editorInput.value=_d3;
this.sig1=MochiKit.Signal.connect(this.editorInput,"onkeydown",this,this.onKeyDown);
this.sig2=MochiKit.Signal.connect(this.editorInput,"onblur",this,this.doneEditing);
this.sig3=MochiKit.Signal.connect(this.editorInput,"onkeypress",this,this.onKeyPress);
this.updateOpts(this.mgr.chosenOption,this.mgr.numOptions);
this.timer=setInterval(MochiKit.Base.method(this,this.contentCheck),500);
},contentCheck:function(){
var dom=MochiKit.DOM;
var _d6=this.editorInput.value;
if(_d6===this.oldText){
return;
}
this.mode="edit";
this.oldText=_d6;
if(_d6.length<=0){
QuillUtil.setNodeText(this.node,"");
dom.setNodeAttribute(this.node,"word","");
return;
}
dom.setNodeAttribute(this.node,"word",_d6);
wm.getWordMapping(dom.getNodeAttribute(this.node,"lang"),_d6,MochiKit.Base.method(this,this.callbackFunc));
},callbackFunc:function(m){
this.mgr=new OptMgr(m,null,this.textengine.getLang());
this.textengine.replaceText(this.node,m.engWord,m.preferred);
this.updateOpts(this.mgr.chosenOption,this.mgr.numOptions);
this.restoreColor();
},onKeyPress:function(evt){
var s=evt.key().string;
if(!s.match(/[a-zA-Z\^\/~\.]/)&&s.length>0){
evt.stop();
}
},onKeyDown:function(evt){
var s=evt.key().string;
var opt;
logger.info(s);
switch(s){
case "KEY_BACKSPACE":
case "KEY_DELETE":
case "KEY_HOME":
case "KEY_END":
break;
case "KEY_ARROW_RIGHT":
if(QuillUtil.getCursorPosition(this.editorInput)>=this.editorInput.value.length){
this.doneEditing();
}
break;
case "KEY_ARROW_LEFT":
if(QuillUtil.getCursorPosition(this.editorInput)<=0){
this.doneEditing(true);
}
break;
case "KEY_Q":
if(evt.modifier().alt){
this.makeCorrection();
evt.stop();
}
break;
case "KEY_ESCAPE":
case "KEY_ENTER":
case "KEY_SPACEBAR":
evt.stop();
this.doneEditing();
break;
case "KEY_TAB":
evt.stop();
if(evt.modifier().shift){
this.chooseOption("previous");
}else{
this.chooseOption("next");
}
}
},chooseOption:function(_dd){
if(_dd==="prevous"){
opt=this.mgr.choosePrevious();
}else{
opt=this.mgr.chooseNext();
}
QuillUtil.setNodeText(this.node,opt[1]);
this.updateOpts(opt[0],this.mgr.numOptions);
},setCursorAtStart:function(){
QuillUtil.setCursorPosition(this.editorInput,0);
},makeCorrection:function(){
var pos=QuillUtil.getCursorPosition(this.editorInput);
if(pos<=0){
return;
}
this.mode="correction";
var _df=this;
var _e0=MochiKit.DOM.getNodeAttribute(this.node,"lang");
var opt=wm.getMapping(_e0,this.editorInput.value);
var _e2=opt.optmap[this.editorInput.value];
function callback(_e3,_e4){
logger.info(_e0);
_df.mgr=new OptMgr(new WordMapping(opt.engWord,_e3,_e3[0],"",_e4),opt.preferred,_e0);
_df.updateOpts(_df.mgr.chosenOption,_df.mgr.numOptions);
_df.changeColor();
}
QuillUtil.setNodeText(this.optSpan,"...");
if(_e2){
wm.getCorrections(_e0,_e2,opt.engWord,pos-1,callback,"getCorrections");
}else{
wm.getCorrections(_e0,opt.preferred,opt.engWord,pos-1,callback,"getCorrectionsStr");
}
}};
var TextEngine=function(_e5,_e6,_e7){
this.lang="english";
this.mycharlimit=Quill.Config.client.charlimit;
this.getLang=function(){
return this.lang;
};
this.setLang=function(_e8){
this.lang=_e8;
};
this.getFontSize=function(){
if(Quill.Config.fontSizes&&Quill.Config.fontSizes.hasOwnProperty(this.lang)){
return Quill.Config.fontSizes[this.lang];
}else{
return ["12px","20px"];
}
};
var ifr=MochiKit.DOM.getElement(_e5);
this.ifr=ifr;
this.doc=ifr.contentDocument?ifr.contentDocument:ifr.contentWindow.document;
this.win=ifr.contentWindow;
try{
this.doc.designMode="on";
}
catch(e){
var _ea=this;
var _eb=false;
MochiKit.Signal.connect(_ea.win,"onfocus",function(){
if(!_eb){
_ea.doc.designMode="on";
_eb=true;
}
});
}
if(this.doc.body){
this.displayArea=this.doc.body;
this.displayArea.innerHTML="<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>";
}else{
this.doc.write("<head></head><body></body>");
this.doc.close();
this.displayArea=this.doc.body;
}
this.displayArea.style.overflow="auto";
this.displayArea.style.margin="0px";
this.displayArea.style.padding="5px";
this.displayArea.style.lineHeight="20px";
this.displayArea.style.wordWrap="break-word";
this.setFontSizes();
if(QuillUtil.getBrowser()==="moz"){
this.displayArea.innerHTML=Quill.Config.client.preFill+"<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>";
}else{
this.displayArea.innerHTML=Quill.Config.client.preFill;
}
this.tooltip=new ToolTip(_e6+"wordTip",_e6+"wordTD",_e6+"optTD",_e6+"editorInput",this);
this.menu=new OptMenu(this);
MochiKit.Signal.connect(this.doc,"onkeypress",this,this.onKeyPress);
MochiKit.Signal.connect(this.doc,"onkeydown",this,this.onKeyDown);
MochiKit.Signal.connect(this.doc,"onkeyup",this,this.onKeyUp);
MochiKit.Signal.connect(this.doc,"onclick",this,this.showOptions);
if(QuillUtil.getBrowser()==="moz"){
MochiKit.Signal.connect(this.doc,"onblur",this,this.onBlur);
MochiKit.Signal.connect(this.doc,"onfocus",this,this.onFocus);
this.xlitText=this.xlitTextFF;
}else{
MochiKit.Signal.connect(this.win,"onblur",this,this.onBlur);
MochiKit.Signal.connect(this.win,"onfocus",this,this.onFocus);
MochiKit.Signal.connect(this.displayArea,"onpaste",this,this.onPaste);
MochiKit.Signal.connect(this.displayArea,"oncut",this,this.onCut);
}
if(this.mycharlimit){
this.count=this.mycharlimit;
}
this.countSpan=MochiKit.DOM.getElement(_e7);
this.updateCount(0);
if(typeof (this.count)!=="undefined"){
setInterval(MochiKit.Base.method(this,this.updateCount),500);
}
this.callback=MochiKit.Base.method(this,this.callbackFunc);
};
TextEngine.prototype.setCharLimit=function(_ec){
this.mycharlimit=_ec;
this.count=this.mycharlimit;
this.updateCount(0);
};
TextEngine.prototype.charCount=function(){
var txt=this.displayArea.innerHTML;
if(this.hasPrefillText()){
return 0;
}
if(QuillUtil.getBrowser()=="moz"){
txt=txt.replace(/<br>$/i,"");
}
txt=txt.replace(/(<br)/gi,"*$1").replace(/<[^>]*>/g,"").replace(/&nbsp;/gi,"*").replace(/&amp;/gi,"*");
txt=txt.replace(/&lt;/gi,"*").replace(/&gt;/gi,"*").replace(/&quot;/gi,"*").replace(/&apos;/gi,"*");
return txt.length;
};
TextEngine.prototype.removeExtraContent=function(){
var _ee=this.mycharlimit;
var _ef;
for(var i=this.displayArea.childNodes.length-1,_f1=this.charCount();i>=0&&_f1>_ee;--i,_f1=this.charCount()){
_ef=this.displayArea.childNodes[i];
if((_ef.nodeName==="BR")||(_ef.nodeName==="SPAN"&&typeof (_ef.word)!=="undefined")){
MochiKit.DOM.removeElement(_ef);
}else{
var _f2=_f1-_ee;
var txt;
if(typeof (_ef.innerText)!=="undefined"){
txt=_ef.innerText;
}else{
if(typeof (_ef.textContent)!=="undefined"){
txt=_ef.textContent;
}else{
continue;
}
}
txt=txt.substr(0,txt.length-_f2);
if(typeof (_ef.innerText)!=="undefined"){
_ef.innerText=txt;
}else{
_ef.textContent=txt;
}
}
}
};
TextEngine.prototype.updateCount=function(){
if(typeof (this.count)==="undefined"){
return false;
}
var _f4=this.mycharlimit;
if(_f4<1){
return;
}
var _f5=this.charCount();
if(_f5>_f4){
this.removeExtraContent();
_f5=this.charCount();
}
var _f6=_f4-_f5;
this.count=_f6<0?0:_f6;
QuillUtil.setNodeText(this.countSpan,((_f5>_f4)?_f4:_f5)+" characters entered. (Max "+_f4+" characters).");
};
TextEngine.prototype.limitReached=function(){
if(typeof (this.count)==="undefined"){
return false;
}
var _f7=this.mycharlimit;
if(_f7<1){
return false;
}
return (this.count<=0);
};
TextEngine.prototype.setFontSizes=function(){
var _f8=this.getFontSize();
this.doc.body.style.fontSize=_f8[0];
this.doc.body.style.lineHeight=_f8[1];
var _f9=MochiKit.DOM.getElement("indicDiv");
if(_f9){
_f9.style.fontSize=_f8[0];
_f9.style.lineHeight=_f8[1];
}
var _fa=MochiKit.DOM.getElement("cOptions");
if(_fa){
_fa.style.fontSize=_f8[0];
}
var _fb=MochiKit.DOM.getElement("langUnicode");
if(_fb){
_fb.style.fontSize=_f8[0];
}
var ki=MochiKit.DOM.getElement("keyInput");
if(ki){
ki.style.lineHeight=_f8[1];
}
};
TextEngine.prototype.loadImage=function(_fd){
if(_fd===""||this.lang!=="english"){
return;
}
this.tooltip.hide();
this.hideMenu();
this.displayArea.focus();
this.onFocus();
var i=MochiKit.DOM.withDocument(this.doc,MochiKit.DOM.IMG);
i.src=_fd;
var _ff=this.getWidgetAtCursor();
if(_ff){
_ff=_ff.nextSibling;
if(_ff){
this.displayArea.insertBefore(i,_ff);
}else{
if(QuillUtil.getBrowser()==="moz"&&MochiKit.DOM.getNodeAttribute(this.displayArea.lastChild,"_moz_editor_bogus_node")==="TRUE"){
this.displayArea.insertBefore(i,this.displayArea.lastChild);
}else{
this.displayArea.appendChild(i);
}
}
}else{
if(QuillUtil.getBrowser()==="moz"&&MochiKit.DOM.getNodeAttribute(this.displayArea.lastChild,"_moz_editor_bogus_node")==="TRUE"){
this.displayArea.insertBefore(i,this.displayArea.lastChild);
}else{
this.displayArea.appendChild(i);
}
}
this.setCursorAfterWidget(i);
};
TextEngine.prototype.prefill=function(text){
var sel=this.getSelection();
var lang=this.getLang();
var that=this;
this.setLang("english");
this.xlitText(text,function(_104){
if(sel.atAnchorStart){
if(sel.anchorNode){
that.setCursorBeforeWidget(sel.anchorNode);
}
that.doc.selection.createRange().pasteHTML(_104);
}else{
if(sel.anchorNode){
that.setCursorAfterWidget(sel.anchorNode);
}
that.doc.selection.createRange().pasteHTML(_104);
}
that.setLang(lang);
});
};
TextEngine.prototype.onPaste=function(evt){
var data=window.clipboardData.getData("Text");
var sel=this.getSelection();
var that=this;
this.xlitText(data,function(_109){
if(sel.atAnchorStart){
if(sel.anchorNode){
that.setCursorBeforeWidget(sel.anchorNode);
}
that.doc.selection.createRange().pasteHTML(_109);
}else{
if(sel.anchorNode){
that.setCursorAfterWidget(sel.anchorNode);
}
that.doc.selection.createRange().pasteHTML(_109);
}
});
evt.stop();
};
TextEngine.prototype.setText=function(text){
var that=this;
this.xlitText(text,function(_10c){
logger.info("got callback",_10c);
that.displayArea.innerHTML=_10c;
});
};
TextEngine.prototype.xlitTextFF=function(text,func){
var iarr=Quill.splitSpecial(text);
var _110=iarr.length;
var that=this;
function process(text){
var s="<span>";
var i,_115;
for(i=0;i<text.length;i++){
switch(text.charAt(i)){
case " ":
_115=0;
while(i<text.length&&text.charAt(i)===" "){
_115+=1;
s+="&nbsp;";
i++;
}
if(_115>1){
s=[s.slice(0,-6)," "].join("");
}
i--;
break;
case "\n":
s=[s,"</span><br><span>"].join("");
break;
default:
s=[s,text.charAt(i)].join("");
}
}
return s+"</span>";
}
function callbk(idx,m){
_110-=1;
iarr[idx]=["<span word=\"",m.engWord,"\" lang=\"",that.getLang(),"\">",m.preferred,"</span>"].join("");
if(_110<=0){
func(iarr.join("")+"<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>");
}
}
for(var i=0;i<iarr.length;i++){
if(iarr[i].match(/[a-zA-Z]/)){
wm.getWordMapping(this.getLang(),iarr[i],MochiKit.Base.partial(callbk,i));
}else{
iarr[i]=process(iarr[i]);
_110-=1;
if(_110<=0){
func(iarr.join(""));
}
}
}
};
TextEngine.prototype.xlitText=function(text,func){
var iarr=Quill.splitSpecial(text);
var _11c=iarr.length;
var that=this;
function process(text){
var s="";
var i,_121;
var _122=false;
for(i=0;i<text.length;i++){
switch(text.charAt(i)){
case " ":
if(!_122){
s+="<span>";
_122=true;
}
_121=0;
while(i<text.length&&text.charAt(i)===" "){
_121+=1;
s+="&nbsp;";
i++;
}
if(_121>1){
s=[s.slice(0,-6)," "].join("");
}
i--;
break;
case "\n":
if(_122){
s=[s,"</span><br>"].join("");
_122=false;
}else{
s=[s,"<br>"].join("");
}
break;
default:
if(!_122){
s+="<span>";
_122=true;
}
s=[s,text.charAt(i)].join("");
}
}
if(_122){
s+="</span>";
}
return s;
}
function callbk(idx,m){
_11c-=1;
iarr[idx]=["<span word=\"",m.engWord,"\" lang=\"",that.getLang(),"\">",m.preferred,"</span>"].join("");
if(_11c<=0){
func(iarr.join(""));
}
}
for(var i=0;i<iarr.length;i++){
if(iarr[i].match(/[a-zA-Z]/)){
wm.getWordMapping(this.getLang(),iarr[i],MochiKit.Base.partial(callbk,i));
}else{
iarr[i]=process(iarr[i]);
_11c-=1;
if(_11c<=0){
func(iarr.join(""));
}
}
}
};
TextEngine.prototype.onCut=function(evt){
window.clipboardData.setData("Text",this.getTextSelection());
this.deleteSelection(this.getSelection(),evt);
};
TextEngine.prototype.hasPrefillText=function(){
var txt=this.displayArea.innerHTML;
var _128=Quill.Config.client.preFill;
for(i=0;i<this.displayArea.childNodes.length;i++){
if(this.displayArea.childNodes[i].className==="spanDispArea"){
return false;
}
}
txt=txt.replace(/<[^>]*>/g,"");
_128=_128.replace(/<[^>]*>/g,"");
if(txt.toLowerCase()===_128.toLowerCase()){
return true;
}else{
return false;
}
};
TextEngine.prototype.onBlur=function(evt){
if(this.getText().match(/^\s*$/)){
if(QuillUtil.getBrowser()==="moz"){
this.displayArea.innerHTML=Quill.Config.client.preFill+"<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>";
}else{
this.displayArea.innerHTML=Quill.Config.client.preFill;
}
}
};
TextEngine.prototype.onFocus=function(evt){
if(this.hasPrefillText()){
if(QuillUtil.getBrowser()==="moz"){
this.displayArea.innerHTML="<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>";
}else{
this.displayArea.innerHTML="";
}
}
};
TextEngine.prototype.hideMenu=function(){
if(this.menu.enabled()){
this.menu.cleanup();
}
};
TextEngine.prototype.getSelection=function(){
var _12b;
var _12c;
var _12d;
var _12e;
var that=this;
var sel;
var ret={};
if(this.win.getSelection){
sel=this.win.getSelection();
if(sel.anchorNode.nodeName==="BODY"){
if(sel.anchorOffset===0){
ret.anchorNode=this.displayArea.childNodes[0];
}else{
ret.anchorNode=this.displayArea.childNodes[sel.anchorOffset-1];
}
ret.atAnchorEnd=true;
}else{
if(sel.anchorNode.parentNode&&sel.anchorNode.parentNode.nodeName!=="BODY"){
ret.anchorNode=sel.anchorNode.parentNode;
if(sel.anchorOffset===sel.anchorNode.nodeValue.length){
ret.atAnchorEnd=true;
}
}else{
ret.anchorNode=sel.anchorNode;
if(sel.anchorOffset===sel.anchorNode.nodeValue.length){
ret.atAnchorEnd=true;
}
}
if(sel.anchorOffset===0){
ret.atAnchorStart=true;
}
}
ret.anchorOffset=sel.anchorOffset;
ret.focusNode=sel.focusNode;
ret.focusOffset=sel.focusOffset;
ret.isCollapsed=sel.isCollapsed;
return ret;
}else{
_12b=this.doc.selection.createRange().duplicate();
_12b.collapse(true);
_12c=this.doc.selection.createRange().duplicate();
_12c.collapse(false);
_12b.pasteHTML("<span id=\"fuquaSpan1\"></span>");
_12d=this.doc.getElementById("fuquaSpan1");
ret.anchorNode=_12d.parentNode;
try{
if(_12d.previousSibling&&_12d.previousSibling.nodeName==="#text"){
ret.anchorOffset=_12d.previousSibling.nodeValue.length;
}
}
catch(e){
if(e.message==="Invalid Argument."){
ret.anchorOffset=0;
}
}
if(!_12d.nextSibling||_12d.parentNode.nodeName==="BODY"){
ret.atAnchorEnd=true;
}
if(!_12d.previousSibling){
ret.atAnchorStart=true;
}
if(_12b.compareEndPoints("StartToStart",_12c)===0){
ret.isCollapsed=true;
MochiKit.DOM.withDocument(this.doc,function(){
MochiKit.DOM.removeElement(_12d);
});
return ret;
}else{
ret.isCollapsed=false;
}
_12c.pasteHTML("<span id=\"fuquaSpan2\"></span>");
_12e=this.doc.getElementById("fuquaSpan2");
ret.focusNode=_12e.parentNode;
if(_12e.previousSibling&&_12e.previousSibling.nodeName==="#text"){
ret.focusOffset=_12e.previousSibling.nodeValue.length;
}
if(!_12e.previousSibling||_12e.parentNode.nodeName==="BODY"){
ret.atFocusStart=true;
}
MochiKit.DOM.withDocument(this.doc,function(){
MochiKit.DOM.removeElement(_12d);
});
MochiKit.DOM.withDocument(this.doc,function(){
MochiKit.DOM.removeElement(_12e);
});
return ret;
}
};
TextEngine.prototype.addNewline=function(node){
var n=MochiKit.DOM.withDocument(this.doc,MochiKit.DOM.BR);
this.add(n,node);
return n;
};
TextEngine.prototype.setCursor=function(_134,node){
var _136;
var sel;
if(this.win.getSelection){
_136=this.doc.createRange();
_136.selectNode(node);
_136.collapse(_134);
sel=this.win.getSelection();
sel.removeAllRanges();
sel.addRange(_136);
}else{
if(this.doc.selection){
logger.info("where",_134,node);
_136=this.displayArea.createTextRange();
_136.moveToElementText(node);
_136.collapse(_134);
_136.select();
}
}
};
TextEngine.prototype.setCursorBeforeWidget=MochiKit.Base.partial(TextEngine.prototype.setCursor,true);
TextEngine.prototype.setCursorAfterWidget=MochiKit.Base.partial(TextEngine.prototype.setCursor,false);
TextEngine.prototype.getTextSelection=function(){
if(this.win.getSelection){
return this.win.getSelection().toString();
}else{
return this.doc.selection.createRange().text;
}
};
TextEngine.prototype.getWidgetAtCursor=function(){
var n;
var sel;
var _13a;
var _13b;
var elem;
if(this.win.getSelection){
sel=this.win.getSelection();
n=sel.anchorNode;
if(n.nodeName.toUpperCase()==="BODY"){
_13b=sel.anchorOffset;
if(_13b>0){
_13b-=1;
}
n=this.displayArea.childNodes[_13b];
}else{
if(n.parentNode&&n.parentNode.nodeName.toUpperCase()==="BODY"){
return n;
}
return n.parentNode;
}
return n;
}else{
_13a=this.doc.selection.createRange().duplicate();
_13a.collapse(true);
_13a.pasteHTML("<span id=\"fuquaSpan\"></span>");
elem=this.doc.getElementById("fuquaSpan");
if(elem.parentNode&&elem.parentNode.nodeName!=="BODY"){
n=elem.parentNode;
}else{
n=elem.previousSibling;
}
MochiKit.DOM.withDocument(this.doc,function(){
MochiKit.DOM.removeElement(elem);
});
return n;
}
return null;
};
TextEngine.prototype.showOptions=function(evt){
var tgt=evt.target();
var _13f;
var mgr;
if(this.menu.enabled()){
this.menu.cleanup();
}
this.tooltip.hide();
if(!tgt||tgt===this.displayArea){
return;
}
_13f=this.getWidgetContent(tgt);
if(_13f[0]!=="word"){
return;
}
if(evt.modifier().ctrl||evt.modifier().alt){
evt.stop();
this.tooltip.editWord(tgt,_13f[1]);
}else{
this.menu.update(tgt,wm.getMapping(_13f[2],_13f[1]));
}
};
TextEngine.prototype.getWidgetContent=function(node){
var c=MochiKit.DOM.getNodeAttribute(node,"word");
if(c){
return ["word",c,MochiKit.DOM.getNodeAttribute(node,"lang")];
}
return ["",""];
};
TextEngine.prototype.addText=function(_143,_144,text,lang){
var dom=MochiKit.DOM;
var sp=dom.withDocument(this.doc,function(){
var s=dom.SPAN(text);
dom.setElementClass(s,"spanDispArea");
dom.setNodeAttribute(s,"word",_144);
dom.setNodeAttribute(s,"length",_144.length);
dom.setNodeAttribute(s,"lang",lang);
return s;
});
var font=Quill.Config.fonts[lang];
if(font){
sp.style.fontFamily=font+",'Arial Unicode MS',Arial, Verdana, Helvetica,sans-serif";
}else{
sp.style.fontFamily="Arial, Verdana, Helvetica,sans-serif";
}
var _14b=this.getFontSize();
sp.style.fontSize=_14b[0];
this.add(sp,_143);
return sp;
};
TextEngine.prototype.nuke=function(sel){
function removeRecurse(node,stop){
if(!node){
return;
}
if(node==stop){
MochiKit.DOM.withDocument(this.doc,MochiKit.Base.partial(MochiKit.DOM.removeElement,node));
}else{
removeRecurse(node.nextSibling,stop);
MochiKit.DOM.withDocument(this.doc,MochiKit.Base.partial(MochiKit.DOM.removeElement,node));
}
}
removeRecurse(sel.anchorNode,sel.focusNode);
};
TextEngine.prototype.replaceText=function(n,_150,text){
if(n){
QuillUtil.setNodeText(n,text);
}else{
logger.warn("Tried to replace non-existent widget at",n,_150,text);
}
};
TextEngine.prototype.add=function(node,_153){
this.displayArea.insertBefore(node,_153);
};
TextEngine.prototype.addTextNode=function(text,_155){
var n=this.doc.createTextNode(text);
this.add(n,_155);
return n;
};
TextEngine.prototype.addSpan=function(text,_158){
var _159=this.getFontSize();
var t=MochiKit.DOM.withDocument(this.doc,MochiKit.Base.partial(MochiKit.DOM.SPAN,text));
t.style.fontSize=_159[0];
this.add(t,_158);
return t;
};
TextEngine.prototype.remove=function(node){
if(!node){
logger.warn("Tried to remove non-existent widget",node);
}else{
MochiKit.DOM.removeElement(node);
}
};
TextEngine.prototype.getText=function(){
var i;
var txt="";
var ret="";
if(this.hasPrefillText()){
return ret;
}
for(i=0;i<this.displayArea.childNodes.length;i++){
txt=this.displayArea.childNodes[i].innerText;
if(txt){
ret+=txt;
}else{
txt=this.displayArea.childNodes[i].textContent;
if(txt){
ret+=txt;
}else{
if(this.displayArea.childNodes[i].nodeName==="BR"){
ret+="\n";
}else{
if(this.displayArea.childNodes[i].nodeName==="IMG"){
ret+="<img src=\""+this.displayArea.childNodes[i].src+"\" />";
}else{
txt=QuillUtil.getNodeText(this.displayArea.childNodes[i]);
if(typeof (txt)!=="string"){
txt=this.displayArea.childNodes[i].data;
}
ret+=txt;
}
}
}
}
}
return ret;
};
TextEngine.prototype.getHTML=function(){
return this.displayArea.innerHTML;
};
TextEngine.prototype.getEnglishText=function(){
var i;
var word;
var ret="";
if(this.hasPrefillText()){
return ret;
}
for(i=0;i<this.displayArea.childNodes.length;i++){
word=MochiKit.DOM.getNodeAttribute(this.displayArea.childNodes[i],"word");
if(word){
ret+=word;
}else{
if(this.displayArea.childNodes[i].nodeName==="BR"){
ret+="\n";
}else{
if(this.displayArea.childNodes[i].nodeName==="IMG"){
ret+="<img src=\""+this.displayArea.childNodes[i].src+"\" />";
}else{
ret+=QuillUtil.getNodeText(this.displayArea.childNodes[i]);
}
}
}
}
return ret;
};
TextEngine.prototype.doneEditing=function(node,_163,_164){
this.win.focus();
if(_163){
this.remove(node);
}else{
if(_164){
this.setCursorBeforeWidget(node);
}else{
this.setCursorAfterWidget(node);
}
}
};
TextEngine.prototype.forceFocus=function(){
this.win.focus();
};
TextEngine.prototype.onKeyUp=function(evt){
var s=evt.key().string;
var node;
var c;
var mgr;
var sel;
switch(s){
case "KEY_ARROW_UP":
case "KEY_ARROW_DOWN":
case "KEY_PAGE_UP":
case "KEY_PAGE_DOWN":
case "KEY_HOME":
case "KEY_END":
this.hideMenu();
node=this.getWidgetAtCursor();
c=this.getWidgetContent(node);
if(c[0]==="word"){
mgr=new OptMgr(wm.getMapping(c[2],c[1]),QuillUtil.getNodeText(node),MochiKit.DOM.getNodeAttribute(node,"lang"));
this.tooltip.update(node,c[1]);
this.tooltip.updateOpts(mgr.chosenOption,mgr.numOptions);
}else{
this.tooltip.hide();
}
break;
}
};
TextEngine.prototype.onKeyDown=function(evt){
var s=evt.key().string;
var node;
var n;
var c;
var word;
var _171;
var mgr,opt;
var sel;
var _175;
switch(s){
case "KEY_ENTER":
this.tooltip.hide();
if(this.limitReached()){
evt.stop();
return;
}
if(QuillUtil.getBrowser()==="moz"){
return;
}
node=this.getWidgetAtCursor();
if(node){
n=this.addNewline(node.nextSibling);
}else{
n=this.addNewline(null);
}
var t=MochiKit.DOM.withDocument(this.doc,MochiKit.Base.partial(MochiKit.DOM.SPAN,""));
t.innerHTML="&nbsp;";
this.add(t,n.nextSibling);
this.setCursorAfterWidget(t);
t.parentNode.removeChild(t);
this.setCursorAfterWidget(n);
evt.stop();
break;
case "KEY_BACKSPACE":
sel=this.getSelection();
node=sel.anchorNode;
if(!sel.isCollapsed){
this.deleteSelection(sel,evt);
return;
}
c=this.getWidgetContent(node);
if(sel.atAnchorStart){
if(QuillUtil.getBrowser()==="moz"){
this.setCursorBeforeWidget(sel.anchorNode);
}else{
if(c[0]==="word"){
this.setCursorBeforeWidget(sel.anchorNode);
}
}
return;
}
word=c[1].slice(0,-1);
if(c[0]==="word"){
evt.stop();
if(word<=0){
_171=node.prevSibling;
this.remove(node);
this.tooltip.hide();
if(_171){
this.setCursorAfterWidget(_171);
}
}else{
MochiKit.DOM.setNodeAttribute(node,"word",word);
this.tooltip.update(node,word);
wm.getWordMapping(c[2],word,MochiKit.Base.partial(this.callback,node));
this.setCursorAfterWidget(node);
}
}
break;
case "KEY_ESCAPE":
evt.stop();
break;
case "KEY_ARROW_RIGHT":
sel=this.getSelection();
if(sel.atAnchorEnd&&sel.anchorNode.nextSibling){
c=this.getWidgetContent(sel.anchorNode.nextSibling);
if(c[0]==="word"){
this.tooltip.editWord(sel.anchorNode.nextSibling,c[1]);
this.tooltip.setCursorAtStart();
evt.stop();
}
}else{
if(sel.atAnchorStart){
c=this.getWidgetContent(sel.anchorNode);
if(c[0]==="word"){
this.tooltip.editWord(sel.anchorNode,c[1]);
this.tooltip.setCursorAtStart();
evt.stop();
}
}
}
break;
case "KEY_ARROW_LEFT":
sel=this.getSelection();
if(sel.atAnchorEnd){
c=this.getWidgetContent(sel.anchorNode);
if(c[0]==="word"){
this.tooltip.editWord(sel.anchorNode,c[1]);
evt.stop();
}
}else{
if(sel.atAnchorStart&&sel.anchorNode.previousSibling){
c=this.getWidgetContent(sel.anchorNode.previousSibling);
if(c[0]==="word"){
this.tooltip.editWord(sel.anchorNode.previousSibling,c[1]);
evt.stop();
}
}
}
break;
case "KEY_DELETE":
sel=this.getSelection();
if(sel.isCollapsed){
this.deleteChar(sel,evt);
}else{
this.deleteSelection(sel,evt);
}
break;
case "KEY_TAB":
this.hideMenu();
node=this.getWidgetAtCursor();
c=this.getWidgetContent(node);
if(!c||typeof (c[2])==="undefined"){
break;
}
_175=wm.getMapping(c[2],c[1]);
if(!_175){
break;
}
if(c[0]==="word"){
evt.stop();
mgr=new OptMgr(_175,null,MochiKit.DOM.getNodeAttribute(node,"lang"));
if(evt.modifier().shift){
opt=mgr.choosePrevious();
}else{
opt=mgr.chooseNext();
}
this.tooltip.updateOpts(opt[0],mgr.numOptions);
QuillUtil.setNodeText(node,opt[1]);
this.setCursorAfterWidget(node);
}
break;
}
};
TextEngine.prototype.deleteSelection=function(sel,evt){
if(sel.anchorNode.previousSibling){
this.setCursorAfterWidget(sel.anchorNode.previousSibling);
}
if(sel.focusNode.nextSibling){
this.setCursorBeforeWidget(sel.focusNode.nextSibling);
}
this.nuke(sel);
this.tooltip.hide();
evt.stop();
};
TextEngine.prototype.deleteChar=function(sel,evt){
var c;
if(sel.anchorNode.nodeName==="BODY"){
return;
}
logger.info(sel.anchorAtEnd);
var that=this;
function modWord(node,text,lang,_180){
var _181=that;
if(text.length<=1){
that.remove(node);
that.tooltip.hide();
}else{
text=text.substring(1);
MochiKit.DOM.setNodeAttribute(node,"word",text);
logger.info("node is",node);
that.tooltip.update(node,text);
wm.getWordMapping(lang,text,function(m){
_181.callback(node,m);
if(_180){
_181.setCursorBeforeWidget(node);
}
});
}
}
if(sel.atAnchorEnd){
c=this.getWidgetContent(sel.anchorNode.nextSibling);
logger.info("yo1",c);
if(c[0]==="word"){
evt.stop();
modWord(sel.anchorNode.nextSibling,c[1],c[2]);
}
}else{
if(sel.atAnchorStart){
c=this.getWidgetContent(sel.anchorNode);
if(c[0]==="word"){
evt.stop();
modWord(sel.anchorNode,c[1],c[2],true);
}
}else{
c=this.getWidgetContent(sel.anchorNode);
logger.info("yo2",c);
if(c[0]==="word"){
evt.stop();
}
}
}
};
TextEngine.prototype.callbackFunc=function(node,m){
var mgr=new OptMgr(m,null,this.lang);
if(MochiKit.DOM.getNodeAttribute(node,"word")===m.engWord){
try{
this.replaceText(node,m.engWord,m.preferred);
}
catch(e){
logger.warn("Exception in callbackFunc",m,node,e);
}
}
if(this.tooltip.getWord()===m.engWord){
this.tooltip.updateOpts(mgr.chosenOption,mgr.numOptions);
}
};
TextEngine.prototype.onKeyPress=function(evt){
var s=evt.key().string;
var node,_189;
var c;
var word;
var t;
var mod=evt.modifier();
var sel=this.getSelection();
if(mod.alt||mod.ctrl){
return;
}
this.hideMenu();
if((s.length!=0)&&this.limitReached()){
evt.stop();
return;
}
if(s.match(/[a-zA-Z]/)){
node=this.getWidgetAtCursor();
if(node){
c=this.getWidgetContent(node);
if(c[0]==="word"){
word=c[1]+s;
MochiKit.DOM.setNodeAttribute(node,"word",word);
this.tooltip.update(node,word);
wm.getWordMapping(c[2],word,MochiKit.Base.partial(this.callback,node));
this.setCursorAfterWidget(node);
}else{
if(QuillUtil.getBrowser()==="moz"&&node.nodeName==="BR"&&!node.nextSibling){
_189=this.addText(node,s," ",this.getLang());
_189.innerHTML="&nbsp;";
}else{
_189=this.addText(node.nextSibling,s," ",this.getLang());
if(QuillUtil.getBrowser()==="moz"){
_189.innerHTML="&nbsp;";
}
}
this.setCursorAfterWidget(_189);
this.tooltip.update(_189,s);
wm.getWordMapping(this.getLang(),s,MochiKit.Base.partial(this.callback,_189));
}
}else{
_189=this.addText(null,s," ",this.getLang());
this.setCursorAfterWidget(_189);
this.tooltip.update(_189,s);
wm.getWordMapping(this.getLang(),s,MochiKit.Base.partial(this.callback,_189));
}
evt.stop();
}else{
if(s.length!=0){
this.tooltip.hide();
node=this.getWidgetAtCursor();
if(!node){
t=this.addSpan(s,null);
evt.stop();
this.setCursorAfterWidget(t);
return;
}
c=this.getWidgetContent(node);
if(c[0]==="word"){
if(sel.atAnchorStart){
if(sel.anchorNode.previousSibling){
c=this.getWidgetContent(sel.anchorNode.previousSibling);
if(c[0]==="word"){
t=this.addSpan(s,sel.anchorNode);
this.setCursorAfterWidget(t);
evt.stop();
}else{
if(QuillUtil.getBrowser()==="moz"){
this.setCursorAfterWidget(sel.anchorNode.previousSibling);
}else{
t=this.addSpan(s,sel.anchorNode);
this.setCursorAfterWidget(t);
evt.stop();
}
}
}else{
if(QuillUtil.getBrowser()==="moz"){
this.setCursorBeforeWidget(sel.anchorNode);
}else{
t=this.addSpan(s,sel.anchorNode);
this.setCursorAfterWidget(t);
evt.stop();
}
}
return;
}
if(QuillUtil.getBrowser()==="moz"){
this.setCursorAfterWidget(node);
}else{
if(QuillUtil.getBrowser()==="ie"){
t=this.addSpan(s,node.nextSibling);
this.setCursorAfterWidget(t);
evt.stop();
}
}
}
}
}
this.updateCount(-1);
};
TextEngine.prototype.clearTextArea=function(){
var node=this.displayArea.firstChild;
while(node){
var _190=node.nextSibling;
MochiKit.DOM.removeElement(node);
node=_190;
}
if(this.getText().match(/^\s*$/)){
if(QuillUtil.getBrowser()==="moz"){
this.displayArea.innerHTML=Quill.Config.client.preFill+"<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>";
}else{
this.displayArea.innerHTML=Quill.Config.client.preFill;
}
}
this.displayArea.focus();
};
TextEngine.prototype.setFocus=function(){
if(this.displayArea.lastChild){
this.setCursorAfterWidget(this.displayArea.lastChild);
}else{
this.displayArea.focus();
}
};
TextEngine.prototype.getSaveData=function(){
var i;
return MochiKit.Base.serializeJSON(MochiKit.Base.map(function(node){
var word=MochiKit.DOM.getNodeAttribute(node,"word");
if(word){
return ["word",word,QuillUtil.getNodeText(node),MochiKit.DOM.getNodeAttribute(node,"lang")];
}else{
if(node.nodeName==="BR"){
return ["newline"];
}else{
if(node.nodeName==="#text"){
return (node.textContent?["text",node.textContent]:["text",node.data]);
}else{
if(node.nodeName==="SPAN"){
return ["text",QuillUtil.getNodeText(node)];
}else{
if(node.nodeName==="IMG"){
return ["image",node.src];
}else{
return ["",""];
}
}
}
}
}
},this.displayArea.childNodes));
};
TextEngine.prototype.iframePos=function(){
return MochiKit.DOM.elementPosition(this.ifr);
};
TextEngine.prototype.load=function(data){
var arr;
var i;
var s;
try{
arr=eval("("+data+")");
}
catch(e){
logger.warn("Got exception in load",e);
return;
}
if(this.hasPrefillText()){
this.displayArea.innerHTML="";
}
function process(text){
var s="";
var i,_19b;
for(i=0;i<text.length;i++){
switch(text.charAt(i)){
case " ":
_19b=0;
while(i<text.length&&text.charAt(i)===" "){
_19b+=1;
s+="&nbsp;";
i++;
}
if(_19b>1){
s=[s.slice(0,-6)," "].join("");
}
i--;
break;
default:
s=[s,text.charAt(i)].join("");
}
}
return s;
}
for(i=0;i<arr.length;i++){
switch(arr[i][0]){
case "word":
wm.getWordMapping(arr[i][3],arr[i][1],function(){
});
this.addText(null,arr[i][1],arr[i][2],arr[i][3]);
break;
case "text":
s=MochiKit.DOM.withDocument(this.doc,MochiKit.DOM.SPAN);
QuillUtil.setNodeText(s,arr[i][1]);
MochiKit.DOM.appendChildNodes(this.displayArea,s);
break;
case "newline":
this.addNewline(null);
break;
case "image":
s=MochiKit.DOM.withDocument(this.doc,MochiKit.DOM.IMG);
s.src=arr[i][1];
MochiKit.DOM.appendChildNodes(this.displayArea,s);
break;
default:
logger.warn("Got unknown data in load",arr[i]);
}
}
if(QuillUtil.getBrowser()==="moz"){
this.displayArea.innerHTML+="<br _moz_editor_bogus_node=\"TRUE\" _moz_dirty=\"\"/>";
}
};
MochiKit.Base.update(Quill,{init:function(_19c,_19d,_19e){
var d=MochiKit.DOM.getElement(_19c);
if(!d){
return;
}
var _1a0="Quill"+_19c;
d.innerHTML="\n<table id=\""+_1a0+"mainTable\" class=\"QuillmainTable\" cellspacing=\"1\"> \n<tbody > \n  <tr> \n"+"  </tr>\n  <tr>\n    <td class=\"QuillwhiteBorderBox\" id=\""+_1a0+"compose\" valign=\"top\" colspan=\"2\">\n      <iframe id=\""+_1a0+"indicOutput\" class=\"QuillindicOutput\" name=\"indicOutput\" frameborder=\"0\" scrolling=\"auto\"></iframe>\n    </td>\n  </tr>\n</tbody>\n</table>\n\n<table id=\""+_1a0+"wordTip\" class=\"QuillwordTip\" cellspacing=\"0\" cellpadding=\"0\">\n  <tbody>\n    <tr>\n      <td>\n        <input type=\"text\" size=\"10\" id=\""+_1a0+"editorInput\" style=\"padding-left:2px; border: 0px; display: none\">\n      </td>\n      <td class=\"QuillmyWordTD\" id=\""+_1a0+"wordTD\"></td>\n      <td class=\"QuillmyOptTD\" id=\""+_1a0+"optTD\" valign=\"middle\"></td>\n    </tr>\n  </tbody>\n</table>";
this.initOnce();
var that=this;
window.setTimeout(function(){
var te=new TextEngine(_1a0+"indicOutput",_1a0,_19e);
Quill.objects[_19c]=te;
that.fillLangSelection(_19d,te);
if(!Quill.objects.defaultEngine){
Quill.objects.defaultEngine=Quill.objects[_19c];
}
},200);
},initOnce:function(){
QuillUtil.setupLogging();
QuillUtil.setCharEncoding("utf-8");
wm=new WordMap();
this.initOnce=function(){
};
},fillLangSelection:function(_1a3,_1a4){
var _1a5=MochiKit.DOM.getElement(_1a3);
var lang=_1a4.lang;
var a=[];
a.push([lang,lang.charAt(0).toUpperCase()+lang.substr(1).toLowerCase()]);
for(var l in Quill.Config.supportedLanguages){
if(l!=lang){
a.push([l,l.charAt(0).toUpperCase()+l.substr(1).toLowerCase()]);
}
}
for(var i=0;i<a.length;i++){
var l=a[i][0];
if(QuillUtil.getBrowser()=="ie"){
var o=MochiKit.DOM.OPTION();
o.text=a[i][1];
o.value=l;
_1a5.add(o);
}else{
var o=MochiKit.DOM.OPTION({value:l},a[i][1]);
o.style.fontSize="12px";
_1a5.appendChild(o);
}
}
MochiKit.Signal.connect(_1a5,"onchange",function(ev){
_1a4.setLang(_1a5.value);
});
},setCharLimit:function(_1ac,_1ad){
te=Quill.objects[_1ac];
if(typeof (te)==="undefined"){
window.setTimeout("Quill.setCharLimit('"+_1ac+"',"+_1ad+")",250);
}else{
te.setCharLimit(_1ad);
}
},setText:function(_1ae,text){
te=Quill.objects[_1ae];
if(typeof (te)==="undefined"){
window.setTimeout("Quill.setText('"+_1ae+"','"+text+"')",250);
}else{
te.setText(text);
}
},getLanguageText:function(key){
return this.getObject(key).getText();
},setFocus:function(key){
this.getObject(key).setFocus();
},clearText:function(key){
this.getObject(key).clearTextArea();
},getEnglishText:function(key){
return this.getObject(key).getEnglishText(key);
},loadText:function(text,key){
this.getObject(key).prefill(text);
},save:function(key){
return this.getObject(key).getSaveData();
},load:function(data,key){
if(this.getObject(key)){
this.getObject(key).load(data);
}else{
setTimeout(function(){
Quill.load(data,key);
},200);
}
},loadImage:function(_1b9,key){
this.getObject(key).loadImage(_1b9);
},objects:{},getObject:function(key){
if(this.objects.hasOwnProperty(key)){
return this.objects[key];
}
return this.objects.defaultEngine;
}});

