var App_Cart_Small = { _options: {}, _containerId: 'quick-shopping-cart-container', _container: null, _qtyContainerId: 'header-cart-item-count', _qtyContainerTextId: 'header-cart-item-count-text', _loaded: false, init: function(options) { $.extend(this._options, options); this._container = $('#' + this._containerId); var obj = this; $(this._options.selector).hover(function () { if (!$(obj._container).html()) { obj.reset(); } obj._loadCart(); }); this._initGtm(); }, _loadCart: function() { if (this._loaded) { return; } this._loaded = true; var obj = this; var list = ''; $.ajax({ url: obj._options.url, data: {action: 'getListHtml'}, type: 'GET', dataType: 'jsonp' }).fail(function (status) { obj._loaded = false; }).done(function (json) { if (json.success == true) { obj._container.html(json.html); obj._initGtm(); } else { obj._loaded = false; } }); }, _initGtm: function () { if (!this._options.hasGtm) { return; } var ns = 'gtmCheckout'; var elements = $('[data-checkout-step=1]'); if (elements.length) { var obj = this; elements.unbind('click.' + ns).bind('click.' + ns, function (ev) { ev.preventDefault(); var href = $(this).attr('href'); qs.showLoading(); $.ajax({ url: obj._options.url, data: {action: 'getGtmProducts'}, type: 'GET', dataType: 'jsonp' }).done(function (json) { qs.hideLoading(); if (true == json.success) { lib.Gtm.onCheckout(1, json.products, function () { document.location = href; }); } }); }); } }, updateQty: function(qty) { $('#' + this._qtyContainerId).text(qty); $('#' + this._qtyContainerTextId).text('Item' + (parseInt(qty) != 1 ? 's' : '')); }, reset: function() { this._loaded = false; $(this._container).html($('', {'src': 'images/loading-arrow-16x16.gif', 'alt': 'Loading...'})); } };