/** * 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=$(e).offset(),n=$(e).width(),r=$(e).height();else{var i=e.getContainer();typeof i!="undefined"&&(style=$(i).offset(),n=$(i).width(),r=$(i).height())}style.top=style.top+r,style.width=n,style.position="absolute",style.display="none",this.cont=$("
"),this.cont.css(style),$("body").append(this.cont)}function ContactAutocomplete(e,t){this.pattern=/@([^ \n]+)$/,this.popup=null;var n=this;$(e).unbind("keydown"),$(e).unbind("keyup"),$(e).keydown(function(e){n.popup!==null&&n.popup.onkey(e)}),$(e).keyup(function(e){cpos=$(this).getSelection(),cpos.start==cpos.end&&(match=$(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(){$(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"};$.ajax({type:"POST",url:this.url,data:t,dataType:"json",success:function(t){e.cont.html(""),t.tot>0?(e.cont.show(),$(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=$("