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