PageSourceSearch

https://shop.siriusxm.com/js/acdc-cart.js

js siriusxm.com collected 2026-09-24 08:28:32 UTC 20,152 bytes, 620 lines download raw bytes

1$(function() {
2	$('.form-checkout .error-message').each(function() {
3		if($(this).attr('id') != undefined){
4			$('input[name="' + $(this).attr('id').replace('.errors', '').replace(/\./g, '\\.') + '"]').parent().addClass('error-message-border');
5		}
6	});
7
8	// this is for pdp
9	$('.atc-btn').on('click', function(e) {
10		e.preventDefault();
11		var $target = $(e.target);
12		
13		acdc_cart.gateHandler();
14		var activeGates = acdc_cart.getActiveGates($target,$('input[name=subscription-selection]:checked'));
15		
16		if($target.hasClass('disabled')){
17			return false;
18		}else if(activeGates.length){			
19			var gateId = activeGates.pop();
20			$('#'+ gateId).addClass('visible');
21			return false;
22		}
23
24		addBtnAltLoadingState($target);
25
26		var sku = $('.po-on-selecter').data().productOptions.getOneAndOnlySku();
27		
28		if (sku) {
29			// if subscription is there, add it to cart with radio
30			var $sub = $('input[name=subscription-selection]:checked');
31			
32			var type = $target.data('type');
33			//If the main item didn't have a type, check to see if the sub does
34			if(type == null){
35				type = $sub.data('type'); 
36			}
37
38			if ($sub.length && $sub.val() && type != null) {
39				acdc_cart.addToCart(sku.itemId, $sub.val(), {"type" : type});
40			} else if ($sub.length && $sub.val()) {
41				acdc_cart.addToCart(sku.itemId, $sub.val());
42			} else if ($sub.length && type != null) {
43				acdc_cart.addToCart(sku.itemId, null, {"type" : type});
44			} else {
45				acdc_cart.addToCart(sku.itemId);
46			}
47		} else {
48			alert('Please select all options');
49			removeBtnAltLoadingState($target);
50		}
51	});
52	
53	$(document).on('click', '.atc-se-btn', function(event) {
54		event.preventDefault();
55		
56		var $this = $(this);
57		var productId = $this.data('productId');
58		var subId = $this.data('subscriptionId');
59		var type = $this.data('subscriptionType');
60		var sku = $('.po-tab-' + productId).data('productOptions').getOneAndOnlySku();
61		
62		if(sku != null) {
63			if(type != null) {
64				acdc_cart.addToCart(sku.itemId, subId, {"type" : type});
65			}
66		}
67	});
68
69	// this is for cat
70	$(document).on('click', '.atc-cat', function(e) {
71		e.preventDefault();	
72		var $target = $(e.target);
73		
74		var activeGates = acdc_cart.getActiveGates($target);
75		if (activeGates.length) {
76			var gateId = activeGates.pop();
77			$('#'+ gateId).addClass('visible');
78			return false;
79		}
80
81		addBtnAltLoadingState($target);
82		
83		acdc_cart.addToCart($(this).data('sku-key'));
84	});
85
86	$(document).on('click', '.btn-atc-cart', function(e) {
87		e.preventDefault();
88		var $target = $(e.target);
89
90		addBtnAltLoadingState($target);
91
92		acdc_cart.addToCart($(this).data('sku-key'));
93	});
94
95
96	/* This appears to be redundant
97	acdc_cart.updateCartCount(function(item_count) {
98		acdc_cart.refreshMiniCart(item_count);
99	});
100	*/
101	AcdcCart.addItemsFromCookieToCart(js_site_var['cart_domain'] + js_site_var['context_path'] + '/app/cart/addItems', 'already_loaded', 'remember_cart_items', function() {
102		acdc_cart.updateCartCount(function(item_count) {
103			acdc_cart.refreshMiniCart(item_count);
104		});
105	});
106
107	$('.add-subscription, .edit-subscription').click( function(e){
108		e.preventDefault();
109
110		var $trigger = $(this);
111		var $popup = $('#popup-modify-subscription');
112		var $product = $trigger.closest('.cart-product');
113		var $content = $product.find('.modify-subscription');
114
115		$popup.find('.popup-body').html($content.html());
116
117		var planType = $content.data('plan-type');
118		var term = $content.data('term');
119		var $planTypeInput;
120		var $termInput = $popup.find('.subscription-length input');
121
122		if (planType) {
123			$planTypeInput = $popup.find('input[data-plan-type="' + planType + '"]');
124		} else {
125			$planTypeInput = $popup.find('.subscription-type input').first();
126		}
127
128		if (term) {
129			$termInput = $popup.find('input[data-term="' + term + '"]');
130		} else {
131			$termInput = $popup.find('.subscription-type input').first();
132		}
133
134		$planTypeInput.add($termInput)
135			.prop('checked',true).parent().addClass('selected');
136
137		updatePopupData($popup);
138
139		$popup.addClass('visible');
140	});
141
142	$('#popup-modify-subscription').on('change', ':radio', function(event) {
143		var $popup = $(event.delegateTarget);
144		var $target = $(event.target);
145        var $parent = $target.parent();
146
147        $target.siblings().removeClass("selected");
148        $parent.addClass("selected");
149
150        if ($target.data('plan-type') !== 'undefined'){
151        	updatePopupData($popup);
152        }
153
154        //if everything is selected update the url
155        if ($popup.find('input:checked').length == 2){
156        	$popup.find('.update-cart').attr('href', getUrl($popup));
157        }
158
159    });
160
161    $('#popup-modify-subscription').on('click', '.update-cart', function(event){
162    	event.preventDefault();
163
164    	var $popup = $(event.delegateTarget);
165    	var $target = $(event.target);
166
167    	// If there isn't a URL, let's calculate it
168        if ($target.attr('href') == '#' && $popup.find('input:checked').length == 2){
169        	$popup.find('.update-cart').attr('href', getUrl($popup));
170        }
171
172        window.location.href = $target.attr('href');
173    });
174
175	$('#popup-modify-subscription, #popup-annual-subscription').on('click', '.show-more', function(event) {
176		var $target = $(event.target);
177
178		$target.nextAll('.more-details').slideDown();
179        $target.nextAll('.hide-more').show();
180        $target.hide();
181    });
182
183	$('#popup-modify-subscription, #popup-annual-subscription').on('click', '.hide-more', function(event) {
184		var $target = $(event.target);
185
186        $target.hide();
187        $target.prevAll('.show-more').show();
188        $target.nextAll('.more-details').slideUp();
189    });
190
191    $('.show-toggle').click(function () {
192        $(this).toggleClass('open').nextAll('.collapsed').slideToggle();
193    });
194
195    $('#checkoutCreditCard\\.creditCard\\.number').on('keyup change', function () {
196        var clean_nums = removeIllegalChars($(this).val());
197    	updateCCicon(clean_nums);
198    });
199
200    $(document).ready(function () {
201        $('.form-field :input').each(function () {
202            var parent = $(this).parent();
203            if($(this).hasClass('error')) {
204                parent.addClass('error');
205            } else if(parent.hasClass('error')) {
206                parent.removeClass('error');
207            }
208        });
209        tooltipAdjust();
210        window.addEventListener('resize', tooltipAdjust);
211    });
212    $(window).on('load',function () {
213    	if($('.checkout-step.current').length){
214    		$('html, body').animate({
215                scrollTop: $('.checkout-step.current').offset().top
216            });
217    	}
218    });
219
220    $('.credit-card input').on('keyup change load', function () {
221        $(this).val(removeIllegalChars($(this).val()));
222    });
223
224    $('.exp-month input').on('keyup change load', function () {
225        var inputVal = parseInt($(this).val());
226        if(inputVal === 0 || !inputVal) {
227            $(this).next('.month').text('');
228            if($(this).val().length === 2){
229                $(this).val($(this).val().slice(0, -1));
230			}
231        } else {
232            if(inputVal > 12) {
233                $(this).val(12).next('.month').text(updateMonth(inputVal));
234                $(this).next('.month').css('left', '10%');
235            } else {
236                $(this).next('.month').text(updateMonth(inputVal));
237                if(inputVal >= 10 || $(this).val().length === 2){
238                    $(this).next('.month').css('left', '10%');
239                } else {
240                    $(this).next('.month').css('left', '8%');
241                }
242            }
243        }
244    });
245    
246    $('.checkout-btn').click(function(){
247    	addBtnAltLoadingState(this);
248    });
249
250    // $('#popup-guest-checkout .btn-checkout-login').on('click', function(event){
251    // 	setCookie('self_identified_subscriber', true);
252	// });
253	//
254	// $('#popup-guest-checkout .btn-checkout-guest').on('click', function(event){
255	// 	setCookie('self_identified_subscriber', false);
256	// });
257
258    function updatePopupData(target){
259    	var $popup = $(target);
260		var planType = $popup.find('.subscription-type input:checked').data('plan-type');
261		for(var i = 0; i< relatedSubscriptionPriceData.length; i++){
262			var relatedSub = relatedSubscriptionPriceData[i];
263			var relatedSubPlanType = $popup.find('.possible-selection[data-sku-id="' + relatedSub.itemId + '"]').data('plan-type');
264			if(planType === relatedSubPlanType){
265				var $priceAndText = $popup.find('.subscription-length [data-term="' + relatedSub.time + '"]').next();
266				$priceAndText.find('.rate').html('$' + relatedSub.price);
267				$priceAndText.parent().find('.details').html(relatedSub.popupPlanText);
268			}
269		}
270    }     
271    
272    function getUrl(modSubscription){
273    	$modSubscription = $(modSubscription);
274    	var plan = $modSubscription.find('.subscription-type input:checked').data('plan-type');
275    	var term = $modSubscription.find('.subscription-length input:checked').data('term');
276    	var url = $modSubscription.find('.possible-selection[data-term="' + term + '"][data-plan-type="' + plan + '"]' ).data('replace-link');
277    	return js_site_var['context_path'] + url;
278    }
279
280    function removeIllegalChars(string){
281        return string.replace(/[^0-9]/g, '');
282    }
283
284    function updateCCicon(number) {
285		var type = getCreditCardType(number);
286
287        switch (type) {
288            case "unknown" || undefined || null || '':
289                updateCreditCardIcon("unknown");
290                break;
291            case "diners_club-cb":
292                updateCreditCardIcon("diners_club");
293                break;
294            default:
295                updateCreditCardIcon(type);
296        }
297    }
298
299    function getCreditCardType(accountNumber) {
300
301        var cardType = "unknown";
302
303        // Visa
304        var rgx = new RegExp("^4[0-9]{0,}$");
305        if (accountNumber.match(rgx) !== null)
306            cardType = "visa";
307
308        // Mastercard
309        rgx = new RegExp("^(5[1-5]|222[1-9]|22[3-9]|2[3-6]|27[01]|2720)[0-9]{0,}$");
310        if (accountNumber.match(rgx) !== null)
311            cardType = "mastercard";
312
313        // AMEX
314        rgx = new RegExp("^3[47][0-9]{0,}$");
315        if (accountNumber.match(rgx) !== null)
316            cardType = "amex";
317
318        // Discover
319        rgx = new RegExp("^(6011|65|64[4-9]|62212[6-9]|6221[3-9]|622[2-8]|6229[01]|62292[0-5])[0-9]{0,}$");
320        if (accountNumber.match(rgx) !== null)
321            cardType = "discover";
322
323        // Diners
324        rgx = new RegExp("^3(?:0[0-59]{1}|[689])[0-9]{0,}$");
325        if (accountNumber.match(rgx) !== null)
326            cardType = "diners_club";
327
328        // JCB
329        rgx = new RegExp("^(?:2131|1800|35)[0-9]{0,}$");
330        if (accountNumber.match(rgx) !== null)
331            cardType = "jcb";
332
333		// China Union Pay (81 series)
334		rgx = new RegExp("^81[0-9]{0,}$");
335		if (accountNumber.match(rgx) !== null)
336			cardType = "unionpay";
337
338		// China Union Pay (62 series)
339		rgx = new RegExp("^(621094|62[4-6]|628[2-8]|6229[2-9]|623[0-7])[0-9]{0,}$");
340		if (accountNumber.match(rgx) !== null)
341			cardType = "unionpay";
342
343        return cardType;
344    }
345
346    function updateCreditCardIcon(type) {
347    	var cardImg = "../../css/images/cards/" + type + ".png";
348    	if(!type || type === "unknown"){
349            $('#cc-icon').removeAttr("style").hide();
350            $('.cc-type').val("");
351		} else {
352    		$('.cc-type').val(type.toUpperCase());
353            $('#cc-icon').css("background-image", "url("+cardImg+")").show();
354		}
355	}
356
357    function updateMonth(number) {
358        var monthsMap = {
359            1 : 'Jan', 2 : 'Feb', 3 : 'Mar', 4 : 'Apr', 5 : 'May', 6 : 'Jun', 7 : 'Jul', 8 : 'Aug', 9 : 'Sep', 10 : 'Oct', 11 : 'Nov', 12 : 'Dec'
360        };
361    	return (number > 0 && number < 13) ? ' - ' + monthsMap[number] : '';
362	}
363
364	var tooltipAdjust = debounce(function() {
365        var screenSize = $(window).width();
366        $('.tooltiptext').each(function () {
367            var leftOffset = $(this).offset().left;
368            var widthPlusOffset = leftOffset + $(this).width() + 12;
369            if(widthPlusOffset > screenSize) {
370                var difference = widthPlusOffset - screenSize;
371                var margin = parseInt($(this).css('margin-left').split('px')[0]) - difference;
372                $(this).css('margin-left', margin - 10);
373            } else if(leftOffset < 0) {
374                margin = parseInt($(this).css('margin-left').split('px')[0]) + Math.abs(parseInt(leftOffset));
375                $(this).css('margin-left', margin + 10);
376			}
377        });
378	}, 250);
379
380
381    function debounce(func, wait, immediate) {
382        var timeout;
383        return function() {
384            var context = this, args = arguments;
385            var later = function() {
386                timeout = null;
387                if (!immediate) func.apply(context, args);
388            };
389            var callNow = immediate && !timeout;
390            clearTimeout(timeout);
391            timeout = setTimeout(later, wait);
392            if (callNow) func.apply(context, args);
393        };
394	}
395
396	$(document).on('click', '.event-tracking', function (evt) {
397		var $target = $(evt.target);
398
399		var name = $target.data('tracking-name');
400		var location = $target.data('tracking-location');
401
402		omnitureLinkTrack(name, location);
403	});
404});
405
406var acdc_cart = (function($) {
407	var obj = {};
408
409	obj.refreshMiniCart = function(item_count) {
410		if (item_count == 0) {
411			$('.cart-dropdown').addClass('cart-empty');
412		} else {
413			$('.cart-dropdown').removeClass('cart-empty');
414		}
415
416		$('.cart-dropdown').load(js_site_var['context_path'] + '/app/cart/view', function() {
417		});
418
419		return false;
420	};
421
422	obj.updateCartCount = function(callback) {
423		ajaxWithoutAuth(js_site_var['context_path'] + '/app/cart/view.json', null, 'GET', function(data) {
424			if (data && data.cart) {
425				$('.cart-count').html(data.cart.nonSubscriptionCount);
426				
427				window.cart = data.cart;
428				acdc_cart.gateHandler();
429				
430				if (typeof callback !== 'undefined') {
431					callback(data.cart.nonSubscriptionCount);
432				}
433			}
434		});
435	};
436	
437	obj.gateHandler = function(){
438		var cart = window.cart;
439		var loggedIn = window.loggedIn;
440		if(!cart.itemRestricted){
441			$('[gate-restricted-item="true"]').removeAttr('gate-restricted-item');
442		}
443		if(cart.cartItems.length == 0 && (typeof loggedIn !== 'undefined' && !loggedIn)){
444			$('[gate-cart-items-logged-in="true"]').removeAttr('gate-cart-items-logged-in');
445		}
446		if(cart.cartItems.length == 0){
447			$('[gate-promo-code-item="true"]').removeAttr('gate-promo-code-item');
448		}
449	};
450	
451	obj.getActiveGates = function(atc,fallback){
452		// If we don't have the account/cart information no gates are returned
453		if(window.cart == null ||  window.loggedIn == null){
454			return [];
455		}
456		
457		var active = [];
458		$(atc).each(function(){
459			$.each(this.attributes, function(){
460				 if(this.specified && this.name.indexOf('gate') != -1) {
461					 active.push(this.name);
462			     }
463			});
464		});
465		
466		if(active.length == 0 && typeof fallback !== 'undefined'){
467			$(fallback).each(function(){
468				$.each(this.attributes, function(){
469					 if(this.specified && this.name.indexOf('gate') != -1) {
470						 active.push(this.name);
471				     }
472				});
473			});
474		}
475		return active;
476	};
477
478	/** main function to add items to cart */
479	obj.addToCart = function(item_id, subscription_id, params, callback) {
480		var items = [];
481
482		if (typeof callback === 'undefined') {
483			callback = function() {
484				// redirect to billing step of checkout if the customer is logged in
485				if (window.loggedIn) {
486					window.location.href = js_site_var['context_path'] + '/app/cart/checkout?express=t';
487				} else {
488					window.location.href = js_site_var['context_path'] + '/app/cart/update';
489				}
490			}
491		}
492
493		if (typeof subscription_id != 'undefined' && subscription_id != null) {
494			var linkKey = Math.floor(Math.random() * (1000000 - 1)) + 1;
495
496			items.push({
497				itemId : item_id,
498				quantity : 1,
499				linkPrimary : 't',
500				linkKey : linkKey
501			});
502
503			items.push({
504				itemId : subscription_id,
505				quantity : 1,
506				linkKey : linkKey
507			});
508		} else {
509			items.push({
510				itemId : item_id,
511				quantity : 1
512			});
513		}
514
515		var urlToHit = js_site_var['cart_domain'] + js_site_var['context_path']	+ '/app/cart/addItems';
516		
517		if(typeof params != 'undefined' && params != null){
518			urlToHit = addParameters(urlToHit,params);
519		}
520		
521		// check to make sure maintenance banner is not active before adding to cart
522		var maintenanceCheckUrl = js_site_var['context_path'] + '/app/maintenance/check';
523		ajaxWithoutAuth(maintenanceCheckUrl, null, 'GET', function(data) {
524			if(!data.active) {
525				AcdcCart.addToCart(urlToHit, items, function() {
526					callback();
527				});
528				
529				return false;
530			} else {
531				window.location.reload();
532			}
533		});
534		
535		return false;
536	};
537	
538	obj.shippingEstimate = function(postalCode, shippingEstimateActive, cartTotalBuq){
539
540		var showEstimatedDelivery = true;
541
542		if(typeof shippingEstimateActive == 'string' && shippingEstimateActive.toLowerCase() == "false"){
543			showEstimatedDelivery = false;
544		}else if(typeof shippingEstimateActive == 'boolean'){
545			showEstimatedDelivery = shippingEstimateActive
546		}
547
548		if(typeof postalCode !== 'undefined' && postalCode !== null && typeof postalCode === 'string') {
549			postalCode = postalCode.split('-')[0];
550		}
551
552		if(typeof window.zipCache === 'object' && window.zipCache[postalCode] != null){
553			var estimates =window.zipCache[postalCode];
554
555			acdc_cart.shippingEstimateHandler(estimates, showEstimatedDelivery, cartTotalBuq);
556
557		}else if (postalCode === undefined || postalCode === null || postalCode === '') {
558			//
559		} else {
560			ajaxWithoutAuth(js_site_var['context_path'] + '/app/cart/estimateDo?ta=rates&country=US&postalCode=' + postalCode, null, 'GET', function(data) {
561				var estimates = data.estimates;
562
563				acdc_cart.shippingEstimateHandler(estimates, showEstimatedDelivery, cartTotalBuq);
564				
565				if(typeof window.zipCache == 'undefined'){
566					window.zipCache = {};
567				}
568				window.zipCache[postalCode] = estimates;
569		    });
570		}
571	};
572	
573	obj.shippingEstimateHandler = function(estimates, showEstimateDelivery, cartTotalBuq) {
574		for (var property in estimates) {
575		    if (estimates.hasOwnProperty(property)) {
576		    	var estimate = estimates[property];
577		    	var shippingPriceHtml = null;
578		    	if(estimate.shipping_total_baq == 0 ){
579		    		shippingPriceHtml = '<span class="free-span">FREE </span>&nbsp;&nbsp;<strike>' + estimate.shipping_pretty + '</strike>';
580		    	}else if(estimate.shipping_baq != estimate.shipping_total_baq){
581		    		shippingPriceHtml = '<strong>' + estimate.shipping_total_pretty + '</strong>&nbsp;&nbsp;' 
582		    			+ '<strike>' + estimate.shipping_pretty +  '</strike>';
583		    	}else{
584		    		shippingPriceHtml = estimate.shipping_total_pretty;
585		    	}
586		    	
587		    	$('.ssm-sm-' + property + ' span.sm-price , #sm-' + property + ' ~ div > .sm-price').html(shippingPriceHtml);
588
589				var currentMethod = $('.sxm-radio-button input:checked').val();
590				if(property === currentMethod) {
591					obj.updateSummary(estimate, cartTotalBuq);
592				}
593
594				if(showEstimateDelivery) {
595					if (estimate.delivery_estimate != null) {
596						var deliveryDateEstimate = new Date(estimate.delivery_estimate);
597						var month = deliveryDateEstimate.getMonth() + 1;
598						var date = deliveryDateEstimate.getDate();
599						var year = deliveryDateEstimate.getFullYear();
600						var estimateString = 'Estimated Delivery Date: ' + month + '/' + date + '/' + year;
601						$('.ssm-sm-' + property + ' p.delivery-estimate , #sm-' + property + ' ~div > .delivery-estimate').html(estimateString);
602					} else {
603						$('.ssm-sm-' + property + ' p.delivery-estimate , #sm-' + property + ' ~div > .delivery-estimate').html('Estimated Delivery Date: Not available');
604					}
605				}
606		    }
607    	}
608		console.log(estimates);
609	};
610
611	obj.updateSummary = function(estimate, cartTotalBuq) {
612		$('.mini-cart-total .summary-shipping-price').toggleClass('free-span', estimate.shipping_total_baq == 0);
613		let summaryText = estimate.shipping_total_baq > 0 ? estimate.shipping_total_pretty : 'FREE';
614		$('.mini-cart-total .summary-shipping-price').text(summaryText);
615		let newCartTotalBuq = cartTotalBuq + estimate.shipping_total_baq;
616		$('.mini-cart-total .summary-total').text(formatPrettyPrice(newCartTotalBuq));
617	};
618
619	return obj;
620})(jQuery);

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.