Ajax Search for WooCommerce - Version 1.1.4

Version Description

Download this release

Release Info

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

Code changes from version 1.1.3 to 1.1.4

ajax-search-for-woocommerce.php CHANGED
@@ -1,10 +1,10 @@
1
  <?php
2
 
3
  /**
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.1.3
8
  * Author: Damian Góra
9
  * Author URI: http://damiangora.com
10
  * Text Domain: ajax-search-for-woocommerce
@@ -61,34 +61,58 @@ if ( !class_exists( 'DGWT_WC_Ajax_Search' ) ) {
61
  self::$instance = $this;
62
  }
63
 
64
- /*
65
  * Check requirements
66
  */
67
 
68
  private function check_requirements() {
 
69
  if ( version_compare( PHP_VERSION, '5.3.0' ) < 0 ) {
70
  add_action( 'admin_notices', array( $this, 'admin_notice_php' ) );
71
 
72
  return false;
73
  }
74
 
 
 
 
 
 
 
75
  return true;
76
  }
77
 
78
- /*
79
  * Notice: PHP version less than 5.3
80
  */
81
 
82
  public function admin_notice_php() {
83
  ?>
84
- <div class="error">
85
- <p>
86
  <?php
87
  _e( '<b>Ajax Search for WooCommerce</b>: You need PHP version at least 5.3 to run this plugin. You are currently using PHP version ', 'ajax-search-for-woocommerce' );
88
  echo PHP_VERSION . '.';
89
  ?>
90
- </p>
91
- </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
92
  <?php
93
  }
94
 
