You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
3 lines
4.0 KiB
3 lines
4.0 KiB
/*! UIkit 2.5.0 | http://www.getuikit.com | (c) 2014 YOOtheme | MIT License */
|
|
|
|
(function(t){"function"==typeof define&&define.amd&&define("uikit-autocomplete",["uikit"],function(){return jQuery.UIkit.autocomplete||t(window,window.jQuery,window.jQuery.UIkit)}),window&&window.jQuery&&window.jQuery.UIkit&&t(window,window.jQuery,window.jQuery.UIkit)})(function(t,e,i){var n=function(t,o){var s=e(t);s.data("autocomplete")||(this.options=e.extend({},n.defaults,o),this.element=s,this.dropdown=s.find(".uk-dropdown"),this.template=s.find('script[type="text/autocomplete"]').html(),this.template=i.Utils.template(this.template||this.options.template),this.input=s.find("input:first").attr("autocomplete","off"),this.element.data("autocomplete",this),this.dropdown.length||(this.dropdown=e('<div class="uk-dropdown"></div>').appendTo(s)),this.options.flipDropdown&&this.dropdown.addClass("uk-dropdown-flip"),this.init())};return e.extend(n.prototype,{visible:!1,value:null,selected:null,init:function(){var t=this,n=!1,o=i.Utils.debounce(function(){return n?n=!1:(t.trigger(),void 0)},this.options.delay);this.input.on({keydown:function(e){if(e&&e.which&&!e.shiftKey)switch(e.which){case 13:e.preventDefault(),n=!0,t.select();break;case 38:e.preventDefault(),t.pick("prev");break;case 40:e.preventDefault(),t.pick("next");break;case 27:case 9:t.hide();break;default:}},keyup:o,blur:function(){setTimeout(function(){t.hide()},200)}}),this.dropdown.on("click",".uk-autocomplete-results > *",function(){t.select()}),this.dropdown.on("mouseover",".uk-autocomplete-results > *",function(){t.pick(e(this))})},trigger:function(){var t=this,e=this.value;return this.value=this.input.val(),this.value.length<this.options.minLength?this.hide():(this.value!=e&&t.request(),this)},pick:function(t){var e=this.dropdown.find(".uk-autocomplete-results").children(":not(."+this.options.skipClass+")"),i=!1;if("string"==typeof t||t.hasClass(this.options.skipClass)){if("next"==t||"prev"==t)if(this.selected){var n=e.index(this.selected);i="next"==t?e.eq(e.length>n+1?n+1:0):e.eq(0>n-1?e.length-1:n-1)}else i=e["next"==t?"first":"last"]()}else i=t;i&&i.length&&(this.selected=i,e.removeClass(this.options.hoverClass),this.selected.addClass(this.options.hoverClass))},select:function(){if(this.selected){var t=this.selected.data();this.element.trigger("autocomplete-select",[t,this]),t.value&&this.input.val(t.value),this.hide()}},show:function(){return this.visible?void 0:(this.visible=!0,this.element.addClass("uk-open"),this)},hide:function(){return this.visible?(this.visible=!1,this.element.removeClass("uk-open"),this):void 0},request:function(){var t=this,i=function(e){e&&t.render(e),t.element.removeClass(t.options.loadingClass)};if(this.element.addClass(this.options.loadingClass),this.options.source){var n=this.options.source;switch(typeof this.options.source){case"function":this.options.source.apply(this,[i]);break;case"object":if(n.length){var o=[];n.forEach(function(e){e.value&&-1!=e.value.toLowerCase().indexOf(t.value.toLowerCase())&&o.push(e)}),i(o)}break;case"string":var s={};s[this.options.param]=this.value,e.ajax({url:this.options.source,data:s,type:this.options.method,dataType:"json",complete:function(t){i(t.responseJSON||[])}});break;default:i(null)}}else this.element.removeClass(t.options.loadingClass)},render:function(t){return this.dropdown.empty(),this.selected=!1,this.options.renderer?this.options.renderer.apply(this,[t]):t&&t.length&&(this.dropdown.append(this.template({items:t})),this.show()),this}}),n.defaults={minLength:3,param:"search",method:"post",delay:300,loadingClass:"uk-loading",flipDropdown:!1,skipClass:"uk-skip",hoverClass:"uk-active",source:null,renderer:null,template:'<ul class="uk-nav uk-nav-autocomplete uk-autocomplete-results">{{~items}}<li data-value="{{$item.value}}"><a>{{$item.value}}</a></li>{{/items}}</ul>'},i.autocomplete=n,e(document).on("focus.autocomplete.uikit","[data-uk-autocomplete]",function(){var t=e(this);t.data("autocomplete")||new n(t,i.Utils.options(t.attr("data-uk-autocomplete")))}),n});
|