var itkMiniAutoCompleteModul={ file: "miniautocomplete.js", require: [ ] } function ItkMiniAutoComplete(inputField,url,handler,ajaxhandler,opts) { if (!opts) opts={}; this.multiple=false; if (typeof(inputField)=="object" && inputField.length>0) { this.inputField=$A2(inputField); this.multiple=true; } else this.inputField=[$2(inputField)]; this.handler=handler; this.url=url; this.cursorpos=-1; this.lastValue=""; //letzter Inhalt des Eingabefeldes this.length=0; this.divlist=[]; this.hightlight=-1; this.ajaxhandler=ajaxhandler; this.ajaxdonehandler=opts.ajaxdonehandler; this.selectFirst=itkBool(opts.selectFirst,false); this.minZeichen=itkInt(opts.minZeichen,2); this.minZeichenEnter=itkInt(opts.minZeichenEnter,opts.minZeichen); this.emptyMessage=itkDefault(opts.emptyMessage,null); this.minZeichenMessage=itkDefault(opts.minZeichenMessage,null); this.ladeMessage=itkDefault(opts.ladeMessage,"Liste wird geladen"); this.sendOnEnter=itkBool(opts.sendOnEnter,false); this.speedFaktor=itkInt(opts.speedFaktor,2); this.zIndex=itkInt(opts.zIndex,null); this.hasFocus=false; this.copyFields=itkBool(opts.copyFields,false); // Feld wird aus ret[2][0] kopiert. this.clearOnBlur=itkBool(opts.clearOnBlur,false); this.allowEmpty=itkBool(opts.allowEmpty,false); this.clearOnFocus=itkBool(opts.clearOnFocus,false); this.ignoreEnter=itkBool(opts.ignoreEnter,false); this.currentData=null; // ergebnis des letzten requests this.getValue=function() { if (!this.multiple) return this.inputField[0].value; var ret=[]; for (var i=0;i10) this.speed.list.shift(); var sum=0; for (var i=0;i=this.length) this.cursorpos=this.length-1; } else if (e.keyCode==38) { // up if (this.cursorpos==-1) this.cursorpos=this.length-1; else if (this.cursorpos>0) this.cursorpos--; if (this.cursorpos<0) this.cursorpos=-1; } if (this.cursorpos>=0 && this.cursorpos<=this.length-1) { if (this.highlight>=0 && this.highlight<=this.length-1) itkRemoveClassName(this.divlist[this.highlight],"highlight"); itkAddClassName(this.divlist[this.cursorpos],"highlight"); this.highlight=this.cursorpos; } } else if (e && this.output && e.keyCode==27) { // esc itkStopEvent(e); itkHide(this.output); this.cursorpos=-1; } else if (e && e.keyCode==13 && this.running && (this.selectFirst || this.sendOnEnter)) { itkStopEvent(e); return false; } else if (e && this.output && itkVisible(this.output) && ((e.keyCode==13 && !this.ignoreEnter) || e.keyCode==9)) { if (this.cursorpos==-1) { itkHide(this.output); if (!e.noClear) this.cancelBlur(); } else this.select(this.divlist[this.cursorpos]); } else { var avg=this.calcSpeed() || 500; if (avg>1000) avg=1000; if (e.keyCode==13 && this.sendOnEnter) { itkStopEvent(e); this.sendRequest(true); return false; } else this.timer=window.setTimeout(this.sendRequest.itkBind(this,false),avg*this.speedFaktor); if ((e=="change" || e && e.keyCode==13 && !this.ignoreEnter) && this.running) { itkStopEvent(e); return true; } if (e && ((e.keyCode==13 && !this.ignoreEnter) || e.keyCode==9)) { if (!e.noClear) this.cancelBlur(); } } return true; } this.select=function(div) { itkHide(this.output); this.cursorpos=-1; this.lastValue=div.itkData[0]; if (this.multiple || this.copyFields) { for (var i=0;i(new Date().getTime()-30*1000)) { this.waiting=true; return; } this.running=false; this.waiting=false; this.timer=null; var val=this.joinValue(); if (val!=this.lastValue) { for (var i=0;i=minZeichen+n-1) { this.print(this.ladeMessage); this.running=new Date().getTime(); this.lastValue=val; if (this.output && !this.currentData.printing) itkHide(this.output); var data=this.getValue(); if (this.ajaxhandler) this.ajaxhandler(data,this.doneSuche.itkBind(this)); else ajaxRequest(this.url,{query:data},this.doneSuche.itkBind(this)); } if (val.length0) { if (this.joinValue()==this.lastValue) { itkShow(this.output); if (this.selectFirst && this.cursorpos==-1 && !opts.noKeyDown) { this.keyDown({keyCode:40,noClear:true,noShow:true}); } } else this.sendRequest(false); } else { this.sendRequest(!itkDefined(this.output)); } } this.doneSuche=function(ret) { if (!ret) { this.currentData=null; if (this.output) itkHide(this.output); return; } if (ret.printing && this.currentData && !this.currentData.printing) this.prePrintData=this.currentData; this.currentData=ret; if (!ret.printing) { this.printing=false; this.running=false; this.prePrintData=null; if (this.waiting) { this.waiting=false; this.sendRequest(false); } else if (this.ajaxdonehandler) this.ajaxdonehandler(ret); } this.cursorpos=-1; if (!this.output) { this.output=document.createElement("DIV"); this.output.style.position="absolute"; this.output.style.left="-1000px"; this.output.style.top="-10000px"; itkHide(this.output); this.output.className="miniautocomplete_out"; this.output.style.overflow="auto"; if( itkDefined(this.zIndex) ) this.output.style.zIndex = this.zIndex; document.body.appendChild(this.output); } else { itkHide(this.output); } if (ret.list && ret.list.length>0) { var val=this.joinValue(); if (!ret.printing && (val!=this.lastValue || itkDefined(ret.search) && val!=ret.search)) { itkHide(this.output); } else { this.output.innerHTML=""; this.length=0; this.divlist=[]; for (var i=0;ipage.y+page.height) { y=inpos.y-outpos.height-2; if (ypage.x+page.width) { x=inpos.x+inpos.width-outpos.width-2; if (x