diff --git a/src/bda/plone/cart/browser/cart.js b/src/bda/plone/cart/browser/cart.js index 6d5d964..0970bc0 100644 --- a/src/bda/plone/cart/browser/cart.js +++ b/src/bda/plone/cart/browser/cart.js @@ -5,20 +5,7 @@ (function($, bdajax) { "use strict"; - var CART_EXECUTION_CONTEXT = null, - CART_EXECUTION_URL = null, - CART_PORTLET_IDENTIFYER = '#portlet-cart', - CART_VIEWLET_IDENTIFYER = '#cart_viewlet'; - $(document).ready(function() { - var execution_context = $('.cart_execution_context'); - if (execution_context.length) { - CART_EXECUTION_CONTEXT = execution_context.text(); - } - var execution_url = $('#cart'); - if (execution_url.length) { - CART_EXECUTION_URL = execution_url.data('context-url'); - } cart.init(); cart.query(); if (window.Faceted !== undefined) { @@ -53,7 +40,16 @@ } Cart.prototype.init = function() { - this.cart_node = $('#cart').get(0); + $cart = $('#cart'); + + this.cart_execution_context = $('.cart_execution_context').text() || null; + + var cart_execution_url = $cart.data('context-url'); + this.cart_execution_url = '/' + cart_execution_url ? cart_execution_url : ''; + this.cart_portlet_identifier = '#portlet-cart'; + this.cart_viewlet_identifier = '#cart_viewlet'; + + this.cart_node = $cart.get(0); if (!this.cart_node) { return; } @@ -124,19 +120,19 @@ this.cart_max_article_count = data.cart_settings.cart_max_article_count; if (data.cart_items.length === 0) { if (!data.cart_settings.hide_cart_if_empty) { - $(CART_PORTLET_IDENTIFYER).css('display', 'block'); - $(CART_VIEWLET_IDENTIFYER).css('display', 'block'); + $(this.cart_portlet_identifier).css('display', 'block'); + $(this.cart_viewlet_identifier).css('display', 'block'); } else { - $(CART_PORTLET_IDENTIFYER).css('display', 'none'); - $(CART_VIEWLET_IDENTIFYER).css('display', 'none'); + $(this.cart_portlet_identifier).css('display', 'none'); + $(this.cart_viewlet_identifier).css('display', 'none'); } $('#cart_items', this.cart_node).css('display', 'none'); $('#cart_no_items', this.cart_node).css('display', 'block'); $('#cart_summary', this.cart_node).css('display', 'none'); $('.cart_total_count').html(0); } else { - $(CART_PORTLET_IDENTIFYER).css('display', 'block'); - $(CART_VIEWLET_IDENTIFYER).css('display', 'block'); + $(this.cart_portlet_identifier).css('display', 'block'); + $(this.cart_viewlet_identifier).css('display', 'block'); $('#cart_no_items', this.cart_node).css('display', 'none'); $('#cart_items', this.cart_node).empty(); $('#cart_items', this.cart_node).css('display', 'block'); @@ -295,13 +291,13 @@ uid: defs[0], count: count + '' }; - if (CART_EXECUTION_CONTEXT) { - params.execution_context = CART_EXECUTION_CONTEXT; + if (cart_execution_context) { + params.execution_context = cart_execution_context; } var elem = $(this); var status_message = elem.hasClass('show_status_message'); bdajax.request({ - url: CART_EXECUTION_URL + '/validate_cart_item', + url: this.cart_execution_url + 'validate_cart_item', params: params, type: 'json', success: function(data) { @@ -357,13 +353,13 @@ uid: defs[0], count: count + '' }; - if (CART_EXECUTION_CONTEXT) { - params.execution_context = CART_EXECUTION_CONTEXT; + if (cart_execution_context) { + params.execution_context = cart_execution_context; } var elem = $(this); var status_message = elem.hasClass('show_status_message'); bdajax.request({ - url: CART_EXECUTION_URL + '/validate_cart_item', + url: this.cart_execution_url + 'validate_cart_item', params: params, type: 'json', success: function(data) { @@ -560,11 +556,11 @@ return; } var params = {}; - if (CART_EXECUTION_CONTEXT) { - params.execution_context = CART_EXECUTION_CONTEXT; + if (cart_execution_context) { + params.execution_context = cart_execution_context; } bdajax.request({ - url: CART_EXECUTION_URL + '/cartData', + url: this.cart_execution_url + 'cartData', params: params, type: 'json', success: function(data) { @@ -577,4 +573,4 @@ var cart = new Cart(); window.bda_plone_cart = cart; -})(jQuery, bdajax); \ No newline at end of file +})(jQuery, bdajax);