PageSourceSearch

https://distribucionmayorista.online/themes/warehouse/modules/sticky/views/js/sticky.js

js distribucionmayorista.online collected 2026-10-04 13:26:03 UTC 12,972 bytes, 369 lines download raw bytes

1/**
2* Sticky ecommerce elements in your Store
3*
4* NOTICE OF LICENSE
5*
6* This product is licensed for one customer to use on one installation (test stores and multishop included).
7* Site developer has the right to modify this module to suit their needs, but can not redistribute the module in
8* whole or in part. Any other use of this module constitues a violation of the user agreement.
9*
10* DISCLAIMER
11*
12* NO WARRANTIES OF DATA SAFETY OR MODULE SECURITY
13* ARE EXPRESSED OR IMPLIED. USE THIS MODULE IN ACCORDANCE
14* WITH YOUR MERCHANT AGREEMENT, KNOWING THAT VIOLATIONS OF
15* PCI COMPLIANCY OR A DATA BREACH CAN COST THOUSANDS OF DOLLARS
16* IN FINES AND DAMAGE A STORES REPUTATION. USE AT YOUR OWN RISK.
17*
18*  @author    idnovate
19*  @copyright 2016 idnovate
20*  @license   See above
21*/
22
23function sticky_relocate_header(selector, element_position) {
24    var window_top = $(window).scrollTop();
25
26    if (window_top > element_position) {
27        $(selector).last().addClass('stick_header');
28        $('body').addClass('stick_header_displayed');
29        $(selector).width($(selector).parent().width());
30    } else {
31        $(selector).removeClass('stick_header');
32        $('body').removeClass('stick_header_displayed');
33    }
34}
35
36function sticky_relocate_menu(selector, element_position) {
37    var window_top = $(window).scrollTop();
38
39    if (window_top > element_position) {
40        $(selector).addClass('stick_menu');
41        $('body').addClass('stick_menu_displayed');
42        top = 0;
43        if (sticky_menu_top > 0) {
44            top = sticky_menu_top;
45        }
46        $(selector).css('top', top);
47        $(selector).width($(selector).parent().width());
48    } else {
49       
50        $('body').removeClass('stick_menu_displayed');
51		if($(selector).length) {
52			 $(selector).removeClass('stick_menu');
53			$(selector).prop('style').removeProperty('top');
54			$(selector).prop('style').removeProperty('width');
55		}
56    }
57}
58
59function sticky_relocate_menu_resp(selector, element_position) {
60    if (window.matchMedia('screen and (max-width: 768px)').matches) {
61        var window_top = $(window).scrollTop();
62
63        if (window_top > element_position) {
64            $(selector).addClass('stick_menu_resp');
65            $('body').addClass('stick_menu_resp_displayed');
66            top = 0;
67            if (sticky_menu_resp_top > 0) {
68                top = sticky_menu_resp_top;
69            }
70            $(selector).css('top', top);
71            //$(selector).width($(selector).closest('.container').width());
72            $(selector).width($(selector).parent().width());
73        } else {
74            $(selector).removeClass('stick_menu_resp');
75            $('body').removeClass('stick_menu_resp_displayed');
76            $(selector).prop('style').removeProperty('top');
77            $(selector).width('auto');
78        }
79    }
80}
81
82function sticky_relocate_cart(selector, height_header, position_cart_left, position_cart_top, top_origin) {
83    var window_top = $(window).scrollTop();
84    var height_cart = $(selector + ' a').outerHeight();
85
86    if (window_top > height_header) {
87        $(selector).addClass('stick_cart');
88        $('body').addClass('stick_cart_displayed');
89        if ($('#header .cart_block').length > 0) {
90
91            $('#header .cart_block').css('top', parseFloat(height_cart) + parseFloat(sticky_cart_top));
92        }
93        height_header = parseFloat(height_header) + parseFloat(sticky_cart_top) + parseFloat(sticky_menu_top);
94        $(selector).css('top', height_header);
95        $(selector).css('right', 0);
96    } else {
97        $(selector).removeClass('stick_cart');
98        $('body').removeClass('stick_cart_displayed');
99        if ($('#header .cart_block').length > 0) {
100            $('#header .cart_block').prop('style').removeProperty('top');
101        }
102        $(selector).prop('style').removeProperty('top');
103        $(selector).prop('style').removeProperty('right');
104    }
105}
106
107function sticky_relocate_product_box(selector, height_header, element_position, position_product_box_right, product_box_width_origin) {
108    var window_top = $(window).scrollTop();
109
110    if (window_top > element_position - height_header) {
111        $(selector).addClass('stick_product_box');
112        $('body').addClass('stick_product_box_displayed');
113        $(selector).css('top', height_header);
114        $(selector).css('right', position_product_box_right);
115        $(selector).css('width', product_box_width_origin);
116    } else {
117        $(selector).removeClass('stick_product_box');
118        $('body').removeClass('stick_product_box_displayed');
119        if ($(selector).prop('style')) {
120            $(selector).prop('style').removeProperty('top');
121        }
122        $(selector).prop('style').removeProperty('right');
123    }
124}
125
126function sticky_relocate_filters(selector, element_position, height_filter, height_header, height_origin, width_origin) {
127    var window_top = $(window).scrollTop();
128    if (window_top > element_position - height_header && window_top < $('.footer-container').position().top) {
129        $(selector).addClass('stick_filters');
130        $('body').addClass('stick_filters_displayed');
131        if (sticky_filters_height > 0) {
132            $(selector + ' .block_content').height(sticky_filters_height);
133            $(selector + ' .block_content').css('overflow-y', 'scroll');
134            $(selector).css('top', height_header);
135        }
136        if (sticky_filters_width > 0) {
137            $(selector + ' .block_content').width(sticky_filters_width);
138        }
139    } else if (window_top > $('.footer-container').position().top - height_filter) {
140        $(selector).removeClass('stick_filters');
141        $('body').removeClass('stick_filters_displayed');
142        $(selector).addClass('stick_filters_end');
143        $('body').addClass('stick_filters_end_displayed');
144        $(selector + ' .block_content').height(height_origin);
145        $(selector + ' .block_content').height(width_origin);
146        $(selector).prop('style').removeProperty('top');
147    } else {
148        $(selector).removeClass('stick_filters');
149        $('body').removeClass('stick_filters_displayed');
150        $(selector + ' .block_content').height(height_origin);
151        $(selector + ' .block_content').height(width_origin);
152        $(selector).prop('style').removeProperty('top');
153    }
154}
155
156$(document).ready(function() {
157    calculateOffsets();
158    relocateMe();
159});
160
161$(window).on("scroll", function(e) {
162    relocateMe();
163});
164
165$(window).on('resize' , function(e) {
166    calculateOffsets();
167    relocateMe();
168});
169
170function calculateOffsets() {
171    if ($(cart_selector).length > 0) {
172        var classRemoved = false;
173        var elementDisplayed = false;
174
175        if ($(cart_selector).hasClass('stick_cart')) {
176            $(cart_selector).removeClass('stick_cart');
177            classRemoved = true;
178        }
179
180        if ($(cart_selector).is(":hidden")) {
181            $(cart_selector).show();
182            elementDisplayed = true;
183        }
184
185        position_cart_left = $(cart_selector).offset().left;
186        position_cart_top = $(cart_selector).offset().top;
187        top_origin_cart = parseInt($(cart_selector).css('top'), 10);
188
189        if (classRemoved) {
190            $(cart_selector).addClass('stick_cart');
191        }
192
193        if (elementDisplayed) {
194            $(cart_selector).hide();
195        }
196    }
197
198    if ($(menu_selector).length > 0) {
199        var classRemoved = false;
200        var elementDisplayed = false;
201
202        if ($(menu_selector).hasClass('stick_menu')) {
203            $(menu_selector).removeClass('stick_menu');
204            classRemoved = true;
205        }
206
207        if ($(menu_selector).is(":hidden")) {
208            $(menu_selector).show();
209            elementDisplayed = true;
210        }
211
212        position_menu = $(menu_selector).offset().top;
213
214        if (classRemoved) {
215            $(menu_selector).addClass('stick_menu');
216        }
217
218        if (elementDisplayed) {
219            $(menu_selector).hide();
220        }
221    }
222
223    if ($(menu_resp_selector).length > 0) {
224        var classRemoved = false;
225        var elementDisplayed = false;
226
227        if ($(menu_resp_selector).hasClass('stick_menu_resp')) {
228            $(menu_resp_selector).removeClass('stick_menu_resp');
229            classRemoved = true;
230        }
231
232        if ($(menu_resp_selector).is(":hidden")) {
233            $(menu_resp_selector).show();
234            elementDisplayed = true;
235        }
236
237        position_menu_resp = $(menu_resp_selector).offset().top;
238
239        if (classRemoved) {
240            $(menu_resp_selector).addClass('stick_menu_resp');
241        }
242
243        if (elementDisplayed) {
244            $(menu_resp_selector).hide();
245        }
246    }
247
248    if ($(header_selector).length > 0) {
249        var classRemoved = false;
250        var elementDisplayed = false;
251        var height_header = 0;
252        if ($(header_selector).hasClass('stick_header')) {
253            height_header = $(header_selector).last().outerHeight();
254            $(header_selector).last().removeClass('stick_header');
255            classRemoved = true;
256        }
257
258        if ($(header_selector).is(":hidden")) {
259            $(header_selector).show();
260            elementDisplayed = true;
261        }
262
263        position_header = $(header_selector).last().offset().top;
264
265        if (classRemoved) {
266            $(header_selector).last().addClass('stick_header');
267        }
268
269        if (elementDisplayed) {
270            $(header_selector).hide();
271        }
272    }
273
274    if ($(product_box_selector).length > 0) {
275        var classRemoved = false;
276        var elementDisplayed = false;
277
278        if ($(product_box_selector).hasClass('stick_product_box')) {
279            $(product_box_selector).removeClass('stick_product_box');
280            classRemoved = true;
281        }
282
283        if ($(product_box_selector).is(":hidden")) {
284            $(product_box_selector).show();
285            elementDisplayed = true;
286        }
287
288        if ($(product_box_selector).length > 0) {
289            product_box_position = $(product_box_selector).offset().top;
290        }
291
292        position_product_box_right = $(window).width() - ($(product_box_selector).offset().left + $(product_box_selector).outerWidth(true));
293        product_box_width_origin = $(product_box_selector).outerWidth(true);
294
295        if (sticky_product_box) {
296            $(product_box_selector).last().addClass('stick_product_box');
297        }
298
299        if (elementDisplayed) {
300            $(product_box_selector).hide();
301        }
302    }
303
304    if ($(filters_selector).length > 0) {
305        if ($(filters_selector).length > 0) {
306            var classRemoved = false;
307            var elementDisplayed = false;
308
309            if ($(position_filters).hasClass('stick_filters')) {
310                $(position_filters).removeClass('stick_filters');
311                classRemoved = true;
312            }
313
314            if ($(position_filters).is(":hidden")) {
315                $(position_filters).show();
316                elementDisplayed = true;
317            }
318
319            position_filters = $(filters_selector).offset().top;
320            filters_height_origin = $(filters_selector + '.block_content').outerHeight();
321            filters_width_origin = $(filters_selector + '.block_content').outerWidth(true);
322            height_filter = sticky_filters_height;
323
324            if (height_filter === 0) {
325                height_filter = $(filters_selector + ' .block_content').height();
326            }
327
328            if (classRemoved) {
329                $(position_filters).last().addClass('stick_filters');
330            }
331
332            if (elementDisplayed) {
333                $(position_filters).hide();
334            }
335        }
336    }
337}
338
339function relocateMe() {
340    if (sticky_header) {
341        sticky_relocate_header(header_selector, position_header);
342    }
343
344    if (sticky_menu) {
345        sticky_relocate_menu(menu_selector, position_menu);
346    }
347
348    if (sticky_menu_resp) {
349        if (typeof position_menu_resp !== "undefined") {
350            sticky_relocate_menu_resp(menu_resp_selector, position_menu_resp);
351        }
352    }
353
354    if (sticky_product_box) {
355        if ($(product_box_selector).length > 0) {
356            sticky_relocate_product_box(product_box_selector, height_header, product_box_position, position_product_box_right, product_box_width_origin);
357        }
358    }
359
360    if (sticky_cart) {
361        sticky_relocate_cart(cart_selector, height_header, position_cart_left, position_cart_top, top_origin_cart);
362    }
363
364    if (sticky_filters) {
365        if ($(filters_selector).length > 0) {
366            sticky_relocate_filters(filters_selector, position_filters, height_filter, height_header, filters_height_origin, filters_width_origin);
367        }
368    }
369};

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.