| 1 |
(function ($, elementor) { |
| 2 |
$(window).on("elementor/frontend/init", function () { |
| 3 |
let ModuleHandler = elementorModules.frontend.handlers.Base, MiniCart; |
| 4 |
var debounce = function(func, wait, immediate) { |
| 5 |
var timeout; |
| 6 |
return function() { |
| 7 |
var context = this, |
| 8 |
args = arguments; |
| 9 |
var callNow = immediate && !timeout; |
| 10 |
clearTimeout(timeout); |
| 11 |
timeout = setTimeout(function() { |
| 12 |
timeout = null; |
| 13 |
if (!immediate) { |
| 14 |
func.apply(context, args); |
| 15 |
} |
| 16 |
}, wait); |
| 17 |
if (callNow) func.apply(context, args); |
| 18 |
}; |
| 19 |
}; |
| 20 |
MiniCart = ModuleHandler.extend({ |
| 21 |
bindEvents: function () { |
| 22 |
this.run(); |
| 23 |
}, |
| 24 |
getDefaultSettings: function () { |
| 25 |
return { |
| 26 |
allowHTML: true, |
| 27 |
}; |
| 28 |
}, |
| 29 |
|
| 30 |
onElementChange: debounce(function (prop) { |
| 31 |
if (prop.indexOf('usk_mini_cart') !== -1) { |
| 32 |
this.run(); |
| 33 |
} |
| 34 |
}, 400), |
| 35 |
|
| 36 |
settings: function (key) { |
| 37 |
return this.getElementSettings("usk_mini_cart_" + key); |
| 38 |
}, |
| 39 |
|
| 40 |
|
| 41 |
run: function (key) { |
| 42 |
var options = this.getDefaultSettings(); |
| 43 |
var element = this.findElement(".elementor-widget").get(0); |
| 44 |
if (jQuery(this.$element).hasClass("elementor-section")) { |
| 45 |
element = this.$element.get(0); |
| 46 |
} |
| 47 |
var $container = this.$element.find(".usk-mini-cart-toggle-btn"); |
| 48 |
var $offcanvas = this.$element.find(".usk-mini-cart"); |
| 49 |
if (!$container.length) { |
| 50 |
return; |
| 51 |
} |
| 52 |
var MiniCart_ID = "usk-mini-cart-" + this.$element.data("id"); |
| 53 |
options = $($container).data("settings"); |
| 54 |
toolslide("#" + MiniCart_ID, { |
| 55 |
toggleButton: options.toggleButton, |
| 56 |
position: (this.settings("position") !== undefined) ? this.settings('position') : 'right', |
| 57 |
height: (this.settings('height.size') !== undefined) ? this.settings('height.size') + this.settings('height.unit'): '100%', |
| 58 |
width: (this.settings('width.size') !== undefined) ? this.settings('width.size') + this.settings('width.unit'): '340px', |
| 59 |
closeable: (this.settings('closeable') === 'yes') ? true: false, |
| 60 |
startOpen: (this.settings('startOpen') === 'yes') ? true: false, |
| 61 |
autoclose: (this.settings('autoclose') === 'yes') ? true: false, |
| 62 |
autocloseDelay: (this.settings('autocloseDelay')) ? this.settings('autocloseDelay'): 5000, |
| 63 |
clickOutsideToClose: (this.settings('clickOutsideToClose') === 'yes') ? true: false, |
| 64 |
|
| 65 |
animations: { |
| 66 |
replace: "crossfade 0.5s ease-in-out", |
| 67 |
toggle: "slide 0.5s ease", |
| 68 |
}, |
| 69 |
// listeners: { |
| 70 |
// afterClose: function () { |
| 71 |
// $("body").removeClass("usk-mini-cart-opened"); |
| 72 |
// }, |
| 73 |
// beforeOpen: function () { |
| 74 |
// $("body").addClass("usk-mini-cart-opened"); |
| 75 |
// }, |
| 76 |
// }, |
| 77 |
}); |
| 78 |
$($offcanvas).appendTo("body"); |
| 79 |
}, |
| 80 |
}); |
| 81 |
|
| 82 |
elementorFrontend.hooks.addAction( |
| 83 |
"frontend/element_ready/usk-mini-cart.default", |
| 84 |
function ($scope) { |
| 85 |
elementorFrontend.elementsHandler.addHandler(MiniCart, { |
| 86 |
$element: $scope, |
| 87 |
}); |
| 88 |
} |
| 89 |
); |
| 90 |
}); |
| 91 |
})(jQuery, window.elementorFrontend); |
| 92 |
|