PluginProbe
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder / 51.1.83
King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder v51.1.83
51.1.83 51.1.82 51.1.81 51.1.79 51.1.78 51.1.77 51.1.76 51.1.74 51.1.75 51.1.65 51.1.64 51.1.63 trunk 51.1.14 51.1.2 51.1.35 51.1.36 51.1.37 51.1.38 51.1.39 51.1.44 51.1.45 51.1.46 51.1.47 51.1.49 All 37 releases
king-addons / includes / extensions / Sticky_Add_To_Cart / assets / script.js

script.js in King Addons for Elementor – 80+ Elementor Widgets, 4 000+ Elementor Templates, WooCommerce, Mega Menu, Popup Builder 51.1.83, at includes/extensions/Sticky_Add_To_Cart/assets/script.js

79 lines 2.5 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 (function () {
2 'use strict';
3
4 function start() {
5 // The bar is printed on wp_footer, which can run after this script:
6 // wait for the document before looking for it.
7 var bar = document.querySelector('.king-addons-satc');
8 if (!bar) {
9 return;
10 }
11
12 var cfg = window.kingAddonsStickyAddToCart || {};
13 var offset = parseInt(cfg.offset, 10);
14 if (isNaN(offset)) {
15 offset = 400;
16 }
17
18 // Prefer the real add-to-cart form: the bar earns its place exactly when
19 // the buy button has scrolled out of reach. Without a form on the page,
20 // fall back to a plain scroll offset.
21 var form = document.querySelector('form.cart, .ka-woo-product-atc, #ka-satc-form-anchor');
22
23 // Variable products link the bar to #ka-satc-form-anchor. That id is
24 // printed by the Woo Add To Cart widget; a variations form alone never
25 // had it, so the button jumped nowhere.
26 if (form && !document.getElementById('ka-satc-form-anchor')) {
27 form.id = 'ka-satc-form-anchor';
28 }
29
30 var button = bar.querySelector('.king-addons-satc__button');
31 if (button && (button.getAttribute('href') || '').indexOf('#ka-satc-form-anchor') === 0) {
32 button.addEventListener('click', function (event) {
33 var target = document.getElementById('ka-satc-form-anchor') || form;
34 if (!target) {
35 return;
36 }
37 event.preventDefault();
38 target.scrollIntoView({ behavior: 'smooth', block: 'center' });
39 });
40 }
41
42 bar.hidden = false;
43
44 function update() {
45 var visible;
46
47 if (form) {
48 visible = form.getBoundingClientRect().bottom < 0;
49 } else {
50 visible = window.pageYOffset > offset;
51 }
52
53 bar.classList.toggle('is-visible', visible);
54 }
55
56 var ticking = false;
57 function onScroll() {
58 if (ticking) {
59 return;
60 }
61 ticking = true;
62 window.requestAnimationFrame(function () {
63 update();
64 ticking = false;
65 });
66 }
67
68 window.addEventListener('scroll', onScroll, { passive: true });
69 window.addEventListener('resize', onScroll, { passive: true });
70 update();
71 }
72
73 if ('loading' === document.readyState) {
74 document.addEventListener('DOMContentLoaded', start);
75 } else {
76 start();
77 }
78 })();
79