46 lines
1.6 KiB
JavaScript
46 lines
1.6 KiB
JavaScript
export function cartboxSidebar() {
|
|
$('header')
|
|
.on('click', '[data-header-cart-link]', function() {
|
|
if ($(window).width() > 767 && $(window).height() > 520 && $(this).attr('href')) {
|
|
$('[data-cartbox]').addClass('active');
|
|
$('body').trigger('cartboxOpened');
|
|
return false;
|
|
}
|
|
})
|
|
.on('click', '[data-cartbox-hide]', function() {
|
|
$('[data-cartbox]').removeClass('active');
|
|
|
|
return false;
|
|
})
|
|
.on('change', '[data-cartbox-pieces]', function(e) {
|
|
var me = this;
|
|
wpj.domUtils.resetTimer('cartInfo', 300, function() {
|
|
var $form = $(me).closest('form');
|
|
wpj.domUtils.reloadPartsFromUrl($form.attr('action'), $('.header [data-reload]'), $form.serialize());
|
|
});
|
|
})
|
|
.on('click', '.buy_count button', function(e) {
|
|
var $this = $(this),
|
|
direction = $this.is('.plus') ? 1 : -1,
|
|
$input = $this.closest('form').find(':input');
|
|
$input.val(parseInt($input.val()) + direction).change();
|
|
})
|
|
.on('click', '[data-cart="delete"]', function(e) {
|
|
var $this = $(this);
|
|
|
|
wpj.domUtils.resetTimer('cartInfo', 300, function() {
|
|
wpj.domUtils.reloadPartsFromUrl($this.attr('href'), $('.header [data-reload]'));
|
|
});
|
|
|
|
e.preventDefault();
|
|
});
|
|
|
|
// skrýt cartbox při kliku na aktuální produkt
|
|
$('[data-cartbox]').on('click', '.cartbox-product-list a[href*="' + location.pathname + '"]', function(e) {
|
|
if(location.pathname !== '/') {
|
|
$('[data-cartbox]').removeClass('active');
|
|
return false;
|
|
}
|
|
});
|
|
}
|