PageSourceSearch

https://oookaller.ru/catalog/view/javascript/isearch.js

js oookaller.ru collected 2026-10-07 03:34:09 UTC 14,517 bytes, 440 lines download raw bytes

1$(document).ready(function() {
2function isEmpty(str) {
3   return (typeof str === "undefined" || str === null || str ===  "");
4}    
5//	$(window).load(function() {
6		String.prototype.capitalize = function() {
7			return this.charAt(0).toUpperCase() + this.slice(1);
8		}
9		
10		var searchBoxSelector = 'input[name=filter_name]';
11		var searchParam = 'filter_name';
12		var searchCompatibility = '/onefivefour';
13		var searchButtonSelector = '#search button';
14		var descriptionVariable = 'filter_description';
15		
16		if (ocVersion >= '1.5.5.1') {
17			searchBoxSelector = 'input[name=search]';
18			searchParam = 'search';
19			descriptionVariable = 'description';
20			searchCompatibility = '';
21		}
22		
23		if (ocVersion >= '2.0.0.0') {
24			searchBoxSelector = '#search input';
25		}
26
27		var searchBox = $(searchBoxSelector).first();
28		var originalSearchBox = searchBox;
29		
30		var originalSearchBoxContainer = searchBox.closest('#search').parent().html();
31		searchBox.closest('#search').parent().html('<div class="iSearchBoxWrapper">'+originalSearchBoxContainer+'<div class="clearfix"></div><div class="iSearchBox"></div><div id="iSearchBoxLoadingImage"></div></div>');
32		
33		var originalSearchBoxOffset = $(originalSearchBox).offset();
34		var originalSearchBoxWidth = $(originalSearchBox).innerWidth();
35		var originalSearchBoxHeight = $(originalSearchBox).innerHeight();
36		
37		$('#iSearchBoxLoadingImage').offset({
38			left: (originalSearchBoxOffset.left + originalSearchBoxWidth - 21),
39			top: (originalSearchBoxOffset.top + (originalSearchBoxHeight/2) - ($('#iSearchBoxLoadingImage').innerHeight()/2))
40		});
41		$('#iSearchBoxLoadingImage').hide();
42		$('#iSearchBoxLoadingImage').css('visibility', 'visible');
43		
44		/** Responsive Design logic */
45		var respondOnWidthChange = function() {
46			var searchFieldWidth = searchBox.width() + 16;
47			$('.iSearchBoxWrapper .iSearchBox').width(searchFieldWidth);
48		}
49		
50		var iSearchAjax = null;
51		
52		if (responsiveDesign == 'yes') {
53			$(window).resize(function() {
54				respondOnWidthChange();
55			});
56			respondOnWidthChange();
57		}
58		/** END */
59		
60		/** Close iSearch Box on Body Click */
61		$(document).click(function() {
62			$('.iSearchBox').hide();
63		});
64		$('.iSearchBoxWrapper').click(function(event) {
65			event.stopPropagation();
66		});
67		
68		/** END */
69		
70		/** After Hitting Enter */
71		var goIsearching = function() {
72			url = $('base').attr('href') + 'search'+searchCompatibility;   //index.php?route=product/i
73			var filter_name = $(searchBoxSelector).first().val();
74			filter_name = filter_name.trim();
75            filter_name = filter_name.replace(/\s/g, "+");
76            
77			if (!isEmpty(filter_name)) {
78				url += '&'+searchParam+'=' + encodeURI(filter_name);
79			}
80			if (searchInDescription) {
81				url += '&'+descriptionVariable+'=true';	
82			}
83			location = url;
84		}
85		
86		var useIsearchAfterHittingEnter = function() {
87			$(searchButtonSelector).unbind('click');
88			$(searchButtonSelector).bind('click',function() {
89				goIsearching();
90			});
91			
92			$(searchBoxSelector).first().unbind('keydown');
93			$(searchBoxSelector).first().bind('keydown', function(e) {
94				if (e.keyCode == 13) {
95                    if ($('.iSearchBox li.activekey').length) {
96                        $('.iSearchBox li.activekey').trigger('click');
97                    } else {
98                        goIsearching();
99                    }
100				}
101			});
102	
103		}
104		if (afterHittingEnter == 'isearchengine1541' || afterHittingEnter == 'isearchengine1551' || afterHittingEnter == 'isearchengine2000') {
105			setTimeout(function() {
106				useIsearchAfterHittingEnter();
107			}, 1000);
108		} else {
109			$(searchButtonSelector).bind('click', function() {
110				var url = $('base').attr('href') + 'search';	 
111				var filter_name =  $(searchBoxSelector).first().val();
112				filter_name = filter_name.trim();
113            filter_name = filter_name.replace(/\s/g, "+");
114            
115				if (!isEmpty(filter_name)) {
116					url += '&'+searchParam+'=' + encodeURI(filter_name);
117				}
118				location = url;
119			});
120		
121			$(searchBoxSelector).first().bind('keydown', function(e) {
122				if (e.keyCode == 13) {
123					url = $('base').attr('href') + 'search';
124					 
125					var filter_name =  $(searchBoxSelector).first().val();
126                    filter_name = filter_name.trim();
127            filter_name = filter_name.replace(/\s/g, "+");
128					if (!isEmpty(filter_name)) {
129						url += '&'+searchParam+'=' + encodeURI(filter_name);
130					}
131					
132					location = url;
133				}
134			});	
135		}
136		
137		/** END */
138		
139		/** Non-AJAX Loading */
140		if (useAJAX == 'no') {
141			$.ajax({ 
142				type: 'get',
143				url: 'index.php?route=module/isearch/ajaxget',
144				contentType: "application/json; charset=utf-8",
145				success: function(o) {
146					productsData = generateProductsDataFromJSONResponse(o);
147				}		
148			});
149		}
150		
151		var sortProductsByKeyword = function(keywords, products) {
152			var words = keywords.split(' ');
153			var sortedProducts = [];
154			$(products).each(function(i,e) {
155				productName = (e.name) ? e.name.toString().toLowerCase() : '';
156				if (productName.indexOf(words[0].toLowerCase()) != -1) {
157					sortedProducts.unshift(e);
158				} else {
159					sortedProducts.push(e);
160				}
161			});
162			return sortedProducts;
163		}
164		
165		var filterProductsByKeyword = function(keywords, products, str
165ictMode) {
166			var words = keywords.split(' ');
167			var filteredProducts = [];
168			$(products).each(function(i,e) {
169				productName = (e.name) ? e.name.toString().toLowerCase() : '';
170				productModel = (e.model) ? e.model.toString().toLowerCase() : '';
171				
172				var allWordsExist = true;
173				if (strictMode == 'yes') {
174					words[0] = keywords;	
175				}
176				$(words).each(function(j,w) {
177					if (productName.indexOf(w.toLowerCase()) == -1) {
178						if (searchInModel == 'no') {
179							allWordsExist = false;
180						} else {
181							if (productModel.indexOf(w.toLowerCase()) == -1) {
182								allWordsExist = false;
183							}
184						}
185					}
186				});
187				
188				if (allWordsExist == true) {
189					filteredProducts.push(e);	
190				}
191				
192		
193			});
194			return filteredProducts;
195		}
196		
197		/** END */
198		
199		var runSpellCheck = function($searchVal) {
200			/*if (SCWords) {
201				$(SCWords).each(function(i, e) {
202					if (e.incorrect == $searchVal) {
203						$searchVal = e.correct;
204					}
205				});
206			}*/
207			return $searchVal;
208		}
209		
210		var searchInProducts =function($name , $searchVal) {
211			var iname = $name;
212			var searchSplit = $searchVal.split(' ');
213			var ind = null;
214			$(searchSplit).each(function(i,searchWord) {
215				ind = i;
216				if (iname.toLowerCase().indexOf(searchWord.toLowerCase()) != -1) {
217					var startPos = iname.toLowerCase().indexOf(searchWord.toLowerCase());
218					var extractStr = iname.substr(startPos, searchWord.length);
219					iname = iname.replace(extractStr,'{'+extractStr+'}');
220				}
221			});
222			if (ind != null) {
223				iname = iname.replace(/{/g,'<span class="iMarq">');	
224				iname = iname.replace(/}/g,'</span>');	
225			}
226			return iname;
227
228			var iname = $name;
229			if ($name.toLowerCase().indexOf($searchVal.toLowerCase()) != -1) {
230				var startPos = $name.toLowerCase().indexOf($searchVal.toLowerCase());
231				var extractStr = $name.substr(startPos, $searchVal.length);
232				iname = $name.replace(extractStr,'<span class="iMarq">'+extractStr+'</span>');	
233			}
234			return iname;
235		}
236		
237        $(window).keydown(function(e) {
238            var itemsSet = $('.iSearchBox li:not(.iSearchHeading)');
239
240            if (!itemsSet.length) return;
241
242            var index_next = 0;
243            var index_prev = itemsSet.length - 1;
244
245            $(itemsSet).each(function(index, element) {
246                if ($(element).hasClass('activekey')) {
247                    index_next = index + 1;
248                    index_prev = index - 1;
249
250                    $(element).removeClass('activekey');
251                }
252            });  
253
254            if (index_next >= itemsSet.length) index_next = 0;
255            if (index_prev < 0) index_prev = itemsSet.length - 1;
256
257            if (e.which == 40) { // Down arrow
258                $('.iSearchBox li:not(.iSearchHeading):eq(' + index_next + ')').addClass('activekey');
259            } else if (e.which == 38) { // Up arrow
260                $('.iSearchBox li:not(.iSearchHeading):eq(' + index_prev + ')').addClass('activekey');
261            }
262        });
263        
264		var generateLIs = function(searchVal, fromProducts) {
265            var LIs = '';
266			var suggestionLIs = '';
267			searchVal = $.trim(searchVal);
268			var f = 0;
269			var maxFound = iSearchResultsLimit;
270			
271            var searchSuggestions = fromProducts.suggestions;
272            fromProducts = (fromProducts.products) ? fromProducts.products : productsData;
273			
274			var sortedProducts = fromProducts;
275			if (useAJAX == 'no') {
276				sortedProducts = sortProductsByKeyword(searchVal,fromProducts);
277				sortedProducts = filterProductsByKeyword(searchVal, sortedProducts, useStrictSearch);
278			}
279			$(sortedProducts).each(function(i,e) {
280				e.name = (e.name) ? e.name.toString() : '';
281				e.model = (e.model) ? e.model.toString() : '';
282				e.special = (e.special) ? e.special : '';
283				f++;
284				if (f <= maxFound) {
285					var iname = searchInProducts(e.name, searchVal);
286					var imodel = searchInProducts(e.model, searchVal);
287					var specialClass = (e.special) ? 'specialPrice' : '';
288					var imageTag = (loadImagesOnInstantSearch == 'no') ? '' : '<img src="'+e.image+'" />';
289					LIs += '<li onclick="document.location.href=\''+e.href.replace('\'', '\\\'').replace('%2F', '/')+'\'">'+imageTag+'<div class="iSearchItem"><h3>'+iname+'<div class="iSearchModel">'+imodel+'</div></h3><div class="iSearchPrice"><span class="'+specialClass+'">'+e.price+'</span><div class="iSearchSpecial">'+e.special+'</div></div><div class="clearfix"></div></div></li>';	
290				}
291		
292			});
293
294            console.log(searchSuggestions);
295
296            $(searchSuggestions).each(function(i,e) {
297                suggestionLIs += '<li onclick="document.location.href=\''+e.url.replace('\'', '\\\'').replace('%2F', '/')+'\'">
297' + e.term + '</li>';
298            });
299
300            var routeToController = (afterHittingEnter == 'isearchengine1541' || afterHittingEnter == 'isearchengine1551' || afterHittingEnter == 'isearchengine2000') ? 'search'+searchCompatibility : 'search';
301searchVal = searchVal.replace(/\s/g, "+");
302            var viewAllHref = 'index.php?route='+routeToController+'&'+searchParam+'='+encodeURI(searchVal);
303
304			if (f > maxFound) {
305				var viewAllLink = moreResultsText.replace('(N)', f);
306				var routeToController = (afterHittingEnter == 'isearchengine1541' || afterHittingEnter == 'isearchengine1551' || afterHittingEnter == 'isearchengine2000') ? 'search'+searchCompatibility : 'search';
307				
308				LIs += '<li class="iSearchViewAllResults" onclick="document.location = \'' + viewAllHref + '\'">'+viewAllLink+'</li>';
309			}
310
311			if (f == 0) {
312				LIs += '<li class="iSearchNoResults">'+noResultsText+'</li>';
313			}
314			
315			if (LIs != '' || suggestionLIs != '') {
316                var productHeading = productHeadingInstant;
317                var suggestionHeading = suggestionHeadingInstant;
318
319                var html = '';
320
321                if (suggestionLIs != '') {
322                    var suggestionHtml = '<ul class="isearchProducts">';
323                    suggestionHtml += '<li class="iSearchHeading">' + suggestionHeadingInstant + '</li>';
324                    suggestionHtml += suggestionLIs;
325                    suggestionHtml += '</ul>';
326
327                    html += suggestionHtml;
328                }
329
330                if (LIs != '') {
331                    var productHtml = '<ul class="isearchProducts">';
332                    productHtml += '<li class="iSearchHeading">' + productHeading + '</li>';
333                    productHtml += LIs;
334                    productHtml += '</ul>';
335
336    				html += productHtml;
337                }
338
339                $('.iSearchBox').html(html);
340
341				$('.iSearchBox').slideDown(70);
342			} else {
343				$('.iSearchBox').slideUp(50);
344			}
345			
346		
347		}
348		
349		var generateProductsDataFromJSONResponse = function(jsonObject) {
350			var prodData = {
351                products: [],
352                suggestions: []
353            };
354
355			if (typeof jsonObject.products != 'undefined') {
356                $(jsonObject.products).each(function(i,e) {
357                    var productObj = {
358                        'name' : e.name,
359                        'image' : e.image,
360                        'href' : e.href,
361                        'model' : e.model,
362                        'price' : e.price,
363                        'special' : (e.special) ? e.special : ''
364                    };
365                    $.merge(prodData.products,[productObj]);
366                });
367            }
368
369            if (typeof jsonObject.suggestions != 'undefined') {
370                $(jsonObject.suggestions).each(function(i,e) {
371                    var suggestionObj = {
372                        'url' : e.url,
373                        'term' : e.term
374                    };
375                    $.merge(prodData.suggestions,[suggestionObj]);
376                });
377            }
378            
379			return prodData;
380		}
381		
382		var showSearchResults = function (val, secondTry) { 
383			
384			if (val.length > 1) {
385				if (useAJAX == 'no') {
386					generateLIs(val);
387				} else {
388					iSearchAjax = $.ajax({ 
389						type: 'get',
390						dataType: 'json',
391						url: 'index.php?route=module/isearch/ajaxget&k='+encodeURIComponent(val),
392						contentType: "application/json; charset=utf-8",
393						success: function(o) {
394							var prodData = generateProductsDataFromJSONResponse(o);
395							if (prodData.products == '' && secondTry != true && runSpellCheck(val) != val) {
396								showSearchResults(runSpellCheck(val),true);
397							}
398							generateLIs(val,prodData);
399							
400						},
401						beforeSend: function(jqXHR, settings) {
402							//$('#iSearchBoxLoadingImage').show();
403						},
404						complete: function(jqXHR, textStatus) {
405							//$('#iSearchBoxLoadingImage').hide();	
406						}
407						
408					});
409				}
410				
411			} else {
412				$('.iSearchBox').slideUp(50);
413			}
414		}
415		
416		var typewatch = (function(){
417		  var timer = 0;
418		  return function(callback, ms){
419			clearTimeout (timer);
420			timer = setTimeout(callback, ms);
421		  }  
422		})();
423		
424		$(searchBoxSelector).first().attr('autocomplete', 'off').bind('keyup', function(e) {
425            if (e.which == 38 || e.which == 40) return;
426
427			if ($(this).is(':focus')) {
428				if (iSearchAjax != null) iSearchAjax.abort();
429				var baseVal = $(this).val();
430				if (useAJAX == 'no') {
431					showSearchResults(baseVal);
432				} else {
433					typewatch(function () {
434						showSearchResults(baseVal);
435					}, 300);
436				}
437			}
438		});
439//	});
440});

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.