return subdoc;
}
}
+
+Object.size = function(obj) {
+ var size = 0, key;
+ for (key in obj) {
+ if (obj.hasOwnProperty(key)) size++;
+ }
+ return size;
+};
+
--- /dev/null
+function FluidbookCartRemarkable(cart) {
+ this.cart = cart;
+ this.fluidbook = this.cart.fluidbook;
+ this.items = {};
+ this.init();
+}
+
+FluidbookCartRemarkable.prototype = {
+ init: function () {
+
+ },
+ addToCart: function (ref, quantity) {
+ this.setQuantity(ref, quantity, 'add');
+ },
+ removeFromCart: function (ref) {
+ this.setQuantity(ref, 0, 'set');
+ },
+ setQuantity: function (ref, quantity, operator) {
+ if (operator === undefined) {
+ operator = 'set';
+ }
+ if (quantity === undefined) {
+ quantity = 1;
+ }
+ if (this.items[ref] == null) {
+ this.items[ref] = 0;
+ }
+ var q = this.items[ref];
+ if (operator == 'set') {
+ q = quantity;
+ } else if (operator == 'add') {
+ q += quantity;
+ }
+
+ if (q <= 0) {
+ delete this.items[ref];
+ } else {
+ this.items[ref] = q;
+ }
+ this.updateIcon();
+ },
+ getItemsNumbers: function () {
+ return Object.size(this.items);
+ },
+ updateIcon: function () {
+ $(this.fluidbook).trigger('fluidbook.cart.updateIcon', {number: this.getItemsNumbers()});
+ },
+
+};
\ No newline at end of file
--- /dev/null
+function FluidbookCart(fluidbook) {
+ this.fluidbook = fluidbook;
+ this.enabled = false;
+ this.instance = null;
+ this.init();
+}
+
+FluidbookCart.prototype = {
+ init: function () {
+ if (!this.fluidbook.datas.basket) {
+ return false;
+ }
+ var $this = this;
+ this.enabled = true;
+ this.instance = this.createInstance();
+
+ $(document).on('click', '[data-cart-ref]', function () {
+ $this.instance.addToCart($(this).data('cart-ref'));
+ return false;
+ });
+ },
+ createInstance: function () {
+ switch (this.fluidbook.datas.basketManager) {
+ case "Remarkable":
+ return new FluidbookCartRemarkable(this);
+ default:
+ return null;
+ }
+ },
+}
\ No newline at end of file
this.tooltip = new FluidbookTooltip(this);
this.audiodescription = new FluidbookAudioDescription(this);
this.sound = new FluidbookSound(this);
+ this.cart =new FluidbookCart(this);
if (this.datas.form == 'bulle') {
this.form = new FluidbookBulleForm(this);
this.initTheme();
this.initKeyboardShortcuts();
},
+
initTheme: function () {
if (this.datas.arrowsTheme) {
$('html').addClass('sharp');
var link2 = null;
if (icon == 'home' && !skipHome) {
-
var homeURL = this.fluidbook.datas.home;
if (this.fluidbook.datas.home == '%apphome%' || forceHome && DATAS.phonegap) {
homeURL = decodeURIComponent(window.localStorage.getItem('apphome'));
link = this.addLink(navType, 'nav-download', '#', 'download', 'download', 'download');
} else if (icon == 'print' && this.fluidbook.datas.print) {
link = this.addLink(navType, 'nav-print', '#', 'print', 'print', 'print');
+ } else if (icon == 'basket' && this.fluidbook.cart.enabled) {
+ link = this.addLink(navType, 'nav-basket', '#', 'cart', 'basket', 'basket');
+ $(this.fluidbook).on('fluidbook.cart.updateIcon', {link: link.attr('id')}, function (e, data) {
+ var n = data.number;
+ var l = $("#" + e.data.link);
+
+ if (n === 0) {
+ $(l).find('span.number').remove();
+ } else {
+ if ($(l).find('span.number').length === 0) {
+ $(l).append('<span class="number"></span>');
+ }
+ console.log($(l).find('span.number'));
+ $(l).find('span.number').text(n);
+ }
+ });
} 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');
#nav {
position: relative;
white-space: nowrap;
+
+ #locales {
+ background-color: @icon-color;
+ }
}
input[type="search"]::-webkit-search-decoration,
}
}
+/* Cart */
+.icon-cart {
+ position: relative;
+ span.number {
+ position: absolute;
+ top: 0.7em;
+ left: 0;
+ color: @icon-color;
+ text-align: center;
+ width: 100%;
+ font-size: 0.7em;
+ }
+}
+
// Hack for #1433
html.ios body.portrait #interface {
-moz-transition: none;