/** * Friendica people autocomplete * * require jQuery, jquery.textareas */function ACPopup(e,t){this.idsel=-1,this.element=e,this.searchText="",this.ready=!0,this.kp_timer=!1,this.url=t;var n=530,r=130;if(typeof e.editorId=="undefined")style=$j(e).offset(),n=$j(e).width(),r=$j(e).height();else{var i=e.getContainer();typeof i!="undefined"&&(style=$j(i).offset(),n=$j(i).width(),r=$j(i).height())}style.top=style.top+r,style.width=n,style.position="absolute",style.display="none",this.cont=$j("
"),this.cont.css(style),$j("body").append(this.cont)}function ContactAutocomplete(e,t){this.pattern=/@([^ \n]+)$/,this.popup=null;var n=this;$j(e).unbind("keydown"),$j(e).unbind("keyup"),$j(e).keydown(function(e){n.popup!==null&&n.popup.onkey(e)}),$j(e).keyup(function(e){cpos=$j(this).getSelection(),cpos.start==cpos.end&&(match=$j(this).val().substring(0,cpos.start).match(n.pattern),match!==null?(n.popup===null&&(n.popup=new ACPopup(this,t)),n.popup.ready&&match[1]!==n.popup.searchText&&n.popup.search(match[1]),n.popup.ready||(n.popup=null)):n.popup!==null&&(n.popup.close(),n.popup=null))})}ACPopup.prototype.close=function(){$j(this.cont).remove(),this.ready=!1},ACPopup.prototype.search=function(e){var t=this;this.searchText=e,this.kp_timer&&clearTimeout(this.kp_timer),this.kp_timer=setTimeout(function(){t._search()},500)},ACPopup.prototype._search=function(){console.log("_search");var e=this,t={start:0,count:100,search:this.searchText,type:"c"};$j.ajax({type:"POST",url:this.url,data:t,dataType:"json",success:function(t){e.cont.html(""),t.tot>0?(e.cont.show(),$j(t.items).each(function(){html="{1} ({2})".format(this.photo,this.name,this.nick),e.add(html,this.nick.replace(" ","")+"+"+this.id+" - "+this.link)})):e.cont.hide()}})},ACPopup.prototype.add=function(e,n){var r=this,i=$j("