1/** 2 * 3 * Advanced Search 5 Pro 4 * 5 * @author Presta-Module.com <[email protected]> 6 * @copyright Presta-Module 7 * 8 * ____ __ __ 9 * | _ \ | \/ | 10 * | |_) | | |\/| | 11 * | __/ | | | | 12 * |_| |_| |_| 13 * 14 ****/ 15 16var as4Plugin = { 17 18 // Attributes 19 lastIdSearch: false, 20 // Set to false in order to disable localStorage cache for AJAX queries 21 localCache: false, 22 localCacheKey: '', 23 params: new Array(), 24 extraParams: new Array(), 25 persistentParams: new Array(), 26 fromBackForwardEvent: false, 27 localStorageAvailable: null, 28 blurEffect: true, 29 previousOnPopState: null, 30 31 // Init 32 initDone: false, 33 34 // Get search results selector 35 getSearchResultsSelector: function(idSearch) { 36 return (as4Plugin.getParamValue(idSearch, 'search_results_selector') != '' ? as4Plugin.getParamValue(idSearch, 'search_results_selector') : '#content-wrapper'); 37 }, 38 39 // Get object value from key 40 getObjectValueByKey: function(obj, key) { 41 if (obj.length) { 42 for (var k in obj) { 43 if (obj[k].name == key) { 44 return obj[k].value; 45 } 46 } 47 } 48 return null; 49 }, 50 51 // Get params var 52 getParamValue: function(idSearch, varName) { 53 if (typeof (as4Plugin.params) != 'undefined' && typeof (as4Plugin.params[idSearch]) != 'undefined' && typeof(as4Plugin.params[idSearch][varName]) != 'undefined') { 54 return as4Plugin.params[idSearch][varName]; 55 } 56 return false; 57 }, 58 59 // Set params var 60 setParamValue: function(idSearch, varName, varValue) { 61 as4Plugin.params[idSearch][varName] = varValue; 62 }, 63 64 // Get persistent params var 65 getPersistentParamValue: function(idSearch, varName) {
66 if (typeof(as4Plugin.persistentParams[idSearch]) == 'undefined') { 67 as4Plugin.persistentParams[idSearch] = new Array(); 68 } 69 if (typeof(as4Plugin.persistentParams[idSearch][varName]) != 'undefined') { 70 return as4Plugin.persistentParams[idSearch][varName]; 71 } 72 return false; 73 }, 74 75 // Set persistent params var 76 setPersistentParamValue: function(idSearch, varName, varValue) { 77 if (typeof(as4Plugin.persistentParams[idSearch]) == 'undefined') { 78 as4Plugin.persistentParams[idSearch] = new Array(); 79 } 80 as4Plugin.persistentParams[idSearch][varName] = varValue; 81 }, 82 83 // Prevent some action to be done if search is triggered from back/forward event 84 getASFormOptionsCompleteCallBack: function(arg1) { 85 as4Plugin.fromBackForwardEvent = false; 86 }, 87 88 // Get Ajax dynamic parameters 89 getASFormOptions: function(idSearch) { 90 return { 91 beforeSubmit: as4Plugin.showAsRequest, 92 success: as4Plugin.showAsResponse, 93 complete: as4Plugin.getASFormOptionsCompleteCallBack, 94 localCache: as4Plugin.localCache, 95 localCacheKey: as4Plugin.localCacheKey, 96 cacheTTL: 2, 97 dataType: 'json', 98 data: { 99 ajaxMode: 1, 100 productFilterListData: as4Plugin.getParamValue(idSearch, 'as4_productFilterListData'), 101 productFilterListSource: as4Plugin.getParamValue(idSearch, 'as4_productFilterListSource'), 102 with_product: 1 103 }, 104 method: "POST" 105 }; 106 }, 107 108 // Get Ajax dynamic parameters 109 getASFormDynamicCriterionOptions: function(idSearch) { 110 return { 111 beforeSubmit: as4Plugin.showAsRequest, 112 success: as4Plugin.showAsResponse, 113 localCache: as4Plugin.localCache, 114 localCacheKey: as4Plugin.localCacheKey, 115 cacheTTL: 2, 116 dataType: 'json', 117 mode: 'abort', 118 port: 'asSearch', 119 data: { 120 with_product: 0, 121 ajaxMode: 1, 122 productFilterListData: as4Plugin.getParamValue(idSearch, 'as4_productFilterListData'), 123 productFilterListSource: as4Plugin.getParamValue(idSearch, 'as4_productFilterListSource') 124 }, 125 method: "POST" 126 }; 127 }, 128 129 // Pre-submit callback 130 showAsRequest: function(formData, jqForm, options) { 131 var idSearch = $(jqForm).find('input[name=id_search]').val(); 132 if (typeof(idSearch) == 'undefined' && typeof(history.state) != 'undefined' && history.state != null && typeof(history.state.id_search) != 'undefined' && !isNaN(history.state.id_search)) { 133 idSearch = history.state.id_search; 134 } 135 if (isNaN(idSearch) && as4Plugin.lastIdSearch != false && !isNaN(as4Plugin.lastIdSearch)) { 136 // Retrieve latest known idSearch 137 idSearch = as4Plugin.lastIdSearch; 138 } 139 if (isNaN(idSearch)) { 140 // Retrieve idSearch from ajax call data 141 idSearch = parseInt(as4Plugin.getObjectValueByKey(formData, 'id_search')); 142 } 143 if (!isNaN(idSearch)) {
144 // With product ? 145 withProduct = parseInt(as4Plugin.getObjectValueByKey(formData, 'with_product')); 146 147 as4Plugin.lastIdSearch = idSearch; 148 as4Plugin.setLayer('#PM_ASBlockOutput_' + idSearch); 149 if (withProduct) { 150 as4Plugin.setLayer(as4Plugin.getSearchResultsSelector(idSearch)); 151 // Add CSS classes to center column 152 var centerColumnCssClasses = as4Plugin.getParamValue(idSearch, 'centerColumnCssClasses'); 153 if (typeof(centerColumnCssClasses) != 'undefined' && centerColumnCssClasses != null && centerColumnCssClasses.length > 0) { 154 $(as4Plugin.getSearchResultsSelector(idSearch)).addClass(centerColumnCssClasses); 155 } 156 } 157 } 158 return true; 159 }, 160 161 scrollTop: function(idSearch, context, forceScroll) { 162 if (as4Plugin.getParamValue(idSearch, 'scrollTopActive') == true || forceScroll === true) { 163 pm_scrollTopSelector = as4Plugin.getSearchResultsSelector(idSearch); 164 165 if (typeof($(pm_scrollTopSelector)) != 'undefined' && $(pm_scrollTopSelector).length > 0) { 166 $('html, body').animate({ 167 scrollTop: $(pm_scrollTopSelector).offset().top 168 }, 500); 169 } 170 } 171 }, 172 173 setResultsContents: function(id_search, htmlResults, context, withProduct) { 174 $(document).trigger('as4-Before-Set-Results-Contents', [id_search, context]); 175 var keepCategoryInformation = as4Plugin.getParamValue(id_search, 'keep_category_information'); 176 var searchResultsSelector = as4Plugin.getSearchResultsSelector(id_search); 177 178 // Init sliders 179 as4Plugin.initSliders(); 180 181 // Init toggleLink 182 as4Plugin.initCriterionHideToggleLink(); 183 184 if (!keepCategoryInformation) { 185 $('#main .block-category').remove(); 186 } 187 188 var destinationElement = $('body ' + searchResultsSelector); 189 if ($(destinationElement).length > 0) { 190 // Animation complete. 191 $(searchResultsSelector).css('height', 'auto'); 192 } 193 as4Plugin.removeLayer(); 194 $(document).trigger('as4-After-Set-Results-Contents', [id_search, context]); 195 }, 196 197 showAsResponse: function(responseText, statusText, xhr, $form) { 198 if (typeof(responseText.redirect_to_url) != 'undefined' && responseText.redirect_to_url != '') { 199 window.location = responseText.redirect_to_url; 200 return; 201 } 202 203 // Allow to "not" replace rendered products in case we only want facets to be updated 204 if (responseText.rendered_products_top == null) { 205 responseText.rendered_products_top = function() { return $(this) }; 206 } 207 var withProduct = true; 208 if (responseText.rendered_products == null) { 209 withProduct = false; 210 responseText.without_products = true; 211 responseText.rendered_products = function() { return $(this) }; 212 } else { 213 responseText.without_products = false; 214 } 215 if (responseText.rendered_products_bottom == null) { 216 responseText.rendered_products_bottom = function() { return $(this) }; 217 } 218 if (typeof($form) == 'undefined') { 219 $form = $('#PM_ASForm_' + history.state.id_search); 220 } 221 var id_search = $form.find('input[name=id_search]').val(); 222 var step_search = as4Plugin.getParamValue(id_search, 'stepSearch'); 223 var hookName = as4Plugin.getParamValue(id_search, 'hookName'); 224 var searchResultsSelector = as4Plugin.getSearchResultsSelector(id_search); 225 226 if ($('#js-product-list').length == 0 && withProduct) { 227 if (hookName == 'home') { 228 // Remove any extra content from homepage 229 $('#PM_ASBlockOutput_' + responseText.id_search).parent().find('*:not([id="PM_ASBlockOutput_' + responseText.id_search + '"])').remove(); 230 $('#PM_ASBlockOutput_' + responseText.id_search).after('<section id="products"><div id="js-product-list-top"></div><div id="js-product-list"></div><div id="js-product-list-bottom"></div></section>'); 231 } else { 232 $(searchResultsSelector).find('*:not([id="PM_ASBlockOutput_' + responseText.id_search + '"])').remove(); 233 $(searchResultsSelector).prepend('<section id="products"><div id="js-product-list-top"></div><div id="js-product-list"></div><div id="js-product-list-bottom"></div></section>'); 234 } 235 } 236 237 if ((typeof(responseText.remind_selection) != 'undefined' && (responseText.remind_selection == 3 || responseText.remind_selection == 1))) { 238 // Check if #js-active-search-filters exists 239 if (withProduct && $('#js-active-search-filters').length == 0 && $('#js-product-list-top').length > 0) { 240 // Add this missing div first 241 $('#js-product-list-top').parent().prepend('<div id="js-active-search-filters"></div>'); 242 } 243 } else { 244 $('#js-active-search-filters').remove(); 245 } 246 247 // Prevent scroll to the top from the default theme's updateProductList handler when we apply a new criterion 248 var currentTop = $(window).scrollTop(); 249 prestashop.once('updateProductList', function () { 250 $(document).scrollTop(currentTop); 251 }); 252 253 // Emit a product list update event if we have products to show after the request 254 if (!responseText.without_products) { 255 prestashop.emit('updateProductList', responseText); 256 } 257 258 // Update search block (facets) 259 $('#PM_ASBlockOutput_' + responseText.id_search).replaceWith(responseText.rendered_facets); 260 261 // Mobile styles 262 as4Plugin.initMobileStyles(responseText.id_search); 263 264 // Hide selection reminder if empty 265 $('.PM_ASSelectionsDropDown').each(function() { 266 if ($('li.PM_ASSelectionsSelectedCriterion', $(this)).length == 0) { 267 $(this).hide(); 268 } 269 }); 270 271 if (typeof(responseText.current_url) != 'undefined' && responseText.current_url != '') { 272 as4Plugin.pushStateNewURL(responseText.current_url); 273 } 274 275 if (typeof(responseText.html_block) != 'undefined' && responseText.html_block != '' && responseText.html_block != null) { 276 var htmlBlock = responseText.html_block; 277 step_search = false;
278 } else if (step_search == 1) { 279 var next_id_criterion_group = $form.find('input[name="next_id_criterion_group"]').val(); 280 var htmlBlock = responseText.html_criteria_block; 281 as4Plugin.setNextIdCriterionGroup(id_search, responseText.next_id_criterion_group); 282 } 283 // var htmlResults = responseText.html_products; 284 if (htmlBlock) { 285 if (hookName == 'top' || hookName == 'displayTop' || hookName == 'displayNavFullWidth') { 286 if (step_search == 1) { 287 var htmlBlockSelection = responseText.html_selection_block; 288 if (htmlBlockSelection) { 289 $('#PM_ASBlock_' + id_search + ' .PM_ASSelectionsBlock').html(htmlBlockSelection); 290 } 291 $('#PM_ASCriterionsGroup_' + id_search + '_' + next_id_criterion_group).html(htmlBlock); 292 } else { 293 $('#PM_ASBlockOutput_' + id_search).html(htmlBlock); 294 } 295 } else { 296 // Animation complete. 297 if (step_search == 1) { 298 var htmlBlockSelection = responseText.html_selection_block; 299 if (htmlBlockSelection) { 300 $('#PM_ASBlock_' + id_search + ' .PM_ASSelectionsBlock').html(htmlBlockSelection); 301 } 302 $('#PM_ASCriterionsGroup_' + id_search + '_' + next_id_criterion_group).html(htmlBlock); 303 } else { 304 $('#PM_ASBlockOutput_' + id_search).html(htmlBlock); 305 } 306 } 307 } 308 // as4Plugin.setResultsContents(id_search, htmlResults, 'showAsResponse'); 309 as4Plugin.setResultsContents(id_search, '', 'showAsResponse', withProduct); 310 }, 311 312 runSearch: function(id_search, search_method) { 313 if (search_method == 1) { 314 setTimeout(function() { 315 $('#PM_ASForm_' + id_search).ajaxSubmit(as4Plugin.getASFormOptions(id_search)); 316 }, 1); 317 } else if (search_method == 2 || search_method == 4) { 318 setTimeout(function() { 319 $('#PM_ASForm_' + id_search).ajaxSubmit(as4Plugin.getASFormDynamicCriterionOptions(id_search)); 320 }, 1); 321 } 322 }, 323 324 nextStep: function(id_search, search_method) { 325 setTimeout(function() { 326 if (search_method == 2 || search_method == 3 || search_method == 4) { 327 $('#PM_ASForm_' + id_search).ajaxSubmit(as4Plugin.getASFormDynamicCriterionOptions(id_search)); 328 } else { 329 $('#PM_ASForm_' + id_search).ajaxSubmit(as4Plugin.getASFormOptions(id_search)); 330 } 331 }, 1); 332 }, 333 334 getFormSerialized: function(id_search) { 335 return $('#PM_ASForm_' + id_search).serialize(); 336 }, 337 338 getFormSerializedArray: function(id_search) { 339 return $('#PM_ASForm_' + id_search).serializeArray(); 340 }, 341 342 addBestSalesOptions: function(id_search) { 343 if (as4Plugin.getParamValue(id_search, 'addBestSalesOption') == true) { 344 // Add best sales option 345 $(document).ready(function() { 346 $('#selectPrductSort, #selectProductSort, .selectPrductSort').each(function() { 347 $('option[value^="sales:"]', this).remove(); 348 if ($('option[value^="sales:"]', this).length == 0) { 349 if (as4Plugin.getParamValue(id_search, 'orderBy') == 'sales') { 350 $('option:selected', this).prop('selected', false); 351 } 352 // Add new items 353 if (as4Plugin.getParamValue(id_search, 'orderBy') == 'sales' && as4Plugin.getParamValue(id_search, 'orderWay') == 'asc') { 354 $(this).append('<option value="sales:asc" selected="selected">' + as4_orderBySalesAsc + '</option>'); 355 } else { 356 $(this).append('<option value="sales:asc">' + as4_orderBySalesAsc + '</option>'); 357 } 358 if (as4Plugin.getParamValue(id_search, 'orderBy') == 'sales' && as4Plugin.getParamValue(id_search, 'orderWay') == 'desc') { 359 $(this).append('<option value="sales:desc" selected="selected">' + as4_orderBySalesDesc + '</option>'); 360 } else { 361 $(this).append('<option value="sales:desc">' + as4_orderBySalesDesc + '</option>'); 362 } 363 } 364 }); 365 }); 366 } 367 }, 368 369 getIdSearchFromItem: function(item) { 370 if ($(item).parents('.PM_ASBlockOutput').length > 0) { 371 return $(item).parents('.PM_ASBlockOutput').data('id-search'); 372 } else if ($(item).parents('#PM_ASearchResults').length > 0) { 373 return $(item).parents('#PM_ASearchResults').data('id-search'); 374 } else if ($(item).parents('[data-id-search]').length > 0) { 375 return $(item).parents('[data-id-search]').data('id-search'); 376 } 377 return false;
378 }, 379 380 initMobileStyles: function(idSearch) { 381 if (typeof(prestashop) == 'object' && prestashop.responsive.mobile == true) { 382 $('.PM_ASBlockOutput').addClass('PM_ASMobileMode'); 383 if (!isNaN(idSearch)) { 384 $('#PM_ASBlockOutput_' + idSearch).addClass('PM_ASMobileVisible'); 385 } 386 } else if (typeof(prestashop) == 'object' && prestashop.responsive.mobile == false) { 387 $('.PM_ASBlockOutput').removeClass('PM_ASMobileMode'); 388 } 389 }, 390 391 initSearchEngine: function() { 392 // Init is already done... 393 if (as4Plugin.initDone) { 394 return; 395 } 396 as4Plugin.initDone = true; 397 398 $(document).on('click', '.PM_ASBlockOutput .card-header', function(e) { 399 e.preventDefault(); 400 if (typeof(prestashop) == 'object' && prestashop.responsive.mobile == true) { 401 $(this).parents('.PM_ASBlockOutput').toggleClass('PM_ASMobileVisible'); 402 } 403 }); 404 405 $(document).on('click', '.PM_ASBlockOutput .PM_ASResetSearch', function(e) { 406 e.preventDefault(); 407 id_search = as4Plugin.getIdSearchFromItem(this); 408 $(document).trigger('as4-Search-Reset', [id_search]); 409 const resetURL = as4Plugin.getParamValue(id_search, 'resetURL'); 410 if (resetURL.length) { 411 location.href = resetURL; 412 } else { 413 location.href = window.prestashop.urls.current_url; 414 } 415 }); 416 417 $(document).on('click', '.PM_ASSelectionsBlock .PM_ASSelectionsDropDownShowLink', function(e) { 418 e.preventDefault(); 419 $(this).toggleClass('PM_ASSelectionsBlockOpened'); 420 $(this).next('.PM_ASSelectionsDropDownMenu').slideToggle('fast'); 421 }); 422 // Hide selection reminder if empty (on load) 423 $('.PM_ASSelectionsDropDown').each(function() { 424 if ($('li.PM_ASSelectionsSelectedCriterion', $(this)).length == 0) { 425 $(this).hide(); 426 } 427 }); 428 429 $(document).on('click', '.PM_ASBlockOutput .PM_ASLabelCheckbox', function(e) { 430 e.preventDefault(); 431 $('input#' + $(this).attr('for')).trigger('click'); 432 }); 433 434 $(document).on('click', '.PM_ASBlockOutput .PM_ASCriterionEnable .PM_ASCriterionLink', function(e) { 435 e.preventDefault(); 436 437 if ($(this).parents('li').hasClass('PM_ASCriterionDisable')) { 438 return; 439 } 440 id_search = as4Plugin.getIdSearchFromItem(this); 441 id_criterion_group = $(this).data('id-criterion-group'); 442 if (typeof(id_criterion_group) != 'undefined' && as4Plugin.getParamValue(id_search, 'seo_criterion_groups') != '' && as4Plugin.getParamValue(id_search, 'seo_criterion_groups').length > 0) { 443 if ($.inArray(id_criterion_group, as4Plugin.getParamValue(id_search, 'seo_criterion_groups').split(',')) != -1) { 444 return; 445 } 446 } 447 448 if (!$(this).hasClass('PM_ASCriterionLinkSelected')) { 449 $(this).next('input').prop('disabled', false); 450 $(this).addClass('PM_ASCriterionLinkSelected'); 451 } else { 452 $(this).next('input').prop('disabled', true); 453 $(this).removeClass('PM_ASCriterionLinkSelected'); 454 } 455 456 $(document).trigger('as4-Criterion-Change', [id_search, id_criterion_group, $(this).next('input').val(), $.trim($(this).text() == '' ? $(this).attr('title') : $(this).text()), 'link']); 457 }); 458 459 $(document).on('click', '.PM_ASBlockOutput .PM_ASCriterionStepEnable .PM_ASCriterionLink', function(e) { 460 e.preventDefault(); 461 462 if ($(this).parents('li').hasClass('PM_ASCriterionDisable')) { 463 return; 464 } 465 466 id_search = as4Plugin.getIdSearchFromItem(this); 467 id_criterion_group = $(this).data('id-criterion-group'); 468 if (typeof(id_criterion_group) != 'undefined' && as4Plugin.getParamValue(id_search, 'seo_criterion_groups') != '' && as4Plugin.getParamValue(id_search, 'seo_criterion_groups').length > 0) { 469 if ($.inArray(id_criterion_group, as4Plugin.getParamValue(id_search, 'seo_criterion_groups').split(',')) != -1) { 470 return; 471 } 472 } 473 474 if (!$(this).hasClass('PM_ASCriterionLinkSelected')) { 475 $(this).next('input').prop('disabled', false); 476 $(this).addClass('PM_ASCriterionLinkSelected'); 477 } else { 478 $(this).next('input').prop('disabled', true); 479 $(this).removeClass('PM_ASCriterionLinkSelected'); 480 } 481 482 $(document).trigger('as4-Criterion-Change', [id_search, id_criterion_group, $(this).next('input').val(), $.trim($(this).text() == '' ? $(this).attr('title') : $(this).text()), 'link']); 483 }); 484 485 $('body').on('change', '#search_filters select, .PM_ASBlockOutput .PM_ASCriterionGroupSelect', function(e) { 486 e.preventDefault(); 487 e.stopImmediatePropagation(); 488
489 // Do not proceed change event while selectize is open 490 if (typeof (this.selectize) != 'undefined' && this.selectize.isOpen && $(this).attr('multiple') != 'multiple') { 491 return; 492 } 493 494 id_search = as4Plugin.getIdSearchFromItem(this); 495 id_criterion_group = $(this).data('id-criterion-group'); 496 497 $(document).trigger('as4-Criterion-Change', [id_search, id_criterion_group, $(this).val(), $.trim($(this).find('option:selected').text()), 'select']); 498 }); 499 500 $(document).on('click', '.PM_ASBlockOutput .PM_ASCriterionCheckbox', function(e) { 501 id_search = as4Plugin.getIdSearchFromItem(this); 502 id_criterion_group = $(this).data('id-criterion-group'); 503 504 $(document).trigger('as4-Criterion-Change', [id_search, id_criterion_group, $(this).val(), $.trim($('label[for="as4c_' + $(this).attr('data-id-criterion-group') + '_' + $(this).val() + '"]').text()), 'checkbox']); 505 }); 506 507 // Numeric range 508 $(document).on('change', '.PM_ASCriterionsGroup input[type=number]', function(e) { 509 e.preventDefault(); 510 511 id_search = as4Plugin.getIdSearchFromItem(this); 512 id_criterion_group = $(this).data('id-criterion-group'); 513 search_method = as4Plugin.getParamValue(id_search, 'searchMethod'); 514 step_search = as4Plugin.getParamValue(id_search, 'stepSearch'); 515 516 min = parseFloat($('#PM_ASInputCritRange' + id_search + '_' + id_criterion_group + '_min').val()); 517 max = parseFloat($('#PM_ASInputCritRange' + id_search + '_' + id_criterion_group + '_max').val()); 518 519 if (min == "NaN" || max == "NaN") { 520 return false; 521 } 522 523 newInputValue = (min <= max ? min : max) + "~" + (max >= min ? max : min); 524 $('#PM_ASInputCritRange' + id_search + '_' + id_criterion_group).val(newInputValue); 525 526 if (step_search == 1) { 527 as4Plugin.nextStep(id_search, search_method); 528 } else { 529 if (search_method == 1) { 530 $('#PM_ASForm_' + id_search + '').ajaxSubmit(as4Plugin.getASFormOptions(id_search)); 531 } 532 if (search_method == 2 || search_method == 4) { 533 $('#PM_ASForm_' + id_search + '').ajaxSubmit(as4Plugin.getASFormDynamicCriterionOptions(id_search)); 534 } 535 } 536 537 $(document).trigger('as4-Criterion-Change', [id_search, id_criterion_group, null, null, 'range']); 538 }); 539 540 // Reset criterions group 541 $(document).on('click', '.PM_ASBlockOutput .PM_ASResetGroup', function(e) { 542 e.preventDefault(); 543 544 id_search = as4Plugin.getIdSearchFromItem(this); 545 id_criterion_group = $(this).attr('rel'); 546 search_method = as4Plugin.getParamValue(id_search, 'searchMethod'); 547 548 $(document).trigger('as4-Criterion-Group-Reset', [id_search, id_criterion_group]); 549 $('#PM_ASForm_' + id_search + ' input[name=reset_group]').val(id_criterion_group); 550 551 // In case we are in "Last criterion selected" mode, the reset button must re-execute the step, not the search 552 if (search_method == 3) { 553 as4Plugin.nextStep(id_search, search_method); 554 } else { 555 as4Plugin.runSearch(id_search, search_method); 556 } 557 }); 558 559 // Skip criterions group (step search) 560 $(document).on('click', '.PM_ASBlockOutput .PM_ASSkipGroup', function(e) { 561 e.preventDefault(); 562 563 id_search = as4Plugin.getIdSearchFromItem(this); 564 id_criterion_group = $(this).attr('rel'); 565 search_method = as4Plugin.getParamValue(id_search, 'searchMethod'); 566 567 $('#PM_ASForm_' + id_search + ' [name="as4c[' + id_criterion_group + '][]"]').prop('disabled', true); 568 $('#PM_ASForm_' + id_search + ' [name="as4c[' + id_criterion_group + '][]"][value="-1"]').prop('disabled', false); 569 $(document).trigger('as4-Criterion-Group-Skip', [id_search, id_criterion_group, search_method]); 570 as4Plugin.nextStep(id_search, search_method); 571 }); 572 573 // Show advanced Search 574 $(document).on('click', '.PM_ASBlockOutput .PM_ASShowCriterionsGroupHidden a', function(e) { 575 e.preventDefault(); 576 577 var id_search = as4Plugin.getIdSearchFromItem(this); 578 var e = $(this); 579 var hideState = $(e).parent('.PM_ASShowCriterionsGroupHidden').next('.PM_ASCriterionsGroupHidden:hidden').length; 580 $.ajax({ 581 method: "POST", 582 url: ASSearchUrl, 583 cache: false, 584 data: ('setHideCriterionStatus=1&id_search=' + id_search + '&state=' + hideState + '&productFilterListData=' + as4Plugin.getParamValue(id_search, 'as4_productFilterListData') + '&productFilterListSource=' + as4Plugin.getParamValue(id_search, 'as4_productFilterListSource')), 585 success: function(responseText) { 586 if (hideState == 0) { 587 $(e).parent().removeClass('PM_ASShowCriterionsGroupHiddenOpen'); 588 } else { 589 $(e).parent().addClass('PM_ASShowCriterionsGroupHiddenOpen'); 590 } 591 $(e).parent('.PM_ASShowCriterionsGroupHidden').nextAll('.PM_ASCriterionsGroupHidden').slideToggle('fast'); 592 as4Plugin.searchResponseCallback(id_search); 593 } 594 }); 595 }); 596 // /From initSearch 597 598 // From initNotMulticriteriaElements 599 $(document).on('mousedown', '.PM_ASNotMulticriteria', function(e) { 600 e.preventDefault(); 601 602 if ($(this).parents('li').hasClass('PM_ASCriterionDisable')) { 603 return; 604 } 605 // For checkbox 606 if ($(this).attr('type') == 'checkbox') { 607 if (!$(this).prop('checked')) { 608 var curIndex = $(this).parent('li').index(); 609 $(this).parent('li').parent('ul').find('li:not(:eq(' + curIndex + ')) > input[type=checkbox]').prop('checked', false); 610 } 611 } else { 612 if (!$(this).hasClass('PM_ASCriterionLinkSelected')) { 613 var curIndex = $(this).parent('li').index(); 614 $(this).parent('li').parent('ul').find('li:eq(' + curIndex + ') > input[type=hidden]').prop('disabled', false); 615 $(this).parent('li').parent('ul').find('li:not(:eq(' + curIndex + ')) > input[type=hidden]').prop('disabled', true); 616 $(this).parent('li').parent('ul').find('li > a').removeClass('PM_ASCriterionLinkSelected'); 617 } 618 } 619 }); 620 // /From initNotMulticriteriaElements 621 622 // From initFormSearchBlocLink 623 $(document).on('click', '.PM_ASSelectionsRemoveLink', function(e) { 624 e.preventDefault(); 625 var id_search = as4Plugin.getIdSearchFromItem(this); 626 627 $(this).next('input').prop('disabled', true); 628 $(this).parents('form').ajaxSubmit(as4Plugin.getASFormOptions(id_search)); 629 }); 630 631 $(document).on('click', '.PM_ASBlockOutput .PM_ASCriterionHideToggleClick a', function(e) { 632 e.preventDefault(); 633 $(this).parents('.PM_ASCriterions').find('.PM_ASCriterionHide').slideToggle('fast'); 634 $(this).parents('.PM_ASCriterions').find('.PM_ASCriterionGroupColor.color_to_pick_list li.PM_ASCriterionHide, .PM_ASCriterionGroupImage li.PM_ASCriterionHide').css('display', 'inline-block'); 635 $(this).children('.PM_ASHide, .PM_ASShow').toggle(); 636 }); 637 // /From initFormSearchBlocLink 638 639 // From initFormSearchBlockLevelDepth 640 /* Level Depth */ 641 $(document).on('click', '.PM_ASBlockOutput .PM_ASCriterionOpenClose', function(e) { 642 e.preventDefault(); 643 id_category = $(this).data('id-category'); 644 id_search = as4Plugin.getIdSearchFromItem(this); 645 event_type = 'open'; 646 647 if ($(this).hasClass('PM_ASCriterionClose')) { 648 event_type = 'open'; 649 $(this).removeClass('PM_ASCriterionClose').addClass('PM_ASCriterionOpen'); 650 } else if ($(this).hasClass('PM_ASCriterionOpen')) { 651 event_type = 'close'; 652 $(this).removeClass('PM_ASCriterionOpen').addClass('PM_ASCriterionClose'); 653 } 654 655 as4Plugin.closeNestedCategories(event_type, id_category, true); 656 }); 657 $(document).on('click', '.PM_ASBlockOutput .PM_ASCriterionLevelChoose', function(e) { 658 e.preventDefault(); 659 660 id_criterion = $(this).data('id-criterion'); 661 id_criterion_group = $(this).data('id-criterion-group'); 662 id_search = as4Plugin.getIdSearchFromItem(this); 663 currentCategoryLevelItem = $('#PM_ASCriterionGroupSelect_' + id_search + '_' + id_criterion_group); 664 currentSelectedCategory = $('option[value="' + id_criterion + '"]', currentCategoryLevelItem); 665 666 if (currentSelectedCategory.length > 0 && currentSelectedCategory.prop('selected') == true) { 667 // Category is already selected, we must unselect it 668 $('option:selected', currentCategoryLevelItem).prop('selected', false); 669 currentCategoryLevelItem.trigger('change'); 670 } else { 671 $('option:selected', currentCategoryLevelItem).prop('selected', false); 672 currentSelectedCategory.prop('selected', true); 673 currentCategoryLevelItem.trigger('change'); 674 } 675 }); 676 /* /Level Depth */ 677 // /From initFormSearchBlockLevelDepth 678 679 $(document).on('click', '.PM_ASSubmitSearch', function(e) { 680 e.preventDefault(); 681 var id_search = as4Plugin.getIdSearchFromItem(this); 682 $(this).parents('form').ajaxSubmit(as4Plugin.getASFormOptions(id_search)); 683 }); 684 685 as4Plugin.removeOldEvents(); 686 }, 687 688 closeNestedCategories: function(eventType, idCategory, onlyShowNextLevel) { 689 if (!isNaN(idCategory)) { 690 $('#PM_ASBlock_' + id_search + ' .PM_ASCriterionLevel[data-id-p
690arent="' + idCategory + '"]').each(function() { 691 if (eventType == 'close') { 692 $('.PM_ASCriterionOpenClose', this).removeClass('PM_ASCriterionOpen').addClass('PM_ASCriterionClose'); 693 $(this).slideUp(); 694 } else { 695 if (onlyShowNextLevel) { 696 $(this).slideDown(); 697 } 698 } 699 700 nestedCategoryId = $('.PM_ASCriterionOpenClose', this).data('id-category'); 701 as4Plugin.closeNestedCategories(event_type, nestedCategoryId, false); 702 }); 703 } 704 }, 705 706 handleFilterButtonEvent: function(id_search) { 707 // Open search engine filters when native "Filter" button is pressed 708 setTimeout(function () { 709 $('body').off('click', '#search_filter_toggler'); 710 if (typeof (id_search) == 'undefined') { 711 $('body').on('click', '#search_filter_toggler', function () { 712 if ($('.PM_ASBlockOutput:not(.PM_ASMobileVisible) .card-header').size() > 0) { 713 searchBlock = $('.PM_ASBlockOutput:not(.PM_ASMobileVisible) .card-header'); 714 searchBlock.get(0).click(); 715 $('html, body').animate({ 716 scrollTop: searchBlock.offset().top 717 }, 500); 718 } 719 }); 720 } else { 721 $('body').on('click', '#search_filter_toggler', function () { 722 $('#PM_ASBlockOutput_' + id_search + ':not(.PM_ASMobileVisible) .card-header').click(); 723 $('html, body').animate({ 724 scrollTop: $('#PM_ASBlockOutput_' + id_search + ' .card-header').offset().top 725 }, 500); 726 }); 727 } 728 }, 200); 729 }, 730 731 removeOldEvents: function(id_search) { 732 as4Plugin.handleFilterButtonEvent(id_search); 733 $('body').off('change', '#search_filters select'); 734 $(document).off('change', '#search_filters select'); 735 }, 736 737 initSliders: function() { 738 $('.PM_ASCritRange').each(function() { 739 sliderItem = $(this); 740 id_search = as4Plugin.getIdSearchFromItem(sliderItem); 741 742 sliderItem.slider({ 743 range: true, 744 min: $(this).data('min'), 745 max: $(this).data('max'), 746 step: $(this).data('step'), 747 values: $(this).data('values'), 748 disabled: $(this).data('disabled'), 749 slide: function(event, ui) { 750 id_search = $(this).data('id-search'); 751 752 as4Plugin.assignRangeValues($(this), id_search, ui); 753 }, 754 stop: function(event, ui) { 755 id_search = $(this).data('id-search'); 756 search_method = as4Plugin.getParamValue(id_search, 'searchMethod'); 757 step_search = as4Plugin.getParamValue(id_search, 'stepSearch'); 758 759 as4Plugin.assignRangeValues($(this), id_search, ui); 760 761 if (step_search == 1) { 762 as4Plugin.nextStep(id_search, search_method); 763 } else { 764 if (search_method == 1) { 765 $('#PM_ASForm_' + id_search).ajaxSubmit(as4Plugin.getASFormOptions(id_search)); 766 } 767 if (search_method == 2 || search_method == 4) { 768 $('#PM_ASForm_' + id_search).ajaxSubmit(as4Plugin.getASFormDynamicCriterionOptions(id_search)); 769 } 770 } 771 } 772 }); 773 }); 774 }, 775 776 initCriterionHideToggleLink: function() { 777 $('.PM_ASCriterionHideToggleLink').click(function(e) { 778 e.preventDefault(); 779 return; 780 }); 781 782 $('.PM_ASBlockOutput .PM_ASCriterionsToggleHover').hoverIntent(function(e) { 783 if (typeof(e.toElement) != 'undefined' && ($(e.toElement).is('.PM_ASResetGroup') || $(e.toElement).is('.PM_ASSkipGroup'))) { 784 e.preventDefault(); 785 return; 786 } 787 $(this).addClass('PM_ASCriterionGroupToggleHover'); 788 $(this).find('.PM_ASCriterionHide').stop().slideDown('fast'); 789 $(this).find('.PM_ASCriterionGroupColor.color_to_pick_list li.PM_ASCriterionHide').css('display', 'inline-block'); 790 $(this).find('.PM_ASCriterionGroupImage li.PM_ASCriterionHide').css('display', 'inline-block'); 791 }, function() { 792 $(this).removeClass('PM_ASCriterionGroupToggleHover'); 793 $(this).find('.PM_ASCriterionHide').stop().slideUp('fast', function() { 794 $(this).parents('.PM_ASCriterions').removeClass('PM_ASCriterionGroupToggleHover'); 795 }); 796 $(this).find('.PM_ASCriterionGroupColor.color_to_pick_list li.PM_ASCriterionHide').css('display', 'none'); 797 $(this).find('.PM_ASCriterionGroupImage li.PM_ASCriterionHide').css('display', 'none'); 798 }); 799 }, 800 801 assignRangeValues: function(slider, id_search, ui) { 802 slideMinValue = Math.round(ui.values[0]*100)/100; 803 slideMaxValue = Math.round(ui.values[1]*100)/100; 804 805 if (typeof (slider.data('currency-iso-code')) != 'undefined' && slider.data('currency-iso-code') != null && slider.data('currency-iso-code').length > 0) { 806 // Price slider 807 let formatterOptions = { 808 currencyIsoCode: slider.data('currency-iso-code'), 809 currencyPrecision: slider.data('currency-precision') 810 }; 811 $('#PM_ASCritRangeValue' + id_search + '_' + slider.data('id-criterion-group')).html(as4Plugin.formatCurrency(formatterOptions, slideMinValue) + ' - ' + as4Plugin.formatCurrency(formatterOptions, slideMaxValue)); 812 } else { 813 $('#PM_ASCritRangeValue' + id_search + '_' + slider.data('id-criterion-group')).html(slider.data('left-range-sign') + slideMinValue + slider.data('right-range-sign') + ' - ' + slider.data('left-range-sign') + slideMaxValue + slider.data('right-range-sign')); 814 } 815 $('#PM_ASInputCritRange' + id_search + '_' + slider.data('id-criterion-group')).val('' + slideMinValue + '~' + slideMaxValue); 816 }, 817 818 initSearchBlock: function(id_search, search_method, step_search) { 819 $(document).trigger('as4-Before-Init-Search-Block', [id_search, search_method, step_search]); 820 821 // Init sliders 822 as4Plugin.initSliders(); 823 824 // Init toggleLink 825 as4Plugin.initCriterionHideToggleLink(); 826 827 as4Plugin.removeOldEvents(id_search); 828 829 // Submit search 830 if (search_method == 2 || search_method == 4) { 831 $('#PM_ASForm_' + id_search).ajaxForm(as4Plugin.getASFormOptions(id_search)); 832 } 833 $(document).trigger('as4-After-Init-Search-Block', [id_search, search_method, step_search]); 834 as4Plugin.searchResponseCallback(id_search); 835 }, 836 837 // Set Next Id Criterion Group when step_search is on 838 setNextIdCriterionGroup: function(id_search, next_id_criterion_group) { 839 var input_next_id_criterion_group = $('#PM_ASBlock_' + id_search).find('input[name="next_id_criterion_group"]'); 840 if (next_id_criterion_group != 0) { 841 $(input_next_id_criterion_group).val(next_id_criterion_group); 842 } else { 843 $(input_next_id_criterion_group).val(''); 844 } 845 }, 846 847 848 moveFormContainerForSEOPages: function() { 849 if (typeof($('div#PM_ASFormContainerHidden')) != 'undefined' && $('div#PM_ASFormContainerHidden').length > 0) { 850 var element_parent = $('div#PM_ASFormContainerHidden').parent().parent(); 851 if (typeof(element_parent) != 'undefined' && $(element).length > 0) { 852 var element = $('div#PM_ASFormContainerHidden').detach(); 853 $(element_parent).append(element); 854 } 855 } 856 }, 857 858 searchResponseCallback: function(id_search) { 859 as4Plugin.removeOldEvents(id_search); 860 861 $(document).trigger('as4-Before-Response-Callback'); 862 //Override button add to cart from results 863 if ($('#PM_ASearchResults').length > 0) { 864 if (typeof initAp4CartLink == 'function') { 865 initAp4CartLink(); 866 } 867 if (typeof(ajaxCart) != 'undefined') { 868 ajaxCart.overrideButtonsInThePage(); 869 } 870 if (typeof(modalAjaxCart) != 'undefined') { 871 modalAjaxCart.overrideButtonsInThePage(); 872 } 873 // Init PS 1.6 theme default behaviour 874 if (typeof(display) != 'undefined' && display instanceof Function) { 875 // Set default display to grid view 876 var view = 'grid'; 877 if ($.totalStorage instanceof Function) { 878 viewFromLocalStorage = $.totalStorage('display'); 879 if (typeof(viewFromLocalStorage) != 'undefined' && viewFromLocalStorage) { 880 // Get display mode from local storage 881 view = viewFromLocalStorage; 882 } 883 } 884 try {
885 // Apply display mode if different than grid (default mode) 886 if (view && view != 'grid') { 887 display(view); 888 } 889 } catch (e) { } 890 891 if (typeof(blockHover) != 'undefined' && blockHover instanceof Function) { 892 blockHover(); 893 } 894 $('#grid').click(function(e) { 895 e.preventDefault(); 896 try { 897 display('grid'); 898 } catch (e) { } 899 }); 900 $('#list').click(function(e) { 901 e.preventDefault(); 902 try { 903 display('list'); 904 } catch (e) { } 905 }); 906 } 907 // /Init PS 1.6 theme default behaviour 908 } 909 910 // Add best sales options 911 as4Plugin.addBestSalesOptions(id_search); 912 913 $(document).ready(function() { 914 // Init chosen items (select with filters) 915 // On mobile, we don't specify the "visible" because we hide the filters on page load 916 $(".PM_ASBlockOutput select.chosen:visible, .PM_ASBlockOutput select.as4-select:visible, .PM_ASBlockOutput.PM_ASMobileMode select.as4-select").each(function() { 917 selectizePlugins = []; 918 if ($(this).prop('multiple')) { 919 selectizePlugins = ['remove_button']; 920 } 921 $(this).selectize({ 922 plugins: selectizePlugins, 923 hideSelected: true, 924 copyClassesToDropdown: false, 925 closeAfterSelect: true, 926 allowEmptyOption: true 927 }); 928 }); 929 // Product comparison 930 if (typeof(reloadProductComparison) != 'undefined') { 931 reloadProductComparison(); 932 } 933 if (typeof(compareButtonsStatusRefresh) != 'undefined' && typeof(comparedProductsIds) != 'undefined') { 934 compareButtonsStatusRefresh(); 935 } 936 if (typeof(totalCompareButtons) != 'undefined') { 937 totalCompareButtons(); 938 } 939 // /Product comparison 940 941 // IQIT Lazy Load 942 if(typeof(iqit_lazy_load) != "undefined" && iqit_lazy_load !== null && iqit_lazy_load) { 943 $("ul.product_list img.lazy").lazyload({ 944 threshold : 200, 945 skip_invisible : false 946 }); 947 } 948 // /IQIT Lazy Load 949 }); 950 $(document).trigger('as4-After-Response-Callback'); 951 }, 952 953 pushNewState: function(idSearch, fromInit) { 954 if (fromInit == true && as4Plugin.getPersistentParamValue(idSearch, 'pushInitStateDone') == false) { 955 as4Plugin.setPersistentParamValue(idSearch, 'pushInitStateDone', true); 956 } else if (fromInit == true && as4Plugin.getPersistentParamValue(idSearch, 'pushInitStateDone')) { 957 return; 958 } 959 960 formOptionsObject = as4Plugin.getASFormOptions(idSearch); 961 for (paramKey in as4Plugin.extraParams) { 962 formOptionsObject.data[as4Plugin.extraParams[paramKey].name] = as4Plugin.extraParams[paramKey].value; 963 } 964 // Reset extra parameters 965 as4Plugin.extraParams = new Array(); 966 967 history.replaceState({ 968 id_search: idSearch, 969 formOptionsData: formOptionsObject.data, 970 formSerializedArray: as4Plugin.getFormSerializedArray(idSearch), 971 stateFromInit: fromInit, 972 }, null, null); 973 }, 974 975 pushStateNewURL: function(url) { 976 if (document.location != url) { 977 history.pushState(null, null, url); 978 } 979 }, 980 981 // Check if current browser is Safari 982 isSafari: function() { 983 safariRegexp = new RegExp('^(?!.*(?:Chrome|Edge)).*Safari'); 984 return (safariRegexp.test(navigator.userAgent) == true); 985 }, 986 987 // Add layer and spinner 988 setLayer: function(pmAjaxSpinnerTarget) { 989 // Create the spinner here 990 if (as4Plugin.blurEffect) { 991 $(pmAjaxSpinnerTarget).addClass('as4-loader-blur'); 992 } 993 $(pmAjaxSpinnerTarget).append('<div class="as4-loader"></div>'); 994 $(pmAjaxSpinnerTarget).find('.as4-loader').each(function() { 995 $(this).css('top', -$(pmAjaxSpinnerTarget).outerHeight() / 2); 996 }); 997 }, 998 999 // Remove layer and spinner 1000 removeLayer: function(pmAjaxSpinnerTarget) { 1001 // Remove layer and spinner 1002 $('.as4-loader-blur').removeClass('as4-loader-blur'); 1003 $('.as4-loader').remove(); 1004 }, 1005 1006 // Send event to Google Analytics 1007 sendGAEvent: function(eventCategory, eventAction, eventLabel) { 1008 if (typeof ga !== 'undefined') { 1009 ga('send', 'event', { 1010 eventCategory: eventCategory, 1011 eventAction: eventAction, 1012 eventLabel: eventLabel 1013 }); 1014 } 1015 }, 1016 1017 // Test if LocalStorage is available 1018 isLocalStorageAvailable: function() { 1019 if (as4Plugin.localStorageAvailable == null) { 1020 var vTest = 'as4Test'; 1021 try { 1022 localStorage.setItem(vTest, vTest); 1023 localStorage.removeItem(vTest); 1024 as4Plugin.localStorageAvailable = true; 1025 // Clear expired cache 1026 as4Plugin.clearExpiredLocalStorage(); 1027 } catch (e) { 1028 as4Plugin.localStorageAvailable = false;
1029 } 1030 } 1031 return as4Plugin.localStorageAvailable; 1032 }, 1033 1034 // Clear expired cache 1035 clearExpiredLocalStorage: function() { 1036 for (var i = 0; i < localStorage.length; i++){ 1037 cacheKey = localStorage.key(i); 1038 if (cacheKey.includes('advancedsearch4') && !cacheKey.includes('cachettl')) { 1039 ttl = localStorage.getItem(cacheKey + 'cachettl'); 1040 if (ttl && ttl < +new Date()) { 1041 localStorage.removeItem(cacheKey); 1042 localStorage.removeItem(cacheKey + 'cachettl'); 1043 } 1044 } 1045 } 1046 }, 1047 1048 // Format currency regarding format 1049 formatCurrency: function(options, value) { 1050 if ((typeof (Intl) == 'undefined') || (typeof (Intl.NumberFormat) == 'undefined')) { 1051 return value; 1052 } 1053 1054 return (new Intl.NumberFormat(window.navigator.language, { 1055 style: 'currency', 1056 currency: options.currencyIsoCode, 1057 minimumFractionDigits: (options.currencyPrecision != '' ? options.currencyPrecision : undefined) 1058 }).format(value)); 1059 } 1060} 1061 1062// Emit a custom event once this plugin file has been loaded in order to let our inline script know that it can init the 1063// engines on the page, if any 1064const as4PluginEventReady = new CustomEvent('as4PluginReady', { detail: as4Plugin }); 1065document.dispatchEvent(as4PluginEventReady);
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.