/** * * Advanced Search 4 * * @author Presta-Module.com * @copyright Presta-Module * * ____ __ __ * | _ \ | \/ | * | |_) | | |\/| | * | __/ | | | | * |_| |_| |_| * ****/ /* Events than can be implemented for custom integration or interaction (with Google Analytics Events for example) */ /* $(document).on('as4-Before-Init-Search-Block', function(e, idSearch, searchMethod, stepSearch) {}); $(document).on('as4-After-Init-Search-Block', function(e, idSearch, searchMethod, stepSearch) {}); $(document).on('as4-Before-Init-Search-Results', function(e, idSearch, searchMethod, stepSearch) {}); $(document).on('as4-After-Init-Search-Results', function(e, idSearch, searchMethod, stepSearch) {}); $(document).on('as4-Criterion-Change', function(e, idSearch, idCriterionGroup, idCriterion, criterionName, groupType) {}); $(document).on('as4-Before-Response-Callback', function(e) {}); $(document).on('as4-After-Response-Callback', function(e) {}); $(document).on('as4-Before-Set-Results-Contents', function(e, idSearch, context) {}); $(document).on('as4-After-Set-Results-Contents', function(e, idSearch, context) {}); $(document).on('as4-Search-Reset', function(e, idSearch) {}); $(document).on('as4-Criterion-Group-Reset', function(e, idSearch, idCriterionGroup) {}); $(document).on('as4-Criterion-Group-Skip', function(e, idSearch, idCriterionGroup, searchMethod) {}); */ /*! * hoverIntent v1.8.0 // 2014.06.29 // jQuery v1.9.1+ * http://cherne.net/brian/resources/jquery.hoverIntent.html * * You may use hoverIntent under the terms of the MIT license. Basically that * means you are free to use hoverIntent as long as this header is left intact. * Copyright 2007, 2014 Brian Cherne */ (function($){$.fn.hoverIntent=function(handlerIn,handlerOut,selector){var cfg={interval:100,sensitivity:6,timeout:0};if(typeof handlerIn==="object"){cfg=$.extend(cfg,handlerIn)}else{if($.isFunction(handlerOut)){cfg=$.extend(cfg,{over:handlerIn,out:handlerOut,selector:selector})}else{cfg=$.extend(cfg,{over:handlerIn,out:handlerIn,selector:handlerOut})}}var cX,cY,pX,pY;var track=function(ev){cX=ev.pageX;cY=ev.pageY};var compare=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);if(Math.sqrt((pX-cX)*(pX-cX)+(pY-cY)*(pY-cY)) 0) { // Previous page was generated by AS4, refresh this one as4Plugin.previousOnPopState = null; // Reload current page location.reload(); } else { as4Plugin.previousOnPopState = null; } return; } // Set event source flag as4Plugin.fromBackForwardEvent = true; formOptionsObject = as4Plugin.getASFormOptions(event.state.id_search); // Replace data from the old one formOptionsObject.data = $.param(event.state.formSerializedArray) + '&' + $.param(event.state.formOptionsData); formOptionsObject.url = $('#PM_ASForm_' + event.state.id_search).attr('action'); formOptionsObject.form = $('#PM_ASForm_' + event.state.id_search); // Submit new search query (data from history) $.ajax(formOptionsObject); as4Plugin.previousOnPopState = event.state.id_search; } else { if (typeof(prestashop) != 'object') { if (!isNaN(as4Plugin.previousOnPopState) && as4Plugin.previousOnPopState != null && as4Plugin.previousOnPopState > 0) { // Previous page was generated by AS4, refresh this one as4Plugin.previousOnPopState = null; // Reload current page location.reload(); } else { as4Plugin.previousOnPopState = null; } } } }; }, 500); }; $(document).on('as4-After-Init-Search-Block', function(e, idSearch, searchMethod, stepSearch) { // Let's save form state after search engine init, only if it's not coming from a back/forward browser event if (typeof(prestashop) == 'object') { if (!as4Plugin.fromBackForwardEvent) { as4Plugin.pushNewState(idSearch, true); } } }); $(document).on('as4-Before-Set-Results-Contents', function(e, idSearch, context) { // Let's save form state just before result is updated, only if it's not coming from a back/forward browser event if (!as4Plugin.fromBackForwardEvent) { as4Plugin.pushNewState(idSearch); } // Let's prepare GA event to announce a that search results is available eventLabel = []; availableCriterionsGroups = as4Plugin.getParamValue(idSearch, 'availableCriterionsGroups'); $.each(as4Plugin.getParamValue(idSearch, 'selectedCriterions'), function(idCriterionGroup, selectedCriterions) { $.each(selectedCriterions, function(index2, selectedCriterion) { eventLabel.push(availableCriterionsGroups[idCriterionGroup] + ': ' + selectedCriterion.value); }); }); // Send GA Event as4Plugin.sendGAEvent('Advanced Search', 'Show Results', eventLabel.join(', ')) }); // Do something when a new criterion is selected $(document).on('as4-Criterion-Change', function(e, idSearch, idCriterionGroup, idCriterion, criterionName, groupType) { step_search = as4Plugin.getParamValue(idSearch, 'stepSearch'); search_method = as4Plugin.getParamValue(idSearch, 'searchMethod'); // Send GA Event availableCriterionsGroups = as4Plugin.getParamValue(idSearch, 'availableCriterionsGroups'); as4Plugin.sendGAEvent('Advanced Search', 'Criterion Selected', availableCriterionsGroups[idCriterionGroup] + ': ' + criterionName) if (step_search == 1) { as4Plugin.nextStep(idSearch, search_method); } else { as4Plugin.runSearch(idSearch, search_method); } }); // PrestaShop 1.7 specific if (typeof(prestashop) == 'object') { prestashop.on('responsive update', function(event) { as4Plugin.initMobileStyles(); }); prestashop.on('updateProductList', function(event) { if (typeof(as4Plugin) == 'object' && typeof(event.id_search) != 'undefined' && !isNaN(event.id_search)) { scrollTopActive = as4Plugin.getParamValue(event.id_search, 'scrollTopActive'); if (!scrollTopActive) { if (typeof(event.without_products) == 'undefined') { // Native ajax call as4Plugin.scrollTop(event.id_search, 'updateProductList', (scrollTopActive == false)); } } else { if (typeof(event.without_products) == 'undefined') { as4Plugin.scrollTop(event.id_search, 'updateProductList', (scrollTopActive == false)); } else { if (!event.without_products) { as4Plugin.scrollTop(event.id_search, 'updateProductList', (event.without_products == false)); } } } } // Retrieve 'order' parameter from URL in case the order is changed by the user // and assign it to our 'orderby' hidden input if (typeof(as4Plugin) == 'object') { setTimeout(function() { var currentUrlParams = window.location.href.substring(window.location.href.indexOf('?', 0)); var orderRegexp = new RegExp(/[?&]order=\w+\.\w+\.\w+/); // If we find a order parameter in the URL, we retrieve its value, and assign it to our input if (currentUrlParams.match(orderRegexp)) { var matchedOrder = currentUrlParams.match(orderRegexp)[0]; var cleanedMatchedOrder = matchedOrder.substr(matchedOrder.indexOf('=', 0) + 1); if (cleanedMatchedOrder.length > 0) { $('.PM_ASForm input[name="orderby"]').prop('disabled', false); $('.PM_ASForm input[name="orderby"]').val(cleanedMatchedOrder); } } }, 100); } }); }