PageSourceSearch

https://deloklimat.ru/wp-content/themes/woodmart/js/scripts/global/ajaxSearch.js?ver=7.0.4

js deloklimat.ru collected 2026-10-06 07:10:30 UTC 5,883 bytes, 190 lines download raw bytes

1/* global woodmart_settings */
2(function($) {
3	woodmartThemeModule.$document.on('wdShopPageInit', function () {
4		woodmartThemeModule.ajaxSearch();
5	});
6
7	$.each([
8		'frontend/element_ready/wd_search.default'
9	], function(index, value) {
10		woodmartThemeModule.wdElementorAddAction(value, function() {
11			woodmartThemeModule.ajaxSearch();
12		});
13	});
14
15	woodmartThemeModule.ajaxSearch = function() {
16		if (typeof ($.fn.devbridgeAutocomplete) == 'undefined') {
17			return;
18		}
19
20		var escapeRegExChars = function(value) {
21			return value.replace(/[\-\[\]\/\{\}\(\)\*\+\?\.\\\^\$\|]/g, '\\$&');
22		};
23
24		$('form.woodmart-ajax-search').each(function() {
25			var $this         = $(this),
26			    number        = parseInt($this.data('count')),
27			    thumbnail     = parseInt($this.data('thumbnail')),
28			    symbols_count = parseInt($this.data('symbols_count')),
29			    productCat    = $this.find('[name="product_cat"]'),
30				$parent       = $this.parent(),
31				$results      = $parent.find('.wd-dropdown-results > .wd-scroll-content'),
32			    postType      = $this.data('post_type'),
33			    url           = woodmart_settings.ajaxurl + '?action=woodmart_ajax_search',
34			    price         = parseInt($this.data('price')),
35			    sku           = $this.data('sku'),
36				isFullScreen2 = $this.parents('.wd-search-full-screen-2').length,
37				$parentResult = $parent.find('.wd-dropdown-results');
38
39			if (number > 0) {
40				url += '&number=' + number;
41			}
42			url += '&post_type=' + postType;
43
44			$results.on('click', '.view-all-results', function() {
45				$this.submit();
46			});
47
48			if (productCat.length && productCat.val() !== '') {
49				url += '&product_cat=' + productCat.val();
50			}
51
52			$this.find('[type="text"]').on('focus keyup', function() {
53				var $input = $(this);
54
55				if ( isFullScreen2 ) {
56					$parentResult.removeClass('wd-no-results');
57				}
58
59				if ($input.hasClass('wd-search-inited')) {
60					return;
61				}
62
63				$input.devbridgeAutocomplete({
64					serviceUrl      : url,
65					appendTo        : $results,
66					minChars        : symbols_count,
67					deferRequestBy  : woodmart_settings.ajax_search_delay,
68					onSelect        : function(suggestion) {
69						if (suggestion.permalink.length > 0) {
70							window.location.href = suggestion.permalink;
71						}
72					},
73					onHide          : function() {
74						$parentResult.removeClass('wd-opened');
75					},
76					onSearchStart   : function() {
77						$this.addClass('search-loading');
78					},
79					beforeRender    : function(container) {
80						$(container).find('.suggestion-divider-title').parent().addClass('suggestion-divider');
81						$(container).find('.no-found-msg').parent().addClass('suggestion-no-found');
82						if (container[0].childElementCount > 2) {
83							$(container).append('<div class="view-all-results"><span>' + woodmart_settings.all_results + '</span></div>');
84						}
85
86						$(container).removeAttr('style');
87					},
88					onSearchComplete: function() {
89						$this.removeClass('search-loading');
90
91						woodmartThemeModule.$document.trigger('wood-images-loaded');
92
93					},
94					formatResult    : function(suggestion, currentValue) {
95						if (currentValue === '&') {
96							currentValue = '&#038;';
97						}
98						var pattern     = '(' + escapeRegExChars(currentValue) + ')',
99						    returnValue = '';
100
101						if (suggestion.divider) {
102							returnValue += ' <h5 class="suggestion-divider-title">' + suggestion.divider + '</h5>';
103						}
104
105						if (thumbnail && suggestion.thumbnail) {
106							returnValue += ' <div class="suggestion-thumb">' + suggestion.thumbnail + '</div>';
107						}
108
109						if (suggestion.value) {
110							returnValue += ' <div class="suggestion-content set-cont-mb-s reset-last-child">';
111							returnValue += '<h4 class="wd-entities-title">' + suggestion.value
112								.replace(new RegExp(pattern, 'gi'), '<strong>$1<\/strong>')
113								.replace(/&lt;(\/?strong)&gt;/g, '<$1>') + '</h4>';
114						}
115
116						if (sku && suggestion.sku) {
117							returnValue += ' <p class="suggestion-sku">' + suggestion.sku + '</p>';
118						}
119
120						if (price && suggestion.price) {
121							returnValue += ' <p class="price">' + suggestion.price + '</p>';
122						}
123
124						if (suggestion.value) {
125							returnValue += ' </div>';
126						}
127
128						if (suggestion.products_not_found) {
129							returnValue = '<span class="no-found-msg">' + suggestion.value + '</span>';
130						}
131
132						if (isFullScreen2 && suggestion.no_results) {
133							$parentResult.addClass('wd-no-results');
134						}
135
136						$parentResult.addClass('wd-opened');
137						$this.parents('div[class*=\'wd-search-full-\']').addClass('wd-searched');
138
139						return returnValue;
140					}
141				});
142
143				if (productCat.length) {
144					var searchForm = $this.find('[type="text"]').devbridgeAutocomplete(),
145					    serviceUrl = woodmart_settings.ajaxurl + '?action=woodmart_ajax_search';
146
147					if (number > 0) {
148						serviceUrl += '&number=' + number;
149					}
150
151					serviceUrl += '&post_type=' + postType;
152
153					productCat.on('cat_selected', function() {
154						if (productCat.val() !== '') {
155							searchForm.setOptions({
156								serviceUrl: serviceUrl + '&product_cat=' + productCat.val()
157							});
158						} else {
159							searchForm.setOptions({
160								serviceUrl: serviceUrl
161							});
162						}
163
164						searchForm.hide();
165						searchForm.onValueChange();
166					});
167				}
168
169				$input.addClass('wd-search-inited');
170			});
171
172
173			woodmartThemeModule.$document.on('click', function(e) {
174				var target = e.target;
175
176				if (!$(target).is('.wd-search-form') && !$(target).parents().is('.wd-search-form') && !$(target).is('.wd-search-full-screen') && !$(target).parents().is('.wd-search-full-screen')) {
177					$this.find('[type="text"]').devbridgeAutocomplete('hide');
178				}
179			});
180
181			$('.wd-dropdown-results > .wd-scroll-content').on('click', function(e) {
182				e.stopPropagation();
183			});
184		});
185	};
186
187	$(document).ready(function() {
188		woodmartThemeModule.ajaxSearch();
189	});
190})(jQuery);

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