PageSourceSearch

https://bodo.su/wa-apps/shop/plugins/searchautocomplete/js/jquery.autocomplete.min.js?1.8.0

js bodo.su collected 2026-09-24 12:09:03 UTC 10,653 bytes, 21 lines download raw bytes

1(function(c){"function"===typeof define&&define.amd?define(["jquery"],c):c(jQuery)})(function(c){function h(a,b){var e=function(){},e={autoSelectFirst:!1,appendTo:"body",serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:h.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,onSearchStart:e,onSearchComplete:e,containerClass:"autocomplete-suggestions",tabDisabled:!1,dataType:"text",currentRequest:null,lookupFilter:function(a,
2b,c){return-1!==a.value.toLowerCase().indexOf(c)},paramName:"query",transformResult:function(a){return"string"===typeof a?c.parseJSON(a):a}};this.element=a;this.el=c(a);this.suggestions=[];this.badQueries=[];this.selectedIndex=-1;this.currentValue=this.element.value;this.intervalId=0;this.cachedResponse=[];this.onChange=this.onChangeInterval=null;this.isLocal=!1;this.suggestionsContainer=null;this.options=c.extend({},e,b);this.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"};
3this.hint=null;this.hintValue="";this.selection=null;this.initialize();this.setOptions(b)}var l=function(){return{escapeRegExChars:function(a){return a.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},createNode:function(a){var b=document.createElement("div");b.innerHTML=a;return b.firstChild}}}();h.utils=l;c.SearchAutocomplete=h;h.formatResult=function(a,b){var c="("+l.escapeRegExChars(b)+")";return a.value.replace(new RegExp(c,"gi"),"<strong>$1</strong>")};h.prototype={killerFn:null,initialize:function(){var a=
4this,b="."+a.classes.suggestion,e=a.classes.selected,d=a.options,f;a.element.setAttribute("autocomplete","off");a.killerFn=function(b){0===c(b.target).closest("."+a.options.containerClass).length&&(a.killSuggestions(),a.disableKillerFn())};a.suggestionsContainer=h.utils.createNode('<div class="'+d.containerClass+'" style="position: absolute; display: none;"><span></span></div>');f=c(a.suggestionsContainer);f.appendTo(d.appendTo);"auto"!==d.width&&f.width(d.width);f.on("mouseover.autocomplete",b,function(){a.activate(c(this).data("index"))});
5f.on("mouseout.autocomplete",function(){a.selectedIndex=-1;f.children("."+e).removeClass(e)});f.on("click.autocomplete",b,function(){a.select(c(this).data("index"))});a.fixPosition();a.fixPositionCapture=function(){a.visible&&a.fixPosition()};c(window).on("resize",a.fixPositionCapture);a.el.on("keydown.autocomplete",function(b){a.onKeyPress(b);a.fixPosition()});a.el.on("keyup.autocomplete",function(b){a.onKeyUp(b)});a.el.on("blur.autocomplete",function(){a.onBlur()});a.el.on("focus.autocomplete",
6function(){a.fixPosition()});a.el.on("change.autocomplete",function(b){a.onKeyUp(b)})},onBlur:function(){this.enableKillerFn()},setOptions:function(a){var b=this.options;c.extend(b,a);if(this.isLocal=c.isArray(b.lookup))b.lookup=this.verifySuggestionsFormat(b.lookup);c(this.suggestionsContainer).css({"max-height":b.maxHeight+"px",width:b.width+"px","z-index":b.zIndex})},clearCache:function(){this.cachedResponse=[];this.badQueries=[]},clear:function(){this.clearCache();this.currentValue="";this.suggestions=
7[]},disable:function(){this.disabled=!0},enable:function(){this.disabled=!1},fixPosition:function(){var a;"body"===this.options.appendTo&&(a=this.el.offset(),c(this.suggestionsContainer).css({top:a.top+this.el.outerHeight()+"px",left:a.left+"px"}))},enableKillerFn:function(){c(document).on("click.autocomplete",this.killerFn)},disableKillerFn:function(){c(document).off("click.autocomplete",this.killerFn)},killSuggestions:function(){var a=this;a.stopKillSuggestions();a.intervalId=window.setInterval(function(){a.hide();
8a.stopKillSuggestions()},300)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var a=this.el.val().length,b=this.element.selectionStart;return"number"===typeof b?b===a:document.selection?(b=document.selection.createRange(),b.moveStart("character",-a),a===b.text.length):!0},onKeyPress:function(a){if(!this.disabled&&!this.visible&&40===a.which&&this.currentValue)this.suggest();else if(!this.disabled&&this.visible){switch(a.which){case 27:this.el.val(this.currentValue);
9this.hide();break;case 39:if(this.hint&&this.options.onHint&&this.isCursorAtEnd()){this.selectHint();break}return;case 9:if(this.hint&&this.options.onHint){this.selectHint();return}case 13:if(-1===this.selectedIndex){this.hide();return}this.select(this.selectedIndex);if(9===a.which&&!1===this.options.tabDisabled)return;break;case 38:this.moveUp();break;case 40:this.moveDown();break;default:return}a.stopImmediatePropagation();a.preventDefault()}},onKeyUp:function(a){var b=this;if(!b.disabled){switch(a.which){case 38:case 40:return}clearInterval(b.onChangeInterval);
10if(b.currentValue!==b.el.val())if(b.findBestHint(),0<b.options.deferRequestBy)b.onChangeInterval=setInterval(function(){b.onValueChange()},b.options.deferRequestBy);else b.onValueChange()}},onValueChange:function(){var a;this.selection&&(this.selection=null,(this.options.onInvalidateSelection||
10c.noop)());clearInterval(this.onChangeInterval);this.currentValue=this.el.val();a=this.getQuery(this.currentValue);this.selectedIndex=-1;a.length<this.options.minChars?this.hide():this.getSuggestions(a)},getQuery:function(a){var b=
11this.options.delimiter;if(!b)return c.trim(a);a=a.split(b);return c.trim(a[a.length-1])},getSuggestionsLocal:function(a){var b=a.toLowerCase(),e=this.options.lookupFilter;return{suggestions:c.grep(this.options.lookup,function(c){return e(c,a,b)})}},getSuggestions:function(a){var b,e=this,d=e.options,f=d.serviceUrl;(b=e.isLocal?e.getSuggestionsLocal(a):e.cachedResponse[a])&&c.isArray(b.suggestions)?(e.suggestions=b.suggestions,e.suggest()):e.isBadQuery(a)||(d.params[d.paramName]=a,!1!==d.onSearchStart.call(e.element,
12d.params)&&(c.isFunction(d.serviceUrl)&&(f=d.serviceUrl.call(e.element,a)),null!=this.currentRequest&&this.currentRequest.abort(),this.currentRequest=c.ajax({url:f,data:d.ignoreParams?null:d.params,type:d.type,dataType:d.dataType}).done(function(b){e.processResponse(b,a);d.onSearchComplete.call(e.element,a)})))},isBadQuery:function(a){for(var b=this.badQueries,c=b.length;c--;)if(0===a.indexOf(b[c]))return!0;return!1},hide:function(){this.visible=!1;this.selectedIndex=-1;c(this.suggestionsContainer).hide();
13this.signalHint(null)},suggest:function(){if(0===this.suggestions.length)this.hide();else{var a=this.options.formatResult,b=this.getQuery(this.currentValue),e=this.classes.suggestion,d=this.classes.selected,f=c(this.suggestionsContainer),g="",k;c.each(this.suggestions,function(c,d){g+='<div class="'+e+'" data-index="'+c+'">'+a(d,b)+"</div>"});"auto"===this.options.width&&(k=this.el.outerWidth()-2,f.width(0<k?k:300));f.html(g).show();this.visible=!0;this.options.autoSelectFirst&&(this.selectedIndex=
140,f.children().first().addClass(d));this.findBestHint()}},findBestHint:function(){var a=this.el.val().toLowerCase(),b=null;a&&(c.each(this.suggestions,function(c,d){var f=0===d.value.toLowerCase().indexOf(a);f&&(b=d);return!f}),this.signalHint(b))},signalHint:function(a){var b="";a&&(b=this.currentValue+a.value.substr(this.currentValue.length));this.hintValue!==b&&(this.hintValue=b,this.hint=a,(this.options.onHint||c.noop)(b))},verifySuggestionsFormat:function(a){return a.length&&"string"===typeof a[0]?
15c.map(a,function(a){return{value:a,data:null}}):a},processResponse:function(a,b){var c=this.options,d=c.transformResult(a,b);d.suggestions=this.verifySuggestionsFormat(d.suggestions);c.noCache||(this.cachedResponse[d[c.paramName]]=d,0===d.suggestions.length&&this.badQueries.push(d[c.paramName]));b===this.getQuery(this.currentValue)&&(this.suggestions=d.suggestions,this.suggest())},activate:function(a){var b=this.classes.selected,e=c(this.suggestionsContainer),d=e.children();e.children("."+b).removeClass(b);
16this.selectedIndex=a;return-1!==this.selectedIndex&&d.length>this.selectedIndex?(a=d.get(this.selectedIndex),c(a).addClass(b),a):null},selectHint:function(){var a=c.inArray(this.hint,this.suggestions);this.select(a)},select:function(a){this.hide();this.onSelect(a)},moveUp:function(){-1!==this.selectedIndex&&(0===this.selectedIndex?(c(this.suggestionsContainer).children().first().removeClass(this.classes.selected),this.selectedIndex=-1,this.el.val(this.currentValue),this.findBestHint()):this.adjustScroll(this.selectedIndex-
171))},moveDown:function(){this.selectedIndex!==this.suggestions.length-1&&this.adjustScroll(this.selectedIndex+1)},adjustScroll:function(a){var b=this.activate(a),e,d;b&&(b=b.offsetTop,e=c(this.suggestionsContainer).scrollTop(),d=e+this.options.maxHeight-25,b<e?c(this.suggestionsContainer).scrollTop(b):b>d&&c(this.suggestionsContainer).scrollTop(b-this.options.maxHeight+25),this.el.val(this.getValue(this.suggestions[a].value)),this.signalHint(null))},onSelect:function(a){var b=this.options.onSelect;
18a=this.suggestions[a];this.currentValue=this.getValue(a.value);this.el.val(this.currentValue);this.signalHint(null);this.suggestions=[];this.selection=a;c.isFunction(b)&&b.call(this.element,a)},getValue:function(a){var b=this.options.delimiter,c;if(!b)return a;c=this.currentValue;b=c.split(b);return 1===b.length?a:c.substr(0,c.length-b[b.length-1].length)+a},dispose:function(){this.el.off(".autocomplete").removeData("autocomplete");this.disableKillerFn();c(window).off("resize",this.fixPositionCapture);
19c(this.suggestionsContainer).remove()}};c.fn.searchautocomplete=c.fn.autocomplete=function(a,b){function e(a,b){if(3==a.nodeType){b=b.split(" ");b=jQuery.grep(b,function(a,b){return""!=a});b=jQuery.map(b,function(a,b){return a.replace(/[-[\]{}()*+?.,\\^$|#\s]/g,"\\$&")});if(0==b.length)return this;var c=new RegExp("("+b.join("|")+")","ig"),d=jQuery("<div></div>").text(a.data).html();jQuery(a).replaceWith(d.replace(c,'<span class="highlight">$1</span>'))}else if(1==a.nodeType&&a.childNodes&&!/(script|style)/i.test(a.tagName)&&
20!/(price|highlight)/i.test(a.className))for(c=0;c<a.childNodes.length;c++)e(a.childNodes[c],b)}if(0===arguments.length)return this.first().data("searchautocomplete");a=c.extend({maxHeight:700,deferRequestBy:150,formatResult:function(a,b){var d=c("<div></div>").append(a.html).get(0);e(d,b);return c(d).html()},onSearchStart:function(){c(this).addClass("autocomplete-loading")},onSearchComplete:function(){c(this).removeClass("autocomplete-loading")},onSelect:function(a){location.href=a.url}},a);var d=
21!a.width;return this.each(function(){var e=c(this),g=e.data("searchautocomplete");if("string"===typeof a){if(g&&"function"===typeof g[a])g[a](b)}else g&&g.dispose&&g.dispose(),d&&(a.width=Math.max(c(this).width(),250)),g=new h(this,a),e.data("searchautocomplete",g)})}});

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.