if (typeof Countries === "object") {
Countries.updateProvinceLabel = function(e, t) {
if (typeof e === "string" && Countries[e] && Countries[e].provinces) {
if (typeof t !== "object") {
t = document.getElementById("address_province_label");
if (t === null) {
return
}
}
t.innerHTML = Countries[e].label;
var n = jQuery(t).parent();
var r = n.find("select");
n.find(".custom-style-select-box-inner").html(Countries[e].provinces[0])
}
}
}
if (typeof Shopify.Cart === "undefined") {
Shopify.Cart = {}
}
Shopify.Cart.ShippingCalculator = function() {
var _config = {
submitButton: "Calculate shipping",
submitButtonDisabled: "Calculating...",
templateId: "shipping-calculator-response-template",
wrapperId: "wrapper-response",
customerIsLoggedIn: false,
moneyFormat: "$ {{amount}}"
};
var _render = function(e) {
var t = jQuery("#" + _config.templateId);
var n = jQuery("#" + _config.wrapperId);
if (t.length && n.length) {
t.tmpl(e).appendTo(n);
if (typeof Currency !== "undefined" && typeof Currency.convertAll === "function") {
var r = "";
if (jQuery("[name=currencies]").size()) {
r = jQuery("[name=currencies]").val()
} else {
if (jQuery("#currencies span.selected").size()) {
r = jQuery("#currencies span.selected").attr("data-currency")
}
}
if (r !== "") {
Currency.convertAll(shopCurrency, r, "#wrapper-response span.money, #estimated-shipping em span.money")
}
}
}
};
var _enableButtons = function() {
jQuery(".get-rates").removeAttr("disabled").removeClass("disabled").val(_config.submitButton)
};
var _disableButtons = function() {
jQuery(".get-rates").val(_config.submitButtonDisabled).attr("disabled", "disabled").addClass("disabled")
};
var _getCartShippingRatesForDestination = function(e) {
var t = {
type: "GET",
url: "/cart/shipping_rates.json",
data: jQuery.param({
shipping_address: e
}),
dataType: "json",
success: function(t) {
rates = t.shipping_rates;
_onCartShippingRatesUpdate(rates, e)
},
error: function(e, t) {
_onError(e, t)
}
};
jQuery.ajax(t)
};
var _fullMessagesFromErrors = function(e) {
var t = [];
jQuery.each(e, function(e, n) {
jQuery.each(n, function(n, r) {
t.push(e + " " + r)
})
});
return t
};
var _onError = function(XMLHttpRequest, textStatus) {
jQuery("#estimated-shipping").hide();
jQuery("#estimated-shipping em").empty();
_enableButtons();
var feedback = "";
if (XMLHttpRequest.responseText != "") {
var data = eval("(" + XMLHttpRequest.responseText + ")");
if (!!data.message) {
feedback = data.message + "(" + data.status + "): " + data.description
} else {
feedback = "Error : " + _fullMessagesFromErrors(data).join("; ")
}
if (feedback === "Error : country is not supported.") {
feedback = "We do not ship to this destination."
}
} else {
feedback = "Error : Code is invalid"
}
_render({
rates: [],
errorFeedback: feedback,
success: false
});
jQuery("#" + _config.wrapperId).show()
};
var _onCartShippingRatesUpdate = function(e, t) {
_enableButtons();
var n = "";
if (t.zip) {
n += t.zip + ", "
}
if (t.province) {
n += t.province + ", "
}
n += t.country;
if (e.length) {
if (e[0].price == "0.00") {
jQuery("#estimated-shipping em").html("FREE")
} else {
jQuery("#estimated-shipping em").html(_formatRate(e[0].price))
}
}
_render({
rates: e,
address: n,
success: true
});
jQuery("#" + _config.wrapperId + ", #estimated-shipping").fadeIn()
};
var _formatRate = function(e) {
function i(e) {
return e.replace(/(\d+)(\d{3}[\.,]?)/, "$1,$2")
}
function s(e, t) {
var n = e.toFixed(t).toString();
if (n.match(/^\.\d+/)) {
return "0" + n
} else {
return n
}
}
if (typeof e == "string") {
e = e.replace(".", "")
}
var t = "";
var n = /\{\{\s*(\w+)\s*\}\}/;
var r = _config.moneyFormat;
switch (r.match(n)[1]) {
case "amount":
t = i(s(e / 100, 2));
break;
case "amount_no_decimals":
t = i(s(e / 100, 0));
break;
case "amount_with_comma_separator":
t = s(e / 100, 2).replace(/\./, ",");
break;
case "amount_no_decimals_with_comma_separator":
t = i(s(e / 100, 0)).replace(/\./, ",");
break
}
return r.replace(n, t)
};
_init = function() {
new Shopify.CountryProvinceSelector("address_country", "address_province", {
hideElement: "address_province_container"
});
var e = jQuery("#address_country");
var t = jQuery("#address_province_label").get(0);
if (typeof Countries !== "undefined") {
Countries.updateProvinceLabel(e.val(), t);
e.change(function() {
Countries.updateProvinceLabel(e.val(), t)
})
}
jQuery(".get-rates").click(function(e) {
e.preventDefault();
_disableButtons();
jQuery("#" + _config.wrapperId).empty().hide();
var t = {};
t.zip = jQuery("#address_zip").val() || "";
t.country = jQuery("#address_country").val() || "";
t.province = jQuery("#address_province").val() || "";
_getCartShippingRatesForDestination(t)
});
if (_config.customerIsLoggedIn) {
jQuery(".get-rates:eq(0)").trigger("click")
}
};
return {
show: function(e) {
e = e || {};
jQuery.extend(_config, e);
jQuery(function() {
_init()
})
},
getConfig: function() {
return _config
},
formatRate: function(e) {
return _formatRate(e)
}
}
}()
Here is the ajax.js:
if (typeof Countries === "object") {
Countries.updateProvinceLabel = function(e, t) {
if (typeof e === "string" && Countries[e] && Countries[e].provinces) {
if (typeof t !== "object") {
t = document.getElementById("address_province_label");
if (t === null) {
return
}
}
t.innerHTML = Countries[e].label;
var n = jQuery(t).parent();
var r = n.find("select");
n.find(".custom-style-select-box-inner").html(Countries[e].provinces[0])
}
}
}
if (typeof Shopify.Cart === "undefined") {
Shopify.Cart = {}
}
Shopify.Cart.ShippingCalculator = function() {
var _config = {
submitButton: "Calculate shipping",
submitButtonDisabled: "Calculating...",
templateId: "shipping-calculator-response-template",
wrapperId: "wrapper-response",
customerIsLoggedIn: false,
moneyFormat: "$ {{amount}}"
};
var _render = function(e) {
var t = jQuery("#" + _config.templateId);
var n = jQuery("#" + _config.wrapperId);
if (t.length && n.length) {
t.tmpl(e).appendTo(n);
if (typeof Currency !== "undefined" && typeof Currency.convertAll === "function") {
var r = "";
if (jQuery("[name=currencies]").size()) {
r = jQuery("[name=currencies]").val()
} else {
if (jQuery("#currencies span.selected").size()) {
r = jQuery("#currencies span.selected").attr("data-currency")
}
}
if (r !== "") {
Currency.convertAll(shopCurrency, r, "#wrapper-response span.money, #estimated-shipping em span.money")
}
}
}
};
var _enableButtons = function() {
jQuery(".get-rates").removeAttr("disabled").removeClass("disabled").val(_config.submitButton)
};
var _disableButtons = function() {
jQuery(".get-rates").val(_config.submitButtonDisabled).attr("disabled", "disabled").addClass("disabled")
};
var _getCartShippingRatesForDestination = function(e) {
var t = {
type: "GET",
url: "/cart/shipping_rates.json",
data: jQuery.param({
shipping_address: e
}),
dataType: "json",
success: function(t) {
rates = t.shipping_rates;
_onCartShippingRatesUpdate(rates, e)
},
error: function(e, t) {
_onError(e, t)
}
};
jQuery.ajax(t)
};
var _fullMessagesFromErrors = function(e) {
var t = [];
jQuery.each(e, function(e, n) {
jQuery.each(n, function(n, r) {
t.push(e + " " + r)
})
});
return t
};
var _onError = function(XMLHttpRequest, textStatus) {
jQuery("#estimated-shipping").hide();
jQuery("#estimated-shipping em").empty();
_enableButtons();
var feedback = "";
if (XMLHttpRequest.responseText != "") {
var data = eval("(" + XMLHttpRequest.responseText + ")");
if (!!data.message) {
feedback = data.message + "(" + data.status + "): " + data.description
} else {
feedback = "Error : " + _fullMessagesFromErrors(data).join("; ")
}
if (feedback === "Error : country is not supported.") {
feedback = "We do not ship to this destination."
}
} else {
feedback = "Error : Code is invalid"
}
_render({
rates: [],
errorFeedback: feedback,
success: false
});
jQuery("#" + _config.wrapperId).show()
};
var _onCartShippingRatesUpdate = function(e, t) {
_enableButtons();
var n = "";
if (t.zip) {
n += t.zip + ", "
}
if (t.province) {
n += t.province + ", "
}
n += t.country;
if (e.length) {
if (e[0].price == "0.00") {
jQuery("#estimated-shipping em").html("FREE")
} else {
jQuery("#estimated-shipping em").html(_formatRate(e[0].price))
}
}
_render({
rates: e,
address: n,
success: true
});
jQuery("#" + _config.wrapperId + ", #estimated-shipping").fadeIn()
};
var _formatRate = function(e) {
function i(e) {
return e.replace(/(\d+)(\d{3}[\.,]?)/, "$1,$2")
}
function s(e, t) {
var n = e.toFixed(t).toString();
if (n.match(/^\.\d+/)) {
return "0" + n
} else {
return n
}
}
if (typeof e == "string") {
e = e.replace(".", "")
}
var t = "";
var n = /\{\{\s*(\w+)\s*\}\}/;
var r = _config.moneyFormat;
switch (r.match(n)[1]) {
case "amount":
t = i(s(e / 100, 2));
break;
case "amount_no_decimals":
t = i(s(e / 100, 0));
break;
case "amount_with_comma_separator":
t = s(e / 100, 2).replace(/\./, ",");
break;
case "amount_no_decimals_with_comma_separator":
t = i(s(e / 100, 0)).replace(/\./, ",");
break
}
return r.replace(n, t)
};
_init = function() {
new Shopify.CountryProvinceSelector("address_country", "address_province", {
hideElement: "address_province_container"
});
var e = jQuery("#address_country");
var t = jQuery("#address_province_label").get(0);
if (typeof Countries !== "undefined") {
Countries.updateProvinceLabel(e.val(), t);
e.change(function() {
Countries.updateProvinceLabel(e.val(), t)
})
}
jQuery(".get-rates").click(function(e) {
e.preventDefault();
_disableButtons();
jQuery("#" + _config.wrapperId).empty().hide();
var t = {};
t.zip = jQuery("#address_zip").val() || "";
t.country = jQuery("#address_country").val() || "";
t.province = jQuery("#address_province").val() || "";
_getCartShippingRatesForDestination(t)
});
if (_config.customerIsLoggedIn) {
jQuery(".get-rates:eq(0)").trigger("click")
}
};
return {
show: function(e) {
e = e || {};
jQuery.extend(_config, e);
jQuery(function() {
_init()
})
},
getConfig: function() {
return _config
},
formatRate: function(e) {
return _formatRate(e)
}
}
}()