From 3b5061ea9e4c2563e861d9bfa5def9469cddf34e Mon Sep 17 00:00:00 2001 From: Vincent Vanwaelscappel Date: Tue, 5 Apr 2022 10:31:46 +0200 Subject: [PATCH] wip #4259 @0.5 --- .../fluidbook/cart/fluidbook.cart.thiriet.js | 36 ++++++++++ js/libs/fluidbook/fluidbook.cart.js | 68 ++++++++++--------- 2 files changed, 71 insertions(+), 33 deletions(-) create mode 100644 js/libs/fluidbook/cart/fluidbook.cart.thiriet.js diff --git a/js/libs/fluidbook/cart/fluidbook.cart.thiriet.js b/js/libs/fluidbook/cart/fluidbook.cart.thiriet.js new file mode 100644 index 00000000..d202ce0c --- /dev/null +++ b/js/libs/fluidbook/cart/fluidbook.cart.thiriet.js @@ -0,0 +1,36 @@ +function FluidbookCartThiriet(cart) { + this.cart = cart; + this.fluidbook = this.cart.fluidbook; + this.handleClicks = true; + this.init(); +} + +FluidbookCartThiriet.prototype = { + init: function () { + $(document).on(this.fluidbook.input.clickEvent, '[data-cart-ref] .add', function () { + try { + plusProduct($(this).data('cart-ref')); + } catch (e) { + console.warn('plusProduct() is unavailable'); + console.error(e); + } + }); + $(document).on(this.fluidbook.input.clickEvent, '[data-cart-ref] .remove', function () { + try { + minusProduct($(this).data('cart-ref')); + } catch (e) { + console.warn('minusProduct() is unavailable'); + console.error(e); + } + }); + + $(document).on(this.fluidbook.input.clickEvent, '[data-cart-ref] .info', function () { + try { + infoProduct($(this).data('cart-ref')); + } catch (e) { + console.warn('infoProduct() is unavailable'); + console.error(e); + } + }); + }, +}; \ No newline at end of file diff --git a/js/libs/fluidbook/fluidbook.cart.js b/js/libs/fluidbook/fluidbook.cart.js index 0bdfbff2..97d6665f 100644 --- a/js/libs/fluidbook/fluidbook.cart.js +++ b/js/libs/fluidbook/fluidbook.cart.js @@ -16,46 +16,48 @@ FluidbookCart.prototype = { this.enabled = true; this.instance = this.createInstance(); - $(document).on(this.fluidbook.input.clickEvent, '[data-cart-delete]', function () { - if ($(this).closest('.override-delete').length > 0) { - return true; - } - $this.instance.removeFromCart($(this).data('cart-delete')); - $this.instance.updateCart(false); - return false; - }); - - $(document).on(this.fluidbook.input.clickEvent, '[data-cart-ref]', function () { - try { - var qty = 1; - if ($(this).data('cart-qty') !== null) { - qty = parseInt($(this).attr('data-cart-qty')); + if (this.instance.handleClicks !== true) { + $(document).on(this.fluidbook.input.clickEvent, '[data-cart-delete]', function () { + if ($(this).closest('.override-delete').length > 0) { + return true; } + $this.instance.removeFromCart($(this).data('cart-delete')); + $this.instance.updateCart(false); + return false; + }); - var ref = $(this).data('cart-ref'); - - $this.fluidbook.stats.track(15, $this.fluidbook.currentPage, ref); - - var tooltipStyle = ''; + $(document).on(this.fluidbook.input.clickEvent, '[data-cart-ref]', function () { try { - tooltipStyle = $this.instance.getTooltipStyle(); + var qty = 1; + if ($(this).data('cart-qty') !== null) { + qty = parseInt($(this).attr('data-cart-qty')); + } + + var ref = $(this).data('cart-ref'); + + $this.fluidbook.stats.track(15, $this.fluidbook.currentPage, ref); + + var tooltipStyle = ''; + try { + tooltipStyle = $this.instance.getTooltipStyle(); + } catch (e) { + + } + var tooltip = $this.instance.addToCart(ref, qty); + if (tooltip === undefined || tooltip === null || !tooltip || tooltip === true || tooltip === false || tooltip === 'true' || tooltip === 'false') { + tooltip = $this.fluidbook.l10n.__("the item has been added to your cart"); + } + $this.fluidbook.tooltip.displayTooltip(tooltip, tooltipStyle); + setTimeout(function () { + $this.fluidbook.tooltip.hideTooltip(); + }, 2500); } catch (e) { } - var tooltip = $this.instance.addToCart(ref, qty); - if (tooltip === undefined || tooltip === null || !tooltip || tooltip === true || tooltip === false || tooltip === 'true' || tooltip === 'false') { - tooltip = $this.fluidbook.l10n.__("the item has been added to your cart"); - } - $this.fluidbook.tooltip.displayTooltip(tooltip, tooltipStyle); - setTimeout(function () { - $this.fluidbook.tooltip.hideTooltip(); - }, 2500); - } catch (e) { - - } - return false; - }); + return false; + }); + } $(this.fluidbook).on('fluidbook.links.ready', function () { $this.updateLinks(); -- 2.39.5