PageSourceSearch

https://alanparsons.com/cdn/shop/t/3/assets/jquery.ajax-cart.min.js?v=173173619150874324791729031637

js alanparsons.com collected 2026-10-02 07:46:32 UTC 11,049 bytes, 209 lines download raw bytes

1! function($) {
2    var AjaxCart = function($ele, settings) {
3        this.$ele = $ele, this.settings = settings, this.connection = new CartConnection, this.cartDisplay = new CartDisplay(this.settings.cartCountElement,this.settings.cartDropdownElement), this.cartPrice = new CartPrice(this.settings.cartPriceElement), this.cartFormQueue = [], this.cartForms = [], this._buildForms(), this._addEventHandlers()
4    };
5    AjaxCart.prototype._buildForms = function() {
6        var self = this;
7        this.$ele.find('form[action="/cart/add"]').each(function(i) {
8            var cartForm = new ProductForm(this, self.settings.form, i);
9            self.cartForms.push(cartForm)
10        }), this.$ele.find('form[action="/cart"]').each(function(i) {
11            var cartForm = new CartForm(this, self.settings.form, i);
12            self.cartForms.push(cartForm)
13        })
14    }, AjaxCart.prototype._addEventHandlers = function() {
15        var self = this;
16        this.$ele.on("cartCollected", function(e, cartData) {
17            self.cart = cartData, self.cartCount = cartData.item_count, self.cartDisplay.updateCartCountElement(self.cartCount), self.cartDisplay.updateCartDropdownElement(self.cartCount, cartData)
18        }), this.$ele.on("sendToCart", function(e, formData, formID) {
19            var form = self.cartForms[formID];
20            self.cartFormQueue.push(form), self.connection.postToCart(formData, form)
21        }), this.$ele.on("postToCartSuccess", function(e, result) {
22            result.item_count ? (self.cartCount = result.item_count, self.cartPrice.updatePriceElement(result)) : self.cartCount++, self.cartDisplay.updateCartCountElement(self.cartCount);
23            var cartForm = self.cartFormQueue.shift();
24            cartForm.sendToCartSuccess(result)
25            self.connection.getCart();
26          
27          if(typeof trigger_messages == 'function')
28          {
29            trigger_messages();
30          }
31
32        }), this.$ele.on("postToCartError", function(e, err, status) {
33            var cartForm = self.cartFormQueue.shift();
34            cartForm.sendToCartError(err, status)
35        })
36    };
37    var CartConnection = function() {
38        this.getCart()
39    };
40    CartConnection.prototype.getCart = function() {
41        $.ajax({
42            type: "GET",
43            dataType: "json",
44            url: "/cart.js"
45        }).done(function(data) {
46            $.event.trigger("cartCollected", data)
47        })
48    }, CartConnection.prototype.postToCart = function(formData, form) {
49        if(formData.indexOf('quantity=0') == -1) {
50           $.ajax({
51            type: "POST",
52            dataType: "json",
53            url: form.postURL,
54            data: formData
55        }).done(function(result) {
56            $.event.trigger("postToCartSuccess", result)
57        }).fail(function(err, status) {
58            $.event.trigger("postToCartError", [err, status])
59        })
60        }
61        else {
62			$.event.trigger("postToCartError", [null, 0])
63        }
64    };
65    var CartForm = function(form, settings, id) {
66        this.$form = $(form), this.settings = settings, this.id = id, this.postURL = "/cart/update.js", this._addEventHandlers()
67    };
68    CartForm.prototype.sendToCartSuccess = function() {
69        var message = "Cart successfully updated.";
70        this._displayMessage(message, "success")
71    }, CartForm.prototype.sendToCartError = function(err, status) {
72        try {
73            var response = jQuery.parseJSON(err.responseText);
74            this._displayMessage(response.message + ": " + response.description, "danger")
75        } catch (e) {
76            this._displayMessage("ERROR: There was an error adding your item to the cart.", "danger")
77        }
78    }, CartForm.prototype._addEventHandlers = function() {
79        var self = this;
80        this.$form.on("keyup", '[name^="updates"]', function(e) {
81            this === document.activeElement && self._isNumberKeyCode(e.keyCode) && (e.preventDefault(), $.event.trigger("sendToCart", [self.$form.serialize(), self.id]))
82        })
83    }, CartForm.prototype._displayMessage = function(message, messageType) {
84        var messageMarkup = this.settings.cartMessageMarkup(message, messageType);
85        this.$form.prepend(messageMarkup);
86        var self = this;
87        window.setTimeout(function() {
88            self._removeMessage()
89        }, 6e3)
90    }, CartForm.prototype._removeMessage = function() {
91        this.$form.find(".ajax-cart-message").hide(186, function() {
92            this.remove()
93        })
94    }, CartForm.prototype._isNumberKeyCode = function(keyCode) {
95        var keyMatch = !1,
96            keyCodes = [8, 9, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 96, 97, 98, 99, 100, 101, 102, 103, 104, 105];
97        for (var i in keyCodes)
98            if (keyCode === keyCodes[i]) {
99                keyMatch = !0;
100                break
101            }
102        return keyMatch
103    };
104    var ProductForm = function(form, settings, id) {
105        this.$form = $(form), this.settings = settings, this.id = id, this.postURL = "/cart/add.js", this.formButton = this._getFormButton(), this._addEventHandlers()
106    };
107    ProductForm.prototype.sendToCartSuccess = function(result) {
108        var message = result.title + ' successfully added. <a href="/cart">
108View cart</a>';
109        this._displayMessage(message, "success")
110    }, ProductForm.prototype.sendToCartError = function(err, status) {
111        try {
112            var response = jQuery.parseJSON(err.responseText);
113            this._displayMessage(response.message + ": " + response.description, "danger")
114        } catch (e) {
115            this._displayMessage("ERROR: There was an error adding your item to the cart.", "danger")
116        }
117    }, ProductForm.prototype._getFormButton = function() {
118        var $button = this.$form.find('input[name="add"],button[name="add"]');
119        return $button.length > 0 ? new CartFormButton($button, this.settings) : !1
120    }, ProductForm.prototype._addEventHandlers = function() {
121        var self = this;
122        this.$form.on("submit", function(e) {
123            e.preventDefault(), self.formButton && self.formButton.updateButton("Adding...", !0), $.event.trigger("sendToCart", [$(this).serialize(), self.id])
124        })
125    }, ProductForm.prototype._displayMessage = function(message, messageType) {
126        this.formButton.updateButton(!1, !1);
127        var messageMarkup = this.settings.productMessageMarkup(message, messageType);
128        this.$form.append(messageMarkup);
129        var self = this;
130        window.setTimeout(function() {
131            self._removeMessage()
132        }, 6e3)
133    }, ProductForm.prototype._removeMessage = function() {
134        this.$form.find(".ajax-cart-message").hide(186, function() {
135            this.remove()
136        })
137    };
138    var CartFormButton = function($ele, settings) {
139        this.$ele = $ele, this.settings = settings, this.defaultSubmitValue = this.$ele.val() || this.settings.defaultSubmitValue
140    };
141    CartFormButton.prototype.updateButton = function(message, disable) {
142        message || (message = this.defaultSubmitValue), this.$ele.val(message).prop("disabled", disable)
143    };
144    var CartDisplay = function(cartCountElement, cartDropdownElement) {
145        this.$cartCountElement = $(cartCountElement), this.$cartCountBadge = this.$cartCountElement.find(".badge"), this.$cartDropdownElement = $(cartDropdownElement)
146    };
147    CartDisplay.prototype.updateCartCountElement = function(count) {
148        count > 0 && (0 === this.$cartCountBadge.length && (this.$cartCountElement.append(' <span class="badge"></span> <span class="caret"></span>'), this.$cartCountBadge = this.$cartCountElement.find(".badge")), this.$cartCountBadge.text() !== count && this.$cartCountBadge.text(count))
149    };
150    CartDisplay.prototype.updateCartDropdownElement = function(count, cart) {
151      $('li.quick-cart-row').remove();
152      if(cart.item_count == 0) {
153        $(".cart-dropdown").prepend('<li class="quick-cart-row text-center">Your cart is empty</li>');
154      }
155      else {
156        for(var i = 0; i < cart.items.length; i++) {
157        	$(".cart-dropdown").prepend('<li class="quick-cart-row"><a href="'+cart.items[i].url+'">'+ cart.items[i].title +' x'+cart.items[i].quantity+'</a><span class="quick-remove" href="javascript:void(0);" onclick="Shopify.removeItem('+ cart.items[i].variant_id +')"><i class="fa fa-times"></i></span></li>');
158        }
159      }
160    };  
161    var CartPrice = function(ele) {
162        this.$ele = $(ele), this.freeShipping = $(document).data("_freeShipping")
163    };
164    CartPrice.prototype.updatePriceElement = function(result) {
165        if (this.$ele.length > 0) {
166            var formattedMoney = Shopify.formatMoney(result.total_price);
167            this.$ele.find(".money").replaceWith('<span class="money">' + formattedMoney + "</span>"), "undefined" != typeof Currency && Currency.shopCurrency !== Currency.currentCurrency && Currency.convertAll(Currency.shopCurrency, Currency.currentCurrency), this.freeShipping && this.freeShipping.update({
168                cart_total: result.total_price
169            }), this._recalcShipping()
170        }
171    }, CartPrice.prototype._recalcShipping = function() {
172        var $shippingCalc = $(".shipping-calculator-wrapper"),
173            $responseWrapper = $shippingCalc.find("#wrapper-response");
174        $shippingCalc.length > 0 && "" !== $responseWrapper.html() && $shippingCalc.find(".get-rates").trigger("click")
175    }, $.fn.ajaxCart = function(opts) {
176        var settings = $.extend({}, $.fn.ajaxCart.defaults, opts);
177        return this.each(function() {
178            var $ele = $(this);
179            $ele.data("_ajaxCart", new AjaxCart($ele, settings))
180        })
181    }, $.fn.ajaxCart.defaults = {
182        cartCountElement: ".cartCount",
183       	cartDropdownElement: ".cart-dropdown",
184        cartPriceElement: 'form[action="/cart"] .product-price',
185        form: {
186            defaultSubmitValue: "Add to cart",
187            productMessageMarkup: function(message, messageType) {
188                return '<span class="ajax-cart-message help-block text-' + messageType + '">' + message + "</span>"
189            },
190            cartMessageMarkup: function(message, messageType) {
191                return '<div class="ajax-cart-message alert alert-' + messageType + '">' + message + "</div>"
192            }
193        }
194    }
195    
196Shopify.onCartUpdate = function(cart) {
197  	  $('li.quick-cart-row').remove();
198  	  $('.cartCount').find(".badge").text(cart.item_count);
199      if(cart.item_count == 0) {
200        $(".cart-dropdown").prepend('<li class="quick-cart-row text-center">Your cart is empty</li>');
201      }
202      else {
203        for(var i = 0; i < cart.items.length; i++) {
204        	$(".cart-dropdown").prepend('<li class="quick-cart-row"><a href="'+cart.items[i].url+'">'+ cart.items[i].title +' x'+cart.items[i].quantity+'</a><span class="quick-remove" href="javascript:void(0);" onclick="Shopify.removeItem('+ cart.items[i].variant_id +')"><i class="fa fa-times"></i></span></li>');
205        }
206      }
207};    
208    
209}(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.