PageSourceSearch

https://www.kleen-ritecorp.com/scripts/addtocart.js

js kleen-ritecorp.com collected 2026-10-04 00:01:59 UTC 6,200 bytes, 209 lines download raw bytes

1(function($) {
2	// These match the ShoppingCart.cs CartTypeEnum values (also match equal values in minicart.js)
3	var cartType_Shopping = 0;
4	var cartType_Wish = 1;
5
6	$.initializeAddToCartForms = function(options) {
7		var minicartEnabled = false;
8		if ($.minicart && $.minicart.cartEnabled)
9			minicartEnabled = $.minicart.cartEnabled;
10
11		var miniwishEnabled = false;
12		if ($.minicart && $.minicart.wishEnabled)
13			miniwishEnabled = $.minicart.wishEnabled;
14
15		var settings = $.extend(
16			{
17				quantitySelector: '.js-validate-quantity',
18				errorSelector: '.js-add-to-cart-errors',
19				cartFormSelector: '.js-add-to-cart-form',
20				kitFormSelector: '.kit-add-to-cart-form',
21				addToCartButtonSelector: '.js-add-to-cart-button',
22				addToWishButtonSelector: '.js-wishlist-button',
23				isWishListSelector: '.js-is-wishlist',
24				ajaxAddToCartUrl: 'minicart/ajaxaddtocart',
25				ajaxAddKitToCartUrl: 'minicart/ajaxaddkittocart',
26				addToCartMessage: 'Adding to cart',
27				addToWishMessage: 'Adding to wishlist',
28				invalidQuantityMessage: 'Please enter a valid quantity',
29				addToCartFailureMessage:
30					'Your item was not added to the cart because of an error',
31				addToWishFailureMessage:
32					'Your item was not added to the wishlist because of an error',
33				// These Urls should always be sent in as params on jscript contructor !!
34				checkoutUrl: 'checkout',
35				loginUrl: 'signin'
36			},
37			options
38		);
39
40		function clearMessages(form) {
41			$(form)
42				.find(settings.errorSelector)
43				.html('');
44		}
45
46		function addMessage(message, form) {
47			$(form)
48				.find(settings.errorSelector)
49				.append('<div class="alert alert-danger">' + message + '</div>');
50		}
51
52		function validateAddToCart(form) {
53			clearMessages(form);
54			var quantity = $(form).find(settings.quantitySelector);
55			if (quantity.length && !(quantity.val() > 0)) {
56				addMessage(settings.invalidQuantityMessage, form);
57				return false;
58			}
59			return true;
60		}
61
62		function ajaxAddToCart(form, isWish, isKit) {
63			var cartType = isWish == 'true' ? cartType_Wish : cartType_Shopping;
64			var loadingMessage =
65				isWish == 'true'
66					? settings.addToWishMessage
67					: settings.addToCartMessage;
68			var errorMsg =
69				isWish == 'true'
70					? settings.addToWishFailureMessage
71					: settings.addToCartFailureMessage;
72			var ajaxUrl =
73				isKit == 'true'
74					? settings.ajaxAddKitToCartUrl
75					: settings.ajaxAddToCartUrl;
76
77			clearMessages(form);
78			$.minicart.showLoading(loadingMessage);
79			$.ajax({
80				type: 'POST',
81				url: ajaxUrl,
82				data: $(form).serialize(),
83				success: function(data, status) {
84					$.minicart.hideLoading();
85					if (data && data.Status) {
86						// If the add was successful
87						if (data.Status === 'Success') {
88							if (
89								(cartType == cartType_Shopping &&
90									$.minicart.cartEnabled &&
91									!$.minicart.onCheckoutPage) ||
92								(cartType == cartType_Wish && $.minicart.wishEnabled)
93							) {
94								$.minicart.showMiniCart(data.MinicartData, cartType);
95								//ANW added
96								if (cartType == cartType_Wish) {
97
98									var str = $(form).serialize();
99									var pid_start = str.indexOf('=') + 1;
100									var pid_end = str.indexOf('&', pid_start);
101									var productID = str.substring(pid_start, pid_end);
102
103									var vid_start = str.indexOf('&') + 11;
104									var vid_end = str.indexOf('&', vid_start);
105									var variantID = str.substring(vid_start, vid_end);
106
107									$("#" + productID + "_" + variantID + "_addToWish").addClass("fav");
108								}
109							} else {
110								window.location.href = settings.checkoutUrl;
111							}
112						}
113						// If the add was not successful
114						else {
115							// Response requires a redirect
116							if (
117								data.Status === 'RequiresLogin' ||
118								data.Status === 'SessionTimeout' ||
119								data.Status === 'Forbidden'
120							)
121								window.location.href = settings.loginUrl;
122
123							// Stay here, display msgs
124							if (data.Messages) {
125								for (var i = 0; i < data.Messages.length; i++) {
126									addMessage(data.Messages[i].Message, form);
127								}
128							}
129						}
130					} else {
131						addMessage(errorMsg, form);
132					}
133				},
134				error: function() {
135					$.minicart.hideLoading();
136					addMessage(errorMsg, form);
137				}
138			});
139		}
140
141		/* SearchSpring Fix */
142		/*$(settings.cartFormSelector).on('submit', function(event) {*/
143		$(settings.cartFormSelector).off('submit').on('submit', function (event) {
144			var isWish = $(this)
145				.find(settings.isWishListSelector)
146				.val();
147
148			if (!validateAddToCart(this)) {
149				event.preventDefault();
150			} else if (
151				(isWish.toLowerCase() === 'false' && minicartEnabled) ||
152				(isWish.toLowerCase() === 'true' && miniwishEnabled)
153			) {
154				ajaxAddToCart(this, isWish, 'false');
155				event.preventDefault();
156			}
157			// Otherwise post normally
158		});
159
160		$(settings.kitFormSelector).on('submit', function(event) {
161			var isWish = $(this)
162				.find(settings.isWishListSelector)
163				.val();
164
165			if (
166				(isWish.toLowerCase() === 'false' && minicartEnabled) ||
167				(isWish.toLowerCase() === 'true' && miniwishEnabled)
168			) {
169				ajaxAddToCart(this, isWish, 'true');
170				event.preventDefault();
171			}
172			// Otherwise post normally
173		});
174
175		$(settings.addToCartButtonSelector).on('click', function(event) {
176			var form = $(this).closest('form');
177			form.find(settings.isWishListSelector).val('false');
178		});
179
180		$(settings.addToWishButtonSelector).on('click', function(event) {
181			var form = $(this).closest('form');
182			form.find(settings.isWishListSelector).val('true');
183		});
184	};
185})(adnsf$);
186
187//ANW added 11/7/2019
188(function ($) {
189	$(function () {
190		updateMinicartLink();
191	});
192
193	new MutationObserver((mutationList, observer) => { updateMinicartLink(); }).observe($('.js-minicart-total')[0], { attributes: true, childList: true, subtree: true });
194
195	//$('.js-minicart-total').on('DOMSubtreeModified', function () {
196	//	updateMinicartLink();
197	//})
198})(adnsf$);
199
200function updateMinicartLink() {
201	var a = $('.js-minicart-total').html();
202	if (typeof a == "undefined") {
203		$('#custom-cart').hide();
204	} else {
205		$('#custom-cart').show();
206		$('#tp').html('<small><i>My Cart</i></small><br/><strong id=\'cart-price\'>' + a + '</strong>');
207	}
208}
209//****************************

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.