@@ -97,7 +121,7 @@ if ( !class_exists( 'DGWT_WC_Ajax_Search' ) ) {
97
  */
98
  private function constants() {
99
 
100
- $this->define( 'DGWT_WCAS_VERSION', '1.1.3' );
101
  $this->define( 'DGWT_WCAS_NAME', 'Ajax Search for WooCommerce' );
102
  $this->define( 'DGWT_WCAS_FILE', __FILE__ );
103
  $this->define( 'DGWT_WCAS_DIR', plugin_dir_path( __FILE__ ) );
@@ -146,6 +170,7 @@ if ( !class_exists( 'DGWT_WC_Ajax_Search' ) ) {
146
  require_once DGWT_WCAS_DIR . 'includes/register-scripts.php';
147
 
148
  require_once DGWT_WCAS_DIR . 'includes/admin/admin-menus.php';
 
149
 
150
  require_once DGWT_WCAS_DIR . 'includes/widget.php';
151
  require_once DGWT_WCAS_DIR . 'includes/style.php';
1
  <?php
2
 
3
  /**
4
+ * Plugin Name: AJAX Search for WooCommerce
5
  * Plugin URI: https://wordpress.org/plugins/ajax-search-for-woocommerce/
6
+ * Description: Allows your customers to search products easily and quickly. It will display the results instantly while typing in an inputbox.
7
+ * Version: 1.1.4
8
  * Author: Damian Góra
9
  * Author URI: http://damiangora.com
10
  * Text Domain: ajax-search-for-woocommerce
61
  self::$instance = $this;
62
  }
63
 
64
+ /**
65
  * Check requirements
66
  */
67
 
68
  private function check_requirements() {
69
+
70
  if ( version_compare( PHP_VERSION, '5.3.0' ) < 0 ) {
71
  add_action( 'admin_notices', array( $this, 'admin_notice_php' ) );
72
 
73
  return false;
74
  }
75
 
76
+ if ( !class_exists('WooCommerce')) {
77
+ add_action( 'admin_notices', array( $this, 'admin_notice_no_woocommerce' ) );
78
+
79
+ return false;
80
+ }
81
+
82
  return true;
83
  }
84
 
85
+ /**
86
  * Notice: PHP version less than 5.3
87
  */
88
 
89
  public function admin_notice_php() {
90
  ?>
91
+ <div class="error">
92
+ <p>
93
  <?php
94
  _e( '<b>Ajax Search for WooCommerce</b>: You need PHP version at least 5.3 to run this plugin. You are currently using PHP version ', 'ajax-search-for-woocommerce' );
95
  echo PHP_VERSION . '.';
96
  ?>
97
+ </p>
98
+ </div>
99
+ <?php
100
+ }
101
+
102
+ /**
103
+ * Notice: PHP version less than 5.3
104
+ */
105
+
106
+ public function admin_notice_no_woocommerce() {
107
+ ?>
108
+ <div class="error">
109
+ <p>
110
+ <?php
111
+ printf(__( '<b>Ajax Search for WooCommerce</b> is enabled but not effective. It requires %s in order to work.', 'ajax-search-for-woocommerce' ),
112
+ '<a href="https://pl.wordpress.org/plugins/woocommerce/" target="_blank">WooCommerce</a>');
113
+ ?>
114
+ </p>
115
+ </div>
116
  <?php
117
  }
118
 
121
  */
122
  private function constants() {
123
 
124
+ $this->define( 'DGWT_WCAS_VERSION', '1.1.4' );
125
  $this->define( 'DGWT_WCAS_NAME', 'Ajax Search for WooCommerce' );
126
  $this->define( 'DGWT_WCAS_FILE', __FILE__ );
127
  $this->define( 'DGWT_WCAS_DIR', plugin_dir_path( __FILE__ ) );
170
  require_once DGWT_WCAS_DIR . 'includes/register-scripts.php';
171
 
172
  require_once DGWT_WCAS_DIR . 'includes/admin/admin-menus.php';
173
+ require_once DGWT_WCAS_DIR . 'includes/admin/Promo/FeedbackNotice.php';
174
 
175
  require_once DGWT_WCAS_DIR . 'includes/widget.php';
176
  require_once DGWT_WCAS_DIR . 'includes/style.php';
assets/css/admin-style.css CHANGED
@@ -1,56 +1,127 @@
1
-
2
-
3
- .dgwt-wcas-settings-hr {
4
- display: block;
5
- border-bottom: 1px solid rgba(0,0,0,0.1);
6
- }
7
-
8
-
9
- .dgwt-wcas-settings-group > h2{
10
- display: none;
11
- }
12
- .dgwt-wcas-admin-head {
13
- margin: 30px 0 20px 5px;
14
- }
15
- .dgwt-wcas-admin-head h1 {
16
- display: inline-block;
17
- margin: 0 20px 0 0;
18
- vertical-align: middle;
19
- padding: 0;
20
- }
21
- .wp-core-ui .button.dgwt-wcas-button-preview {
22
- vertical-align: middle;
23
- }
24
- .dgwt-wcas-button-preview .dashicons {
25
- height: 22px;
26
- vertical-align: middle;
27
- margin-right: 5px;
28
- }
29
- .form-table td p.dgwt_wcas_settings-description-field {
30
- color: #777;
31
- display: inline-block;
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{
40
- display: none;
41
- }
42
-
43
-
44
- .dgwt-wcas-settings-info {
45
- background: #fbfbfb none repeat scroll 0 0;
46
- border: 1px solid #ddd;
47
- padding: 15px;
48
- }
49
- .dgwt-wcas-settings-info h4 {
50
- margin-top: 0;
51
- font-size: 15px;
52
- margin-bottom: 7px
53
- }
54
- .dgwt-wcas-settings-info p {
55
- margin-bottom: 10px;
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
56
  }
1
+
2
+
3
+ .dgwt-wcas-settings-hr {
4
+ display: block;
5
+ border-bottom: 1px solid rgba(0,0,0,0.1);
6
+ }
7
+
8
+
9
+ .dgwt-wcas-settings-group > h2{
10
+ display: none;
11
+ }
12
+ .dgwt-wcas-admin-head {
13
+ margin: 30px 0 20px 5px;
14
+ }
15
+ .dgwt-wcas-admin-head h1 {
16
+ display: inline-block;
17
+ margin: 0 20px 0 0;
18
+ vertical-align: middle;
19
+ padding: 0;
20
+ }
21
+ .wp-core-ui .button.dgwt-wcas-button-preview {
22
+ vertical-align: middle;
23
+ }
24
+ .dgwt-wcas-button-preview .dashicons {
25
+ height: 22px;
26
+ vertical-align: middle;
27
+ margin-right: 5px;
28
+ }
29
+ .form-table td p.dgwt_wcas_settings-description-field {
30
+ color: #777;
31
+ display: inline-block;
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{
40
+ display: none;
41
+ }
42
+
43
+
44
+ .dgwt-wcas-settings-info {
45
+ background: #fbfbfb none repeat scroll 0 0;
46
+ border: 1px solid #ddd;
47
+ padding: 15px;
48
+ }
49
+ .dgwt-wcas-settings-info h4 {
50
+ margin-top: 0;
51
+ font-size: 15px;
52
+ margin-bottom: 7px
53
+ }
54
+ .dgwt-wcas-settings-info p {
55
+ margin-bottom: 10px;
56
+ }
57
+
58
+
59
+ .dgwt-wcas-settings-info {
60
+ background: #fbfbfb none repeat scroll 0 0;
61
+ border: 1px solid #ddd;
62
+ padding: 15px;
63
+ }
64
+ .dgwt-wcas-settings-info h4 {
65
+ margin-top: 0;
66
+ font-size: 15px;
67
+ margin-bottom: 7px
68
+ }
69
+ .dgwt-wcas-settings-info p {
70
+ margin-bottom: 10px;
71
+ }
72
+
73
+
74
+ /* Button Container in Review Us Container */
75
+ .dgwt-wcas-review-notice .button-container {
76
+ display: block;
77
+ width: 100%;
78
+ margin: .75em 0 1.5em 0;
79
+ }
80
+
81
+ .dgwt-wcas-review-notice .button-container .dashicons {
82
+ font-size: 14px;
83
+ line-height: 1.9;
84
+ margin-left: -4px;
85
+ }
86
+
87
+ /* Star Icon */
88
+ .dgwt-wcas-review-notice .button-container .dashicons-star-filled {
89
+ color: #E6B800;
90
+ }
91
+
92
+ /* Upgrade Icon */
93
+ .dgwt-wcas-review-notice .button-container .dashicons-upload {
94
+ color: #6E8841;
95
+ }
96
+
97
+ /* Dismiss Icon */
98
+ .dgwt-wcas-review-notice .button-container .dashicons-no-alt {
99
+ color: rgb(220, 58, 58);
100
+ line-height: 2;
101
+ }
102
+
103
+ .dgwt-wcas-review-notice .button-container a {
104
+ margin-right: 10px;
105
+ }
106
+
107
+ /* Dismiss-able Notice */
108
+ .dgwt-wcas-review-notice {
109
+ border-left: 4px solid #00a0d2;
110
+ background: #fefefe;
111
+ padding: 1px 12px;
112
+ padding-top: 10px;
113
+ box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
114
+ -webkit-box-shadow: 0 1px 1px 0 rgba(0,0,0,.1);
115
+ margin: 15px 25px 20px 5px;
116
+ }
117
+
118
+ .dgwt-wcas-review-notice .dgwt-wcas-review-notice-logo {
119
+ background: url('../img/logo-for-review.jpg') no-repeat;
120
+ background-size: 68px;
121
+ float: left;
122
+ margin-top: 5px;
123
+ font-size: 14px;
124
+ height: 80px;
125
+ text-align: center;
126
+ width: 82px;
127
  }
assets/img/logo-for-review.jpg ADDED
Binary file
assets/js/jquery.dgwt-wcas.js CHANGED
@@ -1,1463 +1,1464 @@
1
- /**
2
- * Ajax Autocomplete for jQuery, version 1.2.27
3
- * (c) 2015 Tomas Kirda
4
- *
5
- * Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
6
- * For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
7
- *
8
- * Modified by Damian Góra: http://damiangora.com
9
- */
10
-
11
- /*jslint browser: true, white: true, single: true, this: true, multivar: true */
12
- /*global define, window, document, jQuery, exports, require */
13
-
14
- // Expose plugin as an AMD module if AMD loader is present:
15
- ( function ( factory ) {
16
- "use strict";
17
- if ( typeof define === 'function' && define.amd ) {
18
- // AMD. Register as an anonymous module.
19
- define( [ 'jquery' ], factory );
20
- } else if ( typeof exports === 'object' && typeof require === 'function' ) {
21
- // Browserify
22
- factory( require( 'jquery' ) );
23
- } else {
24
- // Browser globals
25
- factory( jQuery );
26
- }
27
- }( function ( $ ) {
28
- 'use strict';
29
-
30
- var utils = ( function () {
31
- return {
32
- escapeRegExChars: function ( value ) {
33
- return value.replace( /[|\\{}()[\]^$+*?.]/g, "\\$&" );
34
- },
35
- createNode: function ( containerClass ) {
36
- var div = document.createElement( 'div' );
37
- div.className = containerClass;
38
- div.style.position = 'absolute';
39
- div.style.display = 'none';
40
- return div;
41
- }
42
- };
43
- }() ),
44
- keys = {
45
- ESC: 27,
46
- TAB: 9,
47
- RETURN: 13,
48
- LEFT: 37,
49
- UP: 38,
50
- RIGHT: 39,
51
- DOWN: 40
52
- };
53
-
54
- function Autocomplete( el, options ) {
55
- var noop = $.noop,
56
- that = this,
57
- defaults = {
58
- ajaxSettings: { },
59
- autoSelectFirst: false,
60
- appendTo: document.body,
61
- serviceUrl: null,
62
- lookup: null,
63
- onSelect: null,
64
- onMouseOver: null,
65
- onMouseLeave: null,
66
- width: 'auto',
67
- containerDetailsWidth: 'auto',
68
- showDetailsPanel: false,
69
- showImage: false,
70
- showPrice: false,
71
- showSKU: false,
72
- showDescription: false,
73
- showSaleBadge: false,
74
- showFeaturedBadge: false,
75
- saleBadgeText: 'sale',
76
- featuredBadgeText: 'featured',
77
- minChars: 1,
78
- maxHeight: 1000,
79
- deferRequestBy: 0,
80
- params: { },
81
- formatResult: Autocomplete.formatResult,
82
- delimiter: null,
83
- zIndex: 9999,
84
- type: 'GET',
85
- noCache: false,
86
- is_rtl: false,
87
- onSearchStart: noop,
88
- onSearchComplete: noop,
89
- onSearchError: noop,
90
- preserveInput: false,
91
- wrapperaClass: 'dgwt-wcas-search-wrapp',
92
- containerClass: 'dgwt-wcas-suggestions-wrapp',
93
- containerDetailsClass: 'dgwt-wcas-details-wrapp',
94
- cointainerDetailsPos: 'right',
95
- preloaderClass: 'dgwt-wcas-preloader',
96
- closeTrigger: 'dgwt-wcas-close',
97
- tabDisabled: false,
98
- dataType: 'text',
99
- currentRequest: null,
100
- triggerSelectOnValidInput: true,
101
- preventBadQueries: true,
102
- lookupFilter: function ( suggestion, originalQuery, queryLowerCase ) {
103
- return suggestion.value.toLowerCase().indexOf( queryLowerCase ) !== -1;
104
- },
105
- paramName: 'query',
106
- transformResult: function ( response ) {
107
- return typeof response === 'string' ? $.parseJSON( response ) : response;
108
- },
109
- showNoSuggestionNotice: false,
110
- noSuggestionNotice: 'No results',
111
- orientation: 'bottom',
112
- forceFixPosition: false
113
- };
114
-
115
- // Shared variables:
116
- that.element = el;
117
- that.el = $( el );
118
- that.suggestions = [ ];
119
- that.badQueries = [ ];
120
- that.selectedIndex = -1;
121
- that.currentValue = that.element.value;
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;
129
- that.suggestionsContainer = null;
130
- that.detailsContainer = null;
131
- that.noSuggestionsContainer = null;
132
- that.options = $.extend( { }, defaults, options );
133
- that.classes = {
134
- selected: 'dgwt-wcas-suggestion-selected',
135
- suggestion: 'dgwt-wcas-suggestion'
136
- };
137
- that.hint = null;
138
- that.hintValue = '';
139
- that.selection = null;
140
-
141
- // Initialize and set options:
142
- that.initialize();
143
- that.setOptions( options );
144
- }
145
-
146
- Autocomplete.utils = utils;
147
-
148
- $.Autocomplete = Autocomplete;
149
-
150
- Autocomplete.formatResult = function ( suggestionValue, currentValue ) {
151
-
152
- // Do not replace anything if there current value is empty
153
- if ( !currentValue ) {
154
- return suggestionValue;
155
- }
156
- var pattern = '(' + utils.escapeRegExChars( currentValue ) + ')';
157
-
158
- return suggestionValue
159
- .replace( new RegExp( pattern, 'gi' ), '<strong>$1<\/strong>' )
160
- .replace( /&/g, '&amp;' )
161
- .replace( /</g, '&lt;' )
162
- .replace( />/g, '&gt;' )
163
- .replace( /"/g, '&quot;' )
164
- .replace( /&lt;(\/?strong)&gt;/g, '<$1>' );
165
- };
166
-
167
- Autocomplete.prototype = {
168
- killerFn: null,
169
- initialize: function () {
170
- var that = this,
171
- suggestionSelector = '.' + that.classes.suggestion,
172
- selected = that.classes.selected,
173
- options = that.options,
174
- container,
175
- containerDetails,
176
- closeTrigger = '.' + options.closeTrigger;
177
-
178
- // Remove autocomplete attribute to prevent native suggestions:
179
- that.element.setAttribute( 'autocomplete', 'off' );
180
-
181
- that.killerFn = function ( e ) {
182
- if (
183
- $( e.target ).closest( '.' + that.options.containerClass ).length === 0 &&
184
- $( e.target ).closest( '.' + that.options.containerDetailsClass ).length === 0
185
- ) {
186
- that.killSuggestions();
187
- that.disableKillerFn();
188
- }
189
- };
190
-
191
- // html() deals with many types: htmlString or Element or Array or jQuery
192
- that.noSuggestionsContainer = $( '<div class="dgwt-wcas-no-suggestion"></div>' )
193
- .html( this.options.noSuggestionNotice ).get( 0 );
194
-
195
- // Create sugestions container
196
- that.suggestionsContainer = Autocomplete.utils.createNode( options.containerClass );
197
-
198
- container = $( that.suggestionsContainer );
199
-
200
- container.appendTo( that.el.closest( '.' + options.wrapperaClass ) );
201
-
202
- // Add conditiona classes
203
- if ( options.showImage === true )
204
- container.addClass( 'dgwt-wcas-has-img' );
205
- // Price
206
- if ( options.showPrice === true )
207
- container.addClass( 'dgwt-wcas-has-price' );
208
- // Description
209
- if ( options.showDescription === true )
210
- container.addClass( 'dgwt-wcas-has-desc' );
211
- if ( options.showSKU === true )
212
- container.addClass( 'dgwt-wcas-has-sku' );
213
-
214
- // Only set width if it was provided:
215
- if ( options.width !== 'auto' ) {
216
- container.width( options.width );
217
- }
218
-
219
- // Create suggestions details container
220
- if ( options.showDetailsPanel === true ) {
221
- that.detailsContainer = Autocomplete.utils.createNode( options.containerDetailsClass );
222
-
223
- containerDetails = $( that.detailsContainer );
224
-
225
- containerDetails.appendTo( that.el.closest( '.' + options.wrapperaClass ) );
226
- }
227
-
228
-
229
- // Listen for mouse over event on suggestions list:
230
- container.on( 'mouseover.autocomplete', suggestionSelector, function () {
231
- that.onMouseOver( $( this ).data( 'index' ) );
232
- that.activate( $( this ).data( 'index' ) );
233
- } );
234
-
235
- // Deselect active element when mouse leaves suggestions container:
236
- container.on( 'mouseout.autocomplete', function () {
237
- //that.selectedIndex = -1;
238
- // container.children( '.' + selected ).removeClass( selected );
239
- } );
240
-
241
- // Listen for click event on suggestions list:
242
- $( document ).on( 'click.autocomplete', closeTrigger, function ( e ) {
243
- that.killerFn( e );
244
- that.clear( e );
245
- $( this ).removeClass( options.closeTrigger );
246
- that.el.val( '' ).focus();
247
- } );
248
-
249
- // Listen for click close button:
250
- container.on( 'click.autocomplete', suggestionSelector, function () {
251
- that.select( $( this ).data( 'index' ) );
252
- return false;
253
- } );
254
-
255
- that.fixPositionCapture = function () {
256
- if ( that.visible ) {
257
- that.fixPosition();
258
- }
259
- };
260
-
261
- $( window ).on( 'resize.autocomplete', that.fixPositionCapture );
262
-
263
- that.el.on( 'keydown.autocomplete', function ( e ) {
264
- that.onKeyPress( e );
265
- } );
266
- that.el.on( 'keyup.autocomplete', function ( e ) {
267
- that.onKeyUp( e );
268
- } );
269
- that.el.on( 'blur.autocomplete', function () {
270
- that.onBlur();
271
- } );
272
- that.el.on( 'focus.autocomplete', function () {
273
- that.onFocus();
274
- } );
275
- that.el.on( 'change.autocomplete', function ( e ) {
276
- that.onKeyUp( e );
277
- } );
278
- that.el.on( 'input.autocomplete', function ( e ) {
279
- that.onKeyUp( e );
280
- } );
281
- },
282
- onFocus: function () {
283
- var that = this;
284
- that.fixPosition();
285
- if ( that.el.val().length >= that.options.minChars ) {
286
- that.onValueChange();
287
- }
288
- },
289
- onBlur: function () {
290
- this.enableKillerFn();
291
- },
292
- abortAjax: function () {
293
- var that = this;
294
- if ( that.currentRequest ) {
295
- that.currentRequest.abort();
296
- that.currentRequest = null;
297
- }
298
- },
299
- setOptions: function ( suppliedOptions ) {
300
- var that = this,
301
- options = that.options;
302
-
303
- $.extend( options, suppliedOptions );
304
-
305
- that.isLocal = $.isArray( options.lookup );
306
-
307
- if ( that.isLocal ) {
308
- options.lookup = that.verifySuggestionsFormat( options.lookup );
309
- }
310
-
311
- options.orientation = that.validateOrientation( options.orientation, 'bottom' );
312
-
313
- // Adjust height, width and z-index:
314
- $( that.suggestionsContainer ).css( {
315
- 'max-height': options.maxHeight + 'px',
316
- 'width': options.width + 'px',
317
- 'z-index': options.zIndex
318
- } );
319
-
320
- // Add classes
321
- if ( options.showDetailsPanel === true ) {
322
- jQuery( that.suggestionsContainer ).parent().addClass( 'dgwt-wcas-is-details' );
323
- }
324
-
325
- that.options.onSearchComplete = function () {
326
- that.preloader( 'hide', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader' );
327
- that.preloader( 'show', $( '.' + options.preloaderClass ), options.closeTrigger );
328
- };
329
-
330
-
331
- },
332
- clearCache: function () {
333
- this.cachedResponse = { };
334
- this.cachedDetails = { };
335
- this.badQueries = [ ];
336
- },
337
- clear: function () {
338
- this.clearCache();
339
- this.currentValue = '';
340
- this.suggestions = [ ];
341
- },
342
- disable: function () {
343
- var that = this;
344
- that.disabled = true;
345
- clearInterval( that.onChangeInterval );
346
- that.abortAjax();
347
- },
348
- enable: function () {
349
- this.disabled = false;
350
- },
351
- fixPosition: function () {
352
- // Use only when container has already its content
353
- var that = this,
354
- options = that.options,
355
- heigh = 0,
356
- $container = $( that.suggestionsContainer ),
357
- $containerDetails = $( that.detailsContainer ),
358
- containerParent = $container.parent().get( 0 );
359
- // Fix position automatically when appended to body.
360
- // In other cases force parameter must be given.
361
- if ( containerParent !== document.body && !that.options.forceFixPosition ) {
362
- return;
363
- }
364
-
365
- // Choose orientation
366
- var orientation = that.options.orientation,
367
- containerHeight = $container.outerHeight(),
368
- height = that.el.outerHeight(),
369
- offset = that.el.offset(),
370
- styles = { 'top': offset.top, 'left': offset.left };
371
-
372
- if ( orientation === 'auto' ) {
373
- var viewPortHeight = $( window ).height(),
374
- scrollTop = $( window ).scrollTop(),
375
- topOverflow = -scrollTop + offset.top - containerHeight,
376
- bottomOverflow = scrollTop + viewPortHeight - ( offset.top + height + containerHeight );
377
-
378
- orientation = ( Math.max( topOverflow, bottomOverflow ) === topOverflow ) ? 'top' : 'bottom';
379
- }
380
-
381
- if ( orientation === 'top' ) {
382
- styles.top += -containerHeight;
383
- } else {
384
- styles.top += height;
385
- }
386
-
387
- // If container is not positioned to body,
388
- // correct its position using offset parent offset
389
- if ( containerParent !== document.body ) {
390
- var opacity = $container.css( 'opacity' ),
391
- parentOffsetDiff;
392
-
393
- if ( !that.visible ) {
394
- $container.css( 'opacity', 0 ).show();
395
- }
396
-
397
- parentOffsetDiff = $container.offsetParent().offset();
398
- styles.top -= parentOffsetDiff.top;
399
- styles.left -= parentOffsetDiff.left;
400
-
401
- if ( !that.visible ) {
402
- $container.css( 'opacity', opacity ).hide();
403
- }
404
- }
405
-
406
- // -2px to account for suggestions border.
407
- if ( that.options.width === 'auto' ) {
408
- styles.width = ( that.el.outerWidth() - 2 ) + 'px';
409
- }
410
-
411
- $container.css( styles );
412
-
413
- },
414
- fixPositionDetailsBox: function () {
415
-
416
- var that = this,
417
- containerDetails = $( that.detailsContainer );
418
-
419
- if ( containerDetails.length == 0 ) {
420
- return false;
421
- }
422
-
423
- var windowWidth = $( window ).width(),
424
- container = containerDetails.parent(),
425
- containerSugg = containerDetails.prev(),
426
- cDWidth = containerDetails.width(),
427
- cOffset = containerDetails.offset(),
428
- leftBorderCrossed = false,
429
- rightBorderCrossed = false,
430
- maxWidth = 550;
431
-
432
-
433
- // Not set position on the bigger search form
434
- if ( container.width() >= maxWidth ) {
435
- return;
436
- }
437
-
438
-
439
- // Right border crossed
440
- if ( windowWidth < ( cOffset.left + cDWidth ) ) {
441
-
442
- container.removeClass( 'dgwt-wcas-details-right' );
443
- container.addClass( 'dgwt-wcas-details-left' );
444
-
445
- containerDetails.css( 'left', '-' + containerDetails.outerWidth() + 'px' );
446
-
447
- }
448
-
449
- // Left border crossed
450
- if ( cOffset.left < 1 ) {
451
-
452
- container.removeClass( 'dgwt-wcas-details-left' );
453
- container.addClass( 'dgwt-wcas-details-right' );
454
-
455
- containerDetails.css( 'left', containerSugg.outerWidth() + 'px' );
456
- }
457
- },
458
- fixHeight: function ( counter, largestHeight ) {
459
-
460
- var that = this,
461
- options = that.options;
462
-
463
- if ( options.showDetailsPanel != true ) {
464
- return false;
465
- }
466
-
467
- var contSuggestions = $( '.' + options.containerClass ),
468
- contDetails = $( '.' + options.containerDetailsClass ),
469
- sH = 0,
470
- dH = 0,
471
- largestHeight;
472
-
473
- // Height inside a suggestions container
474
- $( '.' + options.containerClass + '> *' ).each( function () {
475
- sH = sH + $( this ).outerHeight();
476
- } );
477
-
478
- // Height inside a suggestions container
479
- $( '.' + options.containerDetailsClass + '> *' ).each( function () {
480
- dH = dH + $( this ).outerHeight();
481
- } );
482
-
483
- if ( sH >= dH ) {
484
- largestHeight = sH;
485
- } else {
486
- largestHeight = dH;
487
- }
488
-
489
- if ( largestHeight > sH || largestHeight > dH ) {
490
- contSuggestions.css( 'height', largestHeight + 'px' );
491
- contDetails.css( 'height', largestHeight + 'px' );
492
- }
493
-
494
- if ( typeof counter === 'undefined' ) {
495
- counter = 0;
496
- }
497
-
498
- // Fix delay
499
- if ( counter < 5 ) {
500
-
501
- setTimeout( function () {
502
- that.fixHeight( counter + 1, largestHeight );
503
-
504
- }, 30 );
505
- } else {
506
- counter = 0;
507
- }
508
- },
509
- enableKillerFn: function () {
510
- var that = this;
511
- $( document ).on( 'click.autocomplete', that.killerFn );
512
- },
513
- disableKillerFn: function () {
514
- var that = this;
515
- $( document ).off( 'click.autocomplete', that.killerFn );
516
- },
517
- killSuggestions: function () {
518
- var that = this,
519
- containerParent = $( that.suggestionsContainer ).parent();
520
- that.stopKillSuggestions();
521
- that.intervalId = window.setInterval( function () {
522
- if ( that.visible ) {
523
-
524
- // No need to restore value when
525
- // preserveInput === true,
526
- // because we did not change it
527
- if ( !that.options.preserveInput ) {
528
- that.el.val( that.currentValue );
529
- }
530
-
531
- that.hide();
532
- containerParent.removeClass( 'dgwt-wcas-open' );
533
- }
534
-
535
- that.stopKillSuggestions();
536
- }, 50 );
537
- },
538
- stopKillSuggestions: function () {
539
- window.clearInterval( this.intervalId );
540
- },
541
- isCursorAtEnd: function () {
542
- var that = this,
543
- valLength = that.el.val().length,
544
- selectionStart = that.element.selectionStart,
545
- range;
546
-
547
- if ( typeof selectionStart === 'number' ) {
548
- return selectionStart === valLength;
549
- }
550
- if ( document.selection ) {
551
- range = document.selection.createRange();
552
- range.moveStart( 'character', -valLength );
553
- return valLength === range.text.length;
554
- }
555
- return true;
556
- },
557
- onKeyPress: function ( e ) {
558
- var that = this;
559
-
560
- // If suggestions are hidden and user presses arrow down, display suggestions:
561
- if ( !that.disabled && !that.visible && e.which === keys.DOWN && that.currentValue ) {
562
- that.suggest();
563
- return;
564
- }
565
-
566
- if ( that.disabled || !that.visible ) {
567
- return;
568
- }
569
-
570
- switch ( e.which ) {
571
- case keys.ESC:
572
- that.el.val( that.currentValue );
573
- that.hide();
574
- break;
575
- case keys.RIGHT:
576
- if ( that.hint && that.options.onHint && that.isCursorAtEnd() ) {
577
- that.selectHint();
578
- break;
579
- }
580
- return;
581
- case keys.TAB:
582
- if ( that.hint && that.options.onHint ) {
583
- that.selectHint();
584
- return;
585
- }
586
- if ( that.selectedIndex === -1 ) {
587
- that.hide();
588
- return;
589
- }
590
- that.select( that.selectedIndex );
591
- if ( that.options.tabDisabled === false ) {
592
- return;
593
- }
594
- break;
595
- case keys.RETURN:
596
- if ( that.selectedIndex === -1 ) {
597
- that.hide();
598
- return;
599
- }
600
- that.select( that.selectedIndex );
601
- break;
602
- case keys.UP:
603
- that.moveUp();
604
- break;
605
- case keys.DOWN:
606
- that.moveDown();
607
- break;
608
- default:
609
- return;
610
- }
611
-
612
- // Cancel event if function did not return:
613
- e.stopImmediatePropagation();
614
- e.preventDefault();
615
- },
616
- onKeyUp: function ( e ) {
617
- var that = this;
618
-
619
- if ( that.disabled ) {
620
- return;
621
- }
622
-
623
- switch ( e.which ) {
624
- case keys.UP:
625
- case keys.DOWN:
626
- return;
627
- }
628
-
629
- clearInterval( that.onChangeInterval );
630
-
631
- if ( that.currentValue !== that.el.val() ) {
632
- that.findBestHint();
633
- if ( that.options.deferRequestBy > 0 ) {
634
- // Defer lookup in case when value changes very quickly:
635
- that.onChangeInterval = setInterval( function () {
636
- that.onValueChange();
637
- }, that.options.deferRequestBy );
638
- } else {
639
- that.onValueChange();
640
- }
641
- }
642
- },
643
- onValueChange: function () {
644
- var that = this,
645
- options = that.options,
646
- value = that.el.val(),
647
- query = that.getQuery( value );
648
-
649
- if ( that.selection && that.currentValue !== query ) {
650
- that.selection = null;
651
- ( options.onInvalidateSelection || $.noop ).call( that.element );
652
- }
653
-
654
- clearInterval( that.onChangeInterval );
655
- that.currentValue = value;
656
- that.selectedIndex = -1;
657
-
658
- // Check existing suggestion for the match before proceeding:
659
- if ( options.triggerSelectOnValidInput && that.isExactMatch( query ) ) {
660
- that.select( 0 );
661
- return;
662
- }
663
-
664
- if ( query.length < options.minChars ) {
665
- $( '.' + that.options.closeTrigger ).removeClass( that.options.closeTrigger );
666
- that.hide();
667
- } else {
668
- that.getSuggestions( query );
669
- }
670
- },
671
- isExactMatch: function ( query ) {
672
- var suggestions = this.suggestions;
673
-
674
- return ( suggestions.length === 1 && suggestions[0].value.toLowerCase() === query.toLowerCase() );
675
- },
676
- getQuery: function ( value ) {
677
- var delimiter = this.options.delimiter,
678
- parts;
679
-
680
- if ( !delimiter ) {
681
- return value;
682
- }
683
- parts = value.split( delimiter );
684
- return $.trim( parts[parts.length - 1] );
685
- },
686
- getSuggestionsLocal: function ( query ) {
687
- var that = this,
688
- options = that.options,
689
- queryLowerCase = query.toLowerCase(),
690
- filter = options.lookupFilter,
691
- limit = parseInt( options.lookupLimit, 10 ),
692
- data;
693
-
694
- data = {
695
- suggestions: $.grep( options.lookup, function ( suggestion ) {
696
- return filter( suggestion, query, queryLowerCase );
697
- } )
698
- };
699
-
700
- if ( limit && data.suggestions.length > limit ) {
701
- data.suggestions = data.suggestions.slice( 0, limit );
702
- }
703
-
704
- return data;
705
- },
706
- getSuggestions: function ( q ) {
707
- var response,
708
- that = this,
709
- options = that.options,
710
- serviceUrl = options.serviceUrl,
711
- params,
712
- cacheKey,
713
- ajaxSettings;
714
-
715
- options.params[options.paramName] = q;
716
- params = options.ignoreParams ? null : options.params;
717
-
718
- that.preloader( 'show', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader' );
719
-
720
- if ( options.onSearchStart.call( that.element, options.params ) === false ) {
721
- return;
722
- }
723
-
724
- if ( $.isFunction( options.lookup ) ) {
725
- options.lookup( q, function ( data ) {
726
- that.suggestions = data.suggestions;
727
- that.suggest();
728
- that.getDetails( data.suggestions[0] );
729
- options.onSearchComplete.call( that.element, q, data.suggestions );
730
- } );
731
- return;
732
- }
733
-
734
- if ( that.isLocal ) {
735
- response = that.getSuggestionsLocal( q );
736
- } else {
737
- if ( $.isFunction( serviceUrl ) ) {
738
- serviceUrl = serviceUrl.call( that.element, q );
739
- }
740
- cacheKey = serviceUrl + '?' + $.param( params || { } );
741
- response = that.cachedResponse[cacheKey];
742
- }
743
-
744
- if ( response && $.isArray( response.suggestions ) ) {
745
- that.suggestions = response.suggestions;
746
- that.suggest();
747
- that.getDetails( response.suggestions[0] );
748
- options.onSearchComplete.call( that.element, q, response.suggestions );
749
- } else if ( !that.isBadQuery( q ) ) {
750
- that.abortAjax();
751
-
752
- ajaxSettings = {
753
- url: serviceUrl,
754
- data: params,
755
- type: options.type,
756
- dataType: options.dataType
757
- };
758
-
759
- $.extend( ajaxSettings, options.ajaxSettings );
760
-
761
- that.currentRequest = $.ajax( ajaxSettings ).done( function ( data ) {
762
- var result;
763
- that.currentRequest = null;
764
- result = options.transformResult( data, q );
765
-
766
- if ( typeof result.suggestions !== 'undefined' ) {
767
- that.processResponse( result, q, cacheKey );
768
- that.getDetails( result.suggestions[0] );
769
- }
770
- options.onSearchComplete.call( that.element, q, result.suggestions );
771
- } ).fail( function ( jqXHR, textStatus, errorThrown ) {
772
- options.onSearchError.call( that.element, q, jqXHR, textStatus, errorThrown );
773
- } );
774
- } else {
775
- options.onSearchComplete.call( that.element, q, [ ] );
776
- }
777
-
778
- },
779
- getDetails: function ( suggestion ) {
780
-
781
- var that = this,
782
- options = that.options;
783
-
784
- // Disable details panel
785
- if ( options.showDetailsPanel != true || $( window ).width() < 992 || ( 'ontouchend' in document ) ) {
786
- return false;
787
- }
788
-
789
- // Brake if there are no suggestions
790
- if ( suggestion == null ) {
791
- return;
792
- }
793
-
794
- var cacheKey,
795
- containerDetails = $( '.' + options.containerDetailsClass ),
796
- result;
797
-
798
- that.fixHeight();
799
-
800
- var data = {
801
- action: dgwt_wcas.action_result_details,
802
- post_id: suggestion.post_id != null ? suggestion.post_id : 0,
803
- term_id: suggestion.term_id != null ? suggestion.term_id : 0,
804
- taxonomy: suggestion.taxonomy != null ? suggestion.taxonomy : '',
805
- value: suggestion.value != null ? suggestion.value : '',
806
- };
807
-
808
- // Add to cache
809
- cacheKey = data.action + data.post_id + data.term_id + data.taxonomy;
810
- result = that.cachedDetails[cacheKey];
811
-
812
- if ( result != null ) {
813
-
814
- // Load response from cache
815
- containerDetails.html( result.details );
816
- that.fixHeight();
817
- that.fixPositionDetailsBox();
818
-
819
- } else {
820
-
821
- containerDetails.html( '' );
822
- that.preloader( 'show', containerDetails, '', true );
823
-
824
- // Prevent duplicate ajax requests
825
- if ( $.inArray( cacheKey, that.detailsRequestsSent ) != -1 ) {
826
- return;
827
- } else {
828
- that.detailsRequestsSent.push( cacheKey );
829
- }
830
-
831
- $.ajax( {
832
- data: data,
833
- type: 'post',
834
- url: dgwt_wcas.ajax_details_endpoint,
835
- success: function ( response ) {
836
-
837
- var result = typeof response === 'string' ? jQuery.parseJSON( response ) : response;
838
-
839
- // Cached response
840
- that.cachedDetails[cacheKey] = result;
841
-
842
- that.preloader( 'hide', containerDetails, '', true );
843
-
844
- if ( result.details != null ) {
845
- containerDetails.html( result.details );
846
- } else {
847
- // @TODO Co wyświetlić w details box gdy napotkamy błąd?
848
- containerDetails.html( '' );
849
- }
850
- that.fixPositionDetailsBox();
851
- that.fixHeight();
852
- },
853
- error: function ( jqXHR, exception ) {
854
-
855
- that.preloader( 'hide', containerDetails, '', true );
856
-
857
- containerDetails.html( jqXHR );
858
- that.fixPositionDetailsBox();
859
- that.fixHeight();
860
- },
861
- } );
862
- }
863
- },
864
- isBadQuery: function ( q ) {
865
- if ( !this.options.preventBadQueries ) {
866
- return false;
867
- }
868
-
869
- var badQueries = this.badQueries,
870
- i = badQueries.length;
871
-
872
- while ( i-- ) {
873
- if ( q.indexOf( badQueries[i] ) === 0 ) {
874
- return true;
875
- }
876
- }
877
-
878
- return false;
879
- },
880
- hide: function () {
881
- var that = this,
882
- container = $( that.suggestionsContainer ),
883
- containerDetails = $( that.detailsContainer );
884
-
885
- if ( $.isFunction( that.options.onHide ) && that.visible ) {
886
- that.options.onHide.call( that.element, container );
887
- }
888
-
889
- that.visible = false;
890
- that.selectedIndex = -1;
891
- clearInterval( that.onChangeInterval );
892
- $( that.suggestionsContainer ).hide();
893
- $( that.detailsContainer ).hide();
894
- that.signalHint( null );
895
- },
896
- suggest: function () {
897
- if (!this.suggestions.length) {
898
- if ( this.options.showNoSuggestionNotice ) {
899
- this.noSuggestions();
900
- } else {
901
- this.hide();
902
- }
903
- return;
904
- }
905
-
906
- var that = this,
907
- options = that.options,
908
- groupBy = options.groupBy,
909
- formatResult = options.formatResult,
910
- value = that.getQuery( that.currentValue ),
911
- className = that.classes.suggestion,
912
- classSelected = that.classes.selected,
913
- container = $( that.suggestionsContainer ),
914
- containerDetails = $( that.detailsContainer ),
915
- noSuggestionsContainer = $( that.noSuggestionsContainer ),
916
- beforeRender = options.beforeRender,
917
- html = '',
918
- category,
919
- formatGroup = function ( suggestion, index ) {
920
- var currentCategory = suggestion.data[groupBy];
921
-
922
- if ( category === currentCategory ) {
923
- return '';
924
- }
925
-
926
- category = currentCategory;
927
-
928
- return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
929
- };
930
-
931
- if ( options.triggerSelectOnValidInput && that.isExactMatch( value ) ) {
932
- that.select( 0 );
933
- return;
934
- }
935
-
936
- // Build suggestions inner HTML:
937
- $.each( that.suggestions, function ( i, suggestion ) {
938
-
939
- var parent = '',
940
- dataAttrs = '',
941
- is_img = false;
942
-
943
- if ( groupBy ) {
944
- html += formatGroup( suggestion, value, i );
945
- }
946
-
947
- if ( typeof suggestion.post_id == 'undefined' ) {
948
- html += '<div class="' + className + ' dgwt-wcas-nores" data-index="'+i+'">';
949
- html += '<span class="dgwt-wcas-st">' + suggestion.value + '</span>';
950
- html += '</div>';
951
- } else {
952
-
953
- if ( typeof suggestion.parents != 'undefined' ) {
954
- parent = suggestion.parents;
955
- }
956
-
957
- // Image
958
- if ( options.showImage === true && typeof suggestion.thumb_html != 'undefined' ) {
959
- is_img = true;
960
- }
961
-
962
- // One suggestion HTML
963
- dataAttrs += typeof suggestion.post_id != 'undefined' ? 'data-post-id="' + suggestion.post_id + '" ' : '';
964
- dataAttrs += typeof suggestion.taxonomy != 'undefined' ? 'data-taxonomy="' + suggestion.taxonomy + '" ' : '';
965
- dataAttrs += typeof suggestion.term_id != 'undefined' ? 'data-term-id="' + suggestion.term_id + '" ' : '';
966
- html += '<div class="' + className + '" data-index="' + i + '" ' + dataAttrs + '>';
967
-
968
- // Image
969
- if ( is_img ) {
970
- html += '<span class="dgwt-wcas-si">' + suggestion.thumb_html + '</span>';
971
- }
972
-
973
-
974
- html += is_img ? '<div class="dgwt-wcas-content-wrapp">' : '';
975
-
976
-
977
- // Title
978
- html += '<span class="dgwt-wcas-st">';
979
- html += '<span>' + formatResult( suggestion.value, value ) + parent + '</span>'
980
- // SKU
981
- if ( options.showSKU === true && typeof suggestion.sku != 'undefined' && suggestion.sku.length > 0 ) {
982
- html += '<span class="dgwt-wcas-sku">(SKU: ' + formatResult( suggestion.sku, value ) + ')</span>';
983
- }
984
- html += '</span>';
985
-
986
- // Price
987
- if ( options.showPrice === true && typeof suggestion.price != 'undefined' ) {
988
- html += '<span class="dgwt-wcas-sp">' + suggestion.price + '</span>';
989
- }
990
-
991
- // Description
992
- if ( options.showDescription === true && typeof suggestion.desc != 'undefined' ) {
993
- html += '<span class="dgwt-wcas-sd">' + formatResult( suggestion.desc, value ) + '</span>';
994
- }
995
-
996
- // On sale product badge
997
- if ( options.showFeaturedBadge === true && suggestion.on_sale === true ) {
998
- html += '<span class="dgwt-wcas-badge dgwt-wcas-badge-os">' + options.saleBadgeText + '</span>';
999
- }
1000
-
1001
- // Featured product badge
1002
- if ( options.showFeaturedBadge === true && suggestion.featured === true ) {
1003
- html += '<span class="dgwt-wcas-badge dgwt-wcas-badge-f">' + options.featuredBadgeText + '</span>';
1004
- }
1005
-
1006
-
1007
- html += is_img ? '</div>' : '';
1008
- html += '</div>';
1009
-
1010
- }
1011
- } );
1012
-
1013
- this.adjustContainerWidth();
1014
-
1015
- noSuggestionsContainer.detach();
1016
- container.html( html );
1017
-
1018
- if ( $.isFunction( beforeRender ) ) {
1019
- beforeRender.call( that.element, container, that.suggestions );
1020
- }
1021
-
1022
- that.fixPosition();
1023
- container.show();
1024
-
1025
- // Add class on show
1026
- container.parent().addClass( 'dgwt-wcas-open' );
1027
-
1028
- if ( options.showDetailsPanel === true ) {
1029
- containerDetails.show();
1030
- }
1031
-
1032
- // Select first value by default:
1033
- if ( options.autoSelectFirst ) {
1034
- that.selectedIndex = 0;
1035
- container.scrollTop( 0 );
1036
- container.children( '.' + className ).first().addClass( classSelected );
1037
- }
1038
-
1039
- that.visible = true;
1040
- that.findBestHint();
1041
- },
1042
- noSuggestions: function () {
1043
- var that = this,
1044
- container = $( that.suggestionsContainer ),
1045
- noSuggestionsContainer = $( that.noSuggestionsContainer );
1046
-
1047
- this.adjustContainerWidth();
1048
-
1049
- // Some explicit steps. Be careful here as it easy to get
1050
- // noSuggestionsContainer removed from DOM if not detached properly.
1051
- noSuggestionsContainer.detach();
1052
- container.empty(); // clean suggestions if any
1053
- container.append( noSuggestionsContainer );
1054
-
1055
- that.fixPosition();
1056
-
1057
- container.show();
1058
- that.visible = true;
1059
- },
1060
- adjustContainerWidth: function () {
1061
- var that = this,
1062
- options = that.options,
1063
- width,
1064
- container = $( that.suggestionsContainer ).parent(),
1065
- containerSugg = $( that.suggestionsContainer ),
1066
- containerDetails = $( that.detailsContainer ),
1067
- maxWidth = 550;
1068
-
1069
- // If width is auto, adjust width before displaying suggestions,
1070
- if ( options.width === 'auto' ) {
1071
- width = that.el.outerWidth();
1072
- containerSugg.css( 'width', width + 'px' );
1073
- }
1074
-
1075
-
1076
- // Set specific style on the bigger search form
1077
- if ( container.width() >= maxWidth && options.showDetailsPanel === true ) {
1078
-
1079
- container.addClass( 'dgwt-wcas-full-width' );
1080
-
1081
- containerSugg.outerWidth( 300 );
1082
- containerDetails.innerWidth( container.width() - 300 );
1083
-
1084
- container.removeClass( 'dgwt-wcas-details-left' );
1085
- container.removeClass( 'dgwt-wcas-details-right' );
1086
-
1087
- if ( options.is_rtl === true ) {
1088
-
1089
- containerDetails.css( 'left', '0' );
1090
- containerSugg.css( 'right', '0' );
1091
- } else {
1092
-
1093
- containerDetails.css( 'right', '0' );
1094
- containerSugg.css( 'left', '0' );
1095
- }
1096
-
1097
-
1098
- return;
1099
- }
1100
-
1101
- if ( options.cointainerDetailsPos === 'left' ) {
1102
- containerDetails.parent().addClass( 'dgwt-wcas-details-left' );
1103
- containerDetails.css( 'left', '-' + containerDetails.outerWidth() + 'px' );
1104
-
1105
- } else {
1106
- containerDetails.parent().addClass( 'dgwt-wcas-details-right' );
1107
- containerDetails.css( 'left', container.outerWidth() + 'px' );
1108
- }
1109
-
1110
- },
1111
- findBestHint: function () {
1112
- var that = this,
1113
- value = that.el.val().toLowerCase(),
1114
- bestMatch = null;
1115
-
1116
- if ( !value ) {
1117
- return;
1118
- }
1119
-
1120
- $.each( that.suggestions, function ( i, suggestion ) {
1121
- var foundMatch = suggestion.value.toLowerCase().indexOf( value ) === 0;
1122
- if ( foundMatch ) {
1123
- bestMatch = suggestion;
1124
- }
1125
- return !foundMatch;
1126
- } );
1127
-
1128
- that.signalHint( bestMatch );
1129
- },
1130
- signalHint: function ( suggestion ) {
1131
- var hintValue = '',
1132
- that = this;
1133
- if ( suggestion ) {
1134
- hintValue = that.currentValue + suggestion.value.substr( that.currentValue.length );
1135
- }
1136
- if ( that.hintValue !== hintValue ) {
1137
- that.hintValue = hintValue;
1138
- that.hint = suggestion;
1139
- ( this.options.onHint || $.noop )( hintValue );
1140
- }
1141
- },
1142
- /*
1143
- * Manages preloader
1144
- *
1145
- * @param action (show or hide)
1146
- * @param container (parent selector)
1147
- * @param cssClass
1148
- * @param detailsBox bool
1149
- */
1150
- preloader: function ( action, container, cssClass, detailsBox ) {
1151
-
1152
- var html,
1153
- defaultClass = 'dgwt-wcas-preloader-wrapp',
1154
- cssClasses = cssClass == null ? defaultClass : defaultClass + ' ' + cssClass;
1155
-
1156
- // Disable preloader and check if container exist
1157
-
1158
- if ( dgwt_wcas.show_preloader != 1 || container.length == 0 ) {
1159
- return;
1160
- }
1161
-
1162
- if ( detailsBox !== true ) {
1163
- if ( action === 'hide' ) {
1164
- container.removeClass( cssClass );
1165
- } else {
1166
- container.addClass( cssClass );
1167
- }
1168
- return;
1169
- }
1170
-
1171
- // Action hide
1172
- if ( action === 'hide' ) {
1173
- $( defaultClass ).remove();
1174
- return
1175
- }
1176
-
1177
- // Action show
1178
- if ( action === 'show' ) {
1179
- html = '<div class="' + cssClasses + '"><div class="dgwt-wcas-default-preloader"></div></div>';
1180
-
1181
- container.html( html );
1182
- }
1183
- },
1184
- verifySuggestionsFormat: function ( suggestions ) {
1185
-
1186
- // If suggestions is string array, convert them to supported format:
1187
- if ( suggestions.length && typeof suggestions[0] === 'string' ) {
1188
- return $.map( suggestions, function ( value ) {
1189
- return { value: value, data: null };
1190
- } );
1191
- }
1192
-
1193
- return suggestions;
1194
- },
1195
- validateOrientation: function ( orientation, fallback ) {
1196
- orientation = $.trim( orientation || '' ).toLowerCase();
1197
-
1198
- if ( $.inArray( orientation, [ 'auto', 'bottom', 'top' ] ) === -1 ) {
1199
- orientation = fallback;
1200
- }
1201
-
1202
- return orientation;
1203
- },
1204
- processResponse: function ( result, originalQuery, cacheKey ) {
1205
- var that = this,
1206
- options = that.options;
1207
-
1208
- result.suggestions = that.verifySuggestionsFormat( result.suggestions );
1209
-
1210
- // Cache results if cache is not disabled:
1211
- if ( !options.noCache ) {
1212
- that.cachedResponse[cacheKey] = result;
1213
- if (options.preventBadQueries && !result.suggestions.length) {
1214
- that.badQueries.push( originalQuery );
1215
- }
1216
- }
1217
-
1218
- // Return if originalQuery is not matching current query:
1219
- if ( originalQuery !== that.getQuery( that.currentValue ) ) {
1220
- return;
1221
- }
1222
-
1223
- that.suggestions = result.suggestions;
1224
- that.suggest();
1225
- },
1226
- activate: function ( index ) {
1227
- var that = this,
1228
- activeItem,
1229
- selected = that.classes.selected,
1230
- container = $( that.suggestionsContainer ),
1231
- children = container.find( '.' + that.classes.suggestion );
1232
-
1233
- container.find( '.' + selected ).removeClass( selected );
1234
-
1235
- that.selectedIndex = index;
1236
-
1237
- if ( that.selectedIndex !== -1 && children.length > that.selectedIndex ) {
1238
- activeItem = children.get( that.selectedIndex );
1239
- $( activeItem ).addClass( selected );
1240
- return activeItem;
1241
- }
1242
-
1243
- return null;
1244
- },
1245
- selectHint: function () {
1246
- var that = this,
1247
- i = $.inArray( that.hint, that.suggestions );
1248
-
1249
- that.select( i );
1250
- },
1251
- select: function ( i ) {
1252
- var that = this;
1253
- that.hide();
1254
- that.onSelect( i );
1255
- that.disableKillerFn();
1256
- },
1257
- moveUp: function () {
1258
- var that = this;
1259
-
1260
- if ( that.selectedIndex === -1 ) {
1261
- return;
1262
- }
1263
-
1264
- if ( that.selectedIndex === 0 ) {
1265
- $( that.suggestionsContainer ).children().first().removeClass( that.classes.selected );
1266
- that.selectedIndex = -1;
1267
- that.el.val( that.currentValue );
1268
- that.findBestHint();
1269
- return;
1270
- }
1271
-
1272
- that.adjustScroll( that.selectedIndex - 1 );
1273
- },
1274
- moveDown: function () {
1275
- var that = this;
1276
-
1277
- if ( that.selectedIndex === ( that.suggestions.length - 1 ) ) {
1278
- return;
1279
- }
1280
-
1281
- that.adjustScroll( that.selectedIndex + 1 );
1282
- },
1283
- adjustScroll: function ( index ) {
1284
- var that = this,
1285
- activeItem = that.activate( index );
1286
-
1287
- if ( !activeItem ) {
1288
- return;
1289
- }
1290
-
1291
- var offsetTop,
1292
- upperBound,
1293
- lowerBound,
1294
- heightDelta = $( activeItem ).outerHeight();
1295
-
1296
- offsetTop = activeItem.offsetTop;
1297
- upperBound = $( that.suggestionsContainer ).scrollTop();
1298
- lowerBound = upperBound + that.options.maxHeight - heightDelta;
1299
-
1300
- if ( offsetTop < upperBound ) {
1301
- $( that.suggestionsContainer ).scrollTop( offsetTop );
1302
- } else if ( offsetTop > lowerBound ) {
1303
- $( that.suggestionsContainer ).scrollTop( offsetTop - that.options.maxHeight + heightDelta );
1304
- }
1305
-
1306
- if ( !that.options.preserveInput ) {
1307
- that.el.val( that.getValue( that.suggestions[index].value ) );
1308
- }
1309
- that.signalHint( null );
1310
- },
1311
- onSelect: function ( index ) {
1312
- var that = this,
1313
- onSelectCallback = that.options.onSelect,
1314
- suggestion = that.suggestions[index];
1315
-
1316
- that.currentValue = that.getValue( suggestion.value );
1317
-
1318
- if ( that.currentValue !== that.el.val() && !that.options.preserveInput ) {
1319
- that.el.val( that.currentValue );
1320
- }
1321
-
1322
- if ( suggestion.id != -1 ) {
1323
- window.location.href = suggestion.url;
1324
- }
1325
-
1326
- that.signalHint( null );
1327
- that.suggestions = [ ];
1328
- that.selection = suggestion;
1329
- if ( $.isFunction( onSelectCallback ) ) {
1330
- onSelectCallback.call( that.element, suggestion );
1331
- }
1332
- },
1333
- onMouseOver: function ( index ) {
1334
- var that = this,
1335
- onMouseOverCallback = that.options.onMouseOver,
1336
- suggestion = that.suggestions[index];
1337
-
1338
- if ( that.selectedIndex !== index ) {
1339
- that.getDetails( suggestion );
1340
- }
1341
-
1342
- if ( $.isFunction( onMouseOverCallback ) ) {
1343
- onMouseOverCallback.call( that.element, suggestion );
1344
- }
1345
- },
1346
- onMouseLeave: function ( index ) {
1347
- var that = this,
1348
- onMouseLeaveCallback = that.options.onMouseLeave,
1349
- suggestion = that.suggestions[index];
1350
-
1351
- if ( $.isFunction( onMouseLeaveCallback ) ) {
1352
- onMouseLeaveCallback.call( that.element, suggestion );
1353
- }
1354
- },
1355
- getValue: function ( value ) {
1356
- var that = this,
1357
- delimiter = that.options.delimiter,
1358
- currentValue,
1359
- parts;
1360
-
1361
- if ( !delimiter ) {
1362
- return value;
1363
- }
1364
-
1365
- currentValue = that.currentValue;
1366
- parts = currentValue.split( delimiter );
1367
-
1368
- if ( parts.length === 1 ) {
1369
- return value;
1370
- }
1371
-
1372
- return currentValue.substr( 0, currentValue.length - parts[parts.length - 1].length ) + value;
1373
- },
1374
- dispose: function () {
1375
- var that = this;
1376
- that.el.off( '.autocomplete' ).removeData( 'autocomplete' );
1377
- that.disableKillerFn();
1378
- $( window ).off( 'resize.autocomplete', that.fixPositionCapture );
1379
- $( that.suggestionsContainer ).remove();
1380
- }
1381
- };
1382
-
1383
-
1384
-
1385
-
1386
- // Create chainable jQuery plugin:
1387
- $.fn.dgwtWcasAutocomplete = function ( options, args ) {
1388
- var dataKey = 'autocomplete';
1389
- // If function invoked without argument return
1390
- // instance of the first matched element:
1391
- if (!arguments.length) {
1392
- return this.first().data( dataKey );
1393
- }
1394
-
1395
- return this.each( function () {
1396
- var inputElement = $( this ),
1397
- instance = inputElement.data( dataKey );
1398
-
1399
- if ( typeof options === 'string' ) {
1400
- if ( instance && typeof instance[options] === 'function' ) {
1401
- instance[options]( args );
1402
- }
1403
- } else {
1404
- // If instance already exists, destroy it:
1405
- if ( instance && instance.dispose ) {
1406
- instance.dispose();
1407
- }
1408
- instance = new Autocomplete( this, options );
1409
- inputElement.data( dataKey, instance );
1410
- }
1411
- } );
1412
- };
1413
-
1414
-
1415
-
1416
- ( function () {
1417
-
1418
- // RUN
1419
- $( document ).ready( function () {
1420
- "use strict";
1421
-
1422
- /*-----------------------------------------------------------------
1423
- /* Positioning search preloader
1424
- /*------------ -----------------------------------------------------*/
1425
- if ( $( '.dgwt-wcas-search-submit' ).length > 0 ) {
1426
- $( '.dgwt-wcas-preloader' ).css( 'right', $( '.dgwt-wcas-search-submit' ).outerWidth() + 'px' );
1427
- }
1428
-
1429
- /*-----------------------------------------------------------------
1430
- /* Fire autocomplete
1431
- /*------------ -----------------------------------------------------*/
1432
- var showDetailsPanel = dgwt_wcas.show_details_box == 1 ? true : false;
1433
-
1434
- // Disable details panel on small screens
1435
- if ( jQuery( window ).width() < 992 || ( 'ontouchend' in document ) ) {
1436
- showDetailsPanel = false;
1437
- }
1438
-
1439
- $( '.dgwt-wcas-search-input' ).dgwtWcasAutocomplete( {
1440
- minChars: dgwt_wcas.min_chars,
1441
- width: dgwt_wcas.sug_width,
1442
- autoSelectFirst: false,
1443
- triggerSelectOnValidInput: false,
1444
- serviceUrl: dgwt_wcas.ajax_search_endpoint,
1445
- paramName: 'dgwt_wcas_keyword',
1446
- showDetailsPanel: showDetailsPanel,
1447
- showImage: dgwt_wcas.show_images == 1 ? true : false,
1448
- showPrice: dgwt_wcas.show_price == 1 ? true : false,
1449
- showDescription: dgwt_wcas.show_desc == 1 ? true : false,
1450
- showSKU: dgwt_wcas.show_sku == 1 ? true : false,
1451
- showSaleBadge: dgwt_wcas.show_sale_badge == 1 ? true : false,
1452
- showFeaturedBadge: dgwt_wcas.show_featured_badge == 1 ? true : false,
1453
- saleBadgeText: dgwt_wcas.t.sale_badge,
1454
- featuredBadgeText: dgwt_wcas.t.featured_badge,
1455
- cointainerDetailsPos: dgwt_wcas.details_box_pos,
1456
- is_rtl: dgwt_wcas.is_rtl == 1 ? true : false
1457
- } );
1458
-
1459
- } );
1460
-
1461
- }() );
1462
-
1463
- } ) );
 
1
+ /**
2
+ * Ajax Autocomplete for jQuery, version 1.2.27
3
+ * (c) 2015 Tomas Kirda
4
+ *
5
+ * Ajax Autocomplete for jQuery is freely distributable under the terms of an MIT-style license.
6
+ * For details, see the web site: https://github.com/devbridge/jQuery-Autocomplete
7
+ *
8
+ * Modified by Damian Góra: http://damiangora.com
9
+ */
10
+
11
+ /*jslint browser: true, white: true, single: true, this: true, multivar: true */
12
+ /*global define, window, document, jQuery, exports, require */
13
+
14
+ // Expose plugin as an AMD module if AMD loader is present:
15
+ ( function ( factory ) {
16
+ "use strict";
17
+ if ( typeof define === 'function' && define.amd ) {
18
+ // AMD. Register as an anonymous module.
19
+ define( [ 'jquery' ], factory );
20
+ } else if ( typeof exports === 'object' && typeof require === 'function' ) {
21
+ // Browserify
22
+ factory( require( 'jquery' ) );
23
+ } else {
24
+ // Browser globals
25
+ factory( jQuery );
26
+ }
27
+ }( function ( $ ) {
28
+ 'use strict';
29
+
30
+ var utils = ( function () {
31
+ return {
32
+ escapeRegExChars: function ( value ) {
33
+ return value.replace( /[|\\{}()[\]^$+*?.]/g, "\\$&" );
34
+ },
35
+ createNode: function ( containerClass ) {
36
+ var div = document.createElement( 'div' );
37
+ div.className = containerClass;
38
+ div.style.position = 'absolute';
39
+ div.style.display = 'none';
40
+ return div;
41
+ }
42
+ };
43
+ }() ),
44
+ keys = {
45
+ ESC: 27,
46
+ TAB: 9,
47
+ RETURN: 13,
48
+ LEFT: 37,
49
+ UP: 38,
50
+ RIGHT: 39,
51
+ DOWN: 40
52
+ };
53
+
54
+ function Autocomplete( el, options ) {
55
+ var noop = $.noop,
56
+ that = this,
57
+ defaults = {
58
+ ajaxSettings: { },
59
+ autoSelectFirst: false,
60
+ appendTo: document.body,
61
+ serviceUrl: null,
62
+ lookup: null,
63
+ onSelect: null,
64
+ onMouseOver: null,
65
+ onMouseLeave: null,
66
+ width: 'auto',
67
+ containerDetailsWidth: 'auto',
68
+ showDetailsPanel: false,
69
+ showImage: false,
70
+ showPrice: false,
71
+ showSKU: false,
72
+ showDescription: false,
73
+ showSaleBadge: false,
74
+ showFeaturedBadge: false,
75
+ saleBadgeText: 'sale',
76
+ featuredBadgeText: 'featured',
77
+ minChars: 1,
78
+ maxHeight: 1000,
79
+ deferRequestBy: 0,
80
+ params: { },
81
+ formatResult: Autocomplete.formatResult,
82
+ delimiter: null,
83
+ zIndex: 9999,
84
+ type: 'GET',
85
+ noCache: false,
86
+ is_rtl: false,
87
+ onSearchStart: noop,
88
+ onSearchComplete: noop,
89
+ onSearchError: noop,
90
+ preserveInput: false,
91
+ wrapperaClass: 'dgwt-wcas-search-wrapp',
92
+ containerClass: 'dgwt-wcas-suggestions-wrapp',
93
+ containerDetailsClass: 'dgwt-wcas-details-wrapp',
94
+ cointainerDetailsPos: 'right',
95
+ preloaderClass: 'dgwt-wcas-preloader',
96
+ closeTrigger: 'dgwt-wcas-close',
97
+ tabDisabled: false,
98
+ dataType: 'text',
99
+ currentRequest: null,
100
+ triggerSelectOnValidInput: true,
101
+ preventBadQueries: true,
102
+ lookupFilter: function ( suggestion, originalQuery, queryLowerCase ) {
103
+ return suggestion.value.toLowerCase().indexOf( queryLowerCase ) !== -1;
104
+ },
105
+ paramName: 'query',
106
+ transformResult: function ( response ) {
107
+ return typeof response === 'string' ? $.parseJSON( response ) : response;
108
+ },
109
+ showNoSuggestionNotice: false,
110
+ noSuggestionNotice: 'No results',
111
+ orientation: 'bottom',
112
+ forceFixPosition: false
113
+ };
114
+
115
+ // Shared variables:
116
+ that.element = el;
117
+ that.el = $( el );
118
+ that.suggestions = [ ];
119
+ that.badQueries = [ ];
120
+ that.selectedIndex = -1;
121
+ that.currentValue = that.element.value;
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;
129
+ that.suggestionsContainer = null;
130
+ that.detailsContainer = null;
131
+ that.noSuggestionsContainer = null;
132
+ that.options = $.extend( { }, defaults, options );
133
+ that.classes = {
134
+ selected: 'dgwt-wcas-suggestion-selected',
135
+ suggestion: 'dgwt-wcas-suggestion'
136
+ };
137
+ that.hint = null;
138
+ that.hintValue = '';
139
+ that.selection = null;
140
+
141
+ // Initialize and set options:
142
+ that.initialize();
143
+ that.setOptions( options );
144
+ }
145
+
146
+ Autocomplete.utils = utils;
147
+
148
+ $.Autocomplete = Autocomplete;
149
+
150
+ Autocomplete.formatResult = function ( suggestionValue, currentValue ) {
151
+
152
+ // Do not replace anything if there current value is empty
153
+ if ( !currentValue ) {
154
+ return suggestionValue;
155
+ }
156
+ var pattern = '(' + utils.escapeRegExChars( currentValue ) + ')';
157
+
158
+ return suggestionValue
159
+ .replace( new RegExp( pattern, 'gi' ), '<strong>$1<\/strong>' )
160
+ .replace( /&/g, '&amp;' )
161
+ .replace( /</g, '&lt;' )
162
+ .replace( />/g, '&gt;' )
163
+ .replace( /"/g, '&quot;' )
164
+ .replace( /&lt;(\/?strong)&gt;/g, '<$1>' );
165
+ };
166
+
167
+ Autocomplete.prototype = {
168
+ killerFn: null,
169
+ initialize: function () {
170
+ var that = this,
171
+ suggestionSelector = '.' + that.classes.suggestion,
172
+ selected = that.classes.selected,
173
+ options = that.options,
174
+ container,
175
+ containerDetails,
176
+ closeTrigger = '.' + options.closeTrigger;
177
+
178
+ // Remove autocomplete attribute to prevent native suggestions:
179
+ that.element.setAttribute( 'autocomplete', 'off' );
180
+
181
+ that.killerFn = function ( e ) {
182
+ if (
183
+ $( e.target ).closest( '.' + that.options.containerClass ).length === 0 &&
184
+ $( e.target ).closest( '.' + that.options.containerDetailsClass ).length === 0
185
+ ) {
186
+ that.killSuggestions();
187
+ that.disableKillerFn();
188
+ }
189
+ };
190
+
191
+ // html() deals with many types: htmlString or Element or Array or jQuery
192
+ that.noSuggestionsContainer = $( '<div class="dgwt-wcas-no-suggestion"></div>' )
193
+ .html( this.options.noSuggestionNotice ).get( 0 );
194
+
195
+ // Create sugestions container
196
+ that.suggestionsContainer = Autocomplete.utils.createNode( options.containerClass );
197
+
198
+ container = $( that.suggestionsContainer );
199
+
200
+ container.appendTo( that.el.closest( '.' + options.wrapperaClass ) );
201
+
202
+ // Add conditiona classes
203
+ if ( options.showImage === true )
204
+ container.addClass( 'dgwt-wcas-has-img' );
205
+ // Price
206
+ if ( options.showPrice === true )
207
+ container.addClass( 'dgwt-wcas-has-price' );
208
+ // Description
209
+ if ( options.showDescription === true )
210
+ container.addClass( 'dgwt-wcas-has-desc' );
211
+ if ( options.showSKU === true )
212
+ container.addClass( 'dgwt-wcas-has-sku' );
213
+
214
+ // Only set width if it was provided:
215
+ if ( options.width !== 'auto' ) {
216
+ container.width( options.width );
217
+ }
218
+
219
+ // Create suggestions details container
220
+ if ( options.showDetailsPanel === true ) {
221
+ that.detailsContainer = Autocomplete.utils.createNode( options.containerDetailsClass );
222
+
223
+ containerDetails = $( that.detailsContainer );
224
+
225
+ containerDetails.appendTo( that.el.closest( '.' + options.wrapperaClass ) );
226
+ }
227
+
228
+
229
+ // Listen for mouse over event on suggestions list:
230
+ container.on( 'mouseover.autocomplete', suggestionSelector, function () {
231
+ that.onMouseOver( $( this ).data( 'index' ) );
232
+ that.activate( $( this ).data( 'index' ) );
233
+ } );
234
+
235
+ // Deselect active element when mouse leaves suggestions container:
236
+ container.on( 'mouseout.autocomplete', function () {
237
+ //that.selectedIndex = -1;
238
+ // container.children( '.' + selected ).removeClass( selected );
239
+ } );
240
+
241
+ // Listen for click event on suggestions list:
242
+ $( document ).on( 'click.autocomplete', closeTrigger, function ( e ) {
243
+ that.killerFn( e );
244
+ that.clear( e );
245
+ $( this ).removeClass( options.closeTrigger );
246
+ that.el.val( '' ).focus();
247
+ } );
248
+
249
+ // Listen for click close button:
250
+ container.on( 'click.autocomplete', suggestionSelector, function () {
251
+ that.select( $( this ).data( 'index' ) );
252
+ return false;
253
+ } );
254
+
255
+ that.fixPositionCapture = function () {
256
+ if ( that.visible ) {
257
+ that.fixPosition();
258
+ }
259
+ };
260
+
261
+ $( window ).on( 'resize.autocomplete', that.fixPositionCapture );
262
+
263
+ that.el.on( 'keydown.autocomplete', function ( e ) {
264
+ that.onKeyPress( e );
265
+ } );
266
+ that.el.on( 'keyup.autocomplete', function ( e ) {
267
+ that.onKeyUp( e );
268
+ } );
269
+ that.el.on( 'blur.autocomplete', function () {
270
+ that.onBlur();
271
+ } );
272
+ that.el.on( 'focus.autocomplete', function () {
273
+ that.onFocus();
274
+ } );
275
+ that.el.on( 'change.autocomplete', function ( e ) {
276
+ that.onKeyUp( e );
277
+ } );
278
+ that.el.on( 'input.autocomplete', function ( e ) {
279
+ that.onKeyUp( e );
280
+ } );
281
+ },
282
+ onFocus: function () {
283
+ var that = this;
284
+ that.fixPosition();
285
+ if ( that.el.val().length >= that.options.minChars ) {
286
+ that.onValueChange();
287
+ }
288
+ },
289
+ onBlur: function () {
290
+ this.enableKillerFn();
291
+ },
292
+ abortAjax: function () {
293
+ var that = this;
294
+ if ( that.currentRequest ) {
295
+ that.currentRequest.abort();
296
+ that.currentRequest = null;
297
+ }
298
+ },
299
+ setOptions: function ( suppliedOptions ) {
300
+ var that = this,
301
+ options = that.options;
302
+
303
+ $.extend( options, suppliedOptions );
304
+
305
+ that.isLocal = $.isArray( options.lookup );
306
+
307
+ if ( that.isLocal ) {
308
+ options.lookup = that.verifySuggestionsFormat( options.lookup );
309
+ }
310
+
311
+ options.orientation = that.validateOrientation( options.orientation, 'bottom' );
312
+
313
+ // Adjust height, width and z-index:
314
+ $( that.suggestionsContainer ).css( {
315
+ 'max-height': options.maxHeight + 'px',
316
+ 'width': options.width + 'px',
317
+ 'z-index': options.zIndex
318
+ } );
319
+
320
+ // Add classes
321
+ if ( options.showDetailsPanel === true ) {
322
+ jQuery( that.suggestionsContainer ).parent().addClass( 'dgwt-wcas-is-details' );
323
+ }
324
+
325
+ that.options.onSearchComplete = function () {
326
+ that.preloader( 'hide', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader' );
327
+ that.preloader( 'show', $( '.' + options.preloaderClass ), options.closeTrigger );
328
+ };
329
+
330
+
331
+ },
332
+ clearCache: function () {
333
+ this.cachedResponse = { };
334
+ this.cachedDetails = { };
335
+ this.badQueries = [ ];
336
+ },
337
+ clear: function () {
338
+ this.clearCache();
339
+ this.currentValue = '';
340
+ this.suggestions = [ ];
341
+ },
342
+ disable: function () {
343
+ var that = this;
344
+ that.disabled = true;
345
+ clearInterval( that.onChangeInterval );
346
+ that.abortAjax();
347
+ },
348
+ enable: function () {
349
+ this.disabled = false;
350
+ },
351
+ fixPosition: function () {
352
+ // Use only when container has already its content
353
+ var that = this,
354
+ options = that.options,
355
+ heigh = 0,
356
+ $container = $( that.suggestionsContainer ),
357
+ $containerDetails = $( that.detailsContainer ),
358
+ containerParent = $container.parent().get( 0 );
359
+ // Fix position automatically when appended to body.
360
+ // In other cases force parameter must be given.
361
+ if ( containerParent !== document.body && !that.options.forceFixPosition ) {
362
+ return;
363
+ }
364
+
365
+ // Choose orientation
366
+ var orientation = that.options.orientation,
367
+ containerHeight = $container.outerHeight(),
368
+ height = that.el.outerHeight(),
369
+ offset = that.el.offset(),
370
+ styles = { 'top': offset.top, 'left': offset.left };
371
+
372
+ if ( orientation === 'auto' ) {
373
+ var viewPortHeight = $( window ).height(),
374
+ scrollTop = $( window ).scrollTop(),
375
+ topOverflow = -scrollTop + offset.top - containerHeight,
376
+ bottomOverflow = scrollTop + viewPortHeight - ( offset.top + height + containerHeight );
377
+
378
+ orientation = ( Math.max( topOverflow, bottomOverflow ) === topOverflow ) ? 'top' : 'bottom';
379
+ }
380
+
381
+ if ( orientation === 'top' ) {
382
+ styles.top += -containerHeight;
383
+ } else {
384
+ styles.top += height;
385
+ }
386
+
387
+ // If container is not positioned to body,
388
+ // correct its position using offset parent offset
389
+ if ( containerParent !== document.body ) {
390
+ var opacity = $container.css( 'opacity' ),
391
+ parentOffsetDiff;
392
+
393
+ if ( !that.visible ) {
394
+ $container.css( 'opacity', 0 ).show();
395
+ }
396
+
397
+ parentOffsetDiff = $container.offsetParent().offset();
398
+ styles.top -= parentOffsetDiff.top;
399
+ styles.left -= parentOffsetDiff.left;
400
+
401
+ if ( !that.visible ) {
402
+ $container.css( 'opacity', opacity ).hide();
403
+ }
404
+ }
405
+
406
+ // -2px to account for suggestions border.
407
+ if ( that.options.width === 'auto' ) {
408
+ styles.width = ( that.el.outerWidth() - 2 ) + 'px';
409
+ }
410
+
411
+ $container.css( styles );
412
+
413
+ },
414
+ fixPositionDetailsBox: function () {
415
+
416
+ var that = this,
417
+ containerDetails = $( that.detailsContainer );
418
+
419
+ if ( containerDetails.length == 0 ) {
420
+ return false;
421
+ }
422
+
423
+ var windowWidth = $( window ).width(),
424
+ container = containerDetails.parent(),
425
+ containerSugg = containerDetails.prev(),
426
+ cDWidth = containerDetails.width(),
427
+ cOffset = containerDetails.offset(),
428
+ leftBorderCrossed = false,
429
+ rightBorderCrossed = false,
430
+ maxWidth = 550;
431
+
432
+
433
+ // Not set position on the bigger search form
434
+ if ( container.width() >= maxWidth ) {
435
+ return;
436
+ }
437
+
438
+
439
+ // Right border crossed
440
+ if ( windowWidth < ( cOffset.left + cDWidth ) ) {
441
+
442
+ container.removeClass( 'dgwt-wcas-details-right' );
443
+ container.addClass( 'dgwt-wcas-details-left' );
444
+
445
+ containerDetails.css( 'left', '-' + containerDetails.outerWidth() + 'px' );
446
+
447
+ }
448
+
449
+ // Left border crossed
450
+ if ( cOffset.left < 1 ) {
451
+
452
+ container.removeClass( 'dgwt-wcas-details-left' );
453
+ container.addClass( 'dgwt-wcas-details-right' );
454
+
455
+ containerDetails.css( 'left', containerSugg.outerWidth() + 'px' );
456
+ }
457
+ },
458
+ fixHeight: function ( counter, largestHeight ) {
459
+
460
+ var that = this,
461
+ options = that.options;
462
+
463
+ if ( options.showDetailsPanel != true ) {
464
+ return false;
465
+ }
466
+
467
+ var contSuggestions = $( '.' + options.containerClass ),
468
+ contDetails = $( '.' + options.containerDetailsClass ),
469
+ sH = 0,
470
+ dH = 0,
471
+ largestHeight;
472
+
473
+ // Height inside a suggestions container
474
+ $( '.' + options.containerClass + '> *' ).each( function () {
475
+ sH = sH + $( this ).outerHeight();
476
+ } );
477
+
478
+ // Height inside a suggestions container
479
+ $( '.' + options.containerDetailsClass + '> *' ).each( function () {
480
+ dH = dH + $( this ).outerHeight();
481
+ } );
482
+
483
+ if ( sH >= dH ) {
484
+ largestHeight = sH;
485
+ } else {
486
+ largestHeight = dH;
487
+ }
488
+
489
+ if ( largestHeight > sH || largestHeight > dH ) {
490
+ contSuggestions.css( 'height', largestHeight + 'px' );
491
+ contDetails.css( 'height', largestHeight + 'px' );
492
+ }
493
+
494
+ if ( typeof counter === 'undefined' ) {
495
+ counter = 0;
496
+ }
497
+
498
+ // Fix delay
499
+ if ( counter < 5 ) {
500
+
501
+ setTimeout( function () {
502
+ that.fixHeight( counter + 1, largestHeight );
503
+
504
+ }, 30 );
505
+ } else {
506
+ counter = 0;
507
+ }
508
+ },
509
+ enableKillerFn: function () {
510
+ var that = this;
511
+ $( document ).on( 'click.autocomplete', that.killerFn );
512
+ },
513
+ disableKillerFn: function () {
514
+ var that = this;
515
+ $( document ).off( 'click.autocomplete', that.killerFn );
516
+ },
517
+ killSuggestions: function () {
518
+ var that = this,
519
+ containerParent = $( that.suggestionsContainer ).parent();
520
+ that.stopKillSuggestions();
521
+ that.intervalId = window.setInterval( function () {
522
+ if ( that.visible ) {
523
+
524
+ // No need to restore value when
525
+ // preserveInput === true,
526
+ // because we did not change it
527
+ if ( !that.options.preserveInput ) {
528
+ that.el.val( that.currentValue );
529
+ }
530
+
531
+ that.hide();
532
+ }
533
+
534
+ that.stopKillSuggestions();
535
+ }, 50 );
536
+ },
537
+ stopKillSuggestions: function () {
538
+ window.clearInterval( this.intervalId );
539
+ },
540
+ isCursorAtEnd: function () {
541
+ var that = this,
542
+ valLength = that.el.val().length,
543
+ selectionStart = that.element.selectionStart,
544
+ range;
545
+
546
+ if ( typeof selectionStart === 'number' ) {
547
+ return selectionStart === valLength;
548
+ }
549
+ if ( document.selection ) {
550
+ range = document.selection.createRange();
551
+ range.moveStart( 'character', -valLength );
552
+ return valLength === range.text.length;
553
+ }
554
+ return true;
555
+ },
556
+ onKeyPress: function ( e ) {
557
+ var that = this;
558
+
559
+ // If suggestions are hidden and user presses arrow down, display suggestions:
560
+ if ( !that.disabled && !that.visible && e.which === keys.DOWN && that.currentValue ) {
561
+ that.suggest();
562
+ return;
563
+ }
564
+
565
+ if ( that.disabled || !that.visible ) {
566
+ return;
567
+ }
568
+
569
+ switch ( e.which ) {
570
+ case keys.ESC:
571
+ that.el.val( that.currentValue );
572
+ that.hide();
573
+ break;
574
+ case keys.RIGHT:
575
+ if ( that.hint && that.options.onHint && that.isCursorAtEnd() ) {
576
+ that.selectHint();
577
+ break;
578
+ }
579
+ return;
580
+ case keys.TAB:
581
+ if ( that.hint && that.options.onHint ) {
582
+ that.selectHint();
583
+ return;
584
+ }
585
+ if ( that.selectedIndex === -1 ) {
586
+ that.hide();
587
+ return;
588
+ }
589
+ that.select( that.selectedIndex );
590
+ if ( that.options.tabDisabled === false ) {
591
+ return;
592
+ }
593
+ break;
594
+ case keys.RETURN:
595
+ if ( that.selectedIndex === -1 ) {
596
+ that.hide();
597
+ return;
598
+ }
599
+ that.select( that.selectedIndex );
600
+ break;
601
+ case keys.UP:
602
+ that.moveUp();
603
+ break;
604
+ case keys.DOWN:
605
+ that.moveDown();
606
+ break;
607
+ default:
608
+ return;
609
+ }
610
+
611
+ // Cancel event if function did not return:
612
+ e.stopImmediatePropagation();
613
+ e.preventDefault();
614
+ },
615
+ onKeyUp: function ( e ) {
616
+ var that = this;
617
+
618
+ if ( that.disabled ) {
619
+ return;
620
+ }
621
+
622
+ switch ( e.which ) {
623
+ case keys.UP:
624
+ case keys.DOWN:
625
+ return;
626
+ }
627
+
628
+ clearInterval( that.onChangeInterval );
629
+
630
+ if ( that.currentValue !== that.el.val() ) {
631
+ that.findBestHint();
632
+ if ( that.options.deferRequestBy > 0 ) {
633
+ // Defer lookup in case when value changes very quickly:
634
+ that.onChangeInterval = setInterval( function () {
635
+ that.onValueChange();
636
+ }, that.options.deferRequestBy );
637
+ } else {
638
+ that.onValueChange();
639
+ }
640
+ }
641
+ },
642
+ onValueChange: function () {
643
+ var that = this,
644
+ options = that.options,
645
+ value = that.el.val(),
646
+ query = that.getQuery( value );
647
+
648
+ if ( that.selection && that.currentValue !== query ) {
649
+ that.selection = null;
650
+ ( options.onInvalidateSelection || $.noop ).call( that.element );
651
+ }
652
+
653
+ clearInterval( that.onChangeInterval );
654
+ that.currentValue = value;
655
+ that.selectedIndex = -1;
656
+
657
+ // Check existing suggestion for the match before proceeding:
658
+ if ( options.triggerSelectOnValidInput && that.isExactMatch( query ) ) {
659
+ that.select( 0 );
660
+ return;
661
+ }
662
+
663
+ if ( query.length < options.minChars ) {
664
+ $( '.' + that.options.closeTrigger ).removeClass( that.options.closeTrigger );
665
+ that.hide();
666
+ } else {
667
+ that.getSuggestions( query );
668
+ }
669
+ },
670
+ isExactMatch: function ( query ) {
671
+ var suggestions = this.suggestions;
672
+
673
+ return ( suggestions.length === 1 && suggestions[0].value.toLowerCase() === query.toLowerCase() );
674
+ },
675
+ getQuery: function ( value ) {
676
+ var delimiter = this.options.delimiter,
677
+ parts;
678
+
679
+ if ( !delimiter ) {
680
+ return value;
681
+ }
682
+ parts = value.split( delimiter );
683
+ return $.trim( parts[parts.length - 1] );
684
+ },
685
+ getSuggestionsLocal: function ( query ) {
686
+ var that = this,
687
+ options = that.options,
688
+ queryLowerCase = query.toLowerCase(),
689
+ filter = options.lookupFilter,
690
+ limit = parseInt( options.lookupLimit, 10 ),
691
+ data;
692
+
693
+ data = {
694
+ suggestions: $.grep( options.lookup, function ( suggestion ) {
695
+ return filter( suggestion, query, queryLowerCase );
696
+ } )
697
+ };
698
+
699
+ if ( limit && data.suggestions.length > limit ) {
700
+ data.suggestions = data.suggestions.slice( 0, limit );
701
+ }
702
+
703
+ return data;
704
+ },
705
+ getSuggestions: function ( q ) {
706
+ var response,
707
+ that = this,
708
+ options = that.options,
709
+ serviceUrl = options.serviceUrl,
710
+ params,
711
+ cacheKey,
712
+ ajaxSettings;
713
+
714
+ options.params[options.paramName] = q;
715
+ params = options.ignoreParams ? null : options.params;
716
+
717
+ that.preloader( 'show', $( '.' + options.preloaderClass ), 'dgwt-wcas-inner-preloader' );
718
+
719
+ if ( options.onSearchStart.call( that.element, options.params ) === false ) {
720
+ return;
721
+ }
722
+
723
+ if ( $.isFunction( options.lookup ) ) {
724
+ options.lookup( q, function ( data ) {
725
+ that.suggestions = data.suggestions;
726
+ that.suggest();
727
+ that.getDetails( data.suggestions[0] );
728
+ options.onSearchComplete.call( that.element, q, data.suggestions );
729
+ } );
730
+ return;
731
+ }
732
+
733
+ if ( that.isLocal ) {
734
+ response = that.getSuggestionsLocal( q );
735
+ } else {
736
+ if ( $.isFunction( serviceUrl ) ) {
737
+ serviceUrl = serviceUrl.call( that.element, q );
738
+ }
739
+ cacheKey = serviceUrl + '?' + $.param( params || { } );
740
+ response = that.cachedResponse[cacheKey];
741
+ }
742
+
743
+ if ( response && $.isArray( response.suggestions ) ) {
744
+ that.suggestions = response.suggestions;
745
+ that.suggest();
746
+ that.getDetails( response.suggestions[0] );
747
+ options.onSearchComplete.call( that.element, q, response.suggestions );
748
+ } else if ( !that.isBadQuery( q ) ) {
749
+ that.abortAjax();
750
+
751
+ ajaxSettings = {
752
+ url: serviceUrl,
753
+ data: params,
754
+ type: options.type,
755
+ dataType: options.dataType
756
+ };
757
+
758
+ $.extend( ajaxSettings, options.ajaxSettings );
759
+
760
+ that.currentRequest = $.ajax( ajaxSettings ).done( function ( data ) {
761
+ var result;
762
+ that.currentRequest = null;
763
+ result = options.transformResult( data, q );
764
+
765
+ if ( typeof result.suggestions !== 'undefined' ) {
766
+ that.processResponse( result, q, cacheKey );
767
+ that.getDetails( result.suggestions[0] );
768
+ }
769
+ options.onSearchComplete.call( that.element, q, result.suggestions );
770
+ } ).fail( function ( jqXHR, textStatus, errorThrown ) {
771
+ options.onSearchError.call( that.element, q, jqXHR, textStatus, errorThrown );
772
+ } );
773
+ } else {
774
+ options.onSearchComplete.call( that.element, q, [ ] );
775
+ }
776
+
777
+ },
778
+ getDetails: function ( suggestion ) {
779
+
780
+ var that = this,
781
+ options = that.options;
782
+
783
+ // Disable details panel
784
+ if ( options.showDetailsPanel != true || $( window ).width() < 992 || ( 'ontouchend' in document ) ) {
785
+ return false;
786
+ }
787
+
788
+ // Brake if there are no suggestions
789
+ if ( suggestion == null ) {
790
+ return;
791
+ }
792
+
793
+ var cacheKey,
794
+ containerDetails = $( '.' + options.containerDetailsClass ),
795
+ result;
796
+
797
+ that.fixHeight();
798
+
799
+ var data = {
800
+ action: dgwt_wcas.action_result_details,
801
+ post_id: suggestion.post_id != null ? suggestion.post_id : 0,
802
+ term_id: suggestion.term_id != null ? suggestion.term_id : 0,
803
+ taxonomy: suggestion.taxonomy != null ? suggestion.taxonomy : '',
804
+ value: suggestion.value != null ? suggestion.value : '',
805
+ };
806
+
807
+ // Add to cache
808
+ cacheKey = data.action + data.post_id + data.term_id + data.taxonomy;
809
+ result = that.cachedDetails[cacheKey];
810
+
811
+ if ( result != null ) {
812
+
813
+ // Load response from cache
814
+ containerDetails.html( result.details );
815
+ that.fixHeight();
816
+ that.fixPositionDetailsBox();
817
+
818
+ } else {
819
+
820
+ containerDetails.html( '' );
821
+ that.preloader( 'show', containerDetails, '', true );
822
+
823
+ // Prevent duplicate ajax requests
824
+ if ( $.inArray( cacheKey, that.detailsRequestsSent ) != -1 ) {
825
+ return;
826
+ } else {
827
+ that.detailsRequestsSent.push( cacheKey );
828
+ }
829
+
830
+ $.ajax( {
831
+ data: data,
832
+ type: 'post',
833
+ url: dgwt_wcas.ajax_details_endpoint,
834
+ success: function ( response ) {
835
+
836
+ var result = typeof response === 'string' ? jQuery.parseJSON( response ) : response;
837
+
838
+ // Cached response
839
+ that.cachedDetails[cacheKey] = result;
840
+
841
+ that.preloader( 'hide', containerDetails, '', true );
842
+
843
+ if ( result.details != null ) {
844
+ containerDetails.html( result.details );
845
+ } else {
846
+ // @TODO Co wyświetlić w details box gdy napotkamy błąd?
847
+ containerDetails.html( '' );
848
+ }
849
+ that.fixPositionDetailsBox();
850
+ that.fixHeight();
851
+ },
852
+ error: function ( jqXHR, exception ) {
853
+
854
+ that.preloader( 'hide', containerDetails, '', true );
855
+
856
+ containerDetails.html( jqXHR );
857
+ that.fixPositionDetailsBox();
858
+ that.fixHeight();
859
+ },
860
+ } );
861
+ }
862
+ },
863
+ isBadQuery: function ( q ) {
864
+ if ( !this.options.preventBadQueries ) {
865
+ return false;
866
+ }
867
+
868
+ var badQueries = this.badQueries,
869
+ i = badQueries.length;
870
+
871
+ while ( i-- ) {
872
+ if ( q.indexOf( badQueries[i] ) === 0 ) {
873
+ return true;
874
+ }
875
+ }
876
+
877
+ return false;
878
+ },
879
+ hide: function () {
880
+ var that = this,
881
+ container = $( that.suggestionsContainer ),
882
+ containerDetails = $( that.detailsContainer ),
883
+ containerParent = $( that.suggestionsContainer ).parent();
884
+
885
+ if ( $.isFunction( that.options.onHide ) && that.visible ) {
886
+ that.options.onHide.call( that.element, container );
887
+ }
888
+
889
+ that.visible = false;
890
+ that.selectedIndex = -1;
891
+ clearInterval( that.onChangeInterval );
892
+ $( that.suggestionsContainer ).hide();
893
+ $( that.detailsContainer ).hide();
894
+ containerParent.removeClass( 'dgwt-wcas-open' );
895
+ that.signalHint( null );
896
+ },
897
+ suggest: function () {
898
+ if (!this.suggestions.length) {
899
+ if ( this.options.showNoSuggestionNotice ) {
900
+ this.noSuggestions();
901
+ } else {
902
+ this.hide();
903
+ }
904
+ return;
905
+ }
906
+
907
+ var that = this,
908
+ options = that.options,
909
+ groupBy = options.groupBy,
910
+ formatResult = options.formatResult,
911
+ value = that.getQuery( that.currentValue ),
912
+ className = that.classes.suggestion,
913
+ classSelected = that.classes.selected,
914
+ container = $( that.suggestionsContainer ),
915
+ containerDetails = $( that.detailsContainer ),
916
+ noSuggestionsContainer = $( that.noSuggestionsContainer ),
917
+ beforeRender = options.beforeRender,
918
+ html = '',
919
+ category,
920
+ formatGroup = function ( suggestion, index ) {
921
+ var currentCategory = suggestion.data[groupBy];
922
+
923
+ if ( category === currentCategory ) {
924
+ return '';
925
+ }
926
+
927
+ category = currentCategory;
928
+
929
+ return '<div class="autocomplete-group"><strong>' + category + '</strong></div>';
930
+ };
931
+
932
+ if ( options.triggerSelectOnValidInput && that.isExactMatch( value ) ) {
933
+ that.select( 0 );
934
+ return;
935
+ }
936
+
937
+ // Build suggestions inner HTML:
938
+ $.each( that.suggestions, function ( i, suggestion ) {
939
+
940
+ var parent = '',
941
+ dataAttrs = '',
942
+ is_img = false;
943
+
944
+ if ( groupBy ) {
945
+ html += formatGroup( suggestion, value, i );
946
+ }
947
+
948
+ if ( typeof suggestion.post_id == 'undefined' ) {
949
+ html += '<div class="' + className + ' dgwt-wcas-nores" data-index="'+i+'">';
950
+ html += '<span class="dgwt-wcas-st">' + suggestion.value + '</span>';
951
+ html += '</div>';
952
+ } else {
953
+
954
+ if ( typeof suggestion.parents != 'undefined' ) {
955
+ parent = suggestion.parents;
956
+ }
957
+
958
+ // Image
959
+ if ( options.showImage === true && typeof suggestion.thumb_html != 'undefined' ) {
960
+ is_img = true;
961
+ }
962
+
963
+ // One suggestion HTML
964
+ dataAttrs += typeof suggestion.post_id != 'undefined' ? 'data-post-id="' + suggestion.post_id + '" ' : '';
965
+ dataAttrs += typeof suggestion.taxonomy != 'undefined' ? 'data-taxonomy="' + suggestion.taxonomy + '" ' : '';
966
+ dataAttrs += typeof suggestion.term_id != 'undefined' ? 'data-term-id="' + suggestion.term_id + '" ' : '';
967
+ html += '<div class="' + className + '" data-index="' + i + '" ' + dataAttrs + '>';
968
+
969
+ // Image
970
+ if ( is_img ) {
971
+ html += '<span class="dgwt-wcas-si">' + suggestion.thumb_html + '</span>';
972
+ }
973
+
974
+
975
+ html += is_img ? '<div class="dgwt-wcas-content-wrapp">' : '';
976
+
977
+
978
+ // Title
979
+ html += '<span class="dgwt-wcas-st">';
980
+ html += '<span>' + formatResult( suggestion.value, value ) + parent + '</span>'
981
+ // SKU
982
+ if ( options.showSKU === true && typeof suggestion.sku != 'undefined' && suggestion.sku.length > 0 ) {
983
+ html += '<span class="dgwt-wcas-sku">(SKU: ' + formatResult( suggestion.sku, value ) + ')</span>';
984
+ }
985
+ html += '</span>';
986
+
987
+ // Price
988
+ if ( options.showPrice === true && typeof suggestion.price != 'undefined' ) {
989
+ html += '<span class="dgwt-wcas-sp">' + suggestion.price + '</span>';
990
+ }
991
+
992
+ // Description
993
+ if ( options.showDescription === true && typeof suggestion.desc != 'undefined' ) {
994
+ html += '<span class="dgwt-wcas-sd">' + formatResult( suggestion.desc, value ) + '</span>';
995
+ }
996
+
997
+ // On sale product badge
998
+ if ( options.showFeaturedBadge === true && suggestion.on_sale === true ) {
999
+ html += '<span class="dgwt-wcas-badge dgwt-wcas-badge-os">' + options.saleBadgeText + '</span>';
1000
+ }
1001
+
1002
+ // Featured product badge
1003
+ if ( options.showFeaturedBadge === true && suggestion.featured === true ) {
1004
+ html += '<span class="dgwt-wcas-badge dgwt-wcas-badge-f">' + options.featuredBadgeText + '</span>';
1005
+ }
1006
+
1007
+
1008
+ html += is_img ? '</div>' : '';
1009
+ html += '</div>';
1010
+
1011
+ }
1012
+ } );
1013
+
1014
+ this.adjustContainerWidth();
1015
+
1016
+ noSuggestionsContainer.detach();
1017
+ container.html( html );
1018
+
1019
+ if ( $.isFunction( beforeRender ) ) {
1020
+ beforeRender.call( that.element, container, that.suggestions );
1021
+ }
1022
+
1023
+ that.fixPosition();
1024
+ container.show();
1025
+
1026
+ // Add class on show
1027
+ container.parent().addClass( 'dgwt-wcas-open' );
1028
+
1029
+ if ( options.showDetailsPanel === true ) {
1030
+ containerDetails.show();
1031
+ }
1032
+
1033
+ // Select first value by default:
1034
+ if ( options.autoSelectFirst ) {
1035
+ that.selectedIndex = 0;
1036
+ container.scrollTop( 0 );
1037
+ container.children( '.' + className ).first().addClass( classSelected );
1038
+ }
1039
+
1040
+ that.visible = true;
1041
+ that.findBestHint();
1042
+ },
1043
+ noSuggestions: function () {
1044
+ var that = this,
1045
+ container = $( that.suggestionsContainer ),
1046
+ noSuggestionsContainer = $( that.noSuggestionsContainer );
1047
+
1048
+ this.adjustContainerWidth();
1049
+
1050
+ // Some explicit steps. Be careful here as it easy to get
1051
+ // noSuggestionsContainer removed from DOM if not detached properly.
1052
+ noSuggestionsContainer.detach();
1053
+ container.empty(); // clean suggestions if any
1054
+ container.append( noSuggestionsContainer );
1055
+
1056
+ that.fixPosition();
1057
+
1058
+ container.show();
1059
+ that.visible = true;
1060
+ },
1061
+ adjustContainerWidth: function () {
1062
+ var that = this,
1063
+ options = that.options,
1064
+ width,
1065
+ container = $( that.suggestionsContainer ).parent(),
1066
+ containerSugg = $( that.suggestionsContainer ),
1067
+ containerDetails = $( that.detailsContainer ),
1068
+ maxWidth = 550;
1069
+
1070
+ // If width is auto, adjust width before displaying suggestions,
1071
+ if ( options.width === 'auto' ) {
1072
+ width = that.el.outerWidth();
1073
+ containerSugg.css( 'width', width + 'px' );
1074
+ }
1075
+
1076
+
1077
+ // Set specific style on the bigger search form
1078
+ if ( container.width() >= maxWidth && options.showDetailsPanel === true ) {
1079
+
1080
+ container.addClass( 'dgwt-wcas-full-width' );
1081
+
1082
+ containerSugg.outerWidth( 300 );
1083
+ containerDetails.innerWidth( container.width() - 300 );
1084
+
1085
+ container.removeClass( 'dgwt-wcas-details-left' );
1086
+ container.removeClass( 'dgwt-wcas-details-right' );
1087
+
1088
+ if ( options.is_rtl === true ) {
1089
+
1090
+ containerDetails.css( 'left', '0' );
1091
+ containerSugg.css( 'right', '0' );
1092
+ } else {
1093
+
1094
+ containerDetails.css( 'right', '0' );
1095
+ containerSugg.css( 'left', '0' );
1096
+ }
1097
+
1098
+
1099
+ return;
1100
+ }
1101
+
1102
+ if ( options.cointainerDetailsPos === 'left' ) {
1103
+ containerDetails.parent().addClass( 'dgwt-wcas-details-left' );
1104
+ containerDetails.css( 'left', '-' + containerDetails.outerWidth() + 'px' );
1105
+
1106
+ } else {
1107
+ containerDetails.parent().addClass( 'dgwt-wcas-details-right' );
1108
+ containerDetails.css( 'left', container.outerWidth() + 'px' );
1109
+ }
1110
+
1111
+ },
1112
+ findBestHint: function () {
1113
+ var that = this,
1114
+ value = that.el.val().toLowerCase(),
1115
+ bestMatch = null;
1116
+
1117
+ if ( !value ) {
1118
+ return;
1119
+ }
1120
+
1121
+ $.each( that.suggestions, function ( i, suggestion ) {
1122
+ var foundMatch = suggestion.value.toLowerCase().indexOf( value ) === 0;
1123
+ if ( foundMatch ) {
1124
+ bestMatch = suggestion;
1125
+ }
1126
+ return !foundMatch;
1127
+ } );
1128
+
1129
+ that.signalHint( bestMatch );
1130
+ },
1131
+ signalHint: function ( suggestion ) {
1132
+ var hintValue = '',
1133
+ that = this;
1134
+ if ( suggestion ) {
1135
+ hintValue = that.currentValue + suggestion.value.substr( that.currentValue.length );
1136
+ }
1137
+ if ( that.hintValue !== hintValue ) {
1138
+ that.hintValue = hintValue;
1139
+ that.hint = suggestion;
1140
+ ( this.options.onHint || $.noop )( hintValue );
1141
+ }
1142
+ },
1143
+ /*
1144
+ * Manages preloader
1145
+ *
1146
+ * @param action (show or hide)
1147
+ * @param container (parent selector)
1148
+ * @param cssClass
1149
+ * @param detailsBox bool
1150
+ */
1151
+ preloader: function ( action, container, cssClass, detailsBox ) {
1152
+
1153
+ var html,
1154
+ defaultClass = 'dgwt-wcas-preloader-wrapp',
1155
+ cssClasses = cssClass == null ? defaultClass : defaultClass + ' ' + cssClass;
1156
+
1157
+ // Disable preloader and check if container exist
1158
+
1159
+ if ( dgwt_wcas.show_preloader != 1 || container.length == 0 ) {
1160
+ return;
1161
+ }
1162
+
1163
+ if ( detailsBox !== true ) {
1164
+ if ( action === 'hide' ) {
1165
+ container.removeClass( cssClass );
1166
+ } else {
1167
+ container.addClass( cssClass );
1168
+ }
1169
+ return;
1170
+ }
1171
+
1172
+ // Action hide
1173
+ if ( action === 'hide' ) {
1174
+ $( defaultClass ).remove();
1175
+ return
1176
+ }
1177
+
1178
+ // Action show
1179
+ if ( action === 'show' ) {
1180
+ html = '<div class="' + cssClasses + '"><div class="dgwt-wcas-default-preloader"></div></div>';
1181
+
1182
+ container.html( html );
1183
+ }
1184
+ },
1185
+ verifySuggestionsFormat: function ( suggestions ) {
1186
+
1187
+ // If suggestions is string array, convert them to supported format:
1188
+ if ( suggestions.length && typeof suggestions[0] === 'string' ) {
1189
+ return $.map( suggestions, function ( value ) {
1190
+ return { value: value, data: null };
1191
+ } );
1192
+ }
1193
+
1194
+ return suggestions;
1195
+ },
1196
+ validateOrientation: function ( orientation, fallback ) {
1197
+ orientation = $.trim( orientation || '' ).toLowerCase();
1198
+
1199
+ if ( $.inArray( orientation, [ 'auto', 'bottom', 'top' ] ) === -1 ) {
1200
+ orientation = fallback;
1201
+ }
1202
+
1203
+ return orientation;
1204
+ },
1205
+ processResponse: function ( result, originalQuery, cacheKey ) {
1206
+ var that = this,
1207
+ options = that.options;
1208
+
1209
+ result.suggestions = that.verifySuggestionsFormat( result.suggestions );
1210
+
1211
+ // Cache results if cache is not disabled:
1212
+ if ( !options.noCache ) {
1213
+ that.cachedResponse[cacheKey] = result;
1214
+ if (options.preventBadQueries && !result.suggestions.length) {
1215
+ that.badQueries.push( originalQuery );
1216
+ }
1217
+ }
1218
+
1219
+ // Return if originalQuery is not matching current query:
1220
+ if ( originalQuery !== that.getQuery( that.currentValue ) ) {
1221
+ return;
1222
+ }
1223
+
1224
+ that.suggestions = result.suggestions;
1225
+ that.suggest();
1226
+ },
1227
+ activate: function ( index ) {
1228
+ var that = this,
1229
+ activeItem,
1230
+ selected = that.classes.selected,
1231
+ container = $( that.suggestionsContainer ),
1232
+ children = container.find( '.' + that.classes.suggestion );
1233
+
1234
+ container.find( '.' + selected ).removeClass( selected );
1235
+
1236
+ that.selectedIndex = index;
1237
+
1238
+ if ( that.selectedIndex !== -1 && children.length > that.selectedIndex ) {
1239
+ activeItem = children.get( that.selectedIndex );
1240
+ $( activeItem ).addClass( selected );
1241
+ return activeItem;
1242
+ }
1243
+
1244
+ return null;
1245
+ },
1246
+ selectHint: function () {
1247
+ var that = this,
1248
+ i = $.inArray( that.hint, that.suggestions );
1249
+
1250
+ that.select( i );
1251
+ },
1252
+ select: function ( i ) {
1253
+ var that = this;
1254
+ that.hide();
1255
+ that.onSelect( i );
1256
+ that.disableKillerFn();
1257
+ },
1258
+ moveUp: function () {
1259
+ var that = this;
1260
+
1261
+ if ( that.selectedIndex === -1 ) {
1262
+ return;
1263
+ }
1264
+
1265
+ if ( that.selectedIndex === 0 ) {
1266
+ $( that.suggestionsContainer ).children().first().removeClass( that.classes.selected );
1267
+ that.selectedIndex = -1;
1268
+ that.el.val( that.currentValue );
1269
+ that.findBestHint();
1270
+ return;
1271
+ }
1272
+
1273
+ that.adjustScroll( that.selectedIndex - 1 );
1274
+ },
1275
+ moveDown: function () {
1276
+ var that = this;
1277
+
1278
+ if ( that.selectedIndex === ( that.suggestions.length - 1 ) ) {
1279
+ return;
1280
+ }
1281
+
1282
+ that.adjustScroll( that.selectedIndex + 1 );
1283
+ },
1284
+ adjustScroll: function ( index ) {
1285
+ var that = this,
1286
+ activeItem = that.activate( index );
1287
+
1288
+ if ( !activeItem ) {
1289
+ return;
1290
+ }
1291
+
1292
+ var offsetTop,
1293
+ upperBound,
1294
+ lowerBound,
1295
+ heightDelta = $( activeItem ).outerHeight();
1296
+
1297
+ offsetTop = activeItem.offsetTop;
1298
+ upperBound = $( that.suggestionsContainer ).scrollTop();
1299
+ lowerBound = upperBound + that.options.maxHeight - heightDelta;
1300
+
1301
+ if ( offsetTop < upperBound ) {
1302
+ $( that.suggestionsContainer ).scrollTop( offsetTop );
1303
+ } else if ( offsetTop > lowerBound ) {
1304
+ $( that.suggestionsContainer ).scrollTop( offsetTop - that.options.maxHeight + heightDelta );
1305
+ }
1306
+
1307
+ if ( !that.options.preserveInput ) {
1308
+ that.el.val( that.getValue( that.suggestions[index].value ) );
1309
+ }
1310
+ that.signalHint( null );
1311
+ },
1312
+ onSelect: function ( index ) {
1313
+ var that = this,
1314
+ onSelectCallback = that.options.onSelect,
1315
+ suggestion = that.suggestions[index];
1316
+
1317
+ that.currentValue = that.getValue( suggestion.value );
1318
+
1319
+ if ( that.currentValue !== that.el.val() && !that.options.preserveInput ) {
1320
+ that.el.val( that.currentValue );
1321
+ }
1322
+
1323
+ if ( suggestion.id != -1 ) {
1324
+ window.location.href = suggestion.url;
1325
+ }
1326
+
1327
+ that.signalHint( null );
1328
+ that.suggestions = [ ];
1329
+ that.selection = suggestion;
1330
+ if ( $.isFunction( onSelectCallback ) ) {
1331
+ onSelectCallback.call( that.element, suggestion );
1332
+ }
1333
+ },
1334
+ onMouseOver: function ( index ) {
1335
+ var that = this,
1336
+ onMouseOverCallback = that.options.onMouseOver,
1337
+ suggestion = that.suggestions[index];
1338
+
1339
+ if ( that.selectedIndex !== index ) {
1340
+ that.getDetails( suggestion );
1341
+ }
1342
+
1343
+ if ( $.isFunction( onMouseOverCallback ) ) {
1344
+ onMouseOverCallback.call( that.element, suggestion );
1345
+ }
1346
+ },
1347
+ onMouseLeave: function ( index ) {
1348
+ var that = this,
1349
+ onMouseLeaveCallback = that.options.onMouseLeave,
1350
+ suggestion = that.suggestions[index];
1351
+
1352
+ if ( $.isFunction( onMouseLeaveCallback ) ) {
1353
+ onMouseLeaveCallback.call( that.element, suggestion );
1354
+ }
1355
+ },
1356
+ getValue: function ( value ) {
1357
+ var that = this,
1358
+ delimiter = that.options.delimiter,
1359
+ currentValue,
1360
+ parts;
1361
+
1362
+ if ( !delimiter ) {
1363
+ return value;
1364
+ }
1365
+
1366
+ currentValue = that.currentValue;
1367
+ parts = currentValue.split( delimiter );
1368
+
1369
+ if ( parts.length === 1 ) {
1370
+ return value;
1371
+ }
1372
+
1373
+ return currentValue.substr( 0, currentValue.length - parts[parts.length - 1].length ) + value;
1374
+ },
1375
+ dispose: function () {
1376
+ var that = this;
1377
+ that.el.off( '.autocomplete' ).removeData( 'autocomplete' );
1378
+ that.disableKillerFn();
1379
+ $( window ).off( 'resize.autocomplete', that.fixPositionCapture );
1380
+ $( that.suggestionsContainer ).remove();
1381
+ }
1382
+ };
1383
+
1384
+
1385
+
1386
+
1387
+ // Create chainable jQuery plugin:
1388
+ $.fn.dgwtWcasAutocomplete = function ( options, args ) {
1389
+ var dataKey = 'autocomplete';
1390
+ // If function invoked without argument return
1391
+ // instance of the first matched element:
1392
+ if (!arguments.length) {
1393
+ return this.first().data( dataKey );
1394
+ }
1395
+
1396
+ return this.each( function () {
1397
+ var inputElement = $( this ),
1398
+ instance = inputElement.data( dataKey );
1399
+
1400
+ if ( typeof options === 'string' ) {
1401
+ if ( instance && typeof instance[options] === 'function' ) {
1402
+ instance[options]( args );
1403
+ }
1404
+ } else {
1405
+ // If instance already exists, destroy it:
1406
+ if ( instance && instance.dispose ) {
1407
+ instance.dispose();
1408
+ }
1409
+ instance = new Autocomplete( this, options );
1410
+ inputElement.data( dataKey, instance );
1411
+ }
1412
+ } );
1413
+ };
1414
+
1415
+
1416
+
1417
+ ( function () {
1418
+
1419
+ // RUN
1420
+ $( document ).ready( function () {
1421
+ "use strict";
1422
+
1423
+ /*-----------------------------------------------------------------
1424
+ /* Positioning search preloader
1425
+ /*------------ -----------------------------------------------------*/
1426
+ if ( $( '.dgwt-wcas-search-submit' ).length > 0 ) {
1427
+ $( '.dgwt-wcas-preloader' ).css( 'right', $( '.dgwt-wcas-search-submit' ).outerWidth() + 'px' );
1428
+ }
1429
+
1430
+ /*-----------------------------------------------------------------
1431
+ /* Fire autocomplete
1432
+ /*------------ -----------------------------------------------------*/
1433
+ var showDetailsPanel = dgwt_wcas.show_details_box == 1 ? true : false;
1434
+
1435
+ // Disable details panel on small screens
1436
+ if ( jQuery( window ).width() < 992 || ( 'ontouchend' in document ) ) {
1437
+ showDetailsPanel = false;
1438
+ }
1439
+
1440
+ $( '.dgwt-wcas-search-input' ).dgwtWcasAutocomplete( {
1441
+ minChars: dgwt_wcas.min_chars,
1442
+ width: dgwt_wcas.sug_width,
1443
+ autoSelectFirst: false,
1444
+ triggerSelectOnValidInput: false,
1445
+ serviceUrl: dgwt_wcas.ajax_search_endpoint,
1446
+ paramName: 'dgwt_wcas_keyword',
1447
+ showDetailsPanel: showDetailsPanel,
1448
+ showImage: dgwt_wcas.show_images == 1 ? true : false,
1449
+ showPrice: dgwt_wcas.show_price == 1 ? true : false,
1450
+ showDescription: dgwt_wcas.show_desc == 1 ? true : false,
1451
+ showSKU: dgwt_wcas.show_sku == 1 ? true : false,
1452
+ showSaleBadge: dgwt_wcas.show_sale_badge == 1 ? true : false,
1453
+ showFeaturedBadge: dgwt_wcas.show_featured_badge == 1 ? true : false,
1454
+ saleBadgeText: dgwt_wcas.t.sale_badge,
1455
+ featuredBadgeText: dgwt_wcas.t.featured_badge,
1456
+ cointainerDetailsPos: dgwt_wcas.details_box_pos,
1457
+ is_rtl: dgwt_wcas.is_rtl == 1 ? true : false
1458
+ } );
1459
+
1460
+ } );
1461
+
1462
+ }() );
1463
+
1464
+ } ) );
assets/js/jquery.dgwt-wcas.min.js CHANGED
@@ -1 +1 @@
1
- !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=e.noop,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){if(!t)return e;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=this,i="."+n.classes.suggestion,o=(n.classes.selected,n.options),a="."+o.closeTrigger;n.element.setAttribute("autocomplete","off"),n.killerFn=function(t){0===e(t.target).closest("."+n.options.containerClass).length&&0===e(t.target).closest("."+n.options.containerDetailsClass).length&&(n.killSuggestions(),n.disableKillerFn())},n.noSuggestionsContainer=e('<div class="dgwt-wcas-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),n.suggestionsContainer=t.utils.createNode(o.containerClass),(s=e(n.suggestionsContainer)).appendTo(n.el.closest("."+o.wrapperaClass)),!0===o.showImage&&s.addClass("dgwt-wcas-has-img"),!0===o.showPrice&&s.addClass("dgwt-wcas-has-price"),!0===o.showDescription&&s.addClass("dgwt-wcas-has-desc"),!0===o.showSKU&&s.addClass("dgwt-wcas-has-sku"),"auto"!==o.width&&s.width(o.width),!0===o.showDetailsPanel&&(n.detailsContainer=t.utils.createNode(o.containerDetailsClass),e(n.detailsContainer).appendTo(n.el.closest("."+o.wrapperaClass))),s.on("mouseover.autocomplete",i,function(){n.onMouseOver(e(this).data("index")),n.activate(e(this).data("index"))}),s.on("mouseout.autocomplete",function(){}),e(document).on("click.autocomplete",a,function(t){n.killerFn(t),n.clear(t),e(this).removeClass(o.closeTrigger),n.el.val("").focus()}),s.on("click.autocomplete",i,function(){return n.select(e(this).data("index")),!1}),n.fixPositionCapture=function(){n.visible&&n.fixPosition()},e(window).on("resize.autocomplete",n.fixPositionCapture),n.el.on("keydown.autocomplete",function(e){n.onKeyPress(e)}),n.el.on("keyup.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("blur.autocomplete",function(){n.onBlur()}),n.el.on("focus.autocomplete",function(){n.onFocus()}),n.el.on("change.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("input.autocomplete",function(e){n.onKeyUp(e)})},onFocus:function(){var e=this;e.fixPosition(),e.el.val().length>=e.options.minChars&&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}),!0===n.showDetailsPanel&&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(r.top+="top"===i?-o: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=e(this.detailsContainer);if(0==t.length)return!1;var s=e(window).width(),n=t.parent(),i=t.prev(),o=t.width(),a=t.offset();n.width()>=550||(s<a.left+o&&(n.removeClass("dgwt-wcas-details-right"),n.addClass("dgwt-wcas-details-left"),t.css("left","-"+t.outerWidth()+"px")),a.left<1&&(n.removeClass("dgwt-wcas-details-left"),n.addClass("dgwt-wcas-details-right"),t.css("left",i.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)>l||s>r)&&(o.css("height",s+"px"),a.css("height",s+"px")),void 0===t&&(t=0),t<5?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.options.preserveInput||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()).moveStart("character",-s),s===e.text.length)},onKeyPress:function(e){var t=this;if(t.disabled||t.visible||e.which!==n.DOWN||!t.currentValue){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),!1===t.options.tabDisabled)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()}}else t.suggest()},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);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)?t.select(0):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.options,i=t.toLowerCase(),o=n.lookupFilter,a=parseInt(n.lookupLimit,10);return s={suggestions:e.grep(n.lookup,function(e){return o(e,t,i)})},a&&s.suggestions.length>a&&(s.suggestions=s.suggestions.slice(0,a)),s},getSuggestions:function(t){var s,n,i,o,a=this,l=a.options,r=l.serviceUrl;l.params[l.paramName]=t,n=l.ignoreParams?null:l.params,a.preloader("show",e("."+l.preloaderClass),"dgwt-wcas-inner-preloader"),!1!==l.onSearchStart.call(a.element,l.params)&&(e.isFunction(l.lookup)?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,void 0!==(s=l.transformResult(e,t)).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,null!=(o=s.cachedDetails[i]))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(""),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(this.suggestions.length){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?"":'<div class="autocomplete-group"><strong>'+(t=n)+"</strong></div>"};n.triggerSelectOnValidInput&&s.isExactMatch(a)?s.select(0):(e.each(s.suggestions,function(e,t){var s="",r="",u=!1;i&&(h+=p(t,0)),void 0===t.post_id?(h+='<div class="'+l+' dgwt-wcas-nores" data-index="'+e+'">',h+='<span class="dgwt-wcas-st">'+t.value+"</span>",h+="</div>"):(void 0!==t.parents&&(s=t.parents),!0===n.showImage&&void 0!==t.thumb_html&&(u=!0),r+=void 0!==t.post_id?'data-post-id="'+t.post_id+'" ':"",r+=void 0!==t.taxonomy?'data-taxonomy="'+t.taxonomy+'" ':"",r+=void 0!==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>",!0===n.showSKU&&void 0!==t.sku&&t.sku.length>0&&(h+='<span class="dgwt-wcas-sku">(SKU: '+o(t.sku,a)+")</span>"),h+="</span>",!0===n.showPrice&&void 0!==t.price&&(h+='<span class="dgwt-wcas-sp">'+t.price+"</span>"),!0===n.showDescription&&void 0!==t.desc&&(h+='<span class="dgwt-wcas-sd">'+o(t.desc,a)+"</span>"),!0===n.showFeaturedBadge&&!0===t.on_sale&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-os">'+n.saleBadgeText+"</span>"),!0===n.showFeaturedBadge&&!0===t.featured&&(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.suggestions),s.fixPosition(),u.show(),u.parent().addClass("dgwt-wcas-open"),!0===n.showDetailsPanel&&c.show(),n.autoSelectFirst&&(s.selectedIndex=0,u.scrollTop(0),u.children("."+l).first().addClass(r)),s.visible=!0,s.findBestHint())}else this.options.showNoSuggestionNotice?this.noSuggestions():this.hide()},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);if("auto"===n.width&&(t=s.el.outerWidth(),o.css("width",t+"px")),i.width()>=550&&!0===n.showDetailsPanel)return 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(!0===n.is_rtl?(a.css("left","0"),o.css("right","0")):(a.css("right","0"),o.css("left","0")));"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;1==dgwt_wcas.show_preloader&&0!=s.length&&(!0===i?"hide"!==t?"show"===t&&(o='<div class="'+l+'"><div class="dgwt-wcas-default-preloader"></div></div>',s.html(o)):e(a).remove():"hide"===t?s.removeClass(n):s.addClass(n))},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&&!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),t.disableKillerFn()},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,a=(o=e(s.suggestionsContainer).scrollTop())+s.options.maxHeight-l,i<o?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){return arguments.length?this.each(function(){var i=e(this),o=i.data("autocomplete");"string"==typeof s?o&&"function"==typeof o[s]&&o[s](n):(o&&o.dispose&&o.dispose(),o=new t(this,s),i.data("autocomplete",o))}):this.first().data("autocomplete")},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;(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:!1,triggerSelectOnValidInput:!1,serviceUrl:dgwt_wcas.ajax_search_endpoint,paramName:"dgwt_wcas_keyword",showDetailsPanel:t,showImage:1==dgwt_wcas.show_images,showPrice:1==dgwt_wcas.show_price,showDescription:1==dgwt_wcas.show_desc,showSKU:1==dgwt_wcas.show_sku,showSaleBadge:1==dgwt_wcas.show_sale_badge,showFeaturedBadge:1==dgwt_wcas.show_featured_badge,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})})}()});
1
+ !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=e.noop,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){if(!t)return e;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=this,i="."+n.classes.suggestion,o=(n.classes.selected,n.options),a="."+o.closeTrigger;n.element.setAttribute("autocomplete","off"),n.killerFn=function(t){0===e(t.target).closest("."+n.options.containerClass).length&&0===e(t.target).closest("."+n.options.containerDetailsClass).length&&(n.killSuggestions(),n.disableKillerFn())},n.noSuggestionsContainer=e('<div class="dgwt-wcas-no-suggestion"></div>').html(this.options.noSuggestionNotice).get(0),n.suggestionsContainer=t.utils.createNode(o.containerClass),(s=e(n.suggestionsContainer)).appendTo(n.el.closest("."+o.wrapperaClass)),!0===o.showImage&&s.addClass("dgwt-wcas-has-img"),!0===o.showPrice&&s.addClass("dgwt-wcas-has-price"),!0===o.showDescription&&s.addClass("dgwt-wcas-has-desc"),!0===o.showSKU&&s.addClass("dgwt-wcas-has-sku"),"auto"!==o.width&&s.width(o.width),!0===o.showDetailsPanel&&(n.detailsContainer=t.utils.createNode(o.containerDetailsClass),e(n.detailsContainer).appendTo(n.el.closest("."+o.wrapperaClass))),s.on("mouseover.autocomplete",i,function(){n.onMouseOver(e(this).data("index")),n.activate(e(this).data("index"))}),s.on("mouseout.autocomplete",function(){}),e(document).on("click.autocomplete",a,function(t){n.killerFn(t),n.clear(t),e(this).removeClass(o.closeTrigger),n.el.val("").focus()}),s.on("click.autocomplete",i,function(){return n.select(e(this).data("index")),!1}),n.fixPositionCapture=function(){n.visible&&n.fixPosition()},e(window).on("resize.autocomplete",n.fixPositionCapture),n.el.on("keydown.autocomplete",function(e){n.onKeyPress(e)}),n.el.on("keyup.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("blur.autocomplete",function(){n.onBlur()}),n.el.on("focus.autocomplete",function(){n.onFocus()}),n.el.on("change.autocomplete",function(e){n.onKeyUp(e)}),n.el.on("input.autocomplete",function(e){n.onKeyUp(e)})},onFocus:function(){var e=this;e.fixPosition(),e.el.val().length>=e.options.minChars&&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}),!0===n.showDetailsPanel&&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(r.top+="top"===i?-o: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=e(this.detailsContainer);if(0==t.length)return!1;var s=e(window).width(),n=t.parent(),i=t.prev(),o=t.width(),a=t.offset();n.width()>=550||(s<a.left+o&&(n.removeClass("dgwt-wcas-details-right"),n.addClass("dgwt-wcas-details-left"),t.css("left","-"+t.outerWidth()+"px")),a.left<1&&(n.removeClass("dgwt-wcas-details-left"),n.addClass("dgwt-wcas-details-right"),t.css("left",i.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)>l||s>r)&&(o.css("height",s+"px"),a.css("height",s+"px")),void 0===t&&(t=0),t<5?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;e(t.suggestionsContainer).parent();t.stopKillSuggestions(),t.intervalId=window.setInterval(function(){t.visible&&(t.options.preserveInput||t.el.val(t.currentValue),t.hide()),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()).moveStart("character",-s),s===e.text.length)},onKeyPress:function(e){var t=this;if(t.disabled||t.visible||e.which!==n.DOWN||!t.currentValue){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),!1===t.options.tabDisabled)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()}}else t.suggest()},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);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)?t.select(0):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.options,i=t.toLowerCase(),o=n.lookupFilter,a=parseInt(n.lookupLimit,10);return s={suggestions:e.grep(n.lookup,function(e){return o(e,t,i)})},a&&s.suggestions.length>a&&(s.suggestions=s.suggestions.slice(0,a)),s},getSuggestions:function(t){var s,n,i,o,a=this,l=a.options,r=l.serviceUrl;l.params[l.paramName]=t,n=l.ignoreParams?null:l.params,a.preloader("show",e("."+l.preloaderClass),"dgwt-wcas-inner-preloader"),!1!==l.onSearchStart.call(a.element,l.params)&&(e.isFunction(l.lookup)?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,void 0!==(s=l.transformResult(e,t)).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,null!=(o=s.cachedDetails[i]))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(""),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),n=(e(t.detailsContainer),e(t.suggestionsContainer).parent());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(),n.removeClass("dgwt-wcas-open"),t.signalHint(null)},suggest:function(){if(this.suggestions.length){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?"":'<div class="autocomplete-group"><strong>'+(t=n)+"</strong></div>"};n.triggerSelectOnValidInput&&s.isExactMatch(a)?s.select(0):(e.each(s.suggestions,function(e,t){var s="",r="",u=!1;i&&(h+=p(t,0)),void 0===t.post_id?(h+='<div class="'+l+' dgwt-wcas-nores" data-index="'+e+'">',h+='<span class="dgwt-wcas-st">'+t.value+"</span>",h+="</div>"):(void 0!==t.parents&&(s=t.parents),!0===n.showImage&&void 0!==t.thumb_html&&(u=!0),r+=void 0!==t.post_id?'data-post-id="'+t.post_id+'" ':"",r+=void 0!==t.taxonomy?'data-taxonomy="'+t.taxonomy+'" ':"",r+=void 0!==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>",!0===n.showSKU&&void 0!==t.sku&&t.sku.length>0&&(h+='<span class="dgwt-wcas-sku">(SKU: '+o(t.sku,a)+")</span>"),h+="</span>",!0===n.showPrice&&void 0!==t.price&&(h+='<span class="dgwt-wcas-sp">'+t.price+"</span>"),!0===n.showDescription&&void 0!==t.desc&&(h+='<span class="dgwt-wcas-sd">'+o(t.desc,a)+"</span>"),!0===n.showFeaturedBadge&&!0===t.on_sale&&(h+='<span class="dgwt-wcas-badge dgwt-wcas-badge-os">'+n.saleBadgeText+"</span>"),!0===n.showFeaturedBadge&&!0===t.featured&&(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.suggestions),s.fixPosition(),u.show(),u.parent().addClass("dgwt-wcas-open"),!0===n.showDetailsPanel&&c.show(),n.autoSelectFirst&&(s.selectedIndex=0,u.scrollTop(0),u.children("."+l).first().addClass(r)),s.visible=!0,s.findBestHint())}else this.options.showNoSuggestionNotice?this.noSuggestions():this.hide()},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);if("auto"===n.width&&(t=s.el.outerWidth(),o.css("width",t+"px")),i.width()>=550&&!0===n.showDetailsPanel)return 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(!0===n.is_rtl?(a.css("left","0"),o.css("right","0")):(a.css("right","0"),o.css("left","0")));"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;1==dgwt_wcas.show_preloader&&0!=s.length&&(!0===i?"hide"!==t?"show"===t&&(o='<div class="'+l+'"><div class="dgwt-wcas-default-preloader"></div></div>',s.html(o)):e(a).remove():"hide"===t?s.removeClass(n):s.addClass(n))},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&&!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),t.disableKillerFn()},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,a=(o=e(s.suggestionsContainer).scrollTop())+s.options.maxHeight-l,i<o?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){return arguments.length?this.each(function(){var i=e(this),o=i.data("autocomplete");"string"==typeof s?o&&"function"==typeof o[s]&&o[s](n):(o&&o.dispose&&o.dispose(),o=new t(this,s),i.data("autocomplete",o))}):this.first().data("autocomplete")},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;(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:!1,triggerSelectOnValidInput:!1,serviceUrl:dgwt_wcas.ajax_search_endpoint,paramName:"dgwt_wcas_keyword",showDetailsPanel:t,showImage:1==dgwt_wcas.show_images,showPrice:1==dgwt_wcas.show_price,showDescription:1==dgwt_wcas.show_desc,showSKU:1==dgwt_wcas.show_sku,showSaleBadge:1==dgwt_wcas.show_sale_badge,showFeaturedBadge:1==dgwt_wcas.show_featured_badge,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})})}()});
includes/admin/Promo/FeedbackNotice.php ADDED
@@ -0,0 +1,174 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Exit if accessed directly
4
+ if ( !defined( 'ABSPATH' ) ) {
5
+ exit;
6
+ }
7
+
8
+
9
+ class DGWT_WCAS_FeedbackNotice {
10
+
11
+ const ACTIVATION_DATE_OPT = 'dgwt_wcas_activation_date';
12
+
13
+ const HIDE_NOTICE_OPT = 'dgwt_wcas_dismiss_review_notice';
14
+
15
+ const DISMISS_AJAX_ACTION = 'dgwt_wcas_dismiss_notice';
16
+
17
+ const REVIEW_URL = 'https://wordpress.org/support/plugin/ajax-search-for-woocommerce/reviews/?filter=5';
18
+
19
+ /**
20
+ * Admin notice offset
21
+ * @var int timestamp
22
+ */
23
+ private $offset;
24
+
25
+ function __construct()
26
+ {
27
+
28
+ $this->offset = strtotime('-7 days');
29
+
30
+ add_action('admin_init', array($this, 'check_installation_date'));
31
+
32
+ add_action( 'wp_ajax_' . self::DISMISS_AJAX_ACTION, array( $this, 'dismiss_notice' ) );
33
+
34
+ add_action('admin_footer', array($this, 'print_dismiss_js'));
35
+
36
+ }
37
+
38
+ /**
39
+ * Check if is possible to display admin notice on the current screen
40
+ * @return bool
41
+ */
42
+ private function allow_display() {
43
+ if (
44
+ in_array( get_current_screen()->base, array( 'dashboard', 'post', 'edit' ) )
45
+ || strpos( get_current_screen()->base, DGWT_WCAS_SETTINGS_KEY ) !== false
46
+ ) {
47
+ return true;
48
+ }
49
+
50
+ return false;
51
+
52
+ }
53
+
54
+ /**
55
+ * Display feedback notice
56
+ * @return null | echo HTML
57
+ */
58
+ public function display_notice()
59
+ {
60
+ global $current_user;
61
+
62
+ if ($this->allow_display())
63
+ {
64
+ ?>
65
+
66
+ <div class="dgwt-wcas-review-notice">
67
+ <div class="dgwt-wcas-review-notice-logo"></div>
68
+ <?php printf( __( "Hey %s, it's Damian Góra from %s. You have used this free plugin for some time now, and I hope you like it!", 'ajax-search-for-woocommerce' ),
69
+ '<strong>' . $current_user->display_name . '</strong>',
70
+ '<strong>' . DGWT_WCAS_NAME . '</strong>'
71
+ ); ?>
72
+ <br />
73
+ <?php printf(__("I have spent countless hours developing it, and it would mean a lot to me if you %ssupport it with a quick review on WordPress.org.%s", 'ajax-search-for-woocommerce'),
74
+ '<strong><a target="_blank" href="' . self::REVIEW_URL . '">', '</a></strong>'
75
+ ); ?>
76
+ <div class="button-container">
77
+ <a href="<?php echo self::REVIEW_URL; ?>" target="_blank" data-link="follow" class="button-secondary dgwt-review-notice-dismiss">
78
+ <span class="dashicons dashicons-star-filled"></span>
79
+ <?php printf(__("Review %s", 'ajax-search-for-woocommerce'),DGWT_WCAS_NAME); ?>
80
+ </a>
81
+ <a href="#" class="button-secondary dgwt-review-notice-dismiss">
82
+ <span class="dashicons dashicons-no-alt"></span>
83
+ <?php _e("No thanks", 'ajax-search-for-woocommerce'); ?>
84
+ </a>
85
+ </div>
86
+ </div>
87
+ <?php
88
+ }
89
+ }
90
+
91
+
92
+ /**
93
+ * Check instalation date
94
+ * @return null
95
+ */
96
+ public function check_installation_date()
97
+ {
98
+
99
+ $date = get_option(self::ACTIVATION_DATE_OPT);
100
+ if (empty($date)) {
101
+ add_option(self::ACTIVATION_DATE_OPT, time());
102
+ }
103
+
104
+ $notice_closed = get_option(self::HIDE_NOTICE_OPT);
105
+
106
+ if (empty($notice_closed)) {
107
+ $install_date = get_option(self::ACTIVATION_DATE_OPT);
108
+
109
+ if ($this->offset >= $install_date && current_user_can('install_plugins'))
110
+ {
111
+ add_action('admin_notices', array($this, 'display_notice'));
112
+ }
113
+ }
114
+
115
+ }
116
+
117
+
118
+ /**
119
+ * Hide admin notice
120
+ *
121
+ * @return null
122
+ */
123
+ public function dismiss_notice() {
124
+
125
+ update_option( self::HIDE_NOTICE_OPT, true );
126
+
127
+ wp_send_json_success();
128
+ }
129
+
130
+ /**
131
+ * Print JS for close admin notice
132
+ */
133
+ public function print_dismiss_js() {
134
+
135
+ if(!$this->allow_display()){
136
+ return false;
137
+ }
138
+ ?>
139
+ <script>
140
+ (function ($) {
141
+
142
+ $( document ).on( 'click', '.dgwt-review-notice-dismiss', function () {
143
+ var $box = $( this ).closest( '.dgwt-wcas-review-notice' ),
144
+ isLink = $( this ).attr('data-link') === 'follow' ? true : false;
145
+
146
+ $box.fadeOut( 700 );
147
+
148
+ $.ajax( {
149
+ url: ajaxurl,
150
+ data: {
151
+ action: '<?php echo self::DISMISS_AJAX_ACTION; ?>',
152
+ }
153
+ } ).done( function ( data ) {
154
+
155
+ setTimeout(function(){
156
+ $box.remove();
157
+ }, 700);
158
+
159
+ } );
160
+
161
+ if(!isLink) {
162
+ return false;
163
+ }
164
+ } );
165
+
166
+ }(jQuery));
167
+ </script>
168
+
169
+ <?php
170
+ }
171
+
172
+ }
173
+
174
+ new DGWT_WCAS_FeedbackNotice();
includes/admin/admin-menus.php CHANGED
@@ -20,7 +20,7 @@ class DGWT_WCAS_Admin_Menu {
20
  */
21
  public function add_menu() {
22
 
23
- add_menu_page( __( 'Ajax Search for WooCommerce', 'ajax-search-for-woocommerce' ), __( 'Woo Ajax Search', 'ajax-search-for-woocommerce' ), 'manage_options', 'dgwt_wcas_settings', array( $this, 'settings_page' ), DGWT_WCAS_URL . '/assets/img/admin-icon.svg', 56);
24
  }
25
 
26
  /**
20
  */
21
  public function add_menu() {
22
 
23
+ add_submenu_page( 'woocommerce', __( 'Ajax Search for WooCommerce', 'ajax-search-for-woocommerce' ), __( 'AJAX search form', 'ajax-search-for-woocommerce' ), 'manage_options', 'dgwt_wcas_settings', array( $this, 'settings_page' ));
24
  }
25
 
26
  /**
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('posts_distinct', array($this, 'search_distinct'), 501, 2);
35
  add_filter( 'posts_join', array( $this, 'search_filters_join' ), 501, 2 );
36
  add_filter( 'pre_get_posts', array( $this, 'change_wp_search_size' ), 500 );
@@ -113,7 +114,7 @@ class DGWT_WCAS_Search {
113
 
114
  $r = array(
115
  'post_id' => $product->get_id(),
116
- 'value' => strip_tags( $product->get_title() ),
117
  'url' => $product->get_permalink(),
118
  );
119
 
@@ -182,9 +183,9 @@ class DGWT_WCAS_Search {
182
  */
183
 
184
  private function get_meta_query() {
185
-
186
  $meta_query = array();
187
-
188
  // Backward compatibility WC < 3.0
189
  if ( dgwt_wcas_compare_wc_version( '3.0', '<' ) ) {
190
  $meta_query = array(
@@ -437,12 +438,39 @@ class DGWT_WCAS_Search {
437
  return $join;
438
  }
439
 
440
- /*
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
441
  * Get taxonomy parent
442
- *
443
  * @param int $term_id
444
  * @param string $taxonomy
445
- *
446
  * @return string
447
  */
448
 
@@ -482,14 +510,25 @@ class DGWT_WCAS_Search {
482
  */
483
 
484
  public function set_search_results_query( $query ) {
 
485
 
486
  if ( !$this->is_ajax_search() && $query->is_search ) {
487
 
488
  if ( $this->is_search_page() ) {
489
 
490
  $query->query_vars[ 'post_type' ] = DGWT_WCAS_WOO_PRODUCT_POST_TYPE;
491
-
 
492
  $query->query_vars[ 'meta_query' ] = $this->get_meta_query();
 
 
 
 
 
 
 
 
 
493
  }
494
  }
495
 
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_where', array( $this, 'fix_woo_excerpt_search' ), 100, 2 );
35
  add_filter('posts_distinct', array($this, 'search_distinct'), 501, 2);
36
  add_filter( 'posts_join', array( $this, 'search_filters_join' ), 501, 2 );
37
  add_filter( 'pre_get_posts', array( $this, 'change_wp_search_size' ), 500 );
114
 
115
  $r = array(
116
  'post_id' => $product->get_id(),
117
+ 'value' => html_entity_decode(wp_strip_all_tags($product->get_title())),
118
  'url' => $product->get_permalink(),
119
  );
120
 
183
  */
184
 
185
  private function get_meta_query() {
186
+
187
  $meta_query = array();
188
+
189
  // Backward compatibility WC < 3.0
190
  if ( dgwt_wcas_compare_wc_version( '3.0', '<' ) ) {
191
  $meta_query = array(
438
  return $join;
439
  }
440
 
441
+ /**
442
+ * Corrects the search by excerpt if necessary.
443
+ * WooCommerce adds search in excerpt by defaults and this should be corrected.
444
+ *
445
+ * @since 1.1.4
446
+ *
447
+ * @param string $where
448
+ * @return string
449
+ */
450
+ public function fix_woo_excerpt_search($where){
451
+ global $wp_the_query;
452
+
453
+ // If this is not a WC Query, do not modify the query
454
+ if ( empty( $wp_the_query->query_vars['wc_query'] ) || empty( $wp_the_query->query_vars['s'] ) ) {
455
+ return $where;
456
+ }
457
+
458
+ if ( DGWT_WCAS()->settings->get_opt( 'search_in_product_excerpt' ) !== 'on' ) {
459
+
460
+ $where = preg_replace(
461
+ "/OR \(post_excerpt\s+LIKE\s*(\'\%[^\%]+\%\')\)/",
462
+ "", $where );
463
+ }
464
+
465
+ return $where;
466
+ }
467
+
468
+ /**
469
  * Get taxonomy parent
470
+ *
471
  * @param int $term_id
472
  * @param string $taxonomy
473
+ *
474
  * @return string
475
  */
476
 
510
  */
511
 
512
  public function set_search_results_query( $query ) {
513
+ global $woocommerce;
514
 
515
  if ( !$this->is_ajax_search() && $query->is_search ) {
516
 
517
  if ( $this->is_search_page() ) {
518
 
519
  $query->query_vars[ 'post_type' ] = DGWT_WCAS_WOO_PRODUCT_POST_TYPE;
520
+ $query->query_vars[ 'ignore_sticky_posts' ] = 1;
521
+ $query->query_vars[ 'suppress_filters' ] = false;
522
  $query->query_vars[ 'meta_query' ] = $this->get_meta_query();
523
+
524
+
525
+ $ordering_args = $woocommerce->query->get_catalog_ordering_args( 'title', 'asc' );
526
+
527
+ $query->query_vars[ 'orderby' ] = $ordering_args[ 'orderby' ];
528
+ $query->query_vars[ 'order' ] = $ordering_args[ 'order' ];
529
+
530
+ $query->query_vars = apply_filters('dgwt_wcas_products_search_page_args', $query->query_vars);
531
+
532
  }
533
  }
534
 
includes/functions.php CHANGED
@@ -148,6 +148,9 @@ function dgwt_wcas_get_product_desc( $product, $length = 130 ) {
148
  }
149
  }
150
  }
 
 
 
151
  return $output;
152
  }
153
 
148
  }
149
  }
150
  }
151
+
152
+ $output = html_entity_decode($output);
153
+
154
  return $output;
155
  }
156
 
includes/install.php CHANGED
@@ -28,7 +28,9 @@ class DGWT_WCAS_Install {
28
  if ( !defined( 'DGWT_WCAS_INSTALLING' ) ) {
29
  define( 'DGWT_WCAS_INSTALLING', true );
30
  }
31
-
 
 
32
  self::create_options();
33
  self::create_cron_jobs();
34
 
@@ -68,7 +70,21 @@ class DGWT_WCAS_Install {
68
 
69
  update_option( DGWT_WCAS_SETTINGS_KEY, $update_options );
70
  }
71
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
72
  /**
73
  * Create cron jobs (clear them first)
74
  */
28
  if ( !defined( 'DGWT_WCAS_INSTALLING' ) ) {
29
  define( 'DGWT_WCAS_INSTALLING', true );
30
  }
31
+
32
+ self::save_activation_date();
33
+
34
  self::create_options();
35
  self::create_cron_jobs();
36
 
70
 
71
  update_option( DGWT_WCAS_SETTINGS_KEY, $update_options );
72
  }
73
+
74
+ /**
75
+ * Save activation timestamp
76
+ * Used to display notice, asking for a feedback
77
+ *
78
+ * @return null
79
+ */
80
+ private static function save_activation_date() {
81
+
82
+ if ( empty( get_option( 'dgwt_wcas_activation_date' ) ) ) {
83
+ update_option( 'dgwt_wcas_activation_date', time() );
84
+ }
85
+
86
+ }
87
+
88
  /**
89
  * Create cron jobs (clear them first)
90
  */
languages/ajax-search-for-woocommerce-pl_PL.mo CHANGED
Binary file
languages/ajax-search-for-woocommerce-pl_PL.po CHANGED
@@ -2,9 +2,9 @@ msgid ""
2
  msgstr ""
3
  "Project-Id-Version: Ajax Search for WooCommerce\n"
4
  "Report-Msgid-Bugs-To: \n"
5
- "POT-Creation-Date: 2017-06-06 22:09+0000\n"
6
- "PO-Revision-Date: 2017-06-07 20:07+0000\n"
7
- "Last-Translator: dgwt-wcas <admin@webtroter.pl>\n"
8
  "Language-Team: Polish\n"
9
  "Language: pl-PL\n"
10
  "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10 >= 2 && n%10<=4 "
@@ -14,6 +14,13 @@ msgstr ""
14
  "Content-Transfer-Encoding: 8bit\n"
15
  "X-Generator: Loco - https://localise.biz/"
16
 
 
 
 
 
 
 
 
17
  #: includes/widget.php:21 includes/admin/admin-menus.php:23
18
  msgid "Woo Ajax Search"
19
  msgstr ""
@@ -23,6 +30,206 @@ msgstr ""
23
  msgid "Ajax Search for WooCommerce"
24
  msgstr ""
25
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
26
  #: includes/admin/settings/class-settings.php:110
27
  msgid "Maximum number of suggestions rows."
28
  msgstr "Maksymalna liczba podpowiedzi."
@@ -205,172 +412,3 @@ msgstr "Tło pola do wpisania frazy"
205
  #: includes/admin/settings/class-settings.php:309
206
  msgid "Search input text"
207
  msgstr "Tekst "
208
-
209
- #: includes/admin/settings/class-settings.php:315
210
- msgid "Search input border"
211
- msgstr ""
212
-
213
- #: includes/admin/settings/class-settings.php:321
214
- msgid "Search submit background"
215
- msgstr ""
216
-
217
- #: includes/admin/settings/class-settings.php:327
218
- msgid "Search submit text"
219
- msgstr ""
220
-
221
- #: includes/admin/settings/class-settings.php:333
222
- msgid "Suggestions"
223
- msgstr ""
224
-
225
- #: includes/admin/settings/class-settings.php:338
226
- msgid "Suggestion background"
227
- msgstr ""
228
-
229
- #: includes/admin/settings/class-settings.php:344
230
- msgid "Suggestion selected"
231
- msgstr ""
232
-
233
- #: includes/admin/settings/class-settings.php:350
234
- msgid "Text color"
235
- msgstr ""
236
-
237
- #: includes/admin/settings/class-settings.php:356
238
- msgid "Highlight color"
239
- msgstr ""
240
-
241
- #: includes/admin/settings/class-settings.php:362
242
- msgid "Border color"
243
- msgstr ""
244
-
245
- #: includes/admin/settings/class-settings.php:368
246
- msgid "Suggestions width"
247
- msgstr ""
248
-
249
- #: includes/admin/settings/class-settings.php:371
250
- msgid ""
251
- "Overvrite the suggestions container width. Leave this field empty to adjust "
252
- "the suggestions container width to the search input width."
253
- msgstr ""
254
-
255
- #: includes/admin/settings/class-settings.php:376
256
- msgid "Preloader"
257
- msgstr ""
258
-
259
- #: includes/admin/settings/class-settings.php:381
260
- msgid "Show preloader"
261
- msgstr ""
262
-
263
- #: includes/admin/settings/class-settings.php:387
264
- msgid "Upload preloader image"
265
- msgstr ""
266
-
267
- #: includes/admin/views/how-to-use.php:2
268
- msgid "There are two easy ways to display the search form"
269
- msgstr ""
270
-
271
- #: includes/admin/views/how-to-use.php:3
272
- #, php-format
273
- msgid "Use a shortcode %s"
274
- msgstr ""
275
-
276
- #: includes/admin/views/how-to-use.php:4
277
- #, php-format
278
- msgid "Go to the %s and choose \"Woo Ajax Search\""
279
- msgstr ""
280
-
281
- #: includes/admin/views/how-to-use.php:4
282
- msgid "Widgets Screen"
283
- msgstr ""
284
-
285
- #. Description of the plugin
286
- msgid ""
287
- "The plugin allows you to display the WooCommerce AJAX search form anywhere "
288
- "on the page."
289
- msgstr ""
290
-
291
- #. URI of the plugin
292
- msgid "https://wordpress.org/plugins/ajax-search-for-woocommerce/"
293
- msgstr ""
294
-
295
- #. Author of the plugin
296
- msgid "Damian Góra"
297
- msgstr ""
298
-
299
- #. Author URI of the plugin
300
- msgid "http://damiangora.com"
301
- msgstr ""
302
-
303
- #: ajax-search-for-woocommerce.php:87
304
- msgid ""
305
- "<b>Ajax Search for WooCommerce</b>: You need PHP version at least 5.3 to run "
306
- "this plugin. You are currently using PHP version "
307
- msgstr ""
308
- "<b>Ajax Search for WooCommerce</b>: Wymagana wersja PHP do uruchomienia "
309
- "wtyczki to 5.3 lub wyższa. Aktualnie używasz wersji "
310
-
311
- #: includes/class-result-details.php:147
312
- msgid "Category"
313
- msgstr "Kategoria"
314
-
315
- #: includes/class-result-details.php:149
316
- msgid "Tag"
317
- msgstr "Tag"
318
-
319
- #: includes/class-search.php:163
320
- msgid "No results"
321
- msgstr "Brak wyników"
322
-
323
- #: includes/class-search.php:259 includes/class-search.php:310
324
- msgid "in"
325
- msgstr "w"
326
-
327
- #: includes/widget.php:19
328
- msgid "Ajax (live) search form for WooCommerce"
329
- msgstr "Ajaxowa wyszukiwarka produktów dla WooCommerce"
330
-
331
- #: includes/widget.php:26
332
- msgid "Title"
333
- msgstr "Tytuł"
334
-
335
- #: includes/register-scripts.php:28
336
- msgctxt "For product badge: on sale"
337
- msgid "sale"
338
- msgstr "sprzedaż"
339
-
340
- #: includes/register-scripts.php:29
341
- msgctxt "For product badge: featured"
342
- msgid "featured"
343
- msgstr "wyróżniony"
344
-
345
- #: includes/tmpl/search-form.php:19
346
- msgid "Products search"
347
- msgstr "Wyszukiwarka produktów"
348
-
349
- #: includes/tmpl/search-form.php:27
350
- #: includes/admin/settings/class-settings.php:139
351
- msgid "Search for products..."
352
- msgstr "Szukaj produktów"
353
-
354
- #: includes/admin/settings/class-settings.php:69
355
- msgid "Basic"
356
- msgstr "Podstawowe"
357
-
358
- #: includes/admin/settings/class-settings.php:73
359
- msgid "Advanced"
360
- msgstr "Zaawansowane"
361
-
362
- #: includes/admin/settings/class-settings.php:77
363
- msgid "Extra Details"
364
- msgstr "Dodatkowe szczegóły"
365
-
366
- #: includes/admin/settings/class-settings.php:81
367
- msgid "Style"
368
- msgstr "Styl"
369
-
370
- #: includes/admin/settings/class-settings.php:101
371
- msgid "How to use?"
372
- msgstr "Jak używać?"
373
-
374
- #: includes/admin/settings/class-settings.php:107
375
- msgid "Suggestions limit"
376
- msgstr "Limit podpowiedzi"
2
  msgstr ""
3
  "Project-Id-Version: Ajax Search for WooCommerce\n"
4
  "Report-Msgid-Bugs-To: \n"
5
+ "POT-Creation-Date: 2017-09-02 23:59+0000\n"
6
+ "PO-Revision-Date: 2017-09-03 01:09+0000\n"
7
+ "Last-Translator: dev_nIXCkVKHG <admin@webtroter.pl>\n"
8
  "Language-Team: Polish\n"
9
  "Language: pl-PL\n"
10
  "Plural-Forms: nplurals=3; plural=(n==1 ? 0 : n%10 >= 2 && n%10<=4 "
14
  "Content-Transfer-Encoding: 8bit\n"
15
  "X-Generator: Loco - https://localise.biz/"
16
 
17
+ #: ajax-search-for-woocommerce.php:111
18
+ #, php-format
19
+ msgid ""
20
+ "<b>Ajax Search for WooCommerce</b> is enabled but not effective. It requires "
21
+ "%s in order to work."
22
+ msgstr ""
23
+
24
  #: includes/widget.php:21 includes/admin/admin-menus.php:23
25
  msgid "Woo Ajax Search"
26
  msgstr ""
30
  msgid "Ajax Search for WooCommerce"
31
  msgstr ""
32
 
33
+ #: includes/admin/settings/class-settings.php:376
34
+ msgid "Preloader"
35
+ msgstr ""
36
+
37
+ #. Description of the plugin
38
+ msgid ""
39
+ "The plugin allows you to display the WooCommerce AJAX search form anywhere "
40
+ "on the page."
41
+ msgstr ""
42
+
43
+ #. Author of the plugin
44
+ msgid "Damian Góra"
45
+ msgstr ""
46
+
47
+ #. Author URI of the plugin
48
+ msgid "http://damiangora.com"
49
+ msgstr ""
50
+
51
+ #: includes/admin/settings/class-settings.php:315
52
+ msgid "Search input border"
53
+ msgstr "Obramowanie inputa"
54
+
55
+ #: includes/admin/settings/class-settings.php:321
56
+ msgid "Search submit background"
57
+ msgstr "Tło przycisku \"szukaj\""
58
+
59
+ #: includes/admin/settings/class-settings.php:327
60
+ msgid "Search submit text"
61
+ msgstr "Tekst na przycisku \"szukaj\""
62
+
63
+ #: includes/admin/settings/class-settings.php:333
64
+ msgid "Suggestions"
65
+ msgstr "Podpowiedzi"
66
+
67
+ #: includes/admin/settings/class-settings.php:338
68
+ msgid "Suggestion background"
69
+ msgstr "Tło podpowiedzi"
70
+
71
+ #: includes/admin/settings/class-settings.php:344
72
+ msgid "Suggestion selected"
73
+ msgstr "Tło zaznaczonej podpowiedzi"
74
+
75
+ #: includes/admin/settings/class-settings.php:350
76
+ msgid "Text color"
77
+ msgstr "Kolor tekstu"
78
+
79
+ #: includes/admin/settings/class-settings.php:356
80
+ msgid "Highlight color"
81
+ msgstr "Kolor podświetlenia"
82
+
83
+ #: includes/admin/settings/class-settings.php:362
84
+ msgid "Border color"
85
+ msgstr "Kolor obramowania"
86
+
87
+ #: includes/admin/settings/class-settings.php:368
88
+ msgid "Suggestions width"
89
+ msgstr "Szerokość pola z podpowiedziami"
90
+
91
+ #: includes/admin/settings/class-settings.php:371
92
+ msgid ""
93
+ "Overvrite the suggestions container width. Leave this field empty to adjust "
94
+ "the suggestions container width to the search input width."
95
+ msgstr ""
96
+ "Nadpisuje szerokość kontenera z podpowiedziami. Gdy zostawisz to pole puste, "
97
+ "kontener zostanie automatycznie rozciągnięty do szerokości inputa "
98
+ "wyszukiwarki."
99
+
100
+ #: includes/admin/settings/class-settings.php:381
101
+ msgid "Show preloader"
102
+ msgstr "Pokaż preloader"
103
+
104
+ #: includes/admin/settings/class-settings.php:387
105
+ msgid "Upload preloader image"
106
+ msgstr "Załaduj zdjęcie na preloader"
107
+
108
+ #: includes/admin/views/how-to-use.php:2
109
+ msgid "There are two easy ways to display the search form"
110
+ msgstr "Wyszukiwarkę można wyświetlić na dwa sposoby"
111
+
112
+ #: includes/admin/views/how-to-use.php:3
113
+ #, php-format
114
+ msgid "Use a shortcode %s"
115
+ msgstr "Użyj shortcode"
116
+
117
+ #: includes/admin/views/how-to-use.php:4
118
+ #, php-format
119
+ msgid "Go to the %s and choose \"Woo Ajax Search\""
120
+ msgstr "Przejdź do %s i wybierz \"Woo Ajax Search\""
121
+
122
+ #: includes/admin/views/how-to-use.php:4
123
+ msgid "Widgets Screen"
124
+ msgstr "Widoku widgetów"
125
+
126
+ #: includes/admin/Promo/FeedbackNotice.php:68
127
+ #, php-format
128
+ msgid ""
129
+ "Hey %s, it's Damian Góra from %s. You have used this free plugin for some "
130
+ "time now, and I hope you like it!"
131
+ msgstr ""
132
+ "Cześć %s, tu Damian Góra z %s. Korzystasz z tej wyszukiwarki produktów od "
133
+ "pewnego czasu i mam nadzieję że Ci się podoba!"
134
+
135
+ #: includes/admin/Promo/FeedbackNotice.php:73
136
+ #, php-format
137
+ msgid ""
138
+ "I have spent countless hours developing it, and it would mean a lot to me if "
139
+ "you %ssupport it with a quick review on WordPress.org.%s"
140
+ msgstr ""
141
+ "Spędziłem wiele godzin na pisaniu tej wtyczki i potrzebuję motywacji do "
142
+ "dalszego rozwoju wyszukiwarki. Byłbym bardzo szczęśliwy gdybyś %socenił/a "
143
+ "moją wtyczkę na WordPress.org.%s Mała rzecz a cieszy :)"
144
+
145
+ #: includes/admin/Promo/FeedbackNotice.php:79
146
+ #, php-format
147
+ msgid "Review %s"
148
+ msgstr "Oceń teraz"
149
+
150
+ #: includes/admin/Promo/FeedbackNotice.php:83
151
+ msgid "No thanks"
152
+ msgstr "Zamknij"
153
+
154
+ #. URI of the plugin
155
+ msgid "https://wordpress.org/plugins/ajax-search-for-woocommerce/"
156
+ msgstr "https://pl.wordpress.org/plugins/ajax-search-for-woocommerce/"
157
+
158
+ #: ajax-search-for-woocommerce.php:94
159
+ msgid ""
160
+ "<b>Ajax Search for WooCommerce</b>: You need PHP version at least 5.3 to run "
161
+ "this plugin. You are currently using PHP version "
162
+ msgstr ""
163
+ "<b>Ajax Search for WooCommerce</b>: Wymagana wersja PHP do uruchomienia "
164
+ "wtyczki to 5.3 lub wyższa. Aktualnie używasz wersji "
165
+
166
+ #: includes/class-result-details.php:147
167
+ msgid "Category"
168
+ msgstr "Kategoria"
169
+
170
+ #: includes/class-result-details.php:149
171
+ msgid "Tag"
172
+ msgstr "Tag"
173
+
174
+ #: includes/class-search.php:167
175
+ msgid "No results"
176
+ msgstr "Brak wyników"
177
+
178
+ #: includes/class-search.php:263 includes/class-search.php:314
179
+ msgid "in"
180
+ msgstr "w"
181
+
182
+ #: includes/widget.php:19
183
+ msgid "Ajax (live) search form for WooCommerce"
184
+ msgstr "Ajaxowa wyszukiwarka produktów dla WooCommerce"
185
+
186
+ #: includes/widget.php:26
187
+ msgid "Title"
188
+ msgstr "Tytuł"
189
+
190
+ #: includes/register-scripts.php:28
191
+ msgctxt "For product badge: on sale"
192
+ msgid "sale"
193
+ msgstr "sprzedaż"
194
+
195
+ #: includes/register-scripts.php:29
196
+ msgctxt "For product badge: featured"
197
+ msgid "featured"
198
+ msgstr "wyróżniony"
199
+
200
+ #: includes/tmpl/search-form.php:19
201
+ msgid "Products search"
202
+ msgstr "Wyszukiwarka produktów"
203
+
204
+ #: includes/tmpl/search-form.php:27
205
+ #: includes/admin/settings/class-settings.php:139
206
+ msgid "Search for products..."
207
+ msgstr "Szukaj produktów"
208
+
209
+ #: includes/admin/settings/class-settings.php:69
210
+ msgid "Basic"
211
+ msgstr "Podstawowe"
212
+
213
+ #: includes/admin/settings/class-settings.php:73
214
+ msgid "Advanced"
215
+ msgstr "Zaawansowane"
216
+
217
+ #: includes/admin/settings/class-settings.php:77
218
+ msgid "Extra Details"
219
+ msgstr "Dodatkowe szczegóły"
220
+
221
+ #: includes/admin/settings/class-settings.php:81
222
+ msgid "Style"
223
+ msgstr "Styl"
224
+
225
+ #: includes/admin/settings/class-settings.php:101
226
+ msgid "How to use?"
227
+ msgstr "Jak używać?"
228
+
229
+ #: includes/admin/settings/class-settings.php:107
230
+ msgid "Suggestions limit"
231
+ msgstr "Limit podpowiedzi"
232
+
233
  #: includes/admin/settings/class-settings.php:110
234
  msgid "Maximum number of suggestions rows."
235
  msgstr "Maksymalna liczba podpowiedzi."
412
  #: includes/admin/settings/class-settings.php:309
413
  msgid "Search input text"
414
  msgstr "Tekst "
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
languages/ajax-search-for-woocommerce.pot CHANGED
@@ -3,8 +3,8 @@ msgid ""
3
  msgstr ""
4
  "Project-Id-Version: PACKAGE VERSION\n"
5
  "Report-Msgid-Bugs-To: \n"
6
- "POT-Creation-Date: 2017-06-06 22:09+0000\n"
7
- "PO-Revision-Date: 1017-06-06 HO:MI+ZONE\n"
8
  "Last-Translator: Damian Góra <wp@damiangora.com>\n"
9
  "Language-Team: \n"
10
  "Language: \n"
@@ -14,12 +14,19 @@ msgstr ""
14
  "Content-Transfer-Encoding: 8bit\n"
15
  "X-Generator: Loco - https://localise.biz/"
16
 
17
- #: ajax-search-for-woocommerce.php:87
18
  msgid ""
19
  "<b>Ajax Search for WooCommerce</b>: You need PHP version at least 5.3 to run "
20
  "this plugin. You are currently using PHP version "
21
  msgstr ""
22
 
 
 
 
 
 
 
 
23
  #: includes/class-result-details.php:147
24
  msgid "Category"
25
  msgstr ""
@@ -28,11 +35,11 @@ msgstr ""
28
  msgid "Tag"
29
  msgstr ""
30
 
31
- #: includes/class-search.php:163
32
  msgid "No results"
33
  msgstr ""
34
 
35
- #: includes/class-search.php:259 includes/class-search.php:310
36
  msgid "in"
37
  msgstr ""
38
 
@@ -350,6 +357,29 @@ msgstr ""
350
  msgid "Widgets Screen"
351
  msgstr ""
352
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
353
  #. Description of the plugin
354
  msgid ""
355
  "The plugin allows you to display the WooCommerce AJAX search form anywhere "
3
  msgstr ""
4
  "Project-Id-Version: PACKAGE VERSION\n"
5
  "Report-Msgid-Bugs-To: \n"
6
+ "POT-Creation-Date: 2017-09-02 23:59+0000\n"
7
+ "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
8
  "Last-Translator: Damian Góra <wp@damiangora.com>\n"
9
  "Language-Team: \n"
10
  "Language: \n"
14
  "Content-Transfer-Encoding: 8bit\n"
15
  "X-Generator: Loco - https://localise.biz/"
16
 
17
+ #: ajax-search-for-woocommerce.php:94
18
  msgid ""
19
  "<b>Ajax Search for WooCommerce</b>: You need PHP version at least 5.3 to run "
20
  "this plugin. You are currently using PHP version "
21
  msgstr ""
22
 
23
+ #: ajax-search-for-woocommerce.php:111
24
+ #, php-format
25
+ msgid ""
26
+ "<b>Ajax Search for WooCommerce</b> is enabled but not effective. It requires "
27
+ "%s in order to work."
28
+ msgstr ""
29
+
30
  #: includes/class-result-details.php:147
31
  msgid "Category"
32
  msgstr ""
35
  msgid "Tag"
36
  msgstr ""
37
 
38
+ #: includes/class-search.php:167
39
  msgid "No results"
40
  msgstr ""
41
 
42
+ #: includes/class-search.php:263 includes/class-search.php:314
43
  msgid "in"
44
  msgstr ""
45
 
357
  msgid "Widgets Screen"
358
  msgstr ""
359
 
360
+ #: includes/admin/Promo/FeedbackNotice.php:68
361
+ #, php-format
362
+ msgid ""
363
+ "Hey %s, it's Damian Góra from %s. You have used this free plugin for some "
364
+ "time now, and I hope you like it!"
365
+ msgstr ""
366
+
367
+ #: includes/admin/Promo/FeedbackNotice.php:73
368
+ #, php-format
369
+ msgid ""
370
+ "I have spent countless hours developing it, and it would mean a lot to me if "
371
+ "you %ssupport it with a quick review on WordPress.org.%s"
372
+ msgstr ""
373
+
374
+ #: includes/admin/Promo/FeedbackNotice.php:79
375
+ #, php-format
376
+ msgid "Review %s"
377
+ msgstr ""
378
+
379
+ #: includes/admin/Promo/FeedbackNotice.php:83
380
+ msgid "No thanks"
381
+ msgstr ""
382
+
383
  #. Description of the plugin
384
  msgid ""
385
  "The plugin allows you to display the WooCommerce AJAX search form anywhere "
readme.txt CHANGED
@@ -3,8 +3,8 @@ 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.8
7
- Stable tag: 1.1.3
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
@@ -12,7 +12,8 @@ Help users easily find and discover products in your store using Ajax Search for
12
 
13
  == Description ==
14
 
15
- The plugin allows you to display the WooCommerce AJAX search form anywhere on the page.
 
16
 
17
  Just enter a few letters and the products which best match your query will appear.
18
  Suggestions can be displayed in a simple form (names of the products only) or in an extended form (includes photos, prices, descriptions, extended information etc.).
@@ -67,6 +68,14 @@ Any suggestions or comments are welcome. Feel free to contact me using this [con
67
 
68
  == Changelog ==
69
 
 
 
 
 
 
 
 
 
70
  = 1.1.3, July 12, 2017 =
71
  * ADD: New WordPress filters
72
  * FIX: Repetitive search results
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.8.1
7
+ Stable tag: 1.1.4
8
  License: GPLv2 or later
9
  License URI: http://www.gnu.org/licenses/gpl-2.0.html
10
 
12
 
13
  == Description ==
14
 
15
+ The plugin allows your customers to search products easily and quickly. It will display the results instantly while typing in an inputbox.
16
+ You can display the WooCommerce AJAX search form anywhere on the page.
17
 
18
  Just enter a few letters and the products which best match your query will appear.
19
  Suggestions can be displayed in a simple form (names of the products only) or in an extended form (includes photos, prices, descriptions, extended information etc.).
68
 
69
  == Changelog ==
70
 
71
+ = 1.1.4, September 03, 2017 =
72
+ * ADD: Admin notice if there is no WooCommerce installed
73
+ * ADD: Admin notice for better feedback from users
74
+ * FIX: Deleting the 'dgwt-wcas-open' class after hiding the suggestion
75
+ * FIX: Allows to display HTML entities in suggestions title and description
76
+ * FIX: Better synchronizing suggestions and resutls on a search page
77
+ * CHANGE: Move menu item to WooCommerce submenu
78
+
79
  = 1.1.3, July 12, 2017 =
80
  * ADD: New WordPress filters
81
  * FIX: Repetitive search results