| 1 |
"use strict"; |
| 2 |
|
| 3 |
(function ($) { |
| 4 |
const initFloatingCart = ($scope) => { |
| 5 |
const $widget = $scope.find(".king-addons-floating-cart"); |
| 6 |
if (!$widget.length) return; |
| 7 |
|
| 8 |
const $button = $widget.find(".king-addons-floating-cart__button"); |
| 9 |
const $panel = $widget.find(".king-addons-floating-cart__panel"); |
| 10 |
if (!$button.length || !$panel.length) return; |
| 11 |
|
| 12 |
const trigger = $button.data("trigger") || "click"; |
| 13 |
const autoOpen = ($button.data("auto-open") || "no") === "yes"; |
| 14 |
|
| 15 |
const openPanel = () => { |
| 16 |
$widget.addClass("is-open"); |
| 17 |
$panel.removeAttr("hidden").attr("aria-hidden", "false"); |
| 18 |
$button.attr("aria-expanded", "true"); |
| 19 |
}; |
| 20 |
|
| 21 |
const closePanel = () => { |
| 22 |
$widget.removeClass("is-open"); |
| 23 |
$panel.attr("hidden", "hidden").attr("aria-hidden", "true"); |
| 24 |
$button.attr("aria-expanded", "false"); |
| 25 |
}; |
| 26 |
|
| 27 |
const togglePanel = () => { |
| 28 |
if ($widget.hasClass("is-open")) { |
| 29 |
closePanel(); |
| 30 |
} else { |
| 31 |
openPanel(); |
| 32 |
} |
| 33 |
}; |
| 34 |
|
| 35 |
if (trigger === "click") { |
| 36 |
$button.on("click", function (event) { |
| 37 |
event.preventDefault(); |
| 38 |
togglePanel(); |
| 39 |
}); |
| 40 |
} else if (trigger === "hover") { |
| 41 |
let hoverTimer; |
| 42 |
$widget.on("mouseenter", () => { |
| 43 |
clearTimeout(hoverTimer); |
| 44 |
openPanel(); |
| 45 |
}); |
| 46 |
$widget.on("mouseleave", () => { |
| 47 |
hoverTimer = setTimeout(closePanel, 150); |
| 48 |
}); |
| 49 |
$button.on("click", (event) => event.preventDefault()); |
| 50 |
} |
| 51 |
|
| 52 |
$(document).on("click", function (event) { |
| 53 |
if (!$widget.is(event.target) && $widget.has(event.target).length === 0) { |
| 54 |
closePanel(); |
| 55 |
} |
| 56 |
}); |
| 57 |
|
| 58 |
if (autoOpen) { |
| 59 |
$(document.body).on("added_to_cart", () => { |
| 60 |
openPanel(); |
| 61 |
}); |
| 62 |
} |
| 63 |
}; |
| 64 |
|
| 65 |
$(window).on("elementor/frontend/init", function () { |
| 66 |
elementorFrontend.hooks.addAction( |
| 67 |
"frontend/element_ready/king-addons-woocommerce-floating-cart-icon.default", |
| 68 |
function ($scope) { |
| 69 |
initFloatingCart($scope); |
| 70 |
} |
| 71 |
); |
| 72 |
}); |
| 73 |
})(jQuery); |
| 74 |
|
| 75 |
|
| 76 |
|
| 77 |
|
| 78 |
|