PageSourceSearch

https://gefest.market/g/templates/shop2/2.130.2/default-3/js/m.smart_search.js

js gefest.market collected 2026-09-30 02:55:23 UTC 8,146 bytes, 262 lines download raw bytes

1var shop2SmartSearch = new Vue({
2  el: '#search-app',
3  mixins: [VueClickaway.mixin],
4  data: {
5    search_query: "", // Строка поиска
6    products: [], // Список продуктов
7    placeholderValue: shop2SmartSearch.placeholderValue,
8    searchBtnValue: shop2SmartSearch.searchBtnValue,
9    foldersList: shop2SmartSearch.folders, // Список категорий
10    vendorsList: shop2SmartSearch.vendors, // Список производителей
11    img_w: shop2SmartSearch.img_width, // Ширина картинок
12    img_h: shop2SmartSearch.img_height, // Высота картинок
13    foundsProduct: 0, // Найдено продуктов
14    foundsFolders: 0, // Найдено категорий
15    foundsVendors: 0, // Найдено производителей
16    limitProducts: shop2SmartSearch.limit_products, // Лимит на вывод товаров 
17    foldersSearch: [], // Найденные категории
18    vendorsSearch: [], // Найденные производители
19    pagginationSearchList: [],
20    windowWidth: window.innerWidth,
21    resultMode: 0,
22    resultType: '',
23    resultToPage: 3,
24    pageCount: 0,
25    pageResultFounds: [],
26    activePage: 1,
27    activeTabs: {
28    	products: false,
29    	folders: false,
30    	vendors: false
31    },
32    allResult: false
33  },
34  mounted: function() {
35  	window.addEventListener('resize', this.handleWindowResize);
36  },
37  beforeDestroy: function () {
38    window.removeEventListener('resize', this. handleWindowResize)
39  },
40  created: function() {
41  	this.renderMode();
42  	this.foldersList.shift();
43  },
44  methods: {
45  	handleWindowResize: function(event) { 
46  		this.windowWidth = event.currentTarget.innerWidth; 
47  	},
48  	setPagination: function(type) {
49  		switch(type) {
50  			case 'products':
51  				this.changePage(1, 'products');
52  				this.pageCount = Math.ceil(this.foundsProduct/this.resultToPage);
53  				break;
54  			case 'folders':
55  				this.pageCount = Math.ceil(this.foundsFolders/this.resultToPage);
56  				break;
57  			case 'vendors':
58  				this.pageCount = Math.ceil(this.foundsVendors/this.resultToPage);
59  				break;
60  		}
61  	},
62  	changePage: function(pageNum, type) {
63  		var startRes = (pageNum - 1) * this.resultToPage;
64  			switch(type) {
65	  			case 'products':
66	  				this.pageResultFounds = this.products.slice(startRes, startRes + this.resultToPage);
67	  				break;
68	  			case 'folders':
69	  				this.pageResultFounds = this.foldersSearch.slice(startRes, startRes + this.resultToPage);
70	  				break;
71	  			case 'vendors':
72	  				this.pageResultFounds = this.foldersSearch.slice(startRes, startRes + this.resultToPage);
73	  				break;
74	  		}
75
76  	},
77  	renderMode: function() {
78  		if (this.windowWidth>960) {
79  			return 'desktop';
80  		}
81  		if (this.windowWidth<=960) {
82  			return 'tab';
83  		}
84  		if (this.windowWidth<=767) {
85  			return 'mobile';
86  		}
87
88  	},
89  	renderType: function(type) {
90  		this.resultMode = 1;
91  		switch(type) {
92  			case 'products':
93  				this.setPagination('products');
94  				this.resultType = 'products';
95  				break;
96  			case 'folders':
97  				this.setPagination('folders');
98  				this.resultType = 'folders';
99  				break;
100  			case 'vendors':
101  				this.setPagination('vendors');
102  				this.resultType = 'vendors';
103  				break;
104  		}
105  	},
106  	backPage: function() {
107	  	this.resultMode = 0; 
108	  	this.activePage = 1;
109  	},
110  	resetData: function() { // Cброс данных
111	    this.resetDataProducts();
112	    this.resetDataFolders();
113	    this.resetDataVendors();
114	    this.resetActiveTabs();
115	    this.allResult = false;
116  	},
117  	resetActiveTabs: function() {
118  		this.activeTabs.products = false;
119  		this.activeTabs.folders = false;
120  		this.activeTabs.vendors = false;
121  	},
122  	resetDataProducts: function() {
123  		this.products = [];
124  		this.foundsProduct = 0;
125  	},
126  	resetDataFolders: function() {
127  		this.foldersSearch = [];
128  		this.foundsFolders = 0;
129  	},
130  	resetDataVendors: function() {
131  		this.vendorsSearch = [];
132  		this.foundsVendors = 0;
133  	},
134  	searchStart: $.debounce(300,function() { // Стартовый запрос поиска
135  		if (this.search_query == "" || this.search_query.length < 2) {
136  			this.resetData();
137  			return;
138  		}
139  		this.searchProductsQuery();
140  		this.searchFoldersQuery();
141  		this.searchVendorsQuery();
142  	}),
143  	searchProductsQuery: function() { // Запрос на поиск продуктов
144  		
145  		var imgQuery = "";
146  		
147  		if (this.img_w || this.img_h) {
148  			imgQuery = '&img_width='+this.img_w+'&img_height='+this.img_h;
149  		}
150  		
151  		fetch('/-/x-api/v1/public/?method=shop2/getProductsBySearchMatches&param[s][search_text]=' 
152  			+ this.search_query 
153  			+ '&param[template]=global:shop2.2.130-search-smart-list-product.tpl'+imgQuery
154  			+ '&param[limit]=' + this.limitProducts)
155	    .then((response) => {
156	        if(response.ok) {
157	            return response.json();
158	        }
159	        throw new Error('Network response was not ok');
160	    })
161	    .then((json) => {
162	        this.products = [];
163	        
164	        if (json.result.found == 0) {
165	        	this.foundsProduct = 0;
166	        	return;
167	        }
168	        var data = JSON.parse(json.result.html);
169	        
170	        this.foundsProduct = json.result.found;
171	        
172	        for(item in data) {
173	        	this.products.push(data[item]);
174	        }
175	        this.visible_result = true;
176	        
177	    })
178	    .catch((error) => {
179	        console.log(error);
180	    });
181  	},
182  	searchFoldersQuery: function() { // Запрос на поиск категорий
183		var result = this.searchFolders(this.foldersList,this.search_query);
184			if (this.addParentsToFolders(result,this.foldersList) != undefined) {
185				this.foldersSearch = this.addParentsToFolders(result,this.foldersList);
186			} else {
187				this.foldersSearch = result;
188			}
189			
190			this.foundsFolders = this.foldersSearch.length;
191			
192  	},
193  	searchFolders: function(folders, text) { // Поиск категорий по ключевому слову
194
195  		var matches = [],
196			search_query = new RegExp($.trim(text),'i');
197		
198		for(item in folders) {
199        	var is_match_name = folders[item].folder_name.match(search_query),
200			   	is_match_alias = folders[item].alias.match(search_query);
201
202				if (is_match_name || is_match_alias) {
203					matches.push(folders[item]);
204					
205					folders[item].folder_name = folders[item].folder_name.replace(/&quot;/g, '\"');
206				}
207        }
208		return matches;
209  	},
210  	addParentsToFolders: function(folders, all_folders) { // Поиск родительских категорий
211		var result = [];
212
213		for(item in folders) {
214			
215			if (folders[item]._level < 2) {
216				return;
217		 	}
218		 	folders[item].parents = [];
219			 	
220			for(item_a in all_folders) {
221				
222				all_folders[item_a]._left = parseInt(all_folders[item_a]._left);
223				all_folders[item_a]._right = parseInt(all_folders[item_a]._right);
224				if (all_folders[item_a]._left < folders[item]._left && all_folders[item_a]._right > folders[item]._right) {
225					folders[item].parents.push(all_folders[item_a]);
226					
227		 		}
228		 	}
229		 	result.push(folders[item]);
230		}
231		return result;
232	},
233	searchVendorsQuery: function() { // Запрос на поиск производителей
234  		this.vendorsSearch = this.searchVendors(this.vendorsList,this.search_query);
235  		this.foundsVendors = this.vendorsSearch.length;
236	},
237	searchVendors: function(vendors, text) { // Поиск производителей по ключевому слову
238  		var matches = [],
239			search_query = new RegExp($.trim(text),'i');
240		
241		for(item in vendors) {
242        	var is_match_name = vendors[item].name.match(search_query),
243			   	is_match_alias = vendors[item].alias.match(search_query);
244				
245				if (is_match_name || is_match_alias) {
246					matches.push(vendors[item]);
247					
248					vendors[item].name = vendors[item].name.replace(/&quot;/g, '\"');
249				}
250        }
251		return matches;
252  	}
253  }
254});
255
256//$(function(){
257	$(document).on('click touchend', '#search-result .search-result-btn', function(){
258		$('#smart-search-block').find('button').click();
259	});
260	
261	$('#search-app').removeClass('hide_search_popup');
262//});

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.