PageSourceSearch

https://softslate.com/js/energize/ECCEditItemQuantityTool.js?ver=1003192257136

js softslate.com collected 2026-10-03 19:25:23 UTC 4,102 bytes, 108 lines download raw bytes

1$(document).ready(function() {
2	
3	// Edits an item in the current user's cart. Replaces the page's HTML cart contents, including
4	// Discounts and estimated shipping.
5
6	// Initialize all tools marked with the ECCEditItemQuantityTool class. See cart.jsp.
7	$('.ECCEditItemQuantityTool').each(function() {
8		$(this).data('eccEditItemTool', new ECCEditItemQuantityTool($(this)));
9	});
10});
11
12ECCEditItemQuantityTool = function(element) {
13	this.element = element;
14	this.syncCode = this.element.find($('.ECCEditItemQuantityTool-syncCode'))[0];
15	this.quantityInput = this.element.find($('.ECCEditItemQuantityTool-quantityInput'))[0];
16	this.removeButton = this.element.find($('.ECCEditItemQuantityTool-removeButton'))[0];
17	this.loadingIconElement = this.element.find('.ECCEditItemQuantityTool-loadingIcon')[0];
18	this.successIconElement = this.element.find('.ECCEditItemQuantityTool-successIcon')[0];
19	this.errorIconElement = this.element.find('.ECCEditItemQuantityTool-errorIcon')[0];
20	
21	// Globalish/page-level elements like the cart badge in the header
22	this.headerCartQuantity = $('#ECCAddItemTool-cartQuantity');
23	this.headerCartQuantities = $('.ECCAddItemTool-cartQuantity');
24	this.cartQuantity = $('.ECCEditItemQuantityTool-cartQuantity')[0].dataset.cartQuantity;
25	this.cartContainer = $('#cartContent');
26	this.errorModal = $('#ECCAddItemTool-errorModal');
27	
28	// Update the header's quantity as the tool is initialized. For if a change was just submitted.
29	$(this.headerCartQuantity).html(this.cartQuantity);
30	$(this.headerCartQuantities).html(this.cartQuantity);
31	
32	var tool = this;
33	
34	// When the quantity is changed or the remove button is clicked, patch using Ajax.
35	$(this.quantityInput).change(function(event) {
36		tool.editItem(event);
37	});
38	$(this.removeButton).click(function(event) {
39		tool.quantityInput.value = '0';
40		tool.editItem(event);
41	});
42}
43
44ECCEditItemQuantityTool.prototype.editItem = function(event) {
45	var tool = this;
46	$(tool.loadingIconElement).show();
47	$(tool.successIconElement).hide();
48	$(tool.errorIconElement).hide();
49	ECCUserMiscTool.disableAllCartActions();
50	var parameters = { };
51	parameters['syncCode'] = $(tool.syncCode).val();
52	parameters['quantity'] = $(tool.quantityInput).val();
53	
54	// Need to include the csrf token in the header.
55	var token = $("meta[name='_csrf']").attr("content");
56	var header = $("meta[name='_csrf_header']").attr("content");
57	
58	$.ajax( {
59		type : "POST",
60		url : ECCSettings.contextPath + "/ajax/html/cart/cartItemQuantity/" + $(tool.syncCode).val(),
61		data : parameters,
62		dataType : "html",
63        beforeSend: function(xhr) {
64            xhr.setRequestHeader(header, token);
65        },
66		success : function(data) {
67			tool.processSuccessful(data); // have to put this inside a function!
68		},
69		error : function(data) {
70			tool.processError(data); // have to put this inside a function!
71		}
72	});
73}
74
75ECCEditItemQuantityTool.prototype.processSuccessful = function(html) {
76	var tool = this;
77	$(tool.cartContainer).html(html);
78	
79	// Note: we update the header's quantity as the tool is initialized above.
80	// But if we just removed the last one, that won't fire. So empty it out here first.
81	$(this.headerCartQuantity).html('');
82	$(this.headerCartQuantities).html('');
83	
84	// Reinitialize tools for all the items that were just re-rendered.
85	ECCToolInitializer.initializeAllTools($(tool.cartContainer));
86}
87
88ECCEditItemQuantityTool.prototype.processError = function(error) {
89	var tool = this;
90	$(tool.loadingIconElement).hide();
91	$(tool.successIconElement).hide();
92	$(tool.errorIconElement).show();
93	ECCUserMiscTool.enableAllCartActions();
94	var errorHtml = "<span class='ajaxError'>Error contacting server. Try reloading the page to start over.</span>";
95	if (error.responseText) {
96		errorHtml = error.responseText;
97	}
98	$(tool.errorIconElement).bind('click', function(event) {
99		$(tool.errorModal).find('.modal-body').html(errorHtml);
100	
101		// Bootstrap 3 does uses jquery; Bootstrap 5 does not.
102		if (typeof bootstrap === 'undefined') {
103			$(tool.errorModal).modal({show:true});
104		} else {
105			new bootstrap.Modal(tool.errorModal, {}).show();
106		}
107	});
108}

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.