Ajax Search for WooCommerce - Version 1.0.1

Version Description

Download this release

Release Info

Developer damian-gora
Plugin Icon 128x128 Ajax Search for WooCommerce
Version 1.0.1
Comparing to
See all releases

Code changes from version 1.0 to 1.0.1

ajax-search-for-woocommerce.php CHANGED
@@ -4,7 +4,7 @@
4
  * Plugin Name: Ajax Search for WooCommerce
5
  * Plugin URI: https://wordpress.org/plugins/ajax-search-for-woocommerce/
6
  * Description: The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
7
- * Version: 1.0
8
  * Author: Damian Góra
9
  * Author URI: http://damiangora.com
10
  * Text Domain: ajax-search-for-woocommerce
@@ -58,7 +58,7 @@ if ( !class_exists( 'DGWT_WC_Ajax_Search' ) ) {
58
  */
59
  private function constants() {
60
 
61
- $this->define( 'DGWT_WCAS_VERSION', '1.0' );
62
  $this->define( 'DGWT_WCAS_NAME', 'Ajax Search for WooCommerce' );
63
  $this->define( 'DGWT_WCAS_FILE', __FILE__ );
64
  $this->define( 'DGWT_WCAS_DIR', plugin_dir_path( __FILE__ ) );
4
  * Plugin Name: Ajax Search for WooCommerce
5
  * Plugin URI: https://wordpress.org/plugins/ajax-search-for-woocommerce/
6
  * Description: The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
7
+ * Version: 1.0.1
8
  * Author: Damian Góra
9
  * Author URI: http://damiangora.com
10
  * Text Domain: ajax-search-for-woocommerce
58
  */
59
  private function constants() {
60
 
61
+ $this->define( 'DGWT_WCAS_VERSION', '1.0.1' );
62
  $this->define( 'DGWT_WCAS_NAME', 'Ajax Search for WooCommerce' );
63
  $this->define( 'DGWT_WCAS_FILE', __FILE__ );
64
  $this->define( 'DGWT_WCAS_DIR', plugin_dir_path( __FILE__ ) );
assets/css/style.css CHANGED
@@ -503,12 +503,15 @@
503
  max-width: 200px;
504
  }
505
 
506
- input[type="search"].dgwt-wcas-search-input, input[type="text"].dgwt-wcas-search-input {
 
507
  -webkit-transition: none;
508
  -moz-transition: none;
509
  -ms-transition: none;
510
  -o-transition: none;
511
  transition: none;
 
 
512
  }
513
 
514
  .dgwt-wcas-pd-desc {
@@ -584,7 +587,7 @@ input[type="submit"].dgwt-wcas-search-submit, button.dgwt-wcas-search-submit{
584
  }
585
  }
586
 
587
- .dgwt-wcas-suggestion strong{
588
  font-weight: bold;
589
  }
590
 
@@ -609,11 +612,9 @@ input[type="submit"].dgwt-wcas-search-submit, button.dgwt-wcas-search-submit{
609
  position: relative;
610
  background: #444;
611
  background: rgba(0,0,0,.2);
612
- border-radius: 10px;
613
- box-shadow: 0 1px 1px rgba(0,0,0,.4) inset, 0 1px 0 rgba(255,255,255,.2);
614
  }
615
 
616
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input{
617
  width: 100%;
618
  height: 40px;
619
  padding: 10px 15px;
@@ -622,45 +623,46 @@ input[type="submit"].dgwt-wcas-search-submit, button.dgwt-wcas-search-submit{
622
  border:1px solid #ddd;
623
  border-radius: 3px;
624
  }
625
- .dgwt-wcas-open .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input {
626
  border-radius: 3px 3px 0 0;
627
  }
628
 
629
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input:focus {
630
  outline: 0;
631
  background: #fff;
632
  box-shadow: 0 0 8px 1px rgba(0,0,0,.1);
633
  }
634
 
635
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input::-webkit-input-placeholder {
636
  color: #999;
637
  font-weight: normal;
638
  font-style: italic;
639
  }
640
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input:-moz-placeholder {
641
  color: #999;
642
  font-weight: normal;
643
  font-style: italic;
644
  }
645
 
646
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input::-moz-placeholder {
647
  color: #999;
648
  font-weight: normal;
649
  font-style: italic;
650
  }
651
 
652
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input:-ms-input-placeholder {
653
  color: #999;
654
  font-weight: normal;
655
  font-style: italic;
656
  }
657
 
658
  /* Form submit button */
659
- .dgwt-wcas-sf-wrapp .dgwt-wcas-search-submit {
660
  overflow: visible;
661
  position: absolute;
662
  border: 0;
663
  padding: 0;
 
664
  cursor: pointer;
665
  height: 40px;
666
  min-width: 50px;
@@ -675,11 +677,13 @@ input[type="submit"].dgwt-wcas-search-submit, button.dgwt-wcas-search-submit{
675
  transition: all 250ms ease-in-out;
676
  text-transform: uppercase;
677
  background-color: #96588A;
678
- border-radius: 3px;
679
  text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3);
 
 
680
  }
681
  .dgwt-wcas-open .dgwt-wcas-sf-wrapp .dgwt-wcas-search-submit{
682
- border-radius: 3px 3px 0 3px;
683
  }
684
 
685
  .dgwt-wcas-sf-wrapp .dgwt-wcas-search-submit:hover{
@@ -804,6 +808,6 @@ input[type="submit"].dgwt-wcas-search-submit, button.dgwt-wcas-search-submit{
804
  fill:#000;
805
  }
806
 
807
- .dgwt-wcas-no-submit .dgwt-wcas-sf-wrapp .dgwt-wcas-search-input {
808
  padding: 10px 15px 10px 40px;
809
  }
503
  max-width: 200px;
504
  }
505
 
506
+ input[type="search"].dgwt-wcas-search-input,
507
+ input[type="text"].dgwt-cas-search-input {
508
  -webkit-transition: none;
509
  -moz-transition: none;
510
  -ms-transition: none;
511
  -o-transition: none;
512
  transition: none;
513
+ -webkit-box-shadow: none;
514
+ box-shadow: none;
515
  }
516
 
517
  .dgwt-wcas-pd-desc {
587
  }
588
  }
589
 
590
+ .dgwt-wcas-suggestion strong{
591
  font-weight: bold;
592
  }
593
 
612
  position: relative;
613
  background: #444;
614
  background: rgba(0,0,0,.2);
 
 
615
  }
616
 
617
+ .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input{
618
  width: 100%;
619
  height: 40px;
620
  padding: 10px 15px;
623
  border:1px solid #ddd;
624
  border-radius: 3px;
625
  }
626
+ .dgwt-wcas-open .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input {
627
  border-radius: 3px 3px 0 0;
628
  }
629
 
630
+ .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input:focus {
631
  outline: 0;
632
  background: #fff;
633
  box-shadow: 0 0 8px 1px rgba(0,0,0,.1);
634
  }
635
 
636
+ .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input::-webkit-input-placeholder {
637
  color: #999;
638
  font-weight: normal;
639
  font-style: italic;
640
  }
641
+ .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input:-moz-placeholder {
642
  color: #999;
643
  font-weight: normal;
644
  font-style: italic;
645
  }
646
 
647
+ .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input::-moz-placeholder {
648
  color: #999;
649
  font-weight: normal;
650
  font-style: italic;
651
  }
652
 
653
+ .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input:-ms-input-placeholder {
654
  color: #999;
655
  font-weight: normal;
656
  font-style: italic;
657
  }
658
 
659
  /* Form submit button */
660
+ .dgwt-wcas-sf-wrapp button.dgwt-wcas-search-submit {
661
  overflow: visible;
662
  position: absolute;
663
  border: 0;
664
  padding: 0;
665
+ margin: 0;
666
  cursor: pointer;
667
  height: 40px;
668
  min-width: 50px;
677
  transition: all 250ms ease-in-out;
678
  text-transform: uppercase;
679
  background-color: #96588A;
680
+ border-radius: 0 2px 2px 0;
681
  text-shadow: 0 -1px 0 rgba(0, 0 ,0, .3);
682
+ -webkit-box-shadow: none;
683
+ box-shadow: none;
684
  }
685
  .dgwt-wcas-open .dgwt-wcas-sf-wrapp .dgwt-wcas-search-submit{
686
+ border-radius: 0 2px 0 0;
687
  }
688
 
689
  .dgwt-wcas-sf-wrapp .dgwt-wcas-search-submit:hover{
808
  fill:#000;
809
  }
810
 
811
+ .dgwt-wcas-no-submit .dgwt-wcas-sf-wrapp input[type="search"].dgwt-wcas-search-input {
812
  padding: 10px 15px 10px 40px;
813
  }
assets/js/jquery.dgwt-wcas.js CHANGED
@@ -122,6 +122,7 @@
122
  that.intervalId = 0;
123
  that.cachedResponse = { };
124
  that.cachedDetails = { };
 
125
  that.onChangeInterval = null;
126
  that.onChange = null;
127
  that.isLocal = false;
@@ -771,7 +772,6 @@
771
  if ( options.showDetailsPanel != true || $( window ).width() < 992 || ( 'ontouchend' in document ) ) {
772
  return false;
773
  }
774
- ;
775
 
776
  // Brake if there are no suggestions
777
  if ( suggestion == null ) {
@@ -808,6 +808,13 @@
808
  containerDetails.html( '' );
809
  that.preloader( 'show', containerDetails, '', true );
810
 
 
 
 
 
 
 
 
811
  $.ajax( {
812
  data: data,
813
  type: 'post',
@@ -1313,7 +1320,11 @@
1313
  var that = this,
1314
  onMouseOverCallback = that.options.onMouseOver,
1315
  suggestion = that.suggestions[index];
1316
- that.getDetails( suggestion );
 
 
 
 
1317
  if ( $.isFunction( onMouseOverCallback ) ) {
1318
  onMouseOverCallback.call( that.element, suggestion );
1319
  }
122
  that.intervalId = 0;
123
  that.cachedResponse = { };
124
  that.cachedDetails = { };
125
+ that.detailsRequestsSent = [ ];
126
  that.onChangeInterval = null;
127
  that.onChange = null;
128
  that.isLocal = false;
772
  if ( options.showDetailsPanel != true || $( window ).width() < 992 || ( 'ontouchend' in document ) ) {
773
  return false;
774
  }
 
775
 
776
  // Brake if there are no suggestions
777
  if ( suggestion == null ) {
808
  containerDetails.html( '' );
809
  that.preloader( 'show', containerDetails, '', true );
810
 
811
+ // Prevent duplicate ajax requests
812
+ if ( $.inArray( cacheKey, that.detailsRequestsSent ) != -1 ) {
813
+ return;
814
+ } else {
815
+ that.detailsRequestsSent.push( cacheKey );
816
+ }
817
+
818
  $.ajax( {
819
  data: data,
820
  type: 'post',
1320
  var that = this,
1321
  onMouseOverCallback = that.options.onMouseOver,
1322
  suggestion = that.suggestions[index];
1323
+
1324
+ if ( that.selectedIndex !== index ) {
1325
+ that.getDetails( suggestion );
1326
+ }
1327
+
1328
  if ( $.isFunction( onMouseOverCallback ) ) {
1329
  onMouseOverCallback.call( that.element, suggestion );
1330
  }
assets/js/jquery.dgwt-wcas.min.js CHANGED
@@ -7,4 +7,4 @@
7
  *
8
  * Modified by Damian Góra: http://damiangora.com
9
  */
10
- !function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(e){"use strict";function t(s,n){var i=function(){},o=this,a={ajaxSettings:{},autoSelectFirst:!1,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,onMouseOver:null,onMouseLeave:null,width:"auto",containerDetailsWidth:"auto",showDetailsPanel:!1,showImage:!1,showPrice:!1,showSKU:!1,showDescription:!1,showSaleBadge:!1,showFeaturedBadge:!1,saleBadgeText:"sale",featuredBadgeText:"featured",minChars:1,maxHeight:1e3,deferRequestBy:0,params:{},formatResult:t.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,is_rtl:!1,onSearchStart:i,onSearchComplete:i,onSearchError:i,preserveInput:!1,wrapperaClass:"dgwt-wcas-search-wrapp",containerClass:"dgwt-wcas-suggestions-wrapp",containerDetailsClass:"dgwt-wcas-details-wrapp",cointainerDetailsPos:"right",preloaderClass:"dgwt-wcas-preloader",closeTrigger:"dgwt-wcas-close",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:function(e,t,s){return-1!==e.value.toLowerCase().indexOf(s)},paramName:"query",transformResult:function(t){return"string"==typeof t?e.parseJSON(t):t},showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1};o.element=s,o.el=e(s),o.suggestions=[],o.badQueries=[],o.selectedIndex=-1,o.currentValue=o.element.value,o.intervalId=0,o.cachedResponse={},o.cachedDetails={},o.onChangeInterval=null,o.onChange=null,o.isLocal=!1,o.suggestionsContainer=null,o.detailsContainer=null,o.noSuggestionsContainer=null,o.options=e.extend({},a,n),o.classes={selected:"dgwt-wcas-suggestion-selected",suggestion:"dgwt-wcas-suggestion"},o.hint=null,o.hintValue="",o.selection=null,o.initialize(),o.setOptions(n)}var s=function(){return{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}}}(),n={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40};t.utils=s,e.Autocomplete=t,t.formatResult=function(e,t){var n="("+s.escapeRegExChars(t)+")";return e.replace(new RegExp(n,"gi"),"<strong>$1</strong>").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/&lt;(\/?strong)&gt;/g,"<$1>")},t.prototype={killerFn:null,initialize:function(){var s,n,i=this,o="."+i.classes.suggestion,a=(i.classes.selected,i.options),l="."+a.closeTrigger;i.element.setAttribute("autocomplete","off"),i.killerFn=function(t){0===e(t.target).closest("."+i.options.containerClass).length&&0===e(t.target).closest("."+i.options.containerDetailsClass).length&&(i.killSuggestions(),i.disableKillerFn())},i.noSuggestionsContainer=e('<div class="dgwt-wcas-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),i.suggestionsContainer=t.utils.createNode(a.containerClass),s=e(i.suggestionsContainer),s.appendTo(i.el.closest("."+a.wrapperaClass)),a.showImage===!0&&s.addClass("dgwt-wcas-has-img"),a.showPrice===!0&&s.addClass("dgwt-wcas-has-price"),a.showDescription===!0&&s.addClass("dgwt-wcas-has-desc"),a.showSKU===!0&&s.addClass("dgwt-wcas-has-sku"),"auto"!==a.width&&s.width(a.width),a.showDetailsPanel===!0&&(i.detailsContainer=t.utils.createNode(a.containerDetailsClass),n=e(i.detailsContainer),n.appendTo(i.el.closest("."+a.wrapperaClass))),s.on("mouseover.autocomplete",o,function(){i.onMouseOver(e(this).data("index")),i.activate(e(this).data("index"))}),s.on("mouseout.autocomplete",function(){}),e(document).on("click.autocomplete",l,function(t){i.killerFn(t),i.clear(t),e(this).removeClass(a.closeTrigger),i.el.val("").focus()}),s.on("click.autocomplete",o,function(){i.select(e(this).data("index"))}),i.fixPositionCapture=function(){i.visible&&i.fixPosition()},e(window).on("resize.autocomplete",i.fixPositionCapture),i.el.on("keydown.autocomplete",function(e){i.onKeyPress(e)}),i.el.on("keyup.autocomplete",function(e){i.onKeyUp(e)}),i.el.on("blur.autocomplete",function(){i.onBlur()}),i.el.on("focus.autocomplete",function(){i.onFocus()}),i.el.on("change.autocomplete",function(e){i.onKeyUp(e)}),i.el.on("input.autocomplete",function(e){i.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(t){var s=this,n=s.options;e.extend(n,t),s.isLocal=e.isArray(n.lookup),s.isLocal&&(n.lookup=s.verifySuggestionsFormat(n.lookup)),n.orientation=s.validateOrientation(n.orientation,"bottom"),e(s.suggestionsContainer).css({"max-height":n.maxHeight+"px",width:n.width+"px","z-index":n.zIndex}),n.showDetailsPanel===!0&&jQuery(s.suggestionsContainer).parent().addClass("dgwt-wcas-is-details"),s.options.onSearchComplete=function(){s.preloader("hide",e("."+n.preloaderClass),"dgwt-wcas-inner-preloader"),s.preloader("show",e("."+n.preloaderClass),n.closeTrigger)}},clearCache:function(){this.cachedResponse={},this.cachedDetails={},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 t=this,s=(t.options,e(t.suggestionsContainer)),n=(e(t.detailsContainer),s.parent().get(0));if(n===document.body||t.options.forceFixPosition){var i=t.options.orientation,o=s.outerHeight(),a=t.el.outerHeight(),l=t.el.offset(),r={top:l.top,left:l.left};if("auto"===i){var u=e(window).height(),c=e(window).scrollTop(),d=-c+l.top-o,g=c+u-(l.top+a+o);i=Math.max(d,g)===d?"top":"bottom"}if("top"===i?r.top+=-o:r.top+=a,n!==document.body){var h,p=s.css("opacity");t.visible||s.css("opacity",0).show(),h=s.offsetParent().offset(),r.top-=h.top,r.left-=h.left,t.visible||s.css("opacity",p).hide()}"auto"===t.options.width&&(r.width=t.el.outerWidth()-2+"px"),s.css(r)}},fixPositionDetailsBox:function(){var t=this,s=e(t.detailsContainer);if(0==s.length)return!1;var n=e(window).width(),i=s.parent(),o=s.prev(),a=s.width(),l=s.offset(),r=550;i.width()>=r||(n<l.left+a&&(i.removeClass("dgwt-wcas-details-right"),i.addClass("dgwt-wcas-details-left"),s.css("left","-"+s.outerWidth()+"px")),l.left<1&&(i.removeClass("dgwt-wcas-details-left"),i.addClass("dgwt-wcas-details-right"),s.css("left",o.outerWidth()+"px")))},fixHeight:function(t,s){var n=this,i=n.options;if(1!=i.showDetailsPanel)return!1;var s,o=e("."+i.containerClass),a=e("."+i.containerDetailsClass),l=0,r=0;e("."+i.containerClass+"> *").each(function(){l+=e(this).outerHeight()}),e("."+i.containerDetailsClass+"> *").each(function(){r+=e(this).outerHeight()}),s=l>=r?l:r,(s>l||s>r)&&(o.css("height",s+"px"),a.css("height",s+"px")),"undefined"==typeof t&&(t=0),5>t?setTimeout(function(){n.fixHeight(t+1,s)},30):t=0},enableKillerFn:function(){var t=this;e(document).on("click.autocomplete",t.killerFn)},disableKillerFn:function(){var t=this;e(document).off("click.autocomplete",t.killerFn)},killSuggestions:function(){var t=this,s=e(t.suggestionsContainer).parent();t.stopKillSuggestions(),t.intervalId=window.setInterval(function(){t.visible&&(t.el.val(t.currentValue),t.hide(),s.removeClass("dgwt-wcas-open")),t.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var e,t=this,s=t.el.val().length,n=t.element.selectionStart;return"number"==typeof n?n===s:document.selection?(e=document.selection.createRange(),e.moveStart("character",-s),s===e.text.length):!0},onKeyPress:function(e){var t=this;if(!t.disabled&&!t.visible&&e.which===n.DOWN&&t.currentValue)return void t.suggest();if(!t.disabled&&t.visible){switch(e.which){case n.ESC:t.el.val(t.currentValue),t.hide();break;case n.RIGHT:if(t.hint&&t.options.onHint&&t.isCursorAtEnd()){t.selectHint();break}return;case n.TAB:if(t.hint&&t.options.onHint)return void t.selectHint();if(-1===t.selectedIndex)return void t.hide();if(t.select(t.selectedIndex),t.options.tabDisabled===!1)return;break;case n.RETURN:if(-1===t.selectedIndex)return void t.hide();t.select(t.selectedIndex);break;case n.UP:t.moveUp();break;case n.DOWN:t.moveDown();break;default:return}e.stopImmediatePropagation(),e.preventDefault()}},onKeyUp:function(e){var t=this;if(!t.disabled){switch(e.which){case n.UP:case n.DOWN:return}clearInterval(t.onChangeInterval),t.currentValue!==t.el.val()&&(t.findBestHint(),t.options.deferRequestBy>0?t.onChangeInterval=setInterval(function(){t.onValueChange()},t.options.deferRequestBy):t.onValueChange())}},onValueChange:function(){var t=this,s=t.options,n=t.el.val(),i=t.getQuery(n);return t.selection&&t.currentValue!==i&&(t.selection=null,(s.onInvalidateSelection||e.noop).call(t.element)),clearInterval(t.onChangeInterval),t.currentValue=n,t.selectedIndex=-1,s.triggerSelectOnValidInput&&t.isExactMatch(i)?void t.select(0):void(i.length<s.minChars?(e("."+t.options.closeTrigger).removeClass(t.options.closeTrigger),t.hide()):t.getSuggestions(i))},isExactMatch:function(e){var t=this.suggestions;return 1===t.length&&t[0].value.toLowerCase()===e.toLowerCase()},getQuery:function(t){var s,n=this.options.delimiter;return n?(s=t.split(n),e.trim(s[s.length-1])):t},getSuggestionsLocal:function(t){var s,n=this,i=n.options,o=t.toLowerCase(),a=i.lookupFilter,l=parseInt(i.lookupLimit,10);return s={suggestions:e.grep(i.lookup,function(e){return a(e,t,o)})},l&&s.suggestions.length>l&&(s.suggestions=s.suggestions.slice(0,l)),s},getSuggestions:function(t){var s,n,i,o,a=this,l=a.options,r=l.serviceUrl;if(l.params[l.paramName]=t,n=l.ignoreParams?null:l.params,a.preloader("show",e("."+l.preloaderClass),"dgwt-wcas-inner-preloader"),l.onSearchStart.call(a.element,l.params)!==!1){if(e.isFunction(l.lookup))return void l.lookup(t,function(e){a.suggestions=e.suggestions,a.suggest(),a.getDetails(e.suggestions[0]),l.onSearchComplete.call(a.element,t,e.suggestions)});a.isLocal?s=a.getSuggestionsLocal(t):(e.isFunction(r)&&(r=r.call(a.element,t)),i=r+"?"+e.param(n||{}),s=a.cachedResponse[i]),s&&e.isArray(s.suggestions)?(a.suggestions=s.suggestions,a.suggest(),a.getDetails(s.suggestions[0]),l.onSearchComplete.call(a.element,t,s.suggestions)):a.isBadQuery(t)?l.onSearchComplete.call(a.element,t,[]):(a.abortAjax(),o={url:r,data:n,type:l.type,dataType:l.dataType},e.extend(o,l.ajaxSettings),a.currentRequest=e.ajax(o).done(function(e){var s;a.currentRequest=null,s=l.transformResult(e,t),"undefined"!=typeof s.suggestions&&(a.processResponse(s,t,i),a.getDetails(s.suggestions[0])),l.onSearchComplete.call(a.element,t,s.suggestions)}).fail(function(e,s,n){l.onSearchError.call(a.element,t,e,s,n)}))}},getDetails:function(t){var s=this,n=s.options;if(1!=n.showDetailsPanel||e(window).width()<992||"ontouchend"in document)return!1;if(null!=t){var i,o,a=e("."+n.containerDetailsClass);s.fixHeight();var l={action:dgwt_wcas.action_result_details,post_id:null!=t.post_id?t.post_id:0,term_id:null!=t.term_id?t.term_id:0,taxonomy:null!=t.taxonomy?t.taxonomy:"",value:null!=t.value?t.value:""};i=l.action+l.post_id+l.term_id+l.taxonomy,o=s.cachedDetails[i],null!=o?(a.html(o.details),s.fixHeight(),s.fixPositionDetailsBox()):(a.html(""),s.preloader("show",a,"",!0),e.ajax({data:l,type:"post",url:dgwt_wcas.ajax_details_endpoint,success:function(e){var t="string"==typeof e?jQuery.parseJSON(e):e;s.cachedDetails[i]=t,s.preloader("hide",a,"",!0),null!=t.details?a.html(t.details):a.html("@TODO BŁĄD"),s.fixPositionDetailsBox(),s.fixHeight()},error:function(e,t){s.preloader("hide",a,"",!0),a.html(e),s.fixPositionDetailsBox(),s.fixHeight()}}))}},isBadQuery:function(e){if(!this.options.preventBadQueries)return!1;for(var t=this.badQueries,s=t.length;s--;)if(0===e.indexOf(t[s]))return!0;return!1},hide:function(){var t=this,s=e(t.suggestionsContainer);e(t.detailsContainer);e.isFunction(t.options.onHide)&&t.visible&&t.options.onHide.call(t.element,s),t.visible=!1,t.selectedIndex=-1,clearInterval(t.onChangeInterval),e(t.suggestionsContainer).hide(),e(t.detailsContainer).hide(),t.signalHint(null)},suggest:function(){if(0===this.suggestions.length)return void(this.options.showNoSuggestionNotice?this.noSuggestions():this.hide());var t,s=this,n=s.options,i=n.groupBy,o=n.formatResult,a=s.getQuery(s.currentValue),l=s.classes.suggestion,r=s.classes.selected,u=e(s.suggestionsContainer),c=e(s.detailsContainer),d=e(s.noSuggestionsContainer),g=n.beforeRender,h="",p=function(e,s){var n=e.data[i];return t===n?"":(t=n,'<div class="autocomplete-group"><strong>'+t+"</strong></div>")};return n.triggerSelectOnValidInput&&s.isExactMatch(a)?void s.select(0):(e.each(s.suggestions,function(e,t){var s="",r="",u=!1;i&&(h+=p(t,a,e)),"undefined"==typeof t.post_id?(h+='<div class="'+l+' dgwt-wcas-nores" data-index="0">',h+='<span class="dgwt-wcas-st">'+t.value+"</span>",h+="</div>"):("undefined"!=typeof t.parents&&(s=t.parents),n.showImage===!0&&"undefined"!=typeof t.thumb_html&&(u=!0),r+="undefined"!=typeof t.post_id?'data-post-id="'+t.post_id+'" ':"",r+="undefined"!=typeof t.taxonomy?'data-taxonomy="'+t.taxonomy+'" ':"",r+="undefined"!=typeof t.term_id?'data-term-id="'+t.term_id+'" ':"",h+='<div class="'+l+'" data-index="'+e+'" '+r+">",u&&(h+='<span class="dgwt-wcas-si">'+t.thumb_html+"</span>"),h+=u?'<div class="dgwt-wcas-content-wrapp">':"",h+='<span class="dgwt-wcas-st">',h+="<span>"+o(t.value,a)+s+"</span>",n.showSKU===!0&&"undefined"!=typeof t.sku&&t.sku.length>0&&(h+='<span class="dgwt-wcas-sku">(SKU: '+o(t.sku,a)+")</span>"),h+="</span>",n.showPrice===!0&&"undefined"!=typeof t.price&&(h+='<span class="dgwt-wcas-sp">'+t.price+"</span>"),n.showDescription===!0&&"undefined"!=typeof t.desc&&(h+='<span class="dgwt-wcas-sd">'+o(t.desc,a)+"</span>"),n.showFeaturedBadge===!0&&t.on_sale===!0&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-os">'+n.saleBadgeText+"</span>"),n.showFeaturedBadge===!0&&t.featured===!0&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-f">'+n.featuredBadgeText+"</span>"),h+=u?"</div>":"",h+="</div>")}),this.adjustContainerWidth(),d.detach(),u.html(h),e.isFunction(g)&&g.call(s.element,u),s.fixPosition(),u.show(),u.parent().addClass("dgwt-wcas-open"),n.showDetailsPanel===!0&&c.show(),n.autoSelectFirst&&(s.selectedIndex=0,u.scrollTop(0),u.children("."+l).first().addClass(r)),s.visible=!0,void s.findBestHint())},noSuggestions:function(){var t=this,s=e(t.suggestionsContainer),n=e(t.noSuggestionsContainer);this.adjustContainerWidth(),n.detach(),s.empty(),s.append(n),t.fixPosition(),s.show(),t.visible=!0},adjustContainerWidth:function(){var t,s=this,n=s.options,i=e(s.suggestionsContainer).parent(),o=e(s.suggestionsContainer),a=e(s.detailsContainer),l=550;return"auto"===n.width&&(t=s.el.outerWidth(),o.css("width",t+"px")),i.width()>=l&&n.showDetailsPanel===!0?(i.addClass("dgwt-wcas-full-width"),o.outerWidth(300),a.innerWidth(i.width()-300),i.removeClass("dgwt-wcas-details-left"),i.removeClass("dgwt-wcas-details-right"),void(n.is_rtl===!0?(a.css("left","0"),o.css("right","0")):(a.css("right","0"),o.css("left","0")))):void("left"===n.cointainerDetailsPos?(a.parent().addClass("dgwt-wcas-details-left"),a.css("left","-"+a.outerWidth()+"px")):(a.parent().addClass("dgwt-wcas-details-right"),a.css("left",i.outerWidth()+"px")))},findBestHint:function(){var t=this,s=t.el.val().toLowerCase(),n=null;s&&(e.each(t.suggestions,function(e,t){var i=0===t.value.toLowerCase().indexOf(s);return i&&(n=t),!i}),t.signalHint(n))},signalHint:function(t){var s="",n=this;t&&(s=n.currentValue+t.value.substr(n.currentValue.length)),n.hintValue!==s&&(n.hintValue=s,n.hint=t,(this.options.onHint||e.noop)(s))},preloader:function(t,s,n,i){var o,a="dgwt-wcas-preloader-wrapp",l=null==n?a:a+" "+n;if(1==dgwt_wcas.show_preloader&&0!=s.length)return i!==!0?void("hide"===t?s.removeClass(n):s.addClass(n)):"hide"===t?void e(a).remove():void("show"===t&&(o='<div class="'+l+'"><div class="dgwt-wcas-default-preloader"></div></div>',s.html(o)))},verifySuggestionsFormat:function(t){return t.length&&"string"==typeof t[0]?e.map(t,function(e){return{value:e,data:null}}):t},validateOrientation:function(t,s){return t=e.trim(t||"").toLowerCase(),-1===e.inArray(t,["auto","bottom","top"])&&(t=s),t},processResponse:function(e,t,s){var n=this,i=n.options;e.suggestions=n.verifySuggestionsFormat(e.suggestions),i.noCache||(n.cachedResponse[s]=e,i.preventBadQueries&&0===e.suggestions.length&&n.badQueries.push(t)),t===n.getQuery(n.currentValue)&&(n.suggestions=e.suggestions,n.suggest())},activate:function(t){var s,n=this,i=n.classes.selected,o=e(n.suggestionsContainer),a=o.find("."+n.classes.suggestion);return o.find("."+i).removeClass(i),n.selectedIndex=t,-1!==n.selectedIndex&&a.length>n.selectedIndex?(s=a.get(n.selectedIndex),e(s).addClass(i),s):null},selectHint:function(){var t=this,s=e.inArray(t.hint,t.suggestions);t.select(s)},select:function(e){var t=this;t.hide(),t.onSelect(e)},moveUp:function(){var t=this;if(-1!==t.selectedIndex)return 0===t.selectedIndex?(e(t.suggestionsContainer).children().first().removeClass(t.classes.selected),t.selectedIndex=-1,t.el.val(t.currentValue),void t.findBestHint()):void t.adjustScroll(t.selectedIndex-1)},moveDown:function(){var e=this;e.selectedIndex!==e.suggestions.length-1&&e.adjustScroll(e.selectedIndex+1)},adjustScroll:function(t){var s=this,n=s.activate(t);if(n){var i,o,a,l=e(n).outerHeight();i=n.offsetTop,o=e(s.suggestionsContainer).scrollTop(),a=o+s.options.maxHeight-l,o>i?e(s.suggestionsContainer).scrollTop(i):i>a&&e(s.suggestionsContainer).scrollTop(i-s.options.maxHeight+l),s.options.preserveInput||s.el.val(s.getValue(s.suggestions[t].value)),s.signalHint(null)}},onSelect:function(t){var s=this,n=s.options.onSelect,i=s.suggestions[t];s.currentValue=s.getValue(i.value),s.currentValue===s.el.val()||s.options.preserveInput||s.el.val(s.currentValue),-1!=i.id&&(window.location.href=i.url),s.signalHint(null),s.suggestions=[],s.selection=i,e.isFunction(n)&&n.call(s.element,i)},onMouseOver:function(t){var s=this,n=s.options.onMouseOver,i=s.suggestions[t];s.getDetails(i),e.isFunction(n)&&n.call(s.element,i)},onMouseLeave:function(t){var s=this,n=s.options.onMouseLeave,i=s.suggestions[t];e.isFunction(n)&&n.call(s.element,i)},getValue:function(e){var t,s,n=this,i=n.options.delimiter;return i?(t=n.currentValue,s=t.split(i),1===s.length?e:t.substr(0,t.length-s[s.length-1].length)+e):e},dispose:function(){var t=this;t.el.off(".autocomplete").removeData("autocomplete"),t.disableKillerFn(),e(window).off("resize.autocomplete",t.fixPositionCapture),e(t.suggestionsContainer).remove()}},e.fn.dgwtWcasAutocomplete=function(s,n){var i="autocomplete";return 0===arguments.length?this.first().data(i):this.each(function(){var o=e(this),a=o.data(i);"string"==typeof s?a&&"function"==typeof a[s]&&a[s](n):(a&&a.dispose&&a.dispose(),a=new t(this,s),o.data(i,a))})},function(){e(document).ready(function(){e(".dgwt-wcas-search-submit").length>0&&e(".dgwt-wcas-preloader").css("right",e(".dgwt-wcas-search-submit").outerWidth()+"px");var t=1==dgwt_wcas.show_details_box?!0:!1;(jQuery(window).width()<992||"ontouchend"in document)&&(t=!1),e(".dgwt-wcas-search-input").dgwtWcasAutocomplete({minChars:dgwt_wcas.min_chars,width:dgwt_wcas.sug_width,autoSelectFirst:!0,triggerSelectOnValidInput:!1,serviceUrl:dgwt_wcas.ajax_search_endpoint,paramName:"dgwt_wcas_keyword",showDetailsPanel:t,showImage:1==dgwt_wcas.show_images?!0:!1,showPrice:1==dgwt_wcas.show_price?!0:!1,showDescription:1==dgwt_wcas.show_desc?!0:!1,showSKU:1==dgwt_wcas.show_sku?!0:!1,showSaleBadge:1==dgwt_wcas.show_sale_badge?!0:!1,showFeaturedBadge:1==dgwt_wcas.show_featured_badge?!0:!1,saleBadgeText:dgwt_wcas.t.sale_badge,featuredBadgeText:dgwt_wcas.t.featured_badge,cointainerDetailsPos:dgwt_wcas.details_box_pos,is_rtl:1==dgwt_wcas.is_rtl?!0:!1})})}()});
7
  *
8
  * Modified by Damian Góra: http://damiangora.com
9
  */
10
+ !function(e){"use strict";"function"==typeof define&&define.amd?define(["jquery"],e):e("object"==typeof exports&&"function"==typeof require?require("jquery"):jQuery)}(function(e){"use strict";function t(s,n){var i=function(){},o=this,a={ajaxSettings:{},autoSelectFirst:!1,appendTo:document.body,serviceUrl:null,lookup:null,onSelect:null,onMouseOver:null,onMouseLeave:null,width:"auto",containerDetailsWidth:"auto",showDetailsPanel:!1,showImage:!1,showPrice:!1,showSKU:!1,showDescription:!1,showSaleBadge:!1,showFeaturedBadge:!1,saleBadgeText:"sale",featuredBadgeText:"featured",minChars:1,maxHeight:1e3,deferRequestBy:0,params:{},formatResult:t.formatResult,delimiter:null,zIndex:9999,type:"GET",noCache:!1,is_rtl:!1,onSearchStart:i,onSearchComplete:i,onSearchError:i,preserveInput:!1,wrapperaClass:"dgwt-wcas-search-wrapp",containerClass:"dgwt-wcas-suggestions-wrapp",containerDetailsClass:"dgwt-wcas-details-wrapp",cointainerDetailsPos:"right",preloaderClass:"dgwt-wcas-preloader",closeTrigger:"dgwt-wcas-close",tabDisabled:!1,dataType:"text",currentRequest:null,triggerSelectOnValidInput:!0,preventBadQueries:!0,lookupFilter:function(e,t,s){return-1!==e.value.toLowerCase().indexOf(s)},paramName:"query",transformResult:function(t){return"string"==typeof t?e.parseJSON(t):t},showNoSuggestionNotice:!1,noSuggestionNotice:"No results",orientation:"bottom",forceFixPosition:!1};o.element=s,o.el=e(s),o.suggestions=[],o.badQueries=[],o.selectedIndex=-1,o.currentValue=o.element.value,o.intervalId=0,o.cachedResponse={},o.cachedDetails={},o.detailsRequestsSent=[],o.onChangeInterval=null,o.onChange=null,o.isLocal=!1,o.suggestionsContainer=null,o.detailsContainer=null,o.noSuggestionsContainer=null,o.options=e.extend({},a,n),o.classes={selected:"dgwt-wcas-suggestion-selected",suggestion:"dgwt-wcas-suggestion"},o.hint=null,o.hintValue="",o.selection=null,o.initialize(),o.setOptions(n)}var s=function(){return{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}}}(),n={ESC:27,TAB:9,RETURN:13,LEFT:37,UP:38,RIGHT:39,DOWN:40};t.utils=s,e.Autocomplete=t,t.formatResult=function(e,t){var n="("+s.escapeRegExChars(t)+")";return e.replace(new RegExp(n,"gi"),"<strong>$1</strong>").replace(/&/g,"&amp;").replace(/</g,"&lt;").replace(/>/g,"&gt;").replace(/"/g,"&quot;").replace(/&lt;(\/?strong)&gt;/g,"<$1>")},t.prototype={killerFn:null,initialize:function(){var s,n,i=this,o="."+i.classes.suggestion,a=(i.classes.selected,i.options),l="."+a.closeTrigger;i.element.setAttribute("autocomplete","off"),i.killerFn=function(t){0===e(t.target).closest("."+i.options.containerClass).length&&0===e(t.target).closest("."+i.options.containerDetailsClass).length&&(i.killSuggestions(),i.disableKillerFn())},i.noSuggestionsContainer=e('<div class="dgwt-wcas-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),i.suggestionsContainer=t.utils.createNode(a.containerClass),s=e(i.suggestionsContainer),s.appendTo(i.el.closest("."+a.wrapperaClass)),a.showImage===!0&&s.addClass("dgwt-wcas-has-img"),a.showPrice===!0&&s.addClass("dgwt-wcas-has-price"),a.showDescription===!0&&s.addClass("dgwt-wcas-has-desc"),a.showSKU===!0&&s.addClass("dgwt-wcas-has-sku"),"auto"!==a.width&&s.width(a.width),a.showDetailsPanel===!0&&(i.detailsContainer=t.utils.createNode(a.containerDetailsClass),n=e(i.detailsContainer),n.appendTo(i.el.closest("."+a.wrapperaClass))),s.on("mouseover.autocomplete",o,function(){i.onMouseOver(e(this).data("index")),i.activate(e(this).data("index"))}),s.on("mouseout.autocomplete",function(){}),e(document).on("click.autocomplete",l,function(t){i.killerFn(t),i.clear(t),e(this).removeClass(a.closeTrigger),i.el.val("").focus()}),s.on("click.autocomplete",o,function(){i.select(e(this).data("index"))}),i.fixPositionCapture=function(){i.visible&&i.fixPosition()},e(window).on("resize.autocomplete",i.fixPositionCapture),i.el.on("keydown.autocomplete",function(e){i.onKeyPress(e)}),i.el.on("keyup.autocomplete",function(e){i.onKeyUp(e)}),i.el.on("blur.autocomplete",function(){i.onBlur()}),i.el.on("focus.autocomplete",function(){i.onFocus()}),i.el.on("change.autocomplete",function(e){i.onKeyUp(e)}),i.el.on("input.autocomplete",function(e){i.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(t){var s=this,n=s.options;e.extend(n,t),s.isLocal=e.isArray(n.lookup),s.isLocal&&(n.lookup=s.verifySuggestionsFormat(n.lookup)),n.orientation=s.validateOrientation(n.orientation,"bottom"),e(s.suggestionsContainer).css({"max-height":n.maxHeight+"px",width:n.width+"px","z-index":n.zIndex}),n.showDetailsPanel===!0&&jQuery(s.suggestionsContainer).parent().addClass("dgwt-wcas-is-details"),s.options.onSearchComplete=function(){s.preloader("hide",e("."+n.preloaderClass),"dgwt-wcas-inner-preloader"),s.preloader("show",e("."+n.preloaderClass),n.closeTrigger)}},clearCache:function(){this.cachedResponse={},this.cachedDetails={},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 t=this,s=(t.options,e(t.suggestionsContainer)),n=(e(t.detailsContainer),s.parent().get(0));if(n===document.body||t.options.forceFixPosition){var i=t.options.orientation,o=s.outerHeight(),a=t.el.outerHeight(),l=t.el.offset(),r={top:l.top,left:l.left};if("auto"===i){var u=e(window).height(),c=e(window).scrollTop(),d=-c+l.top-o,g=c+u-(l.top+a+o);i=Math.max(d,g)===d?"top":"bottom"}if("top"===i?r.top+=-o:r.top+=a,n!==document.body){var h,p=s.css("opacity");t.visible||s.css("opacity",0).show(),h=s.offsetParent().offset(),r.top-=h.top,r.left-=h.left,t.visible||s.css("opacity",p).hide()}"auto"===t.options.width&&(r.width=t.el.outerWidth()-2+"px"),s.css(r)}},fixPositionDetailsBox:function(){var t=this,s=e(t.detailsContainer);if(0==s.length)return!1;var n=e(window).width(),i=s.parent(),o=s.prev(),a=s.width(),l=s.offset(),r=550;i.width()>=r||(n<l.left+a&&(i.removeClass("dgwt-wcas-details-right"),i.addClass("dgwt-wcas-details-left"),s.css("left","-"+s.outerWidth()+"px")),l.left<1&&(i.removeClass("dgwt-wcas-details-left"),i.addClass("dgwt-wcas-details-right"),s.css("left",o.outerWidth()+"px")))},fixHeight:function(t,s){var n=this,i=n.options;if(1!=i.showDetailsPanel)return!1;var s,o=e("."+i.containerClass),a=e("."+i.containerDetailsClass),l=0,r=0;e("."+i.containerClass+"> *").each(function(){l+=e(this).outerHeight()}),e("."+i.containerDetailsClass+"> *").each(function(){r+=e(this).outerHeight()}),s=l>=r?l:r,(s>l||s>r)&&(o.css("height",s+"px"),a.css("height",s+"px")),"undefined"==typeof t&&(t=0),5>t?setTimeout(function(){n.fixHeight(t+1,s)},30):t=0},enableKillerFn:function(){var t=this;e(document).on("click.autocomplete",t.killerFn)},disableKillerFn:function(){var t=this;e(document).off("click.autocomplete",t.killerFn)},killSuggestions:function(){var t=this,s=e(t.suggestionsContainer).parent();t.stopKillSuggestions(),t.intervalId=window.setInterval(function(){t.visible&&(t.el.val(t.currentValue),t.hide(),s.removeClass("dgwt-wcas-open")),t.stopKillSuggestions()},50)},stopKillSuggestions:function(){window.clearInterval(this.intervalId)},isCursorAtEnd:function(){var e,t=this,s=t.el.val().length,n=t.element.selectionStart;return"number"==typeof n?n===s:document.selection?(e=document.selection.createRange(),e.moveStart("character",-s),s===e.text.length):!0},onKeyPress:function(e){var t=this;if(!t.disabled&&!t.visible&&e.which===n.DOWN&&t.currentValue)return void t.suggest();if(!t.disabled&&t.visible){switch(e.which){case n.ESC:t.el.val(t.currentValue),t.hide();break;case n.RIGHT:if(t.hint&&t.options.onHint&&t.isCursorAtEnd()){t.selectHint();break}return;case n.TAB:if(t.hint&&t.options.onHint)return void t.selectHint();if(-1===t.selectedIndex)return void t.hide();if(t.select(t.selectedIndex),t.options.tabDisabled===!1)return;break;case n.RETURN:if(-1===t.selectedIndex)return void t.hide();t.select(t.selectedIndex);break;case n.UP:t.moveUp();break;case n.DOWN:t.moveDown();break;default:return}e.stopImmediatePropagation(),e.preventDefault()}},onKeyUp:function(e){var t=this;if(!t.disabled){switch(e.which){case n.UP:case n.DOWN:return}clearInterval(t.onChangeInterval),t.currentValue!==t.el.val()&&(t.findBestHint(),t.options.deferRequestBy>0?t.onChangeInterval=setInterval(function(){t.onValueChange()},t.options.deferRequestBy):t.onValueChange())}},onValueChange:function(){var t=this,s=t.options,n=t.el.val(),i=t.getQuery(n);return t.selection&&t.currentValue!==i&&(t.selection=null,(s.onInvalidateSelection||e.noop).call(t.element)),clearInterval(t.onChangeInterval),t.currentValue=n,t.selectedIndex=-1,s.triggerSelectOnValidInput&&t.isExactMatch(i)?void t.select(0):void(i.length<s.minChars?(e("."+t.options.closeTrigger).removeClass(t.options.closeTrigger),t.hide()):t.getSuggestions(i))},isExactMatch:function(e){var t=this.suggestions;return 1===t.length&&t[0].value.toLowerCase()===e.toLowerCase()},getQuery:function(t){var s,n=this.options.delimiter;return n?(s=t.split(n),e.trim(s[s.length-1])):t},getSuggestionsLocal:function(t){var s,n=this,i=n.options,o=t.toLowerCase(),a=i.lookupFilter,l=parseInt(i.lookupLimit,10);return s={suggestions:e.grep(i.lookup,function(e){return a(e,t,o)})},l&&s.suggestions.length>l&&(s.suggestions=s.suggestions.slice(0,l)),s},getSuggestions:function(t){var s,n,i,o,a=this,l=a.options,r=l.serviceUrl;if(l.params[l.paramName]=t,n=l.ignoreParams?null:l.params,a.preloader("show",e("."+l.preloaderClass),"dgwt-wcas-inner-preloader"),l.onSearchStart.call(a.element,l.params)!==!1){if(e.isFunction(l.lookup))return void l.lookup(t,function(e){a.suggestions=e.suggestions,a.suggest(),a.getDetails(e.suggestions[0]),l.onSearchComplete.call(a.element,t,e.suggestions)});a.isLocal?s=a.getSuggestionsLocal(t):(e.isFunction(r)&&(r=r.call(a.element,t)),i=r+"?"+e.param(n||{}),s=a.cachedResponse[i]),s&&e.isArray(s.suggestions)?(a.suggestions=s.suggestions,a.suggest(),a.getDetails(s.suggestions[0]),l.onSearchComplete.call(a.element,t,s.suggestions)):a.isBadQuery(t)?l.onSearchComplete.call(a.element,t,[]):(a.abortAjax(),o={url:r,data:n,type:l.type,dataType:l.dataType},e.extend(o,l.ajaxSettings),a.currentRequest=e.ajax(o).done(function(e){var s;a.currentRequest=null,s=l.transformResult(e,t),"undefined"!=typeof s.suggestions&&(a.processResponse(s,t,i),a.getDetails(s.suggestions[0])),l.onSearchComplete.call(a.element,t,s.suggestions)}).fail(function(e,s,n){l.onSearchError.call(a.element,t,e,s,n)}))}},getDetails:function(t){var s=this,n=s.options;if(1!=n.showDetailsPanel||e(window).width()<992||"ontouchend"in document)return!1;if(null!=t){var i,o,a=e("."+n.containerDetailsClass);s.fixHeight();var l={action:dgwt_wcas.action_result_details,post_id:null!=t.post_id?t.post_id:0,term_id:null!=t.term_id?t.term_id:0,taxonomy:null!=t.taxonomy?t.taxonomy:"",value:null!=t.value?t.value:""};if(i=l.action+l.post_id+l.term_id+l.taxonomy,o=s.cachedDetails[i],null!=o)a.html(o.details),s.fixHeight(),s.fixPositionDetailsBox();else{if(a.html(""),s.preloader("show",a,"",!0),-1!=e.inArray(i,s.detailsRequestsSent))return;s.detailsRequestsSent.push(i),e.ajax({data:l,type:"post",url:dgwt_wcas.ajax_details_endpoint,success:function(e){var t="string"==typeof e?jQuery.parseJSON(e):e;s.cachedDetails[i]=t,s.preloader("hide",a,"",!0),null!=t.details?a.html(t.details):a.html("@TODO BŁĄD"),s.fixPositionDetailsBox(),s.fixHeight()},error:function(e,t){s.preloader("hide",a,"",!0),a.html(e),s.fixPositionDetailsBox(),s.fixHeight()}})}}},isBadQuery:function(e){if(!this.options.preventBadQueries)return!1;for(var t=this.badQueries,s=t.length;s--;)if(0===e.indexOf(t[s]))return!0;return!1},hide:function(){var t=this,s=e(t.suggestionsContainer);e(t.detailsContainer);e.isFunction(t.options.onHide)&&t.visible&&t.options.onHide.call(t.element,s),t.visible=!1,t.selectedIndex=-1,clearInterval(t.onChangeInterval),e(t.suggestionsContainer).hide(),e(t.detailsContainer).hide(),t.signalHint(null)},suggest:function(){if(0===this.suggestions.length)return void(this.options.showNoSuggestionNotice?this.noSuggestions():this.hide());var t,s=this,n=s.options,i=n.groupBy,o=n.formatResult,a=s.getQuery(s.currentValue),l=s.classes.suggestion,r=s.classes.selected,u=e(s.suggestionsContainer),c=e(s.detailsContainer),d=e(s.noSuggestionsContainer),g=n.beforeRender,h="",p=function(e,s){var n=e.data[i];return t===n?"":(t=n,'<div class="autocomplete-group"><strong>'+t+"</strong></div>")};return n.triggerSelectOnValidInput&&s.isExactMatch(a)?void s.select(0):(e.each(s.suggestions,function(e,t){var s="",r="",u=!1;i&&(h+=p(t,a,e)),"undefined"==typeof t.post_id?(h+='<div class="'+l+' dgwt-wcas-nores" data-index="0">',h+='<span class="dgwt-wcas-st">'+t.value+"</span>",h+="</div>"):("undefined"!=typeof t.parents&&(s=t.parents),n.showImage===!0&&"undefined"!=typeof t.thumb_html&&(u=!0),r+="undefined"!=typeof t.post_id?'data-post-id="'+t.post_id+'" ':"",r+="undefined"!=typeof t.taxonomy?'data-taxonomy="'+t.taxonomy+'" ':"",r+="undefined"!=typeof t.term_id?'data-term-id="'+t.term_id+'" ':"",h+='<div class="'+l+'" data-index="'+e+'" '+r+">",u&&(h+='<span class="dgwt-wcas-si">'+t.thumb_html+"</span>"),h+=u?'<div class="dgwt-wcas-content-wrapp">':"",h+='<span class="dgwt-wcas-st">',h+="<span>"+o(t.value,a)+s+"</span>",n.showSKU===!0&&"undefined"!=typeof t.sku&&t.sku.length>0&&(h+='<span class="dgwt-wcas-sku">(SKU: '+o(t.sku,a)+")</span>"),h+="</span>",n.showPrice===!0&&"undefined"!=typeof t.price&&(h+='<span class="dgwt-wcas-sp">'+t.price+"</span>"),n.showDescription===!0&&"undefined"!=typeof t.desc&&(h+='<span class="dgwt-wcas-sd">'+o(t.desc,a)+"</span>"),n.showFeaturedBadge===!0&&t.on_sale===!0&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-os">'+n.saleBadgeText+"</span>"),n.showFeaturedBadge===!0&&t.featured===!0&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-f">'+n.featuredBadgeText+"</span>"),h+=u?"</div>":"",h+="</div>")}),this.adjustContainerWidth(),d.detach(),u.html(h),e.isFunction(g)&&g.call(s.element,u),s.fixPosition(),u.show(),u.parent().addClass("dgwt-wcas-open"),n.showDetailsPanel===!0&&c.show(),n.autoSelectFirst&&(s.selectedIndex=0,u.scrollTop(0),u.children("."+l).first().addClass(r)),s.visible=!0,void s.findBestHint())},noSuggestions:function(){var t=this,s=e(t.suggestionsContainer),n=e(t.noSuggestionsContainer);this.adjustContainerWidth(),n.detach(),s.empty(),s.append(n),t.fixPosition(),s.show(),t.visible=!0},adjustContainerWidth:function(){var t,s=this,n=s.options,i=e(s.suggestionsContainer).parent(),o=e(s.suggestionsContainer),a=e(s.detailsContainer),l=550;return"auto"===n.width&&(t=s.el.outerWidth(),o.css("width",t+"px")),i.width()>=l&&n.showDetailsPanel===!0?(i.addClass("dgwt-wcas-full-width"),o.outerWidth(300),a.innerWidth(i.width()-300),i.removeClass("dgwt-wcas-details-left"),i.removeClass("dgwt-wcas-details-right"),void(n.is_rtl===!0?(a.css("left","0"),o.css("right","0")):(a.css("right","0"),o.css("left","0")))):void("left"===n.cointainerDetailsPos?(a.parent().addClass("dgwt-wcas-details-left"),a.css("left","-"+a.outerWidth()+"px")):(a.parent().addClass("dgwt-wcas-details-right"),a.css("left",i.outerWidth()+"px")))},findBestHint:function(){var t=this,s=t.el.val().toLowerCase(),n=null;s&&(e.each(t.suggestions,function(e,t){var i=0===t.value.toLowerCase().indexOf(s);return i&&(n=t),!i}),t.signalHint(n))},signalHint:function(t){var s="",n=this;t&&(s=n.currentValue+t.value.substr(n.currentValue.length)),n.hintValue!==s&&(n.hintValue=s,n.hint=t,(this.options.onHint||e.noop)(s))},preloader:function(t,s,n,i){var o,a="dgwt-wcas-preloader-wrapp",l=null==n?a:a+" "+n;if(1==dgwt_wcas.show_preloader&&0!=s.length)return i!==!0?void("hide"===t?s.removeClass(n):s.addClass(n)):"hide"===t?void e(a).remove():void("show"===t&&(o='<div class="'+l+'"><div class="dgwt-wcas-default-preloader"></div></div>',s.html(o)))},verifySuggestionsFormat:function(t){return t.length&&"string"==typeof t[0]?e.map(t,function(e){return{value:e,data:null}}):t},validateOrientation:function(t,s){return t=e.trim(t||"").toLowerCase(),-1===e.inArray(t,["auto","bottom","top"])&&(t=s),t},processResponse:function(e,t,s){var n=this,i=n.options;e.suggestions=n.verifySuggestionsFormat(e.suggestions),i.noCache||(n.cachedResponse[s]=e,i.preventBadQueries&&0===e.suggestions.length&&n.badQueries.push(t)),t===n.getQuery(n.currentValue)&&(n.suggestions=e.suggestions,n.suggest())},activate:function(t){var s,n=this,i=n.classes.selected,o=e(n.suggestionsContainer),a=o.find("."+n.classes.suggestion);return o.find("."+i).removeClass(i),n.selectedIndex=t,-1!==n.selectedIndex&&a.length>n.selectedIndex?(s=a.get(n.selectedIndex),e(s).addClass(i),s):null},selectHint:function(){var t=this,s=e.inArray(t.hint,t.suggestions);t.select(s)},select:function(e){var t=this;t.hide(),t.onSelect(e)},moveUp:function(){var t=this;if(-1!==t.selectedIndex)return 0===t.selectedIndex?(e(t.suggestionsContainer).children().first().removeClass(t.classes.selected),t.selectedIndex=-1,t.el.val(t.currentValue),void t.findBestHint()):void t.adjustScroll(t.selectedIndex-1)},moveDown:function(){var e=this;e.selectedIndex!==e.suggestions.length-1&&e.adjustScroll(e.selectedIndex+1)},adjustScroll:function(t){var s=this,n=s.activate(t);if(n){var i,o,a,l=e(n).outerHeight();i=n.offsetTop,o=e(s.suggestionsContainer).scrollTop(),a=o+s.options.maxHeight-l,o>i?e(s.suggestionsContainer).scrollTop(i):i>a&&e(s.suggestionsContainer).scrollTop(i-s.options.maxHeight+l),s.options.preserveInput||s.el.val(s.getValue(s.suggestions[t].value)),s.signalHint(null)}},onSelect:function(t){var s=this,n=s.options.onSelect,i=s.suggestions[t];s.currentValue=s.getValue(i.value),s.currentValue===s.el.val()||s.options.preserveInput||s.el.val(s.currentValue),-1!=i.id&&(window.location.href=i.url),s.signalHint(null),s.suggestions=[],s.selection=i,e.isFunction(n)&&n.call(s.element,i)},onMouseOver:function(t){var s=this,n=s.options.onMouseOver,i=s.suggestions[t];s.selectedIndex!==t&&s.getDetails(i),e.isFunction(n)&&n.call(s.element,i)},onMouseLeave:function(t){var s=this,n=s.options.onMouseLeave,i=s.suggestions[t];e.isFunction(n)&&n.call(s.element,i)},getValue:function(e){var t,s,n=this,i=n.options.delimiter;return i?(t=n.currentValue,s=t.split(i),1===s.length?e:t.substr(0,t.length-s[s.length-1].length)+e):e},dispose:function(){var t=this;t.el.off(".autocomplete").removeData("autocomplete"),t.disableKillerFn(),e(window).off("resize.autocomplete",t.fixPositionCapture),e(t.suggestionsContainer).remove()}},e.fn.dgwtWcasAutocomplete=function(s,n){var i="autocomplete";return 0===arguments.length?this.first().data(i):this.each(function(){var o=e(this),a=o.data(i);"string"==typeof s?a&&"function"==typeof a[s]&&a[s](n):(a&&a.dispose&&a.dispose(),a=new t(this,s),o.data(i,a))})},function(){e(document).ready(function(){e(".dgwt-wcas-search-submit").length>0&&e(".dgwt-wcas-preloader").css("right",e(".dgwt-wcas-search-submit").outerWidth()+"px");var t=1==dgwt_wcas.show_details_box?!0:!1;(jQuery(window).width()<992||"ontouchend"in document)&&(t=!1),e(".dgwt-wcas-search-input").dgwtWcasAutocomplete({minChars:dgwt_wcas.min_chars,width:dgwt_wcas.sug_width,autoSelectFirst:!0,triggerSelectOnValidInput:!1,serviceUrl:dgwt_wcas.ajax_search_endpoint,paramName:"dgwt_wcas_keyword",showDetailsPanel:t,showImage:1==dgwt_wcas.show_images?!0:!1,showPrice:1==dgwt_wcas.show_price?!0:!1,showDescription:1==dgwt_wcas.show_desc?!0:!1,showSKU:1==dgwt_wcas.show_sku?!0:!1,showSaleBadge:1==dgwt_wcas.show_sale_badge?!0:!1,showFeaturedBadge:1==dgwt_wcas.show_featured_badge?!0:!1,saleBadgeText:dgwt_wcas.t.sale_badge,featuredBadgeText:dgwt_wcas.t.featured_badge,cointainerDetailsPos:dgwt_wcas.details_box_pos,is_rtl:1==dgwt_wcas.is_rtl?!0:!1})})}()});
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_i
4
  Tags: AJAX, ajax search, autocomplete, category search, custom search, ecommerce, instant search, sive search, product search, products, search, search by sku, search highlight, search plugin, shop, woocommerce, woocommerce live search, WooCommerce Plugin, woocommerce product search, woocommerce search, wordpress search, wp ajax search, wp search, wp search plugin, wp tao
5
  Requires at least: 3.8
6
  Tested up to: 4.5.3
7
- Stable tag: 1.0
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -66,6 +66,11 @@ Any suggestions or comments are welcome. Feel free to contact me using this [con
66
 
67
  == Changelog ==
68
 
 
 
 
 
 
69
  = 1.0, June 24, 2016 =
70
  * NEW: [Option] Exclude out of stock products from suggestions
71
  * NEW: [Option] Overwrite a suggestion container width
4
  Tags: AJAX, ajax search, autocomplete, category search, custom search, ecommerce, instant search, sive search, product search, products, search, search by sku, search highlight, search plugin, shop, woocommerce, woocommerce live search, WooCommerce Plugin, woocommerce product search, woocommerce search, wordpress search, wp ajax search, wp search, wp search plugin, wp tao
5
  Requires at least: 3.8
6
  Tested up to: 4.5.3
7
+ Stable tag: 1.0.1
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
66
 
67
  == Changelog ==
68
 
69
+ = 1.0.1, June 30, 2016 =
70
+ * FIX: Excess AJAX requests in a detail mode
71
+ * FIX: Optimization JS mouseover event in a detail mode
72
+ * FIX: Trivial things in CSS
73
+
74
  = 1.0, June 24, 2016 =
75
  * NEW: [Option] Exclude out of stock products from suggestions
76
  * NEW: [Option] Overwrite a suggestion container width