PageRenderTime 78ms CodeModel.GetById 50ms app.highlight 13ms RepoModel.GetById 9ms app.codeStats 0ms

/libraries/bootstrap/js/bootstrap-typeahead-ajax.min.js

https://bitbucket.org/organicdevelopment/com_bootstrap
JavaScript | 1 lines | 1 code | 0 blank | 0 comment | 0 complexity | 1dd1a0522865bdbeab0961b307b8457e MD5 | raw file
1!function(e){e(function(){e('[data-provide="typeahead"]').each(function(){var t=e(this);var n="";if(t.data("request-url")){t.data("source",function(n){var r=this;r.data=[];if(r.request)r.request.abort();var i=r.options.requestUrl;var s=r.options.requestType;var o=r.options.requestVar;var u={};u[o]=n;if(r.options.requestText)r.process([r.options.requestText]);if(n)r.clearButton.show();else r.clearButton.hide();if(r.timeout)clearTimeout(r.timeout);r.timeout=setTimeout(function(){r.request=e.ajax({url:i,dataType:"json",type:s,data:u,success:function(t){if(r.options.requestIcon){e(r.options.requestIcon).hide()}r.$element.removeClass("requesting");if(r.options.responsePath){var n=r.options.responsePath.split(".");var i=t;e.each(n,function(){if(typeof t[this]=="undefined")return;i=t[this]});t=i}if(r.options.responseProperty){var s=[];var n=r.options.responseProperty.split(".");e.each(t,function(){var t=this;e.each(n,function(e){if(typeof t[this]=="undefined")return;if(e==n.length-1)r.data[t[this]]=t;t=t[this]});s.push(t)});t=s}r.process(t);r.request=null}})},300);t.trigger("typeahead-request",[n]);if(r.options.requestIcon){e(r.options.requestIcon).show()}r.$element.addClass("requesting")});t.data("sorter",function(e){return e});t.data("matcher",function(e){return true});t.data("updater",function(n){if(this.request){this.request.abort();return""}var i=this.data[n]?this.data[n]:null;t.trigger("typeahead-select",[i]);if(r.options.responseTarget&&r.options.responseTargetProperty){var s=r.options.responseTargetProperty.split(".");e.each(s,function(e){if(typeof i[this]=="undefined")return;i=i[this]});e(r.options.responseTarget).val(i?i[s]:"")}return n!=this.options.requestText?n:""});t.typeahead(t.data());var r=t.data("typeahead");var i=e.extend({requestUrl:"",requestType:"post",requestVar:"q",requestText:"Loading...",requestClear:"icon-remove-sign",responseProperty:"",responsePath:"",responseTarget:"",responseTargetProperty:"",submitSelect:false},r.options);r.options=i;if(i.requestClear){r.wrapper=e("<span />",{"class":"typeahead-wrap",style:"position: relative; display: inline-block"});r.$element.css("margin-top","0");r.$element.css("margin-bottom","0");r.clearButton=i.requestClear.match(/^(\.|#)/)?e(i.requestClear):e("<span />",{"class":i.requestClear});r.clearButton.css("position","absolute");r.clearButton.css("top","50%");r.clearButton.css("right","0");r.clearButton.css("margin-top",r.clearButton.outerHeight()/-2);r.clearButton.css("margin-right",r.clearButton.outerWidth()/2);r.clearButton.on("click",function(){r.clear()});t.wrap(r.wrapper).after(r.clearButton.hide())}r.clear=function(){r.$element.val("");r.clearButton.hide();if(r.request)r.request.abort()};t.on("blur",function(){n=e(this).val();r.clear()});t.on("focus",function(){n="";if(e(this).val())r.clearButton.show()});t.on("keypress",function(n){if(n.which===13&&r.shown===false){var i=e(r.$menu).find("li").eq(0).attr("data-value");var s={};switch(i){case r.requestText:case undefined:case"undefined":s[r.options.requestVar]=e(this).val();break;default:s[r.options.requestVar]=i;break}if(r.timeout)clearTimeout(r.timeout);n.preventDefault();t.trigger("typeahead-select",[s])}});if(r.$element.parent("span").siblings("button").length>0){r.$element.parent("span").siblings("button").click({em:t},function(t){if(r.timeout)clearTimeout(r.timeout);t.preventDefault();var i={};i[r.options.requestVar]=n;e(t.data.em).val(n).trigger("typeahead-select",[i])})}if(r.options.submitSelect){t.on("typeahead-select",function(){var e=this;setTimeout(function(){if(t.val()){e.form.submit()}},50)})}}})})}(window.jQuery)