]> _ Git - fluidbook-html5.git/commitdiff
wait #4057 @0.75
authorVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 16 Nov 2020 11:07:36 +0000 (12:07 +0100)
committerVincent Vanwaelscappel <vincent@cubedesigners.com>
Mon, 16 Nov 2020 11:07:36 +0000 (12:07 +0100)
js/libs/fluidbook/cart/fluidbook.cart.puma.js
js/libs/fluidbook/fluidbook.cart.js
js/libs/fluidbook/fluidbook.tooltip.js

index cb2d5437d3057f9ab38f04f72b0517e58167f0ea..f526c2a1b7d9ab8cf7f55d95432cda56bca7c9e6 100644 (file)
@@ -1,3 +1,5 @@
+
+
 function FluidbookCartPuma(cart) {
     var $this = this;
     this.cart = cart;
@@ -28,16 +30,19 @@ FluidbookCartPuma.prototype = {
         if (this.getItems().indexOf(ref) === -1) {
             this.items.push(ref);
             this.save();
-            return true;
+            return this.fluidbook.l10n.__("the item has been added to your cart");
         } else {
             this.removeFromCart(ref);
-            return false;
+            return this.fluidbook.l10n.__("the item has been removed from your cart");
         }
     },
 
-    removeFromCart: function (key) {
-        this.items.splice(key, 1);
-        this.save();
+    removeFromCart: function (ref) {
+        var key = this.items.indexOf(ref);
+        if (key >= 0) {
+            this.items.splice(key, 1);
+            this.save();
+        }
     },
 
     save: function () {
@@ -81,7 +86,7 @@ FluidbookCartPuma.prototype = {
 
     getItems: function () {
         var res = [];
-        var $this=this;
+        var $this = this;
         $(this.items).each(function (i, ref) {
             if ($this.data[ref] !== undefined && $this.data[ref] !== null) {
                 res.push(ref);
index c513e164d79f8e5bb158b2f2c977789d90663d7e..664f25b2f1c8d01ad0dc60331f3dc374ba9267a4 100644 (file)
@@ -1,3 +1,5 @@
+// this.fluidbook.l10n.__("remove from cart")
+
 function FluidbookCart(fluidbook) {
     this.fluidbook = fluidbook;
     this.enabled = false;
@@ -35,9 +37,12 @@ FluidbookCart.prototype = {
             } catch (e) {
 
             }
-            if ($this.instance.addToCart(ref, qty)) {
-                $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"), tooltipStyle);
+            var tooltip = $this.instance.addToCart(ref, qty);
+            if (!tooltip) {
+                tooltip = $this.fluidbook.l10n.__("the item has been added to your cart");
             }
+            $this.fluidbook.tooltip.displayTooltip(tooltip, tooltipStyle);
+
             return false;
         });
 
index b080545bc25795ec29b397359655ed62e6f07f81..27895671db645d9d309db4bf08ce6b002e0356c8 100644 (file)
@@ -107,20 +107,31 @@ FluidbookTooltip.prototype = {
         }
 
         var $this = this;
-
-
         var text = '';
         if ($(target).is('[data-tooltip]')) {
             text = $(target).attr('data-tooltip');
         } else if ($(target).is('[data-keyboard-tooltip]')) {
             text = $(target).attr('data-keyboard-tooltip');
         }
+        var conditionnalText = false;
+        if ($(target).is('[data-tooltip-conditional]')) {
+            $.each($(target).data('tooltip-conditional'), function (condition, ctext) {
+                if ($(target).is(condition)) {
+                    text = '~' + ctext;
+                    conditionnalText = true;
+                    return false;
+                }
+            });
+        }
 
         text = $('<textarea />').html(text).text();
         if (text.substr(0, 1) == '~') {
             var text = $this.fluidbook.l10n.__(text.substring(1));
-            $(target).attr('data-tooltip', text);
+            if (!conditionnalText) {
+                $(target).attr('data-tooltip', text);
+            }
         }
+
         if (text == undefined || text == '') {
             return false;
         }