X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=js%2Ffk.autocomplete.min.js;h=aee31b25c08e4e480f9a017027a70878f871bf1a;hb=cc210bae3de704eaaef608e9083452fb982fff4a;hp=b5d44715f143e7f909c596300441e302add0c289;hpb=52df14313427d52995a5ae507d45d13a9460fef0;p=friendica.git diff --git a/js/fk.autocomplete.min.js b/js/fk.autocomplete.min.js index b5d44715f1..aee31b25c0 100644 --- a/js/fk.autocomplete.min.js +++ b/js/fk.autocomplete.min.js @@ -1,5 +1 @@ -/** - * 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=$("
"+e+"
");i.click(function(e){t=$(this).attr("title").replace(new RegExp(" - .*"),""),typeof r.element.container=="undefined"?(el=$(r.element),sel=el.getSelection(),sel.start=sel.start-r.searchText.length,el.setSelection(sel.start,sel.end).replaceSelectedText(t+" ").collapseSelection(!1),r.close()):(txt=tinyMCE.activeEditor.getContent(),newtxt=txt.replace(r.searchText,t+" "),tinyMCE.activeEditor.setContent(newtxt),tinyMCE.activeEditor.focus(),r.close())}),$(this.cont).append(i)},ACPopup.prototype.onkey=function(e){e.keyCode=="13"&&(this.idsel>-1?(this.cont.children()[this.idsel].click(),e.preventDefault()):this.close()),e.keyCode=="38"&&(cmax=this.cont.children().size()-1,this.idsel--,this.idsel<0&&(this.idsel=cmax),e.preventDefault());if(e.keyCode=="40"||e.keyCode=="9")cmax=this.cont.children().size()-1,this.idsel++,this.idsel>cmax&&(this.idsel=0),e.preventDefault();if(e.keyCode=="38"||e.keyCode=="40"||e.keyCode=="9")this.cont.children().removeClass("selected"),$(this.cont.children()[this.idsel]).addClass("selected");e.keyCode=="27"&&this.close()},function(e){e.fn.contact_autocomplete=function(e){this.each(function(){new ContactAutocomplete(this,e)})}}(jQuery); \ No newline at end of file +function ACPopup(elm,backend_url){this.idsel=-1;this.element=elm;this.searchText="";this.ready=true;this.kp_timer=false;this.url=backend_url;var w=530;var h=130;if(typeof elm.editorId=="undefined"){style=$(elm).offset();w=$(elm).width();h=$(elm).height()}else{var container=elm.getContainer();if(typeof container!="undefined"){style=$(container).offset();w=$(container).width();h=$(container).height()}}style.top=style.top+h;style.width=w;style.position="absolute";style.display="none";this.cont=$("
");this.cont.css(style);$("body").append(this.cont)}ACPopup.prototype.close=function(){$(this.cont).remove();this.ready=false};ACPopup.prototype.search=function(text){var that=this;this.searchText=text;if(this.kp_timer)clearTimeout(this.kp_timer);this.kp_timer=setTimeout(function(){that._search()},500)};ACPopup.prototype._search=function(){console.log("_search");var that=this;var postdata={start:0,count:100,search:this.searchText,type:"c"};$.ajax({type:"POST",url:this.url,data:postdata,dataType:"json",success:function(data){that.cont.html("");if(data.tot>0){that.cont.show();$(data.items).each(function(){html="{1} ({2})".format(this.photo,this.name,this.nick);that.add(html,this.nick.replace(" ","")+"+"+this.id+" - "+this.link)})}else{that.cont.hide()}}})};ACPopup.prototype.add=function(label,value){var that=this;var elm=$("
"+label+"
");elm.click(function(e){t=$(this).attr("title").replace(new RegExp(" - .*"),"");if(typeof that.element.container==="undefined"){el=$(that.element);sel=el.getSelection();sel.start=sel.start-that.searchText.length;el.setSelection(sel.start,sel.end).replaceSelectedText(t+" ").collapseSelection(false);that.close()}else{txt=tinyMCE.activeEditor.getContent();newtxt=txt.replace("@"+that.searchText,"@"+t+" ");tinyMCE.activeEditor.setContent(newtxt);tinyMCE.activeEditor.focus();that.close()}});$(this.cont).append(elm)};ACPopup.prototype.onkey=function(event){if(event.keyCode=="13"){if(this.idsel>-1){this.cont.children()[this.idsel].click();event.preventDefault()}else this.close()}if(event.keyCode=="38"){cmax=this.cont.children().size()-1;this.idsel--;if(this.idsel<0)this.idsel=cmax;event.preventDefault()}if(event.keyCode=="40"||event.keyCode=="9"){cmax=this.cont.children().size()-1;this.idsel++;if(this.idsel>cmax)this.idsel=0;event.preventDefault()}if(event.keyCode=="38"||event.keyCode=="40"||event.keyCode=="9"){this.cont.children().removeClass("selected");$(this.cont.children()[this.idsel]).addClass("selected")}if(event.keyCode=="27"){this.close()}};function ContactAutocomplete(element,backend_url){this.pattern=/@([^ \n]+)$/;this.popup=null;var that=this;$(element).unbind("keydown");$(element).unbind("keyup");$(element).keydown(function(event){if(that.popup!==null)that.popup.onkey(event)});$(element).keyup(function(event){cpos=$(this).getSelection();if(cpos.start==cpos.end){match=$(this).val().substring(0,cpos.start).match(that.pattern);if(match!==null){if(that.popup===null){that.popup=new ACPopup(this,backend_url)}if(that.popup.ready&&match[1]!==that.popup.searchText)that.popup.search(match[1]);if(!that.popup.ready)that.popup=null}else{if(that.popup!==null){that.popup.close();that.popup=null}}}})}(function($){$.fn.contact_autocomplete=function(backend_url){this.each(function(){new ContactAutocomplete(this,backend_url)})}})(jQuery); \ No newline at end of file