File "autocomplete.min.js"
Full Path: /home/ycoalition/public_html/blog/wp-content/themes/woodmart/js/libs/autocomplete.min.js
File size: 12.39 KB
MIME-type: text/plain
Charset: utf-8
!function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):"object"==typeof exports&&"function"==typeof require?e(require("jquery")):e(jQuery)}(function(d){"use strict";var n={escapeRegExChars:function(e){return e.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g,"\\$&")},createNode:function(e){var t=document.createElement("div");return t.className=e,t.style.position="absolute",t.style.display="none",t}},o=27,s=9,i=13,a=38,l=39,r=40;function u(e,t){function n(){}var o=this,s={ajaxSettings:{},autoSelectFirst:!1,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,width:"auto",minChars:1,maxHeight:300,deferRequestBy:0,params:{},formatResult:u.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,onSearchStart:n,onSearchComplete:n,onSearchError:n,preserveInput:!1,containerClass:"autocomplete-suggestions",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:function(e,t,n){return-1!==e.value.toLowerCase().indexOf(n)},paramName:"query",transformResult:function(e){return"string"==typeof e?JSON.parse(e):e},showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1};o.element=e,o.el=d(e),o.suggestions=[],o.badQueries=[],o.selectedIndex=-1,o.currentValue=o.element.value,o.intervalId=0,o.cachedResponse={},o.onChangeInterval=null,o.onChange=null,o.isLocal=!1,o.suggestionsContainer=null,o.noSuggestionsContainer=null,o.options=d.extend({},s,t),o.classes={selected:"autocomplete-selected",suggestion:"autocomplete-suggestion"},o.hint=null,o.hintValue="",o.selection=null,o.initialize(),o.setOptions(t)}u.utils=n,(d.Autocomplete=u).formatResult=function(e,t){t="("+n.escapeRegExChars(t)+")";return e.value.replace(new RegExp(t,"gi"),"<strong>$1</strong>").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/<(\/?strong)>/g,"<$1>")},u.prototype={killerFn:null,initialize:function(){var e,t=this,n="."+t.classes.suggestion,o=t.classes.selected,s=t.options;t.element.setAttribute("autocomplete","off"),t.killerFn=function(e){0===d(e.target).closest("."+t.options.containerClass).length&&(t.killSuggestions(),t.disableKillerFn())},t.noSuggestionsContainer=d('<div class="autocomplete-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),t.suggestionsContainer=u.utils.createNode(s.containerClass),(e=d(t.suggestionsContainer)).appendTo(s.appendTo),"auto"!==s.width&&e.width(s.width),e.on("mouseover.autocomplete",n,function(){t.activate(d(this).data("index"))}),e.on("mouseout.autocomplete",function(){t.selectedIndex=-1,e.children("."+o).removeClass(o)}),e.on("click.autocomplete",n,function(){t.select(d(this).data("index"))}),t.fixPositionCapture=function(){t.visible&&t.fixPosition()},d(window).on("resize.autocomplete",t.fixPositionCapture),t.el.on("keydown.autocomplete",function(e){t.onKeyPress(e)}),t.el.on("keyup.autocomplete",function(e){t.onKeyUp(e)}),t.el.on("blur.autocomplete",function(){t.onBlur()}),t.el.on("focus.autocomplete",function(){t.onFocus()}),t.el.on("change.autocomplete",function(e){t.onKeyUp(e)}),t.el.on("input.autocomplete",function(e){t.onKeyUp(e)})},onFocus:function(){var e=this;e.fixPosition(),0===e.options.minChars&&0===e.el.val().length&&e.onValueChange()},onBlur:function(){this.enableKillerFn()},abortAjax:function(){var e=this;e.currentRequest&&(e.currentRequest.abort(),e.currentRequest=null)},setOptions:function(e){var t=this,n=t.options;d.extend(n,e),t.isLocal=Array.isArray(n.lookup),t.isLocal&&(n.lookup=t.verifySuggestionsFormat(n.lookup)),n.orientation=t.validateOrientation(n.orientation,"bottom"),d(t.suggestionsContainer).css({"max-height":n.maxHeight+"px",width:n.width+"px","z-index":n.zIndex})},clearCache:function(){this.cachedResponse={},this.badQueries=[]},clear:function(){this.clearCache(),this.currentValue="",this.suggestions=[]},disable:function(){var e=this;e.disabled=!0,clearInterval(e.onChangeInterval),e.abortAjax()},enable:function(){this.disabled=!1},fixPosition:function(){var e,t,n,o,s,i,a,l,r=this,u=d(r.suggestionsContainer),c=u.parent().get(0);c!==document.body&&!r.options.forceFixPosition||(i=r.options.orientation,e=u.outerHeight(),t=r.el.outerHeight(),n={top:(l=r.el.offset()).top,left:l.left},"auto"===i&&(a=d(window).height(),o=-(s=d(window).scrollTop())+l.top-e,s=s+a-(l.top+t+e),i=Math.max(o,s)===o?"top":"bottom"),n.top+="top"===i?-e:t,c!==document.body&&(a=u.css("opacity"),r.visible||u.css("opacity",0).show(),l=u.offsetParent().offset(),n.top-=l.top,n.left-=l.left,r.visible||u.css("opacity",a).hide()),"auto"===r.options.width&&(n.width=r.el.outerWidth()-2+"px"),u.css(n))},enableKillerFn:function(){d(document).on("click.autocomplete",this.killerFn)},disableKillerFn:function(){d(document).off("click.autocomplete",this.killerFn)},killSuggestions:function(){var e=this;e.stopKillSuggestions(),e.intervalId=window.setInterval(function(){e.visible&&(e.el.val(e.currentValue),e.hide()),e.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var e=this.el.val().length,t=this.element.selectionStart;return"number"==typeof t?t===e:!document.selection||((t=document.selection.createRange()).moveStart("character",-e),e===t.text.length)},onKeyPress:function(e){var t=this;if(t.disabled||t.visible||e.which!==r||!t.currentValue){if(!t.disabled&&t.visible){switch(e.which){case o:t.el.val(t.currentValue),t.hide();break;case l:if(t.hint&&t.options.onHint&&t.isCursorAtEnd()){t.selectHint();break}return;case s:if(t.hint&&t.options.onHint)return void t.selectHint();if(-1===t.selectedIndex)return void t.hide();if(t.select(t.selectedIndex),!1===t.options.tabDisabled)return;break;case i:if(-1===t.selectedIndex)return void t.hide();t.select(t.selectedIndex);break;case a:t.moveUp();break;case r:t.moveDown();break;default:return}e.stopImmediatePropagation(),e.preventDefault()}}else t.suggest()},onKeyUp:function(e){var t=this;if(!t.disabled){switch(e.which){case a:case r:return}clearInterval(t.onChangeInterval),t.currentValue!==t.el.val()&&(t.findBestHint(),0<t.options.deferRequestBy?t.onChangeInterval=setInterval(function(){t.onValueChange()},t.options.deferRequestBy):t.onValueChange())}},onValueChange:function(){var e=this,t=e.options,n=e.el.val(),o=e.getQuery(n);e.selection&&e.currentValue!==o&&(e.selection=null,(t.onInvalidateSelection||d.noop).call(e.element)),clearInterval(e.onChangeInterval),e.currentValue=n,e.selectedIndex=-1,t.triggerSelectOnValidInput&&e.isExactMatch(o)?e.select(0):o.length<t.minChars?e.hide():e.getSuggestions(o)},isExactMatch:function(e){var t=this.suggestions;return 1===t.length&&t[0].value.toLowerCase()===e.toLowerCase()},getQuery:function(e){var t=this.options.delimiter;return t?(t=e.split(t),null==(t=t[t.length-1])?"":"string"==typeof t?t.trim():(t+"").replace("/^[\\s\ufeff ]+|[\\s\ufeff ]+$/g","")):e},getSuggestionsLocal:function(t){var e=this.options,n=t.toLowerCase(),o=e.lookupFilter,s=parseInt(e.lookupLimit,10),e={suggestions:d.grep(e.lookup,function(e){return o(e,t,n)})};return s&&e.suggestions.length>s&&(e.suggestions=e.suggestions.slice(0,s)),e},getSuggestions:function(o){var e,t,n,s=this,i=s.options,a=i.serviceUrl;i.params[i.paramName]=o,e=i.ignoreParams?null:i.params,!1!==i.onSearchStart.call(s.element,i.params)&&("function"==typeof i.lookup?i.lookup(o,function(e){s.suggestions=e.suggestions,s.suggest(),i.onSearchComplete.call(s.element,o,e.suggestions)}):(n=s.isLocal?s.getSuggestionsLocal(o):("function"==typeof a&&(a=a.call(s.element,o)),t=a+"?"+d.param(e||{}),s.cachedResponse[t]))&&Array.isArray(n.suggestions)?(s.suggestions=n.suggestions,s.suggest(),i.onSearchComplete.call(s.element,o,n.suggestions)):s.isBadQuery(o)?i.onSearchComplete.call(s.element,o,[]):(s.abortAjax(),n={url:a,data:e,type:i.type,dataType:i.dataType},d.extend(n,i.ajaxSettings),s.currentRequest=d.ajax(n).done(function(e){s.currentRequest=null,e=i.transformResult(e,o),s.processResponse(e,o,t),i.onSearchComplete.call(s.element,o,e.suggestions)}).fail(function(e,t,n){i.onSearchError.call(s.element,o,e,t,n)})))},isBadQuery:function(e){if(!this.options.preventBadQueries)return!1;for(var t=this.badQueries,n=t.length;n--;)if(0===e.indexOf(t[n]))return!0;return!1},hide:function(){var e=this,t=d(e.suggestionsContainer);"function"==typeof e.options.onHide&&e.visible&&e.options.onHide.call(e.element,t),e.visible=!1,e.selectedIndex=-1,clearInterval(e.onChangeInterval),d(e.suggestionsContainer).hide(),e.signalHint(null)},suggest:function(){var e,t,n,o,s,i,a,l,r,u,c,g;0===this.suggestions.length?this.options.showNoSuggestionNotice?this.noSuggestions():this.hide():(t=(e=this).options,n=t.groupBy,o=t.formatResult,s=e.getQuery(e.currentValue),i=e.classes.suggestion,a=e.classes.selected,l=d(e.suggestionsContainer),r=d(e.noSuggestionsContainer),u=t.beforeRender,c="",t.triggerSelectOnValidInput&&e.isExactMatch(s)?e.select(0):(d.each(e.suggestions,function(e,t){n&&(c+=function(e){e=e.data[n];return g===e?"":'<div class="autocomplete-group"><strong>'+(g=e)+"</strong></div>"}(t)),c+='<div class="'+i+'" data-index="'+e+'">'+o(t,s)+"</div>"}),this.adjustContainerWidth(),r.detach(),l.html(c),"function"==typeof u&&u.call(e.element,l),e.fixPosition(),l.show(),t.autoSelectFirst&&(e.selectedIndex=0,l.scrollTop(0),l.children("."+i).first().addClass(a)),e.visible=!0,e.findBestHint()))},noSuggestions:function(){var e=d(this.suggestionsContainer),t=d(this.noSuggestionsContainer);this.adjustContainerWidth(),t.detach(),e.empty(),e.append(t),this.fixPosition(),e.show(),this.visible=!0},adjustContainerWidth:function(){var e=this.options,t=d(this.suggestionsContainer);"auto"===e.width&&(e=this.el.outerWidth()-2,t.width(0<e?e:300))},findBestHint:function(){var o=this.el.val().toLowerCase(),s=null;o&&(d.each(this.suggestions,function(e,t){var n=0===t.value.toLowerCase().indexOf(o);return n&&(s=t),!n}),this.signalHint(s))},signalHint:function(e){var t="",n=this;e&&(t=n.currentValue+e.value.substr(n.currentValue.length)),n.hintValue!==t&&(n.hintValue=t,n.hint=e,(this.options.onHint||d.noop)(t))},verifySuggestionsFormat:function(e){return e.length&&"string"==typeof e[0]?d.map(e,function(e){return{value:e,data:null}}):e},validateOrientation:function(e,t){return e=d.trim(e||"").toLowerCase(),e=-1===d.inArray(e,["auto","bottom","top"])?t:e},processResponse:function(e,t,n){var o=this,s=o.options;e.suggestions=o.verifySuggestionsFormat(e.suggestions),s.noCache||(o.cachedResponse[n]=e,s.preventBadQueries&&0===e.suggestions.length&&o.badQueries.push(t)),t===o.getQuery(o.currentValue)&&(o.suggestions=e.suggestions,o.suggest())},activate:function(e){var t=this,n=t.classes.selected,o=d(t.suggestionsContainer),s=o.find("."+t.classes.suggestion);return o.find("."+n).removeClass(n),t.selectedIndex=e,-1!==t.selectedIndex&&s.length>t.selectedIndex?(o=s.get(t.selectedIndex),d(o).addClass(n),o):null},selectHint:function(){var e=d.inArray(this.hint,this.suggestions);this.select(e)},select:function(e){this.hide(),this.onSelect(e)},moveUp:function(){var e=this;if(-1!==e.selectedIndex)return 0===e.selectedIndex?(d(e.suggestionsContainer).children().first().removeClass(e.classes.selected),e.selectedIndex=-1,e.el.val(e.currentValue),void e.findBestHint()):void e.adjustScroll(e.selectedIndex-1)},moveDown:function(){this.selectedIndex!==this.suggestions.length-1&&this.adjustScroll(this.selectedIndex+1)},adjustScroll:function(e){var t,n,o,s=this,i=s.activate(e);i&&(t=d(i).outerHeight(),i=i.offsetTop,o=(n=d(s.suggestionsContainer).scrollTop())+s.options.maxHeight-t,i<n?d(s.suggestionsContainer).scrollTop(i):o<i&&d(s.suggestionsContainer).scrollTop(i-s.options.maxHeight+t),s.options.preserveInput||s.el.val(s.getValue(s.suggestions[e].value)),s.signalHint(null))},onSelect:function(e){var t=this,n=t.options.onSelect,e=t.suggestions[e];t.currentValue=t.getValue(e.value),t.currentValue===t.el.val()||t.options.preserveInput||t.el.val(t.currentValue),t.signalHint(null),t.suggestions=[],t.selection=e,"function"==typeof n&&n.call(t.element,e)},getValue:function(e){var t,n=this.options.delimiter;return!n||1===(n=(t=this.currentValue).split(n)).length?e:t.substr(0,t.length-n[n.length-1].length)+e},dispose:function(){this.el.off(".autocomplete").removeData("autocomplete"),this.disableKillerFn(),d(window).off("resize.autocomplete",this.fixPositionCapture),d(this.suggestionsContainer).remove()}},d.fn.devbridgeAutocomplete=function(n,o){var s="autocomplete";return 0===arguments.length?this.first().data(s):this.each(function(){var e=d(this),t=e.data(s);"string"==typeof n?t&&"function"==typeof t[n]&&t[n](o):(t&&t.dispose&&t.dispose(),t=new u(this,n),e.data(s,t))})}});