PageSourceSearch

https://martinique.microforce.com/modules/responsivemenu/views/js/responsivemenu.js

js microforce.com collected 2026-10-04 09:26:42 UTC 12,804 bytes, 360 lines download raw bytes

1/*
2* 2013-2021 MADEF IT
3*
4* NOTICE OF LICENSE
5*
6* This source file is subject to the Academic Free License (AFL 3.0)
7* that is bundled with this package in the file LICENSE.txt.
8* It is also available through the world-wide-web at this URL:
9* http://opensource.org/licenses/afl-3.0.php
10* If you did not receive a copy of the license and are unable to
11* obtain it through the world-wide-web, please send an email
12* to [email protected] so we can send you a copy immediately.
13*
14* DISCLAIMER
15*
16* Do not edit or add to this file if you wish to upgrade PrestaShop to newer
17* versions in the future. If you wish to customize PrestaShop for your
18* needs please refer to http://www.prestashop.com for more information.
19*
20*  @author    MADEF IT <[email protected]>
21*  @copyright 2013-2021 MADEF IT
22*  @license   http://opensource.org/licenses/afl-3.0.php  Academic Free License (AFL 3.0)
23 */
24
25jQuery(function() {
26    ResponsiveMenu.init();
27    new ResponsiveMenuCart();
28});
29
30var ResponsiveMenu = {
31    hash: '',
32    currentSearchTimeout: null,
33    allowSearchSubmit: false,
34    tree: [],
35    cache: {},
36    loadList: function(list) {
37        var categoryId = list.shift();
38
39        if (typeof categoryId == 'undefined') {
40            return;
41        }
42
43        ResponsiveMenu.load(categoryId, function() { ResponsiveMenu.loadList(list) });
44    },
45    init: function() {
46        ResponsiveMenu.tree = RM_CATEGORY_PATH;
47        ResponsiveMenu.hash = RM_CATEGORY_HASH;
48
49        ResponsiveMenu.initBodyClass();
50
51        var size = ResponsiveMenu.tree.length;
52
53        var menuWidth = jQuery('.rm-pannel').width();
54        jQuery('.js-rm-column').css('width', menuWidth + 'px');
55
56        jQuery('.js-rm-category-content').each((function(key, elm) {
57            var $elm = jQuery(elm);
58
59            var id = $elm.data('id');
60            this.setCache(id, elm.outerHTML);
61            $elm.remove();
62        }).bind(this));
63
64        var tree = ResponsiveMenu.tree.slice();
65        ResponsiveMenu.loadList(tree);
66
67        jQuery(document).on('submit', '[data-use-quick-search=1]', (function(e) {
68            return this.submitSearch();
69        }).bind(this));
70
71        jQuery(document).on('change, keyup', '[data-use-quick-search=1] input', (function() {
72            this.search();
73        }).bind(this));
74
75        if (RM_PULL) {
76            jQuery('.rm-header').appendTo('body');
77            jQuery('.rm-overlay').appendTo('body');
78            jQuery('.rm-pannel').appendTo('body');
79        }
80
81        jQuery('.rm-pannel').click(function() {
82            return false; // Stop propagation
83        });
84
85        jQuery('.rm-header .search').click((function() {
86            this.open();
87        }).bind(this));
88        jQuery('.rm-search-bar__submit').click(function() {
89            jQuery(this).parent().submit();
90        });
91
92        var rmLastClick = new Date();
93        jQuery('.js-rm-trigger, #menu-icon').on('click touchstart tap', (function() {
94            var rmNewClick = new Date();
95
96            if (rmNewClick - rmLastClick < 300) {
97                return;
98            }
99
100            rmLastClick = rmNewClick;
101
102            var menuWidth = jQuery('.rm-pannel').width();
103            var size = ResponsiveMenu.tree.length;
104            jQuery('.js-rm-column').css('width', menuWidth + 'px');
105            jQuery('.rm-container').css('width', (size * menuWidth) + 'px');
106
107            if (jQuery('.rm-overlay').hasClass('rm-overlay--close')) {
108                this.open();
109            } else {
110                this.close();
111            }
112
113            return false;
114        }).bind(this));
115
116        jQuery( window ).resize(function() {
117            var menuWidth = jQuery('.rm-pannel').width();
118            var size = ResponsiveMenu.tree.length;
119            jQuery('.js-rm-column').css('width', menuWidth + 'px');
120            jQuery('.rm-container').css('width', (size * menuWidth) + 'px');
121        });
122
123        jQuery('.rm-container').on('click', '.rm-level__title', function() {
124            window.location.href = jQuery(this).attr('href');
125        });
126        jQuery('.rm-container').on('click', '.rm-login-bar a', function() {
127            window.location.href = jQuery(this).attr('href');
128        });
129
130        jQuery('.rm-container').on('click', '.rm-level__item', function() {
131            if (typeof(jQuery(this).attr('data-load')) !== 'undefined') {
132                ResponsiveMenu.loadMenu(parseInt(jQuery(this).attr('data-load')));
133                return false; // Stop propagation
134            } else {
135                if (jQuery(this).data('target') == 'blank') {
136                    window.open(jQuery(this).attr('href'));
137                } else {
138                    window.location.href = jQuery(this).attr('href');
139                }
140            }
141        });
142
143        jQuery('.rm-container').css('width', (size * menuWidth) + 'px');
144    },
145    open: function() {
146        jQuery('.rm-overlay').removeClass('rm-overlay--close');
147        jQuery('.rm-overlay').addClass('rm-overlay--open');
148        jQuery('.rm-pannel').removeClass('rm-pannel--close');
149        jQuery('.rm-pannel').addClass('rm-pannel--open');
150        jQuery('html').css('overflow-y', 'hidden');
151        jQuery('body').css('overflow-y', 'hidden');
152    },
153    close: function() {
154        jQuery('.rm-overlay').addClass('rm-overlay--close');
155        jQuery('.rm-overlay').removeClass('rm-overlay--open');
156        jQuery('.rm-pannel').addClass('rm-pannel--close');
157        jQuery('.rm-pannel').removeClass('rm-pannel--open');
158        jQuery('html').css('overflow-y', 'auto');
159        jQuery('body').css('overflow-y', 'hidden');
160    },
161    closeSearch: function() {
162        jQuery('.rm-search-bar__submit').val(jQuery('.rm-search-bar__submit').data('open-value'));
163        jQuery('.rm-level').show();
164        jQuery('.js-rm-search-content').remove();
165    },
166    initBodyClass: function() {
167        if (RM_DISPLAY_SEARCH) {
168            jQuery('body').addClass('rm-display-search');
169        }
170        if (RM_HEADER_BAR) {
171            jQuery('body').addClass('rm-body-with-header');
172        }
173    },
174    loadMenu: function(id) {
175        var menuWidth = jQuery('.rm-pannel').width();
176        jQuery('.js-rm-column').css('width', menuWidth + 'px');
177        if ($.inArray(id, ResponsiveMenu.tree) != -1) {
178            var old_id = ResponsiveMenu.tree.pop();
179            var size = ResponsiveMenu.tree.length;
180            jQuery('#rm-category-'+old_id).remove();
181            jQuery('.rm-container').css('width', (size * menuWidth) + 'px');
182        } else {
183            ResponsiveMenu.tree.push(id);
184            var size = ResponsiveMenu.tree.length;
185            jQuery('.rm-container').css('width', (size * menuWidth) + 'px');
186            ResponsiveMenu.load(id);
187        }
188    },
189    load: function(id, callback) {
190        if (ResponsiveMenu.getCache(id) === false) {
191            $.ajax({
192                type: 'GET',
193                url: RM_AJAX_URL,
194                dataType: 'json',
195                data: { id: id, action: 'menu', type: 'category' }
196            }).done(function (data) {
197                if (data.error) {
198                    alert('Error while loading menu');
199                    return;
200                }
201                ResponsiveMenu.hash = data.hash;
202                ResponsiveMenu.setCache(id, data.html);
203                ResponsiveMenu.renderCategory(id);
204
205                if (typeof callback == 'function') {
206                    callback();
207                }
208            }).fail(function(){
209                alert('Error while loading menu');
210                return;
211            });
212        } else {
213            ResponsiveMenu.renderCategory(id);
214
215            if (typeof callback == 'function') {
216                callback();
217            }
218        }
219    },
220    renderCategory: function(id) {
221        jQuery('.rm-container').append(jQuery(ResponsiveMenu.getCache(id)));
222
223        if (RM_CURRENT_CATEGORY) {
224            var CurrentCategoryId = RM_CURRENT_CATEGORY;
225        } else {
226            var CurrentCategoryId = ResponsiveMenu.tree[ResponsiveMenu.tree.length-1];
227            RM_CURRENT_CATEGORY = CurrentCategoryId;
228        }
229        jQuery('.rm-level__item--selected').removeClass('rm-level__item--selected');
230        jQuery('.rm-category-'+CurrentCategoryId).addClass('rm-level__item--selected');
231
232        jQuery('.rm-pannel').scrollTop(0);
233
234        var menuWidth = jQuery('.rm-pannel').width();
235        jQuery('.js-rm-column').css('width', menuWidth + 'px');
236
237    },
238    getCache: function(id)
239    {
240        if (typeof(localStorage) != 'undefined') {
241            if (localStorage.getItem('hash-' + id + '-' + RM_ID_LANG) == ResponsiveMenu.hash) {
242                return localStorage.getItem(id + '-' + RM_ID_LANG);
243            }
244        }
245
246        if (typeof(ResponsiveMenu.cache[id]) != 'undefined') {
247            return ResponsiveMenu.cache[id];
248        }
249
250        return false;
251    },
252    setCache: function(id, value)
253    {
254        if (typeof(localStorage) === 'undefined') {
255            ResponsiveMenu.cache[id] = value;
256            return false;
257        }
258        try {
259            localStorage.setItem('hash-' + id + '-' + RM_ID_LANG, ResponsiveMenu.hash);
260            localStorage.setItem(id + '-' + RM_ID_LANG, value);
261        } catch (e) {
262            ResponsiveMenu.cache[id] = value;
263        }
264    },
265    submitSearch: function() {
266        if (this.allowSearchSubmit) {
267            return true;
268        }
269
270        if (jQuery('.js-rm-search-content').length) {
271            this.closeSearch();
272        } else {
273            this.search();
274        }
275
276        return false;
277    },
278    search: function() {
279        var data = {
280            action: 'search',
281            query: jQuery('[data-use-quick-search=1] [name=search_query]').val(),
282            orderby: jQuery('[data-use-quick-search=1] [name=orderby]').val(),
283            orderway: jQuery('[data-use-quick-search=1] [name=orderway]').val()
284        }
285
286        if (this.currentSearchTimeout != null) {
287            window.clearTimeout(this.currentSearchTimeout);
288        }
289
290        this.currentSearchTimeout = window.setTimeout((function() {
291            jQuery.ajax({
292                type: 'GET',
293                url: RM_AJAX_URL,
294                dataType: 'json',
295                data: data
296            }).done((function (data) {
297                jQuery('.rm-level').show();
298                jQuery('.js-rm-search-content').remove();
299                jQuery('.rm-search-bar__submit').val(jQuery('.rm-search-bar__submit').data('open-value'));
300                this.allowSearchSubmit = false;
301                if (!data.count) {
302                    return;
303                }
304
305                jQuery('.rm-search-bar__submit').val(jQuery('.rm-search-bar__submit').data('close-value'));
306                jQuery('.rm-container').append(jQuery('<div>'+data.template+'</div>').html());
307                jQuery('.rm-level').hide();
308                var menuWidth = jQuery('.rm-pannel').width();
309                jQuery('.js-rm-column').css('width', menuWidth + 'px');
310
311                jQuery('.js-rm-search-content [data-url]').click(function() {
312                    window.location = jQuery(this).data('url');
313                });
314                jQuery('.js-search-see-more').click((function() {
315                    this.allowSearchSubmit = true;
316                    jQuery('[data-use-quick-search]').submit();
317                }).bind(this));
318            }).bind(this));
319        }).bind(this), 500); // Increase this value when your shop is slow
320    }
321};
322
323
324ResponsiveMenuCart = function() {
325    if (parseInt(jQuery.fn.jquery.split('.')[0]) >
325 1 || parseInt(jQuery.fn.jquery.split('.')[0]) === 1 || parseInt(jQuery.fn.jquery.split('.')[1]) > 6) {
326        jQuery(document).on('click touchstart', '#add_to_cart, .ajax_add_to_cart_button', this.onAddToCart);
327    } else {
328        jQuery('#add_to_cart, .ajax_add_to_cart_button, .js-increase-product-quantity, .js-decrease-product-quantity, .cart_quantity_up, .cart_quantity_down').live('click touchstart', this.onAddToCart);
329    }
330
331    if (typeof prestashop != 'undefined') {
332        prestashop.on(
333          'updateCart',
334          (function (event) {
335              this.onAddToCart();
336          }).bind(this)
337        );
338    }
339};
340
341ResponsiveMenuCart.prototype.onAddToCart = function() {
342    window.setTimeout(function() {
343        jQuery.ajax({
344            type: 'GET',
345            url: RM_AJAX_URL,
346            dataType: 'json',
347            data: { action: 'cart' }
348        }).done(function (data) {
349            jQuery('.rm-header .rm-cart .count').text(data.count);
350
351            if (data.count === 0) {
352                jQuery('.rm-header .rm-cart .count').hide();
353            } else {
354                jQuery('.rm-header .rm-cart .count').show();
355            }
356        });
357    }, 500); // Increase this value when your shop is slow
358};
359
360

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.