Version Description
Download this release
Release Info
Developer | damian-gora |
Plugin | Ajax Search for WooCommerce |
Version | 1.0 |
Comparing to | |
See all releases |
Code changes from version 0.9.1 to 1.0
- ajax-search-for-woocommerce.php +2 -2
- assets/css/admin-style.css +2 -0
- assets/css/style.css +18 -1
- assets/js/jquery.dgwt-wcas.js +64 -46
- assets/js/jquery.dgwt-wcas.min.js +1 -1
- includes/admin/settings/class-settings.php +20 -6
- includes/class-search.php +55 -7
- includes/register-scripts.php +15 -3
- readme.txt +15 -5
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: 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', '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
|
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' );
|
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/admin-style.css
CHANGED
@@ -32,6 +32,8 @@
|
|
32 |
font-size: 12px;
|
33 |
margin: 0 0 0 10px;
|
34 |
vertical-align: middle;
|
|
|
|
|
35 |
}
|
36 |
|
37 |
.dgwt_wcas_settings-group > h2{
|
32 |
font-size: 12px;
|
33 |
margin: 0 0 0 10px;
|
34 |
vertical-align: middle;
|
35 |
+
max-width: 96%;
|
36 |
+
max-width: calc(100% - 40px);
|
37 |
}
|
38 |
|
39 |
.dgwt_wcas_settings-group > h2{
|
assets/css/style.css
CHANGED
@@ -164,6 +164,11 @@
|
|
164 |
content: '';
|
165 |
}
|
166 |
|
|
|
|
|
|
|
|
|
|
|
167 |
.dgwt-wcas-has-img .dgwt-wcas-suggestion {
|
168 |
padding: 12px 0;
|
169 |
}
|
@@ -174,6 +179,18 @@
|
|
174 |
color: #444;
|
175 |
font-size: 15px;
|
176 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
177 |
|
178 |
.dgwt-wcas-si {
|
179 |
position: absolute;
|
@@ -567,7 +584,7 @@ input[type="submit"].dgwt-wcas-search-submit, button.dgwt-wcas-search-submit{
|
|
567 |
}
|
568 |
}
|
569 |
|
570 |
-
.dgwt-wcas-
|
571 |
font-weight: bold;
|
572 |
}
|
573 |
|
164 |
content: '';
|
165 |
}
|
166 |
|
167 |
+
.dgwt-wcas-suggestion.dgwt-wcas-nores {
|
168 |
+
cursor: default;
|
169 |
+
opacity: 0.5;
|
170 |
+
}
|
171 |
+
|
172 |
.dgwt-wcas-has-img .dgwt-wcas-suggestion {
|
173 |
padding: 12px 0;
|
174 |
}
|
179 |
color: #444;
|
180 |
font-size: 15px;
|
181 |
}
|
182 |
+
.dgwt-wcas-has-price .dgwt-wcas-st {
|
183 |
+
padding-right: 80px;
|
184 |
+
}
|
185 |
+
|
186 |
+
.dgwt-wcas-sku {
|
187 |
+
font-size: 80%;
|
188 |
+
margin-left: 6px;
|
189 |
+
}
|
190 |
+
.dgwt-wcas-st > span {
|
191 |
+
display: inline-block;
|
192 |
+
vertical-align: middle;
|
193 |
+
}
|
194 |
|
195 |
.dgwt-wcas-si {
|
196 |
position: absolute;
|
584 |
}
|
585 |
}
|
586 |
|
587 |
+
.dgwt-wcas-suggestion strong{
|
588 |
font-weight: bold;
|
589 |
}
|
590 |
|
assets/js/jquery.dgwt-wcas.js
CHANGED
@@ -68,6 +68,7 @@
|
|
68 |
showDetailsPanel: false,
|
69 |
showImage: false,
|
70 |
showPrice: false,
|
|
|
71 |
showDescription: false,
|
72 |
showSaleBadge: false,
|
73 |
showFeaturedBadge: false,
|
@@ -145,10 +146,10 @@
|
|
145 |
|
146 |
$.Autocomplete = Autocomplete;
|
147 |
|
148 |
-
Autocomplete.formatResult = function (
|
149 |
var pattern = '(' + utils.escapeRegExChars( currentValue ) + ')';
|
150 |
|
151 |
-
return
|
152 |
.replace( new RegExp( pattern, 'gi' ), '<strong>$1<\/strong>' )
|
153 |
.replace( /&/g, '&' )
|
154 |
.replace( /</g, '<' )
|
@@ -201,7 +202,8 @@
|
|
201 |
// Description
|
202 |
if ( options.showDescription === true )
|
203 |
container.addClass( 'dgwt-wcas-has-desc' );
|
204 |
-
|
|
|
205 |
|
206 |
// Only set width if it was provided:
|
207 |
if ( options.width !== 'auto' ) {
|
@@ -314,8 +316,8 @@
|
|
314 |
}
|
315 |
|
316 |
that.options.onSearchComplete = function () {
|
317 |
-
that.preloader( 'hide', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader');
|
318 |
-
that.preloader( 'show', $( '.' + options.preloaderClass ), options.closeTrigger);
|
319 |
};
|
320 |
|
321 |
|
@@ -699,7 +701,7 @@
|
|
699 |
options.params[options.paramName] = q;
|
700 |
params = options.ignoreParams ? null : options.params;
|
701 |
|
702 |
-
that.preloader( 'show', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader');
|
703 |
|
704 |
if ( options.onSearchStart.call( that.element, options.params ) === false ) {
|
705 |
return;
|
@@ -804,7 +806,7 @@
|
|
804 |
} else {
|
805 |
|
806 |
containerDetails.html( '' );
|
807 |
-
that.preloader( 'show', containerDetails, '', true);
|
808 |
|
809 |
$.ajax( {
|
810 |
data: data,
|
@@ -817,7 +819,7 @@
|
|
817 |
// Cached response
|
818 |
that.cachedDetails[cacheKey] = result;
|
819 |
|
820 |
-
that.preloader( 'hide', containerDetails, '', true);
|
821 |
|
822 |
if ( result.details != null ) {
|
823 |
containerDetails.html( result.details );
|
@@ -830,7 +832,7 @@
|
|
830 |
},
|
831 |
error: function ( jqXHR, exception ) {
|
832 |
|
833 |
-
that.preloader( 'hide', containerDetails, '', true);
|
834 |
|
835 |
containerDetails.html( jqXHR );
|
836 |
that.fixPositionDetailsBox();
|
@@ -922,56 +924,70 @@
|
|
922 |
html += formatGroup( suggestion, value, i );
|
923 |
}
|
924 |
|
925 |
-
if ( typeof suggestion.
|
926 |
-
|
927 |
-
|
|
|
|
|
928 |
|
929 |
-
|
930 |
-
|
931 |
-
|
932 |
-
}
|
933 |
|
934 |
-
|
935 |
-
|
936 |
-
|
937 |
-
|
938 |
-
html += '<div class="' + className + '" data-index="' + i + '" ' + dataAttrs + '>';
|
939 |
|
940 |
-
|
941 |
-
|
942 |
-
|
943 |
-
|
|
|
944 |
|
|
|
|
|
|
|
|
|
945 |
|
946 |
-
html += is_img ? '<div class="dgwt-wcas-content-wrapp">' : '';
|
947 |
|
|
|
948 |
|
949 |
-
// Title
|
950 |
-
html += '<span class="dgwt-wcas-st">' + formatResult( suggestion, value ) + parent + '</span>';
|
951 |
|
952 |
-
|
953 |
-
|
954 |
-
html += '<span
|
955 |
-
|
|
|
|
|
|
|
|
|
956 |
|
957 |
-
|
958 |
-
|
959 |
-
|
960 |
-
|
961 |
|
962 |
-
|
963 |
-
|
964 |
-
|
965 |
-
|
966 |
|
967 |
-
|
968 |
-
|
969 |
-
|
970 |
-
|
|
|
|
|
|
|
|
|
|
|
971 |
|
972 |
|
973 |
-
|
974 |
-
|
|
|
|
|
975 |
} );
|
976 |
|
977 |
this.adjustContainerWidth();
|
@@ -1397,6 +1413,7 @@
|
|
1397 |
|
1398 |
$( '.dgwt-wcas-search-input' ).dgwtWcasAutocomplete( {
|
1399 |
minChars: dgwt_wcas.min_chars,
|
|
|
1400 |
autoSelectFirst: true,
|
1401 |
triggerSelectOnValidInput: false,
|
1402 |
serviceUrl: dgwt_wcas.ajax_search_endpoint,
|
@@ -1405,6 +1422,7 @@
|
|
1405 |
showImage: dgwt_wcas.show_images == 1 ? true : false,
|
1406 |
showPrice: dgwt_wcas.show_price == 1 ? true : false,
|
1407 |
showDescription: dgwt_wcas.show_desc == 1 ? true : false,
|
|
|
1408 |
showSaleBadge: dgwt_wcas.show_sale_badge == 1 ? true : false,
|
1409 |
showFeaturedBadge: dgwt_wcas.show_featured_badge == 1 ? true : false,
|
1410 |
saleBadgeText: dgwt_wcas.t.sale_badge,
|
68 |
showDetailsPanel: false,
|
69 |
showImage: false,
|
70 |
showPrice: false,
|
71 |
+
showSKU: false,
|
72 |
showDescription: false,
|
73 |
showSaleBadge: false,
|
74 |
showFeaturedBadge: false,
|
146 |
|
147 |
$.Autocomplete = Autocomplete;
|
148 |
|
149 |
+
Autocomplete.formatResult = function ( suggestionValue, currentValue ) {
|
150 |
var pattern = '(' + utils.escapeRegExChars( currentValue ) + ')';
|
151 |
|
152 |
+
return suggestionValue
|
153 |
.replace( new RegExp( pattern, 'gi' ), '<strong>$1<\/strong>' )
|
154 |
.replace( /&/g, '&' )
|
155 |
.replace( /</g, '<' )
|
202 |
// Description
|
203 |
if ( options.showDescription === true )
|
204 |
container.addClass( 'dgwt-wcas-has-desc' );
|
205 |
+
if ( options.showSKU === true )
|
206 |
+
container.addClass( 'dgwt-wcas-has-sku' );
|
207 |
|
208 |
// Only set width if it was provided:
|
209 |
if ( options.width !== 'auto' ) {
|
316 |
}
|
317 |
|
318 |
that.options.onSearchComplete = function () {
|
319 |
+
that.preloader( 'hide', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader' );
|
320 |
+
that.preloader( 'show', $( '.' + options.preloaderClass ), options.closeTrigger );
|
321 |
};
|
322 |
|
323 |
|
701 |
options.params[options.paramName] = q;
|
702 |
params = options.ignoreParams ? null : options.params;
|
703 |
|
704 |
+
that.preloader( 'show', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader' );
|
705 |
|
706 |
if ( options.onSearchStart.call( that.element, options.params ) === false ) {
|
707 |
return;
|
806 |
} else {
|
807 |
|
808 |
containerDetails.html( '' );
|
809 |
+
that.preloader( 'show', containerDetails, '', true );
|
810 |
|
811 |
$.ajax( {
|
812 |
data: data,
|
819 |
// Cached response
|
820 |
that.cachedDetails[cacheKey] = result;
|
821 |
|
822 |
+
that.preloader( 'hide', containerDetails, '', true );
|
823 |
|
824 |
if ( result.details != null ) {
|
825 |
containerDetails.html( result.details );
|
832 |
},
|
833 |
error: function ( jqXHR, exception ) {
|
834 |
|
835 |
+
that.preloader( 'hide', containerDetails, '', true );
|
836 |
|
837 |
containerDetails.html( jqXHR );
|
838 |
that.fixPositionDetailsBox();
|
924 |
html += formatGroup( suggestion, value, i );
|
925 |
}
|
926 |
|
927 |
+
if ( typeof suggestion.post_id == 'undefined' ) {
|
928 |
+
html += '<div class="' + className + ' dgwt-wcas-nores" data-index="0">';
|
929 |
+
html += '<span class="dgwt-wcas-st">' + suggestion.value + '</span>';
|
930 |
+
html += '</div>';
|
931 |
+
} else {
|
932 |
|
933 |
+
if ( typeof suggestion.parents != 'undefined' ) {
|
934 |
+
parent = suggestion.parents;
|
935 |
+
}
|
|
|
936 |
|
937 |
+
// Image
|
938 |
+
if ( options.showImage === true && typeof suggestion.thumb_html != 'undefined' ) {
|
939 |
+
is_img = true;
|
940 |
+
}
|
|
|
941 |
|
942 |
+
// One suggestion HTML
|
943 |
+
dataAttrs += typeof suggestion.post_id != 'undefined' ? 'data-post-id="' + suggestion.post_id + '" ' : '';
|
944 |
+
dataAttrs += typeof suggestion.taxonomy != 'undefined' ? 'data-taxonomy="' + suggestion.taxonomy + '" ' : '';
|
945 |
+
dataAttrs += typeof suggestion.term_id != 'undefined' ? 'data-term-id="' + suggestion.term_id + '" ' : '';
|
946 |
+
html += '<div class="' + className + '" data-index="' + i + '" ' + dataAttrs + '>';
|
947 |
|
948 |
+
// Image
|
949 |
+
if ( is_img ) {
|
950 |
+
html += '<span class="dgwt-wcas-si">' + suggestion.thumb_html + '</span>';
|
951 |
+
}
|
952 |
|
|
|
953 |
|
954 |
+
html += is_img ? '<div class="dgwt-wcas-content-wrapp">' : '';
|
955 |
|
|
|
|
|
956 |
|
957 |
+
// Title
|
958 |
+
html += '<span class="dgwt-wcas-st">';
|
959 |
+
html += '<span>' + formatResult( suggestion.value, value ) + parent + '</span>'
|
960 |
+
// SKU
|
961 |
+
if ( options.showSKU === true && typeof suggestion.sku != 'undefined' && suggestion.sku.length > 0 ) {
|
962 |
+
html += '<span class="dgwt-wcas-sku">(SKU: ' + formatResult( suggestion.sku, value ) + ')</span>';
|
963 |
+
}
|
964 |
+
html += '</span>';
|
965 |
|
966 |
+
// Price
|
967 |
+
if ( options.showPrice === true && typeof suggestion.price != 'undefined' ) {
|
968 |
+
html += '<span class="dgwt-wcas-sp">' + suggestion.price + '</span>';
|
969 |
+
}
|
970 |
|
971 |
+
// Description
|
972 |
+
if ( options.showDescription === true && typeof suggestion.desc != 'undefined' ) {
|
973 |
+
html += '<span class="dgwt-wcas-sd">' + formatResult( suggestion.desc, value ) + '</span>';
|
974 |
+
}
|
975 |
|
976 |
+
// On sale product badge
|
977 |
+
if ( options.showFeaturedBadge === true && suggestion.on_sale === true ) {
|
978 |
+
html += '<span class="dgwt-wcas-badge dgwt-wcas-badge-os">' + options.saleBadgeText + '</span>';
|
979 |
+
}
|
980 |
+
|
981 |
+
// Featured product badge
|
982 |
+
if ( options.showFeaturedBadge === true && suggestion.featured === true ) {
|
983 |
+
html += '<span class="dgwt-wcas-badge dgwt-wcas-badge-f">' + options.featuredBadgeText + '</span>';
|
984 |
+
}
|
985 |
|
986 |
|
987 |
+
html += is_img ? '</div>' : '';
|
988 |
+
html += '</div>';
|
989 |
+
|
990 |
+
}
|
991 |
} );
|
992 |
|
993 |
this.adjustContainerWidth();
|
1413 |
|
1414 |
$( '.dgwt-wcas-search-input' ).dgwtWcasAutocomplete( {
|
1415 |
minChars: dgwt_wcas.min_chars,
|
1416 |
+
width: dgwt_wcas.sug_width,
|
1417 |
autoSelectFirst: true,
|
1418 |
triggerSelectOnValidInput: false,
|
1419 |
serviceUrl: dgwt_wcas.ajax_search_endpoint,
|
1422 |
showImage: dgwt_wcas.show_images == 1 ? true : false,
|
1423 |
showPrice: dgwt_wcas.show_price == 1 ? true : false,
|
1424 |
showDescription: dgwt_wcas.show_desc == 1 ? true : false,
|
1425 |
+
showSKU: dgwt_wcas.show_sku == 1 ? true : false,
|
1426 |
showSaleBadge: dgwt_wcas.show_sale_badge == 1 ? true : false,
|
1427 |
showFeaturedBadge: dgwt_wcas.show_featured_badge == 1 ? true : false,
|
1428 |
saleBadgeText: dgwt_wcas.t.sale_badge,
|
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,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.value.replace(new RegExp(n,"gi"),"<strong>$1</strong>").replace(/&/g,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/<(\/?strong)>/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"),"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.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">'+o(t,a)+s+"</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">'+t.desc+"</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,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,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.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,"&").replace(/</g,"<").replace(/>/g,">").replace(/"/g,""").replace(/<(\/?strong)>/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})})}()});
|
includes/admin/settings/class-settings.php
CHANGED
@@ -183,6 +183,12 @@ class DGWT_WCAS_Settings {
|
|
183 |
'type' => 'checkbox',
|
184 |
'default' => 'off',
|
185 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
186 |
array(
|
187 |
'name' => 'product_suggestion_head',
|
188 |
'label' => '<h3>' . __( 'Suggestions output', DGWT_WCAS_DOMAIN ) . '</h3>',
|
@@ -206,12 +212,12 @@ class DGWT_WCAS_Settings {
|
|
206 |
'type' => 'checkbox',
|
207 |
'default' => 'off',
|
208 |
),
|
209 |
-
|
210 |
-
|
211 |
-
|
212 |
-
|
213 |
-
|
214 |
-
|
215 |
// array(
|
216 |
// 'name' => 'show_sale_badge',
|
217 |
// 'label' => __( 'Show sale badge', DGWT_WCAS_DOMAIN ),
|
@@ -352,6 +358,14 @@ class DGWT_WCAS_Settings {
|
|
352 |
'type' => 'color',
|
353 |
'default' => '',
|
354 |
),
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
355 |
array(
|
356 |
'name' => 'preloader',
|
357 |
'label' => '<h3>' . __( 'Preloader', DGWT_WCAS_DOMAIN ) . '</h3>',
|
183 |
'type' => 'checkbox',
|
184 |
'default' => 'off',
|
185 |
),
|
186 |
+
array(
|
187 |
+
'name' => 'exclude_out_of_stock',
|
188 |
+
'label' => __( "Exclude 'out of stock' products", DGWT_WCAS_DOMAIN ),
|
189 |
+
'type' => 'checkbox',
|
190 |
+
'default' => 'off',
|
191 |
+
),
|
192 |
array(
|
193 |
'name' => 'product_suggestion_head',
|
194 |
'label' => '<h3>' . __( 'Suggestions output', DGWT_WCAS_DOMAIN ) . '</h3>',
|
212 |
'type' => 'checkbox',
|
213 |
'default' => 'off',
|
214 |
),
|
215 |
+
array(
|
216 |
+
'name' => 'show_product_sku',
|
217 |
+
'label' => __( 'Show SKU', DGWT_WCAS_DOMAIN ),
|
218 |
+
'type' => 'checkbox',
|
219 |
+
'default' => 'off',
|
220 |
+
),
|
221 |
// array(
|
222 |
// 'name' => 'show_sale_badge',
|
223 |
// 'label' => __( 'Show sale badge', DGWT_WCAS_DOMAIN ),
|
358 |
'type' => 'color',
|
359 |
'default' => '',
|
360 |
),
|
361 |
+
array(
|
362 |
+
'name' => 'sug_width',
|
363 |
+
'label' => __( 'Suggestions width', DGWT_WCAS_DOMAIN ),
|
364 |
+
'type' => 'number',
|
365 |
+
'size' => 'small',
|
366 |
+
'desc' => ' px. ' . __( 'Overvrite the suggestions container width. Leave this field empty to adjust the suggestions container width to the search input width.', DGWT_WCAS_DOMAIN ),
|
367 |
+
'default' => '',
|
368 |
+
),
|
369 |
array(
|
370 |
'name' => 'preloader',
|
371 |
'label' => '<h3>' . __( 'Preloader', DGWT_WCAS_DOMAIN ) . '</h3>',
|
includes/class-search.php
CHANGED
@@ -31,6 +31,7 @@ class DGWT_WCAS_Search {
|
|
31 |
$this->slots = $this->limit; // Free slots for the results. Default 10
|
32 |
|
33 |
add_filter( 'posts_search', array( $this, 'search_filters' ), 501, 2 );
|
|
|
34 |
add_filter( 'pre_get_posts', array( $this, 'change_wp_search_size' ), 500 );
|
35 |
|
36 |
|
@@ -98,14 +99,31 @@ class DGWT_WCAS_Search {
|
|
98 |
'order' => $ordering_args[ 'order' ],
|
99 |
'suppress_filters' => false,
|
100 |
'meta_query' => array(
|
101 |
-
|
|
|
102 |
'key' => '_visibility',
|
103 |
'value' => array( 'search', 'visible' ),
|
104 |
'compare' => 'IN'
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
105 |
)
|
106 |
)
|
107 |
);
|
108 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
109 |
|
110 |
$products = get_posts( $args );
|
111 |
|
@@ -138,6 +156,11 @@ class DGWT_WCAS_Search {
|
|
138 |
$r[ 'desc' ] = dgwt_wcas_get_product_desc( $product->id, $this->desc_limit );
|
139 |
}
|
140 |
|
|
|
|
|
|
|
|
|
|
|
141 |
// Is on sale
|
142 |
if ( DGWT_WCAS()->settings->get_opt( 'show_sale_badge' ) === 'on' ) {
|
143 |
$r[ 'on_sale' ] = $product->is_on_sale();
|
@@ -160,11 +183,9 @@ class DGWT_WCAS_Search {
|
|
160 |
//@todo show 'No results' as option
|
161 |
if ( empty( $results ) ) {
|
162 |
|
163 |
-
|
164 |
-
|
165 |
-
|
166 |
-
// 'url' => '',
|
167 |
-
// );
|
168 |
}
|
169 |
|
170 |
//@todo Add results to the wp cache
|
@@ -304,6 +325,10 @@ class DGWT_WCAS_Search {
|
|
304 |
public function search_filters( $search, &$wp_query ) {
|
305 |
global $wpdb;
|
306 |
|
|
|
|
|
|
|
|
|
307 |
if ( empty( $search ) ) {
|
308 |
return $search; // skip processing - no search term in query
|
309 |
}
|
@@ -336,6 +361,11 @@ class DGWT_WCAS_Search {
|
|
336 |
$search .= " OR ($wpdb->posts.post_excerpt LIKE '{$n}{$term}{$n}')";
|
337 |
}
|
338 |
|
|
|
|
|
|
|
|
|
|
|
339 |
$search .= ")";
|
340 |
|
341 |
$searchand = ' AND ';
|
@@ -346,10 +376,28 @@ class DGWT_WCAS_Search {
|
|
346 |
if ( !is_user_logged_in() )
|
347 |
$search .= " AND ($wpdb->posts.post_password = '') ";
|
348 |
}
|
349 |
-
|
350 |
return $search;
|
351 |
}
|
352 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
353 |
/*
|
354 |
* Get taxonomy parent
|
355 |
*
|
31 |
$this->slots = $this->limit; // Free slots for the results. Default 10
|
32 |
|
33 |
add_filter( 'posts_search', array( $this, 'search_filters' ), 501, 2 );
|
34 |
+
add_filter( 'posts_join', array( $this, 'search_filters_join' ), 501, 2 );
|
35 |
add_filter( 'pre_get_posts', array( $this, 'change_wp_search_size' ), 500 );
|
36 |
|
37 |
|
99 |
'order' => $ordering_args[ 'order' ],
|
100 |
'suppress_filters' => false,
|
101 |
'meta_query' => array(
|
102 |
+
'relation' => 'AND',
|
103 |
+
1 => array(
|
104 |
'key' => '_visibility',
|
105 |
'value' => array( 'search', 'visible' ),
|
106 |
'compare' => 'IN'
|
107 |
+
),
|
108 |
+
2 => array(
|
109 |
+
'relation' => 'OR',
|
110 |
+
array(
|
111 |
+
'key' => '_visibility',
|
112 |
+
'value' => array( 'search', 'visible' ),
|
113 |
+
'compare' => 'IN'
|
114 |
+
)
|
115 |
)
|
116 |
)
|
117 |
);
|
118 |
|
119 |
+
// Exclude out of stock products from suggestions
|
120 |
+
if ( DGWT_WCAS()->settings->get_opt( 'exclude_out_of_stock' ) === 'on' ) {
|
121 |
+
$args[ 'meta_query' ][ 2 ] = array(
|
122 |
+
'key' => '_stock_status',
|
123 |
+
'value' => 'outofstock',
|
124 |
+
'compare' => 'NOT IN'
|
125 |
+
);
|
126 |
+
}
|
127 |
|
128 |
$products = get_posts( $args );
|
129 |
|
156 |
$r[ 'desc' ] = dgwt_wcas_get_product_desc( $product->id, $this->desc_limit );
|
157 |
}
|
158 |
|
159 |
+
// Get SKU
|
160 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_product_sku' ) === 'on' ) {
|
161 |
+
$r[ 'sku' ] = $product->get_sku();
|
162 |
+
}
|
163 |
+
|
164 |
// Is on sale
|
165 |
if ( DGWT_WCAS()->settings->get_opt( 'show_sale_badge' ) === 'on' ) {
|
166 |
$r[ 'on_sale' ] = $product->is_on_sale();
|
183 |
//@todo show 'No results' as option
|
184 |
if ( empty( $results ) ) {
|
185 |
|
186 |
+
$results[] = array(
|
187 |
+
'value' => __( 'No results', DGWT_WCAS_DOMAIN ),
|
188 |
+
);
|
|
|
|
|
189 |
}
|
190 |
|
191 |
//@todo Add results to the wp cache
|
325 |
public function search_filters( $search, &$wp_query ) {
|
326 |
global $wpdb;
|
327 |
|
328 |
+
if ( !defined( 'DGWT_WCAS_AJAX' ) ) {
|
329 |
+
return $search;
|
330 |
+
}
|
331 |
+
|
332 |
if ( empty( $search ) ) {
|
333 |
return $search; // skip processing - no search term in query
|
334 |
}
|
361 |
$search .= " OR ($wpdb->posts.post_excerpt LIKE '{$n}{$term}{$n}')";
|
362 |
}
|
363 |
|
364 |
+
// Search in SKU
|
365 |
+
if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_sku' ) === 'on' ) {
|
366 |
+
$search .= " OR (dgwt_wcasmsku.meta_key='_sku' AND dgwt_wcasmsku.meta_value LIKE '{$n}{$term}{$n}')";
|
367 |
+
}
|
368 |
+
|
369 |
$search .= ")";
|
370 |
|
371 |
$searchand = ' AND ';
|
376 |
if ( !is_user_logged_in() )
|
377 |
$search .= " AND ($wpdb->posts.post_password = '') ";
|
378 |
}
|
379 |
+
|
380 |
return $search;
|
381 |
}
|
382 |
|
383 |
+
/*
|
384 |
+
* Join the postmeta column in the search posts SQL
|
385 |
+
*/
|
386 |
+
|
387 |
+
public function search_filters_join( $join, $query ) {
|
388 |
+
global $wpdb;
|
389 |
+
|
390 |
+
if ( !defined( 'DGWT_WCAS_AJAX' ) ) {
|
391 |
+
return $join;
|
392 |
+
}
|
393 |
+
|
394 |
+
if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_sku' ) === 'on' ) {
|
395 |
+
$join .= " INNER JOIN $wpdb->postmeta AS dgwt_wcasmsku ON ( $wpdb->posts.ID = dgwt_wcasmsku.post_id )";
|
396 |
+
}
|
397 |
+
|
398 |
+
return $join;
|
399 |
+
}
|
400 |
+
|
401 |
/*
|
402 |
* Get taxonomy parent
|
403 |
*
|
includes/register-scripts.php
CHANGED
@@ -38,6 +38,7 @@ class DGWT_WCAS_Scripts {
|
|
38 |
'action_result_details' => DGWT_WCAS_RESULT_DETAILS_ACTION,
|
39 |
'details_box_pos' => DGWT_WCAS()->settings->get_opt( 'details_box_position' ),
|
40 |
'min_chars' => 3,
|
|
|
41 |
'show_details_box' => false,
|
42 |
'show_images' => false,
|
43 |
'show_price' => false,
|
@@ -57,11 +58,17 @@ class DGWT_WCAS_Scripts {
|
|
57 |
//@todo custom endpoint
|
58 |
}
|
59 |
|
60 |
-
|
61 |
$min_chars = DGWT_WCAS()->settings->get_opt( 'min_chars' );
|
62 |
if ( !empty( $min_chars ) && is_numeric( $min_chars ) ) {
|
63 |
$localize[ 'min_chars' ] = absint( $min_chars );
|
64 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
65 |
|
66 |
|
67 |
// Show/hide details BOX
|
@@ -84,6 +91,11 @@ class DGWT_WCAS_Scripts {
|
|
84 |
$localize[ 'show_desc' ] = true;
|
85 |
}
|
86 |
|
|
|
|
|
|
|
|
|
|
|
87 |
// Show/hide sale badge
|
88 |
if ( DGWT_WCAS()->settings->get_opt( 'show_sale_badge' ) === 'on' ) {
|
89 |
$localize[ 'show_sale_badge' ] = true;
|
@@ -93,12 +105,12 @@ class DGWT_WCAS_Scripts {
|
|
93 |
if ( DGWT_WCAS()->settings->get_opt( 'show_featured_badge' ) === 'on' ) {
|
94 |
$localize[ 'show_featured_badge' ] = true;
|
95 |
}
|
96 |
-
|
97 |
// Set preloader
|
98 |
if ( DGWT_WCAS()->settings->get_opt( 'show_preloader' ) === 'on' ) {
|
99 |
$localize[ 'show_preloader' ] = true;
|
100 |
|
101 |
-
$localize[ 'preloader_url' ] = esc_url( trim(DGWT_WCAS()->settings->get_opt( 'preloader_url' )) );
|
102 |
}
|
103 |
|
104 |
if ( DGWT_WCAS_DEBUG === false ) {
|
38 |
'action_result_details' => DGWT_WCAS_RESULT_DETAILS_ACTION,
|
39 |
'details_box_pos' => DGWT_WCAS()->settings->get_opt( 'details_box_position' ),
|
40 |
'min_chars' => 3,
|
41 |
+
'width' => 'auto',
|
42 |
'show_details_box' => false,
|
43 |
'show_images' => false,
|
44 |
'show_price' => false,
|
58 |
//@todo custom endpoint
|
59 |
}
|
60 |
|
61 |
+
// Min characters
|
62 |
$min_chars = DGWT_WCAS()->settings->get_opt( 'min_chars' );
|
63 |
if ( !empty( $min_chars ) && is_numeric( $min_chars ) ) {
|
64 |
$localize[ 'min_chars' ] = absint( $min_chars );
|
65 |
}
|
66 |
+
|
67 |
+
$sug_width = DGWT_WCAS()->settings->get_opt( 'sug_width' );
|
68 |
+
if ( !empty( $sug_width ) && is_numeric( $sug_width ) && $sug_width > 100 ) {
|
69 |
+
$localize[ 'sug_width' ] = absint( $sug_width );
|
70 |
+
}
|
71 |
+
|
72 |
|
73 |
|
74 |
// Show/hide details BOX
|
91 |
$localize[ 'show_desc' ] = true;
|
92 |
}
|
93 |
|
94 |
+
// Show/hide description
|
95 |
+
if ( DGWT_WCAS()->settings->get_opt( 'show_product_sku' ) === 'on' ) {
|
96 |
+
$localize[ 'show_sku' ] = true;
|
97 |
+
}
|
98 |
+
|
99 |
// Show/hide sale badge
|
100 |
if ( DGWT_WCAS()->settings->get_opt( 'show_sale_badge' ) === 'on' ) {
|
101 |
$localize[ 'show_sale_badge' ] = true;
|
105 |
if ( DGWT_WCAS()->settings->get_opt( 'show_featured_badge' ) === 'on' ) {
|
106 |
$localize[ 'show_featured_badge' ] = true;
|
107 |
}
|
108 |
+
|
109 |
// Set preloader
|
110 |
if ( DGWT_WCAS()->settings->get_opt( 'show_preloader' ) === 'on' ) {
|
111 |
$localize[ 'show_preloader' ] = true;
|
112 |
|
113 |
+
$localize[ 'preloader_url' ] = esc_url( trim( DGWT_WCAS()->settings->get_opt( 'preloader_url' ) ) );
|
114 |
}
|
115 |
|
116 |
if ( DGWT_WCAS_DEBUG === false ) {
|
readme.txt
CHANGED
@@ -1,9 +1,10 @@
|
|
1 |
=== Ajax Search for WooCommerce ===
|
2 |
Contributors: damian-gora
|
|
|
3 |
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
|
4 |
Requires at least: 3.8
|
5 |
-
Tested up to: 4.5.
|
6 |
-
Stable tag: 0
|
7 |
License: GPLv2 or later
|
8 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
9 |
|
@@ -28,9 +29,10 @@ See how it works on the [DEMO](http://damiangora.com/ajax-search-for-woocommerce
|
|
28 |
|
29 |
= Features =
|
30 |
* Search in **products titles, descriptions, excerpt, categories, tags or SKU**.
|
31 |
-
* **Product image** displayed for each suggestion
|
32 |
-
* **Price** displayed for each suggestion
|
33 |
-
* **Description** displayed for each suggestion
|
|
|
34 |
* The **'add to cart' button and** and **extended information** displayed when you hover the mouse over the suggestion
|
35 |
* **Categories and tags** as suggestions
|
36 |
* **Limit** displayed suggestions – you can set your own
|
@@ -64,6 +66,14 @@ Any suggestions or comments are welcome. Feel free to contact me using this [con
|
|
64 |
|
65 |
== Changelog ==
|
66 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
67 |
= 0.9.1, June 5, 2016 =
|
68 |
* ADD: Javascript and CSS dynamic compression
|
69 |
* FIX: Incorrect dimensions of the custom preloader
|
1 |
=== Ajax Search for WooCommerce ===
|
2 |
Contributors: damian-gora
|
3 |
+
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=LD2ALVRLXPZPC
|
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 |
|
29 |
|
30 |
= Features =
|
31 |
* Search in **products titles, descriptions, excerpt, categories, tags or SKU**.
|
32 |
+
* **Product image** can be displayed for each suggestion
|
33 |
+
* **Price** can be displayed for each suggestion
|
34 |
+
* **Description** can be displayed for each suggestion
|
35 |
+
* **SKU** can be displayed for each suggestion
|
36 |
* The **'add to cart' button and** and **extended information** displayed when you hover the mouse over the suggestion
|
37 |
* **Categories and tags** as suggestions
|
38 |
* **Limit** displayed suggestions – you can set your own
|
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
|
72 |
+
* NEW: [Option] Show/hide SKU in suggestions
|
73 |
+
* NEW: Add no results note
|
74 |
+
* FIX: Search in products SKU
|
75 |
+
* FIX: Trivial things in CSS and JS files
|
76 |
+
|
77 |
= 0.9.1, June 5, 2016 =
|
78 |
* ADD: Javascript and CSS dynamic compression
|
79 |
* FIX: Incorrect dimensions of the custom preloader
|