PageSourceSearch

https://www.parade-protection.com/modules/pm_advancedsearch4/views/js/pm_advancedsearch.js

js parade-protection.com collected 2026-10-04 15:09:02 UTC 14,860 bytes, 288 lines download raw bytes

1/**
2 *
3 * Advanced Search 4
4 *
5 * @author Presta-Module.com <[email protected]>
6 * @copyright Presta-Module
7 *
8 *           ____     __  __
9 *          |  _ \   |  \/  |
10 *          | |_) |  | |\/| |
11 *          |  __/   | |  | |
12 *          |_|      |_|  |_|
13 *
14 ****/
15
16/* Events than can be implemented for custom integration or interaction (with Google Analytics Events for example) */
17/*
18$(document).on('as4-Before-Init-Search-Block', function(e, idSearch, searchMethod, stepSearch) {});
19$(document).on('as4-After-Init-Search-Block', function(e, idSearch, searchMethod, stepSearch) {});
20$(document).on('as4-Before-Init-Search-Results', function(e, idSearch, searchMethod, stepSearch) {});
21$(document).on('as4-After-Init-Search-Results', function(e, idSearch, searchMethod, stepSearch) {});
22$(document).on('as4-Criterion-Change', function(e, idSearch, idCriterionGroup, idCriterion, criterionName, groupType) {});
23$(document).on('as4-Before-Response-Callback', function(e) {});
24$(document).on('as4-After-Response-Callback', function(e) {});
25$(document).on('as4-Before-Set-Results-Contents', function(e, idSearch, context) {});
26$(document).on('as4-After-Set-Results-Contents', function(e, idSearch, context) {});
27$(document).on('as4-Search-Reset', function(e, idSearch) {});
28$(document).on('as4-Criterion-Group-Reset', function(e, idSearch, idCriterionGroup) {});
29$(document).on('as4-Criterion-Group-Skip', function(e, idSearch, idCriterionGroup, searchMethod) {});
30*/
31
32/*!
33 * hoverIntent v1.8.0 // 2014.06.29 // jQuery v1.9.1+
34 * http://cherne.net/brian/resources/jquery.hoverIntent.html
35 *
36 * You may use hoverIntent under the terms of the MIT license. Basically that
37 * means you are free to use hoverIntent as long as this header is left intact.
38 * Copyright 2007, 2014 Brian Cherne
39 */
40(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))<cfg.sensitivity){$(ob).off("mousemove.hoverIntent",track);ob.hoverIntent_s=true;return cfg.over.apply(ob,[ev])}else{pX=cX;pY=cY;ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}};var delay=function(ev,ob){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t);ob.hoverIntent_s=false;return cfg.out.apply(ob,[ev])};var handleHover=function(e){var ev=$.extend({},e);var ob=this;if(ob.hoverIntent_t){ob.hoverIntent_t=clearTimeout(ob.hoverIntent_t)}if(e.type==="mouseenter"){pX=ev.pageX;pY=ev.pageY;$(ob).on("mousemove.hoverIntent",track);if(!ob.hoverIntent_s){ob.hoverIntent_t=setTimeout(function(){compare(ev,ob)},cfg.interval)}}else{$(ob).off("mousemove.hoverIntent",track);if(ob.hoverIntent_s){ob.hoverIntent_t=setTimeout(function(){delay(ev,ob)},cfg.timeout)}}};return this.on({"mouseenter.hoverIntent":handleHover,"mouseleave.hoverIntent":handleHover},cfg.selector)}})(jQuery);
41
42/**
43 * https://github.com/SaneMethod/jquery-ajax-localstorage-cache
44 */
45;
46(function($, window) {
47    /**
48     * Generate the cache key under which to store the local data - either the cache key supplied,
49     * or one generated from the url, the type and, if present, the data.
50     */
51    var genCacheKey = function(options) {
52        var url = options.url.replace(/jQuery.*/, '');
53
54        // Strip _={timestamp}, if cache is set to false
55        if (options.cache === false) {
56            url = url.replace(/([?&])_=[^&]*/, '');
57        }
58        if (options.data) {
59            return (as4Plugin.localCacheKey || '') + (options.cacheKey || url + '?' + options.data + options.type);
60        } else {
61            return (as4Plugin.localCacheKey || '') + (options.cacheKey || url + options.type + (options.data || ''));
62        }
63    };
64    /**
65     * Prefilter for caching ajax calls.
66     * See also $.ajaxTransport for the elements that make this compatible with jQuery Deferred.
67     * New parameters available on the ajax call:
68     * localCache   : true // required - either a boolean (in which case localStorage is used), or an object
69     * implementing the Storage interface, in which case that object is used instead.
70     * cacheTTL     : 5,           // optional - cache time in hours, default is 5.
71     * cacheKey     : 'post',      // optional - key under which cached string will be stored
72     * isCacheValid : function  // optional - return true for valid, false for invalid
73     * @method $.ajaxPrefilter
74     * @param options {Object} Options for the ajax call, modified with ajax standard settings
75     */
76    $.ajaxPrefilter(function(options) {
77        var storage = (options.localCache === true) ? window.localStorage : options.localCache,
78            hourstl = options.cacheTTL || 5,
79            cacheKey = genCacheKey(options),
80            cacheValid = options.isCacheValid,
81            ttl,
82            value;
83
84        // Check if localStorage is available
85        if (!storage || (storage && !as4Plugin.isLocalStorageAvailable())) {
86            return;
87        }
88        ttl = storage.getItem(cacheKey + 'cachettl');
89
90        if (cacheValid && typeof cacheValid === 'function' && !cacheValid()) {
91            storage.removeItem(cacheKey);
92        }
93
94        if (ttl && ttl < +new Date()) {
95            storage.removeItem(cacheKey);
96            storage.removeItem(cacheKey + 'cachettl');
97            ttl = 0;
98        }
99
100        value = storage.getItem(cacheKey);
101        if (!value) {
102            // If it not in the cache, we store the data, add success callback - normal callback will proceed
103            if (options.success) {
104                options.realsuccess = options.success;
105            }
106            options.success = function(data) {
107                var strdata = data;
108                if (this.dataType.toLowerCase().indexOf('json') === 0) strdata = JSON.stringify(data);
109
110                // Save the data to storage catching exceptions (possibly QUOTA_EXCEEDED_ERR)
111                try {
112                    storage.setItem(cacheKey, strdata);
113                } catch (e) {
114                    // Remove any incomplete data that may have been saved before the exception was caught
115                    storage.removeItem(cacheKey);
116                    storage.removeItem(cacheKey + 'cachettl');
117                }
118
119                if (options.realsuccess) options.realsuccess(data);
120            };
121
122            // store timestamp
123            if (!ttl) {
124                storage.setItem(cacheKey + 'cachettl', +new Date() + 1000 * 60 * 60 * hourstl);
125            }
126        }
127    });
128
129    /**
130     * This function performs the fetch from cache portion of the functionality needed to cache ajax
131     * calls and still fulfill the jqXHR Deferred Promise interface.
132     * See also $.ajaxPrefilter
133     * @method $.ajaxTransport
134     * @params options {Object} Options for the ajax call, modified with ajax standard settings
135     */
136    $.ajaxTransport("+*", function(options) {
137        if (options.localCache) {
138            var cacheKey = genCacheKey(options),
139                storage = (options.localCache === true) ? window.localStorage : options.localCache,
140                value = (storage) ? storage.getItem(cacheKey) : false;
141
142            if (value) {
143                // In the cache? Get it, parse it to json if the dataType is JSON,
144                // and call the completeCallback with the fetched value.
145                if (options.dataType.toLowerCase().indexOf('json') === 0) value = JSON.parse(value);
146                return {
147                    send: function(headers, completeCallback) {
148                        var response = {};
149                        response[options.dataType] = value;
150                        completeCallback(200, 'success', response, '');
151                    },
152                    abort: function() {
153                        console.log("Aborted ajax transport for json cache.");
154                    }
155                };
156            }
157        }
158    });
159})(jQuery, window);
160
161window.onload = function () {
162    // Fix Safari issue that is firing onpopstate on page load (instead of all other browsers)
163    setTimeout(function() {
164        window.onpopstate = function(event) {
165            if (typeof(event.state) != 'undefined' && event.state != null && typeof(event.state.id_search) != 'undefined' && !isNaN(event.state.id_search)) {
166                if (typeof(event.state.stateFromInit) != 'undefined' && event.state.stateFromInit && as4Plugin.isSafari()) {
167                    if (!isNaN(as4Plugin.previousOnPopState) && as4Plugin.previousOnPopState != null && as4Plugin.previousOnPopState > 0) {
168                        // Previous page was generated by AS4, refresh this one
169                        as4Plugin.previousOnPopState = null;
170                        // Reload current page
171                        location.reload();
172                    } else {
173                        as4Plugin.previousOnPopState = null;
174                    }
175                    return;
176                }
177                // Set event source flag
178                as4Plugin.fromBackForwardEvent = true;
179                formOptionsObject = as4Plugin.getASFormOptions(event.state.id_search);
180                // Replace data from the old one
181                formOptionsObject.data = $.param(event.state.formSeri
181alizedArray) + '&' + $.param(event.state.formOptionsData);
182                formOptionsObject.url = $('#PM_ASForm_' + event.state.id_search).attr('action');
183                formOptionsObject.form = $('#PM_ASForm_' + event.state.id_search);
184                // Submit new search query (data from history)
185                $.ajax(formOptionsObject);
186                as4Plugin.previousOnPopState = event.state.id_search;
187            } else {
188                if (typeof(prestashop) != 'object') {
189                    if (!isNaN(as4Plugin.previousOnPopState) && as4Plugin.previousOnPopState != null && as4Plugin.previousOnPopState > 0) {
190                        // Previous page was generated by AS4, refresh this one
191                        as4Plugin.previousOnPopState = null;
192                        // Reload current page
193                        location.reload();
194                    } else {
195                        as4Plugin.previousOnPopState = null;
196                    }
197                }
198            }
199        };
200    }, 500);
201};
202
203$(document).on('as4-After-Init-Search-Block', function(e, idSearch, searchMethod, stepSearch) {
204    // Let's save form state after search engine init, only if it's not coming from a back/forward browser event
205    if (typeof(prestashop) == 'object') {
206        if (!as4Plugin.fromBackForwardEvent) {
207            as4Plugin.pushNewState(idSearch, true);
208        }
209    }
210});
211
212$(document).on('as4-Before-Set-Results-Contents', function(e, idSearch, context) {
213    // Let's save form state just before result is updated, only if it's not coming from a back/forward browser event
214    if (!as4Plugin.fromBackForwardEvent) {
215        as4Plugin.pushNewState(idSearch);
216    }
217
218    // Let's prepare GA event to announce a that search results is available
219    eventLabel = [];
220    availableCriterionsGroups = as4Plugin.getParamValue(idSearch, 'availableCriterionsGroups');
221    $.each(as4Plugin.getParamValue(idSearch, 'selectedCriterions'), function(idCriterionGroup, selectedCriterions) {
222        $.each(selectedCriterions, function(index2, selectedCriterion) {
223            eventLabel.push(availableCriterionsGroups[idCriterionGroup] + ': ' + selectedCriterion.value);
224        });
225    });
226    // Send GA Event
227    as4Plugin.sendGAEvent('Advanced Search', 'Show Results', eventLabel.join(', '))
228});
229
230// Do something when a new criterion is selected
231$(document).on('as4-Criterion-Change', function(e, idSearch, idCriterionGroup, idCriterion, criterionName, groupType) {
232    step_search = as4Plugin.getParamValue(idSearch, 'stepSearch');
233    search_method = as4Plugin.getParamValue(idSearch, 'searchMethod');
234
235    // Send GA Event
236    availableCriterionsGroups = as4Plugin.getParamValue(idSearch, 'availableCriterionsGroups');
237    as4Plugin.sendGAEvent('Advanced Search', 'Criterion Selected', availableCriterionsGroups[idCriterionGroup] + ': ' + criterionName)
238
239    if (step_search == 1) {
240        as4Plugin.nextStep(idSearch, search_method);
241    } else {
242        as4Plugin.runSearch(idSearch, search_method);
243    }
244});
245
246// PrestaShop 1.7 specific
247if (typeof(prestashop) == 'object') {
248    prestashop.on('responsive update', function(event) {
249        as4Plugin.initMobileStyles();
250    });
251    prestashop.on('updateProductList', function(event) {
252        if (typeof(as4Plugin) == 'object' && typeof(event.id_search) != 'undefined' && !isNaN(event.id_search)) {
253            scrollTopActive = as4Plugin.getParamValue(event.id_search, 'scrollTopActive');
254            if (!scrollTopActive) {
255                if (typeof(event.without_products) == 'undefined') {
256                    // Native ajax call
257                    as4Plugin.scrollTop(event.id_search, 'updateProductList', (scrollTopActive == false));
258                }
259            } else {
260                if (typeof(event.without_products) == 'undefined') {
261                    as4Plugin.scrollTop(event.id_search, 'updateProductList', (scrollTopActive == false));
262                } else {
263                    if (!event.without_products) {
264                        as4Plugin.scrollTop(event.id_search, 'updateProductList', (event.without_products == false));
265                    }
266                }
267            }
268        }
269        // Retrieve 'order' parameter from URL in case the order is changed by the user
270        // and assign it to our 'orderby' hidden input
271        if (typeof(as4Plugin) == 'object') {
272            setTimeout(function() {
273                var currentUrlParams = window.location.href.substring(window.location.href.indexOf('?', 0));
274                var orderRegexp = new RegExp(/[?&]order=\w+\.\w+\.\w+/);
275
276                // If we find a order parameter in the URL, we retrieve its value, and assign it to our input
277                if (currentUrlParams.match(orderRegexp)) {
278                    var matchedOrder = currentUrlParams.match(orderRegexp)[0];
279                    var cleanedMatchedOrder = matchedOrder.substr(matchedOrder.indexOf('=', 0) + 1);
280                    if (cleanedMatchedOrder.length > 0) {
281                        $('.PM_ASForm input[name="orderby"]').prop('disabled', false);
282                        $('.PM_ASForm input[name="orderby"]').val(cleanedMatchedOrder);
283                    }
284                }
285            }, 100);
286        }
287    });
288}

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.