var $this = this;
this.cart = cart;
this.fluidbook = this.cart.fluidbook;
- this.items = {};
+ this.items = this.cart.getSavedData();
this.database;
$.each(this.fluidbook.datas.basketReferences, function (k, v) {
$this.database = {};
FluidbookCartRemarkable.prototype = {
init: function () {
-
+ var $this = this;
+ $(document).on('change', '[data-menu="cart"] .input-number', function () {
+ $this.updateCart();
+ return true;
+ });
},
addToCart: function (ref, quantity) {
this.setQuantity(ref, quantity, 'add');
} else {
this.items[ref] = q;
}
+ this.cart.saveData(this.items);
this.updateIcon();
},
getItemsNumbers: function () {
},
openCart: function (p2, callback) {
+ var $this = this;
+ this._endMenu(this.fluidbook.l10n.__('your cart'), this.getCartContent(), function () {
+ $('input[type="number"]').inputNumber();
+
+ callback();
+ });
+ },
+
+ getCartContent: function () {
var $this = this;
var content = '<table class="cart-items">';
$.each(this.items, function (ref, quantity) {
var item = $this.getItemData(ref);
-
content += '<tr>';
content += '<td class="name">' + item.name + '</td>';
- content += '<td class="quantity">' + quantity + '</td>';
+ content += '<td class="quantity"><input name="' + ref + '" class="cartqty" type="number" min="0" max="100" value="' + quantity + '" step="1" /></td>';
content += '<td class="price_unit">' + $this.formatPrice(item.price, 'HT') + '</td>';
content += '<td class="price_excluding_taxes">' + $this.formatPrice(item.price * quantity, 'HT') + '</td>';
content += '<td class="price">' + $this.formatPrice((item.price * quantity) * (1 + item.tax), 'TTC') + '</td>';
- content += '<td class="delete"></td>';
+ content += '<td class="delete"><a href="#" data-cart-delete="' + ref + '"></a></td>';
+ content += '</tr>';
+ });
+ content += '</table>';
+ return content;
+ },
- content + '</tr>';
+ updateCart: function () {
+ var $this = this;
+ $(".cartqty").each(function () {
+ $this.setQuantity($(this).attr('name'), parseInt($(this).val()), 'set');
});
- content + '</table>';
- this._endMenu(this.fluidbook.l10n.__('your cart'), content, callback);
},
- formatPrice: function (price, currency, suffix) {
+ formatPrice: function (price, suffix) {
if (suffix == undefined) {
suffix = '';
}
return this.database[ref];
},
-
openShipping: function (p2, callback) {
var content = '';
this._endMenu(this.fluidbook.l10n.__('your contact details'), content, callback);
this._endMenu(this.fluidbook.l10n.__('confirmation'), content, callback);
},
-
_endMenu: function (title, content, callback) {
var view = '<div class="caption">' + this.fluidbook.menu.closeButton() + '<h2>' + title + '</h2></div>';
view += '<div class="content">';
return this._cache[key] != null;
}
},
- get: function (key) {
+ get: function (key, defaultValue) {
+ if (defaultValue === undefined) {
+ defaultValue = null;
+ }
var res;
if (this._support) {
res = localStorage.getItem(this._prefix + key);
} else {
res = this._cache[key];
}
+ if (!this.isset(key)) {
+ return defaultValue;
+ }
var f = res.substr(0, 1);
if (f == '[' || f == '{') {
res = json_parse(res);
},
checkValidity: function () {
if (!this.isset('validity') || this.get('validity') != this._date) {
- this.clear();
+ //this.clear();
this.set('validity', this._date);
}
}
$(document).on('click', '[data-cart-ref]', function () {
$this.instance.addToCart($(this).data('cart-ref'));
+ $this.fluidbook.tooltip.displayTooltip($this.fluidbook.l10n.__("the item has been added to your cart"));
return false;
});
},
+ getSavedData: function () {
+ return this.fluidbook.cache.get('cart', {})
+ },
+ saveData: function (data) {
+ this.fluidbook.cache.set('cart', data);
+ },
createInstance: function () {
switch (this.fluidbook.datas.basketManager) {
case "Remarkable":
return null;
}
},
-}
\ No newline at end of file
+};
+
+(function ($) {
+ function JQinputNumber(element) {
+ this.element = element;
+ this.positive = false;
+ this.integer = false;
+ this.step = 1;
+ this.inited = false;
+
+ var istep = parseFloat(this.element.attr('step'));
+ this.min = undefined !== this.element.attr('min') ? parseFloat(this.element.attr('min')) : Number.NEGATIVE_INFINITY;
+ this.max = undefined !== this.element.attr('max') ? parseFloat(this.element.attr('max')) : Number.POSITIVE_INFINITY;
+ this.errorMax = this.element.data('max-error');
+
+ this.integer = (!isNaN(istep) && istep % 1 === 0);
+ this.positive = (this.min > 0);
+
+ if (!isNaN(istep)) {
+ this.step = istep;
+ }
+ this.init();
+ }
+
+ JQinputNumber.prototype = {
+ init: function () {
+ var $this = this;
+
+ this.element.attr('novalidate', 'novalidate');
+ this.element.prop('type', 'text');
+ this.element.wrap('<div class="input-number"></div>');
+ this.wrapper = this.element.parent('.input-number');
+ this.wrapper.prepend('<a href="#" class="minus">-</a>');
+ this.wrapper.append('<a href="#" class="plus">+</a>');
+
+ this.wrapper.on('click', 'a', function () {
+ if ($(this).hasClass('minus')) {
+ $this.increment(-1 * $this.step);
+ } else if ($(this).hasClass('plus')) {
+ $this.increment($this.step);
+ }
+ return false;
+ });
+
+ this.element.on('change', function () {
+ $this.element.val($this.normalize());
+ $this.wrapper.trigger('change');
+ });
+
+ this.element.val(this.normalize());
+ this.inited = true;
+ },
+ normalize: function (v) {
+ var origV;
+ if (v === undefined) {
+ v = this.element.val();
+ }
+ if (typeof v !== "number") {
+
+ if (this.integer) {
+ v = parseInt(v);
+ } else {
+ v = parseFloat(v);
+ }
+
+ }
+ if (isNaN(v)) {
+ v = 0;
+ }
+ origV = v;
+ v = Math.max(v, this.min);
+ v = Math.min(v, this.max);
+ v = Math.round(v / this.step) * this.step;
+ if (v < origV && this.errorMax !== null) {
+ alert(this.errorMax);
+ }
+ return v;
+ },
+ increment: function (i) {
+ var v = this.normalize();
+ var v1 = v;
+ v += i;
+ v = this.normalize(v);
+ if (v === v1) {
+ return;
+ }
+ this.element.val(v);
+ this.wrapper.trigger('change');
+ }
+ };
+
+ jQuery.fn.inputNumber = function () {
+ return this.each(function () {
+ var $this = $(this);
+ $(this).data('inputNumber', new JQinputNumber($this));
+ });
+ };
+})(jQuery);
\ No newline at end of file
$(l).find('span.number').text(n);
}
});
+ this.fluidbook.cart.instance.updateIcon();
} else if (icon == 'lang' && this.fluidbook.l10n.multilangEnabled) {
// Note: the "!" at the beginning of the title/help parameters means that we don't want these strings translated
link = this.addLink(navType, 'nav-locales', '#/locales', 'locales', '!' + this.fluidbook.l10n.getCurrentLanguageName(), '!Select Language');
}
this.displayTooltip(text);
- this.updateTooltipPosition();
return false;
},
});
return false;
}
-
+ this.updateTooltipPosition();
return true;
},
hideTooltip: function () {
}
}
+[data-menu="cart"] {
+ table {
+ width: 1004px;
+ margin-left: 10px;
+ td {
+ padding: 15px;
+ text-align: left;
+ vertical-align: middle;
+ white-space: nowrap;
+ &.name {
+ white-space: normal;
+ }
+ &.price {
+ font-weight: 700;
+ }
+ }
+ .input-number {
+ position: relative;
+ width: 160px;
+ height: 44px;
+ input {
+ height: 44px;
+ width: 60px;
+ display: inline-block;
+ margin: 0 2px;
+ border: 0;
+ vertical-align: top;
+ padding: 20px;
+ text-align: center;
+ }
+ a {
+ display: inline-block;
+ height: 44px;
+ width: 44px;
+ background-color: @menu-button-background;
+ text-align: center;
+ font-weight: 700;
+ font-size: 30px;
+ }
+ }
+ }
+}
+
// Hack for #1433
html.ios body.portrait #interface {
-moz-transition: none;