| Current Path : /home/lejardintz/www/components/com_kunena/template/crypsis/media/js/ |
| Current File : /home/lejardintz/www/components/com_kunena/template/crypsis/media/js/atwho-min.js |
/*! jquery.atwho - v0.4.12 - 2014-06-26
* Copyright (c) 2014 chord.luo <chord.luo@gmail.com>;
* homepage: http://ichord.github.com/At.js
* Licensed MIT
*/
(function(){(function(a){if(typeof define==="function"&&define.amd){return define(["jquery"],a);}else{return a(window.jQuery);}})(function(f){var c,h,d,j,e,i,k,b,a,g=[].slice;d=(function(){function l(m){this.current_flag=null;this.controllers={};this.alias_maps={};this.$inputor=f(m);this.iframe=null;this.setIframe();this.listen();}l.prototype.setIframe=function(n){var m;if(n){this.window=n.contentWindow;this.document=n.contentDocument||this.window.document;this.iframe=n;return this;}else{this.document=this.$inputor[0].ownerDocument;this.window=this.document.defaultView||this.document.parentWindow;try{return this.iframe=this.window.frameElement;}catch(o){m=o;}}};l.prototype.controller=function(m){var q,p,n,o;if(this.alias_maps[m]){p=this.controllers[this.alias_maps[m]];}else{o=this.controllers;for(n in o){q=o[n];if(n===m){p=q;break;}}}if(p){return p;}else{return this.controllers[this.current_flag];}};l.prototype.set_context_for=function(m){this.current_flag=m;return this;};l.prototype.reg=function(n,p){var m,o;m=(o=this.controllers)[n]||(o[n]=new e(this,n));if(p.alias){this.alias_maps[p.alias]=n;}m.init(p);return this;};l.prototype.listen=function(){return this.$inputor.on("keyup.atwhoInner",(function(m){return function(n){return m.on_keyup(n);};})(this)).on("keydown.atwhoInner",(function(m){return function(n){return m.on_keydown(n);};})(this)).on("scroll.atwhoInner",(function(m){return function(o){var n;return(n=m.controller())!=null?n.view.hide(o):void 0;};})(this)).on("blur.atwhoInner",(function(m){return function(n){var o;if(o=m.controller()){return o.view.hide(n,o.get_opt("display_timeout"));}};})(this));};l.prototype.shutdown=function(){var o,m,n;n=this.controllers;for(m in n){o=n[m];o.destroy();delete this.controllers[m];}return this.$inputor.off(".atwhoInner");};l.prototype.dispatch=function(){return f.map(this.controllers,(function(m){return function(o){var n;if(n=o.get_opt("delay")){clearTimeout(m.delayedCallback);return m.delayedCallback=setTimeout(function(){if(o.look_up()){return m.set_context_for(o.at);}},n);}else{if(o.look_up()){return m.set_context_for(o.at);}}};})(this));};l.prototype.on_keyup=function(n){var m;switch(n.keyCode){case k.ESC:n.preventDefault();if((m=this.controller())!=null){m.view.hide();}break;case k.DOWN:case k.UP:case k.CTRL:f.noop();break;case k.P:case k.N:if(!n.ctrlKey){this.dispatch();}break;default:this.dispatch();}};l.prototype.on_keydown=function(o){var m,n;m=(n=this.controller())!=null?n.view:void 0;if(!(m&&m.visible())){return;}switch(o.keyCode){case k.ESC:o.preventDefault();m.hide(o);break;case k.UP:o.preventDefault();m.prev();break;case k.DOWN:o.preventDefault();m.next();break;case k.P:if(!o.ctrlKey){return;}o.preventDefault();m.prev();break;case k.N:if(!o.ctrlKey){return;}o.preventDefault();m.next();break;case k.TAB:case k.ENTER:if(!m.visible()){return;}o.preventDefault();m.choosing=true;m.choose(o);break;default:f.noop();}};return l;})();e=(function(){l.prototype.uid=function(){return(Math.random().toString(16)+"000000000").substr(2,8)+(new Date().getTime());};function l(n,m){this.app=n;this.at=m;this.$inputor=this.app.$inputor;this.id=this.$inputor[0].id||this.uid();this.setting=null;this.query=null;this.pos=0;this.cur_rect=null;this.range=null;c.append(this.$el=f("<div id='atwho-ground-"+this.id+"'></div>"));this.model=new b(this);this.view=new a(this);}l.prototype.init=function(m){this.setting=f.extend({},this.setting||f.fn.atwho["default"],m);this.view.init();return this.model.reload(this.setting.data);};l.prototype.destroy=function(){this.trigger("beforeDestroy");this.model.destroy();this.view.destroy();return this.$el.remove();};l.prototype.call_default=function(){var o,n,m;m=arguments[0],o=2<=arguments.length?g.call(arguments,1):[];try{return i[m].apply(this,o);}catch(p){n=p;return f.error(""+n+" Or maybe At.js doesn't have function "+m);}};l.prototype.trigger=function(m,o){var n,p;if(o==null){o=[];}o.push(this);n=this.get_opt("alias");p=n?""+m+"-"+n+".atwho":""+m+".atwho";return this.$inputor.trigger(p,o);};l.prototype.callbacks=function(m){return this.get_opt("callbacks")[m]||i[m];};l.prototype.get_opt=function(n,m){var o;try{return this.setting[n];}catch(p){o=p;return null;}};l.prototype.content=function(){if(this.$inputor.is("textarea, input")){return this.$inputor.val();}else{return this.$inputor.text();}};l.prototype.catch_query=function(){var m,p,n,q,r,o;p=this.content();m=this.$inputor.caret("pos");o=p.slice(0,m);q=this.callbacks("matcher").call(this,this.at,o,this.get_opt("start_with_space"));if(typeof q==="string"&&q.length<=this.get_opt("max_len",20)){r=m-q.length;n=r+q.length;this.pos=r;q={text:q,head_pos:r,end_pos:n};this.trigger("matched",[this.at,q.text]);}else{q=null;this.view.hide();}return this.query=q;};l.prototype.rect=function(){var n,m;if(!(n=this.$inputor.caret({iframe:this.app.iframe}).caret("offset",this.pos-1))){return;}if(this.$inputor.attr("contentEditable")==="true"){n=(this.cur_rect||(this.cur_rect=n))||n;}m=this.app.document.selection?0:2;return{left:n.left,top:n.top,bottom:n.top+n.height+m};};l.prototype.reset_rect=function(){if(this.$inputor.attr("contentEditable")==="true"){return this.cur_rect=null;}};l.prototype.mark_range=function(){if(this.$inputor.attr("contentEditable")==="true"){if(this.app.window.getSelection){this.range=this.app.window.getSelection().getRangeAt(0);}if(this.app.document.selection){return this.ie8_range=this.app.document.selection.createRange();}}};l.prototype.insert_content_for=function(p){var o,n,m;n=p.data("value");m=this.get_opt("insert_tpl");if(this.$inputor.is("textarea, input")||!m){return n;}o=f.extend({},p.data("item-data"),{"atwho-data-value":n,"atwho-at":this.at});return this.callbacks("tpl_eval").call(this,m,o);};l.prototype.insert=function(s,u){var w,x,p,n,t,v,r,o,m,q,y;w=this.$inputor;if(w.attr("contentEditable")==="true"){p="atwho-view-flag atwho-view-flag-"+(this.get_opt("alias")||this.at);n=""+s+"<span contenteditable='false'> <span>";t="<span contenteditable='false' class='"+p+"'>"+n+"</span>";x=f(t,this.app.document).data("atwho-data-item",u.data("item-data"));if(this.app.document.selection){x=f("<span contenteditable='true'></span>",this.app.document).html(x);}}if(w.is("textarea, input")){s=this.get_opt("space_after")?s+" ":""+s;m=w.val();q=m.slice(0,Math.max(this.query.head_pos-this.at.length,0));y=""+q+s+(m.slice(this.query.end_pos||0));w.val(y);w.caret("pos",q.length+s.length);}else{if(r=this.range){v=r.startOffset-(this.query.end_pos-this.query.head_pos)-this.at.length;r.setStart(r.endContainer,Math.max(v,0));r.setEnd(r.endContainer,r.endOffset);r.deleteContents();r.insertNode(x[0]);r.collapse(false);o=this.app.window.getSelection();o.removeAllRanges();o.addRange(r);}else{if(r=this.ie8_range){r.moveStart("character",this.query.end_pos-this.query.head_pos-this.at.length);r.pasteHTML(n);r.collapse(false);r.select();}}}if(!w.is(":focus")){w.focus();}return w.change();};l.prototype.render_view=function(n){var m;m=this.get_opt("search_key");n=this.callbacks("sorter").call(this,this.query.text,n.slice(0,1001),m);return this.view.render(n.slice(0,this.get_opt("limit")));};l.prototype.look_up=function(){var n,m;if(!(n=this.catch_query())){return;}m=function(o){if(o&&o.length>0){return this.render_view(o);}else{return this.view.hide();}};this.model.query(n.text,f.proxy(m,this));return n;};return l;})();b=(function(){function l(m){this.context=m;this.at=this.context.at;this.storage=this.context.$inputor;}l.prototype.destroy=function(){return this.storage.data(this.at,null);};l.prototype.saved=function(){return this.fetch()>0;};l.prototype.query=function(o,q){var n,m,p;n=this.fetch();m=this.context.get_opt("search_key");n=this.context.callbacks("filter").call(this.context,o,n,m)||[];p=this.context.callbacks("remote_filter");if(n.length>0||(!p&&n.length===0)){return q(n);}else{return p.call(this.context,o,q);}};l.prototype.fetch=function(){return this.storage.data(this.at)||[];};l.prototype.save=function(m){return this.storage.data(this.at,this.context.callbacks("before_save").call(this.context,m||[]));};l.prototype.load=function(m){if(!(this.saved()||!m)){return this._load(m);}};l.prototype.reload=function(m){return this._load(m);};l.prototype._load=function(m){if(typeof m==="string"){return f.ajax(m,{dataType:"json"}).done((function(n){return function(o){return n.save(o);};})(this));}else{return this.save(m);}};return l;})();a=(function(){function l(m){this.context=m;this.$el=f("<div class='atwho-view'><ul class='atwho-view-ul'></ul></div>");this.timeout_id=null;this.context.$el.append(this.$el);this.bind_event();}l.prototype.init=function(){var m;m=this.context.get_opt("alias")||this.context.at.charCodeAt(0);return this.$el.attr({id:"at-view-"+m});};l.prototype.destroy=function(){return this.$el.remove();};l.prototype.bind_event=function(){var m;m=this.$el.find("ul");return m.on("mouseenter.atwho-view","li",function(n){m.find(".cur").removeClass("cur");return f(n.currentTarget).addClass("cur");}).on("click",(function(n){return function(o){n.choose(o);return o.preventDefault();};})(this));};l.prototype.visible=function(){return this.$el.is(":visible");};l.prototype.choose=function(n){var o,m;if((o=this.$el.find(".cur")).length){m=this.context.insert_content_for(o);this.context.insert(this.context.callbacks("before_insert").call(this.context,m,o),o);this.context.trigger("inserted",[o,n]);return this.hide(n);}};l.prototype.reposition=function(m){var o,n;if(m.bottom+this.$el.height()-f(window).scrollTop()>f(window).height()){m.bottom=m.top-this.$el.height();}o={left:m.left,top:m.bottom};if((n=this.context.callbacks("before_reposition"))!=null){n.call(this.context,o);}this.$el.offset(o);return this.context.trigger("reposition",[o]);};l.prototype.next=function(){var n,m;n=this.$el.find(".cur").removeClass("cur");m=n.next();if(!m.length){m=this.$el.find("li:first");}return m.addClass("cur");};l.prototype.prev=function(){var n,m;n=this.$el.find(".cur").removeClass("cur");m=n.prev();if(!m.length){m=this.$el.find("li:last");}return m.addClass("cur");};l.prototype.show=function(){var m;if(this.choosing){this.choosing=false;return;}this.context.mark_range();if(!this.visible()){this.$el.show();this.context.trigger("shown");}if(m=this.context.rect()){return this.reposition(m);}};l.prototype.hide=function(n,m){var o;if(!this.visible()){return;}if(isNaN(m)){this.context.reset_rect();this.$el.hide();return this.context.trigger("hidden",[n]);}else{o=(function(p){return function(){return p.hide();};})(this);clearTimeout(this.timeout_id);return this.timeout_id=setTimeout(o,m);}};l.prototype.render=function(s){var t,p,q,m,o,r,n;if(!(f.isArray(s)&&s.length>0)){this.hide();return;}this.$el.find("ul").empty();p=this.$el.find("ul");o=this.context.get_opt("tpl");for(r=0,n=s.length;r<n;r++){q=s[r];q=f.extend({},q,{"atwho-at":this.context.at});m=this.context.callbacks("tpl_eval").call(this.context,o,q);t=f(this.context.callbacks("highlighter").call(this.context,m,this.context.query.text));t.data("item-data",q);p.append(t);}this.show();if(this.context.get_opt("highlight_first")){return p.find("li:first").addClass("cur");}};return l;})();k={DOWN:40,UP:38,ESC:27,TAB:9,ENTER:13,CTRL:17,P:80,N:78};i={before_save:function(p){var n,o,m,l;if(!f.isArray(p)){return p;}l=[];for(o=0,m=p.length;o<m;o++){n=p[o];if(f.isPlainObject(n)){l.push(n);}else{l.push({name:n});}}return l;},matcher:function(m,o,l){var n,p;m=m.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&");if(l){m="(?:^|\\s)"+m;}p=new RegExp(m+"([A-Za-z0-9_+-]*)$|"+m+"([^\\x00-\\xff]*)$","gi");n=p.exec(o);if(n){return n[2]||n[1];}else{return null;}},filter:function(r,q,o){var n,p,m,l;l=[];for(p=0,m=q.length;p<m;p++){n=q[p];if(~n[o].toLowerCase().indexOf(r.toLowerCase())){l.push(n);}}return l;},remote_filter:null,sorter:function(r,n,p){var o,q,m,l;if(!r){return n;}l=[];for(q=0,m=n.length;q<m;q++){o=n[q];o.atwho_order=o[p].toLowerCase().indexOf(r.toLowerCase());if(o.atwho_order>-1){l.push(o);}}return l.sort(function(t,s){return t.atwho_order-s.atwho_order;});},tpl_eval:function(m,n){var l;try{return m.replace(/\$\{([^\}]*)\}/g,function(p,q,r){return n[q];});}catch(o){l=o;return"";}},highlighter:function(l,n){var m;if(!n){return l;}m=new RegExp(">\\s*(\\w*?)("+n.replace("+","\\+")+")(\\w*)\\s*<","ig");return l.replace(m,function(q,o,r,p){return"> "+o+"<strong>"+r+"</strong>"+p+" <";});},before_insert:function(l,m){return l;}};h={load:function(l,m){var n;if(n=this.controller(l)){return n.model.load(m);}},getInsertedItemsWithIDs:function(l){var o,n,m;if(!(o=this.controller(l))){return[null,null];}if(l){l="-"+(o.get_opt("alias")||o.at);}n=[];m=f.map(this.$inputor.find("span.atwho-view-flag"+(l||"")),function(p){var q;q=f(p).data("atwho-data-item");if(n.indexOf(q.id)>-1){return;}if(q.id){n.push=q.id;}return q;});return[n,m];},getInsertedItems:function(l){return h.getInsertedItemsWithIDs.apply(this,[l])[1];},getInsertedIDs:function(l){return h.getInsertedItemsWithIDs.apply(this,[l])[0];},setIframe:function(l){return this.setIframe(l);},run:function(){return this.dispatch();},destroy:function(){this.shutdown();return this.$inputor.data("atwho",null);}};j={init:function(l){var m,n;n=(m=f(this)).data("atwho");if(!n){m.data("atwho",(n=new d(this)));}n.reg(l.at,l);return this;}};c=f("<div id='atwho-container'></div>");f.fn.atwho=function(n){var l,m;m=arguments;f("body").append(c);l=null;this.filter("textarea, input, [contenteditable=true]").each(function(){var o;if(typeof n==="object"||!n){return j.init.apply(this,m);}else{if(h[n]){if(o=f(this).data("atwho")){return l=h[n].apply(o,Array.prototype.slice.call(m,1));}}else{return f.error("Method "+n+" does not exist on jQuery.caret");}}});return l||this;};f.fn.atwho["default"]={at:void 0,alias:void 0,space_after:true,data:null,tpl:"<li data-value='${atwho-at}${name}'>${name}</li>",insert_tpl:"<span>${atwho-data-value}</span>",callbacks:i,search_key:"name",start_with_space:true,highlight_first:true,limit:5,max_len:20,display_timeout:300,delay:null};});}).call(this);