var AutoHideButton = true;
var CurrencyConverterAppRate = {};
getCurrencyConverter();
var link_custom_js = document.createElement('script');
link_custom_js.src = 'https://www.latiendadelbillarista.com/apps/giraffly-stickycart/stickycart-custom-b59172510dfffff0368bcfd87bf8edc1fb6ab8f6.js';
document.getElementsByTagName("head")[0].appendChild(link_custom_js);
var link = document.createElement("link");
// link.rel = "stylesheet";
link.rel = "preload stylesheet";
link.as = "style";
link.type = "text/css";
link.href = 'https://www.latiendadelbillarista.com/apps/giraffly-stickycart/stickycart-b59172510dfffff0368bcfd87bf8edc1fb6ab8f6.css';
document.getElementsByTagName("head")[0].appendChild(link);
var link_custom_css = document.createElement("link");
// link_custom_css.rel = "stylesheet";
link_custom_css.rel = "preload stylesheet";
link_custom_css.type = "text/css";
link_custom_css.as = "style";
link_custom_css.href = 'https://www.latiendadelbillarista.com/apps/giraffly-stickycart/stickycart-custom-b59172510dfffff0368bcfd87bf8edc1fb6ab8f6.css';
document.getElementsByTagName("head")[0].appendChild(link_custom_css);
var giraffly_default_js=0;
if(window.Currency==undefined){
giraffly_default_js=1;
var cdn_currency_js = document.createElement('script');
cdn_currency_js.src = 'https://cdn.shopify.com/s/javascripts/currencies.js';
document.getElementsByTagName("head")[0].appendChild(cdn_currency_js);
}else if(window.Currency!=undefined && window.Currency.default_currency!=undefined) {
giraffly_default_js = 1;
}
var girafflyMutilCurrency=null;
var hidden_point = 0; //修改成giraffly_hidden_point
var hidden_point_arr=['JPY','CLP','COP','SEK','PYG','ISK','BIF','KRW','DJF','GNF','KMF','RWF','UGX','VND'];
Shopify.locale
if(Shopify.currency.active!=undefined){
if(hidden_point_arr.indexOf(Shopify.currency.active)!=-1){
hidden_point=1;
}else{
hidden_point=0;
}
}
var cartBarUserClient = '';
if (!(navigator.userAgent.match(/(phone|pad|pod|iPhone|iPod|ios|iPad|Android|Mobile|BlackBerry|IEMobile|MQQBrowser|JUC|Fennec|wOSBrowser|BrowserNG|WebOS|Symbian|Windows Phone)/i))) {
cartBarUserClient = 'pc';
} else{
cartBarUserClient = 'phone';
}
function addMiniCartOpenTimes(){
var urls = 'https://api-stickycart.seoant.com/api/v1/addClickTimes?c=b59172510dfffff0368bcfd87bf8edc1fb6ab8f6&shop=www.latiendadelbillarista.com';
fetch(urls, {
method: 'post',
headers: {
'Content-type': 'application/json',
"Access-Control-Request-Headers": "*",
"Access-Control-Request-Method": "*"
},
body: JSON.stringify({
action: 'mini'
})
}).then(json => {
});
}
function girafflyCartBarButton(productJson,updateShoppingCart=true) {
var hideStickyCartClass ='';
hideStickyCartClass = '';
let girafflyCartNumber = productJson.item_count;
window.girafflyCartNumber = girafflyCartNumber;
let car_bar_position = (cartBarUserClient=='pc')? 'right:30px;bottom:115px ': 'right:30px;bottom:125px ';
let car_bar_style = "background-color:#e22120;padding:11px";
let Round_TotalQuantityHtml = '';
let Square_TotalQuantityHtml = '';
Round_TotalQuantityHtml = '
\n' +
'
'+ girafflyReturnAmount(productItems[i].price/100) + ' \n';
}else{
giraffly_del_Content ='
'+ girafflyReturnAmount(productItems[i].price/100)+'
\n'+
'
\n' +
'
'+ girafflyReturnAmount(productItems[i].discounted_price/100) + '\n';
}
let variant_title = (productItems[i].variant_title == null)?'':productItems[i].variant_title;
itemHtml = '
\n' +
'
\n' +
'
\n' +
'
\n' +
product_title +
'
\n' +
'
\n' +
variant_title +
'
\n' +
giraffly_del_Content+
'
\n' +
'
-
\n' +
'
'+ productItems[i].quantity +'
\n' +
'
+
\n' +
'
\n' +
'
\n' +
'
\n' +
'
\n' +
'
\n' +
'
\n' +
'
';
productListHtml += itemHtml;
}
if(productListHtml != ''){
subtotalHtml = '
\n' +
'
\n' +
' Subtotal' +
'
\n' +
'
\n' +
' ' + girafflyReturnAmount(productObj.total_price/100) + '' +
'
\n' +
'
';
}
}
let off_canvas_position = '';
off_canvas_position = 'right: 0;width: 480px;';
let emptyCartStyle = (girafflyCartNumber==0)?'display:block':'display:none';
let canvas_emptyCartHtml = '
' +
empty_cart_text +
'
';
let canvas_footerButtonHtml = '';
canvas_footerButtonHtml = '\n';
let canvas_shoppingCartHtml = '
\n' +
' \n' +
'
\n' +
' \n' +
'
\n' +
'
\n' +
productListHtml +
'
\n' +
canvas_emptyCartHtml +
'
\n' +
'
\n'+
subtotalHtml +
'
\n' +
canvas_footerButtonHtml +
'
\n' +
'
\n' +
' ';
let modal_emptyCarthtml= ' ';
let modal_footerButtonHtml = '';
modal_footerButtonHtml = '';
let modal_shoppingCartHtml = '\n' +
' \n' +
' ';
shoppingCartHtml = canvas_shoppingCartHtml;
let divShoppingCart = document.createElement("div");
divShoppingCart.innerHTML = shoppingCartHtml;
document.body.appendChild(divShoppingCart);
}
function girafflyMiniCartAction(type) {
if(type == 1){
window.location.href="/cart";
}else{
window.location.href="/cart/checkout";
}
}
function closedGirafflyShoppingCart(){
jQuery(".giraffly_Off-Canvas").css('display','none');
jQuery(".giraffly_hoverButton").css('display','block');
//关闭后 将pc和移动端的stickycart显示出来
var body = document.body,
html = document.documentElement;
var scrollHeight = Math.max( body.scrollHeight, body.offsetHeight,html.clientHeight, html.scrollHeight, html.offsetHeight );
var pcheight = scrollHeight * 0;
var phoneheight = scrollHeight * 0;
var y = jQuery(this).scrollTop() + 900;
if(jQuery(this).scrollTop() > 0) {
if(y >= pcheight) {
jQuery(".giraffly_PCPreview_BOX").show();
jQuery(".giraffly_PCPreview").css('display','flex');
}
if(y >= phoneheight) {
jQuery(".giraffly_phoneButtonPreview ").show();
}
}
}
//
function closeMinicartBox() {
if(typeof jQuery != 'undefined' && document.body) {
jQuery('body').on('click', function() {
jQuery(document).mouseup(e => {
var Icon = jQuery('.giraffly_Off-Canvas');
var popIcon = jQuery('.giraffly_Modal_Popups__Container');
let status = jQuery('.giraffly_Off-Canvas').css('display');
if (!Icon.is(e.target) && Icon.has(e.target).length === 0 && !popIcon.is(e.target) && popIcon.has(e.target).length === 0 && status !== 'none') {
closedGirafflyShoppingCart();
}
});
})
} else {
setTimeout(() => {
closeMinicartBox();
}, 1000);
}
}
closeMinicartBox();
function cartBarButtonAction() {
window.location.href="/cart";
}
function getUserShoppingCart() {
fetch("/cart.js",{method: 'GET'})
.then(res => res.json())
.then(json => {
jQuery(".girafflyCartNumber").html(json.item_count);
jQuery(".giraffly_Cart_Price_Number").html(girafflyReturnAmount(json.total_price/100));
}).catch(function(err) {
console.log("error: giraffly - getUserShoppingCart");
});
}
function girafflyProductCountChange(obj,isAdd){
let VId = obj.getAttribute("data-vid");
let needUpdateCount = 0;
let countNumberObj = '';
if(isAdd){
countNumberObj = obj.previousSibling.previousElementSibling;
needUpdateCount = Number(countNumberObj.innerHTML)+1;
needAddProduct(VId,countNumberObj,1,needUpdateCount);
}else{
countNumberObj = obj.nextSibling.nextElementSibling;
needUpdateCount = Number(countNumberObj.innerHTML)-1;
jQuery.ajax({
url : '/cart/change.js',
type: 'post',
data: JSON.stringify({
quantity: needUpdateCount,
id: VId
}),
headers: {
'Content-type': 'application/json'
},
dataType: 'json',
success: function (data) {
jQuery(document).ajaxSuccess(function (event, xhr, settings) {
updateGirafflyShoppingCart();
});
if(data.token != ''){
if(needUpdateCount==0){
let objParent = obj.parentNode.parentNode.parentNode.parentNode.parentNode;
let childParent = obj.parentNode.parentNode.parentNode.parentNode;
objParent.removeChild(childParent);
jQuery(".girafflyCartNumber").html(data.item_count);
jQuery(".giraffly_Cart_Price_Number").html(girafflyReturnAmount(data.total_price/100));
}else{
let proItem = data.items;
let realQuantity = 0;
for(let ik = 0,lk=proItem.length; ik < lk; ik++) {
if(proItem[ik].id == VId){
realQuantity = proItem[ik].quantity;
break;
}
}
if(realQuantity != needUpdateCount){
let needAddNumber = needUpdateCount - realQuantity;
needAddProduct(VId,countNumberObj,needAddNumber,needUpdateCount);
}else{
if(data.item_count != 0){
countNumberObj.innerHTML = needUpdateCount;
jQuery(".girafflyCartNumber").html(data.item_count);
jQuery(".giraffly_Cart_Price_Number").html(girafflyReturnAmount(data.total_price/100));
}else{
jQuery(".giraffly_EmptyCart").show();
jQuery(".girafflyCartNumber").html(0);
jQuery(".giraffly_Subtotal_Show").hide();
}
}
}
}else{
alert("Opps... something wrong.");
}
}
});
}
}
function needAddProduct(vid,obj,needAddCount,needUpdateCount){
jQuery.ajax({
url: '/cart/add.js',
type: 'post',
data: JSON.stringify({
quantity: needAddCount,
id: vid,
}),
headers: {
'Content-type': 'application/json'
},
dataType: 'json',
success: function (json) {
if(json.id){
obj.innerHTML = needUpdateCount;
getUserShoppingCart();
}else{
alert("Opps... something wrong.");
}
}
});
}
function girafflyRemove(productObj){
let dataId = productObj.getAttribute("data-id");
let dataNumber = productObj.getAttribute("data-number");
jQuery.ajax({
url : '/cart/change.js',
type: 'post',
data: JSON.stringify({
quantity: 0,
id: dataId
}),
headers: {
'Content-type': 'application/json'
},
dataType: 'json',
success: function (data) {
if(data.token != ''){
let objParent = productObj.parentNode.parentNode;
let childParent = productObj.parentNode;
objParent.removeChild(childParent);
if(data.item_count != 0){
jQuery(".girafflyCartNumber").html(data.item_count);
jQuery(".giraffly_Cart_Price_Number").html(girafflyReturnAmount(data.total_price/100));
}else{
jQuery(".giraffly_EmptyCart").show();
jQuery(".girafflyCartNumber").html(0);
jQuery(".giraffly_Subtotal_Show").hide();
}
}
}
});
}
function updateGirafflyShoppingCart (){
fetch("/cart.js",{method: 'GET'})
.then(res => res.json())
.then(shoppingCartJson =>
{
sessionStorage.setItem('lastCartCount',shoppingCartJson.item_count);
let productListHtml = '';
let subtotalHtml = '';
if(shoppingCartJson != '') {
let productItems = shoppingCartJson.items;
let itemHtml = '';
for(let i = 0,len=productItems.length; i < len; i++) {
let product_title = productItems[i].product_title;
product_title = (product_title.length < 70)?product_title: product_title.substring(0,70) + '...';
let variant_title = (productItems[i].variant_title == null)?'':productItems[i].variant_title;
var giraffly_del_Content ="";
if(productItems[i].total_discount==0){
giraffly_del_Content = '
\n' +
'
'+ girafflyReturnAmount(productItems[i].price/100) + ' \n';
}else{
giraffly_del_Content ='
'+ girafflyReturnAmount(productItems[i].price/100)+'
\n'+
'
\n' +
'
'+ girafflyReturnAmount(productItems[i].discounted_price/100) + '\n';
}
itemHtml = '
\n' +
'
\n' +
'
\n' +
'
\n' +
product_title +
'
\n' +
'
\n' +
variant_title +
'
\n' +
giraffly_del_Content+
'
\n' +
'
-
\n' +
'
'+ productItems[i].quantity +'
\n' +
'
+
\n' +
'
\n' +
'
\n' +
'
\n' +
'
\n' +
'
\n' +
'
\n' +
'
';
productListHtml += itemHtml;
}
if(productListHtml != ''){
subtotalHtml = '
\n' +
'
\n' +
' Subtotal' +
'
\n' +
'
\n' +
' ' + girafflyReturnAmount(shoppingCartJson.total_price/100) + '' +
'
\n' +
'
';
jQuery(".giraffly_Subtotal_Box").html(subtotalHtml);
jQuery(".giraffly_EmptyCart").hide();
}else{
jQuery(".giraffly_EmptyCart").show();
}
jQuery(".giraffly_Product_List").html(productListHtml);
jQuery(".girafflyCartNumber").html(shoppingCartJson.item_count);
updateCartQuantity(shoppingCartJson.item_count);
let isArr = document.getElementsByClassName("giraffly_hoverButton");
if(productListHtml != '' && isArr.length == 0){
girafflyCartBarButton(shoppingCartJson,false);
}
}
}).catch(function(err) {
console.log("error: giraffly - updateShoppingCart");
});
}
function updateCartIconQuantity() {
// 监听店铺按钮点击更新sticky 购物车
jQuery(`button[type='submit'][class*='add']`).on('click', function() {
if(jQuery('.giraffly_hoverButton').length === 0) {
fetch("/cart.js",{method: 'GET'})
.then(res => res.json())
.then(json => {
girafflyCartBarButton(json);
}).catch(function(err) {
console.log("error: giraffly - getUserShoppingCart");
});
} else {
let currents = jQuery('.girafflyCartNumber').eq(0).text();
let endNum = 0;
if(Number(currents) !== window.girafflyCartNumber) {
endNum = window.girafflyCartNumber || 0;
} else {
endNum = currents;
}
let num = Number(endNum) + 1;
jQuery('.girafflyCartNumber').text(num);
}
})
// 加减
setInterval(() => {
let girafflyCartNumber = jQuery('.girafflyCartNumber');
if(jQuery(`header[class*='active']`).length > 0 && girafflyCartNumber.length > 0) {
let num = Number(girafflyCartNumber.text());
jQuery(`header[class*='active']`).find(`button[id*='minus'][class*='minus']`).on('click', function(){
jQuery('.girafflyCartNumber').text(num === 0 ? 0 : num - 1);
})
jQuery(`header[class*='active']`).find(`button[id*='plus'][class*='plus']`).on('click', function(){
jQuery('.girafflyCartNumber').text(num + 1);
})
jQuery(`header[class*='active']`).find(`button[id*='remove'][class*='remove']`).on('click', function(){
jQuery('.girafflyCartNumber').text(0);
})
}
}, 500)
}
function girafflyAddEventListener(element,type,fn) {
if(element.addEventListener){
element.addEventListener(type,fn,false);
}else if(element.attachEvent){
element.attachEvent("on"+type,fn);
}else{
element["on"+type]=fn;
}
}
function onFetch(callback) {
let logFetch = window.fetch;
window.fetch = function (input, init) {
return new Promise((resolve, reject)=> {
// console.log(input,'listen input fetch...')
// console.log(init,'listen init fetch...')
logFetch(input, init)
.then(function(response) {
callback(input);
resolve(response);
}, reject)
})
}
}
function girafflyCartBartInit(){
// 如果是ajax事件监听
jQuery(document).ajaxSuccess(function (event, xhr, settings) {
if(settings.url.indexOf('/cart.js') !== -1) {
let oldcount = sessionStorage.getItem('cartCount'); // cartjs数量
let newcount = sessionStorage.getItem('lastCartCount'); // 当前数量
// 第二次以上请求
if(newcount && newcount !== '') {
// 如果不相等就请求
if(newcount !== oldcount) {
updateGirafflyShoppingCart();
sessionStorage.setItem('cartCount', newcount);
}
} else {
// 第一次要监听带时间戳的cart请求
updateGirafflyShoppingCart();
}
} else {
updateGirafflyShoppingCart();
}
});
// fetch事件监听
onFetch(fetchPath=> {
var fetchPathString = fetchPath+""
if(fetchPathString.indexOf('/add') != -1) {
updateGirafflyShoppingCart()
}
})
}
if ("undefined" == typeof jQuery || 1 === parseInt(jQuery.fn.jquery) && parseFloat(jQuery.fn.jquery.replace(/^1\./, "")) < 10) {
var cartBarJQ = document.createElement("script");
cartBarJQ.src = ("https:" == document.location.protocol ? "https://" : "http://") + "ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js";
cartBarJQ.onload = function () {
fetch("/cart.js",{method: 'GET'})
.then(res => res.json())
.then(json => {
girafflyCartBarButton(json);
//初次加载
girafflyInitDom(json);
}).catch(function(err) {
console.log("error: giraffly - getShoppingCart");
});
girafflyCartBartInit();
jQuery(document).ajaxSuccess(function (event, xhr, settings) {
if (settings.url == "cart/add.js") {
updateGirafflyShoppingCart();
}
});
};
document.getElementsByTagName("head")[0].appendChild(cartBarJQ);
}else{
fetch("/cart.js",{method: 'GET'})
.then(res => res.json())
.then(json => {
girafflyCartBarButton(json);
//初次加载
girafflyInitDom(json);
}).catch(function(err) {
console.log("error: giraffly - getUserShoppingCart");
});
girafflyCartBartInit();
jQuery(document).ajaxSuccess(function (event, xhr, settings) {
if (settings.url == "cart/add.js") {
updateGirafflyShoppingCart();
}
});
}
function girafflymoneyformat(){
var format = {before_format:"",after_format:""};
// var spanMoneyStr = jQuery("span.money:eq(0)").text();
var spanMoneyStr = "";
var spanMoneyArr = jQuery("span.money");
spanMoneyArr.each(function(){
if(jQuery(this).text() != undefined) {
if(spanMoneyStr.length < jQuery(this).text().length && jQuery(this).text().indexOf('Your Cart Subtotal')==-1) {
spanMoneyStr = jQuery(this).text()
}
}
})
if(spanMoneyStr === '') {
spanMoneyStr = jQuery("span.currency-converter-amount-box:eq(0)").text();
}
if(spanMoneyStr === '') {
spanMoneyStr = jQuery("span.Magic-Currency:eq(0)").text();
}
if(spanMoneyStr === '') {
spanMoneyStr = jQuery("span.product__price:eq(0)").text();
}
if(spanMoneyStr === '') {
spanMoneyStr = jQuery("span.price-item:eq(0)").text();
}
if(spanMoneyStr!=null){
var first_positon = 999;
var end_position = 999;
for(var i=0;i
-1;j--){
if(parseInt(spanMoneyStr[j])||parseInt(spanMoneyStr[j])==0){
if(end_position==999){
end_position=j;
}
}
}
format.before_format= spanMoneyStr.slice(0,first_positon);
format.after_format = spanMoneyStr.slice(end_position+1);
}
return format;
}
function girafflyGetPrice(){
var returnPrice = {price:"",compared_price:""};
// return returnPrice;
var arr =[];
var change_format = girafflymoneyformat();
before_format=change_format.before_format;
after_format=change_format.after_format;
jQuery('span.money').each(function(k) {
if(!isNaN(jQuery(this).html().substring(jQuery(this).html().indexOf(before_format)+before_format.length,jQuery(this).html().indexOf(after_format)))){
arr[k]=jQuery(this).html().substring(jQuery(this).html().indexOf(before_format)+before_format.length,jQuery(this).html().indexOf(after_format));
}else{
arr[k]=0;
}
})
var noZeoArr=[];
for(j=0;j a - b);
if(AS.length>0){
returnPrice.price=before_format+AS[0]+after_format;
returnPrice.compared_price=before_format+AS[AS.length-1]+after_format;
}
return returnPrice;
}
function girafflyChangeCurrency(amount,from,to,comparePrice=false){
// console.log('---------girafflyChangeCurrency-----------start------------')
if(from=="" || to ==""){
return amount;
}
if(from == to){
return amount;
}
if(window.Currency!=undefined && giraffly_default_js!=1){
// console.log('---------------------------1---------------------------')
if(window.Currency.convert!=undefined){
return window.Currency.convert(amount,from,to);
}else{
return amount;
}
}else if(window.DoublyGlobalCurrency!=undefined){
// console.log('---------------------------2--------------------------')
if(window.DoublyGlobalCurrency.convert!=undefined){
// 价格转化有差别国家列表
// const shortname = ['ARS','XPF','COP','CRC','HUF','IDR','PYG','RUB','UYU','VND'];
// let formatAfterPrice = window.DoublyGlobalCurrency.convert(amount,from,to);
// console.log(formatAfterPrice)
// if(shortname.includes(to)) {
// return formatAfterPrice/1000;
// } else {
// return formatAfterPrice;
// }
return window.DoublyGlobalCurrency.convert(amount,from,to);
}else{
return amount;
}
}else if(window.KTCurrency!=undefined){
// console.log('---------------------------3---------------------------')
if(window.KTCurrency.convert!=undefined){
return window.KTCurrency.convert(amount,from,to);
}else{
return amount;
}
}else if(window.Shoppad!=undefined) {
if(Shoppad.apps!=undefined) {
if(Shoppad.apps.coin!=undefined) {
// console.log('---------------------------4---------------------------')
rate = Shoppad.apps.coin.getLocalCurrencyUSDExchangeRate()
// 无小数点的特殊货币则不保留小数部分
if(hidden_point_arr.indexOf(to) === 0) {
return Math.round(amount * rate);
}
return Math.round(amount * rate * 100) / 100;
}
}
}else if(window.localStorage['cbb-currency-converter-currency'] != undefined) {
// console.log('---------------------------5---------------------------')
var toRate = CurrencyConverterAppRate[to];
var fromRate = CurrencyConverterAppRate[from];
// 无小数点的特殊货币则不保留小数部分
if(hidden_point_arr.indexOf(to) === 0) {
return Math.round((amount * toRate) / fromRate);
}
return Math.round(((amount * toRate) / fromRate) * 100) /100;
}else if(window.ACSCurrency != undefined) {
// console.log('---------------------------6---------------------------')
if(window.ACSCurrency.convert != undefined) {
return window.ACSCurrency.convert(amount,from,to);
}else{
return amount;
}
}else if(window.mcc_formatMoney != undefined) {
// console.log('---------------------------7---------------------------')
if(comparePrice) {
tagSelector = $_mcc("span.money").eq(1)
}else{
tagSelector = $_mcc("span.money").eq(0)
}
amount = Conversion(tagSelector,to)
return amount;
}else if(window.currencyhq != undefined) {
// console.log('---------------------------8---------------------------')
// tagSelector = currencyhq.monies;
// if(comparePrice) {
// amount = tagSelector[1]['dataset'].originalUnformatted
// }else{
// amount = tagSelector[0]['dataset'].originalUnformatted
// }
if(comparePrice) {
tagMonies = currencyhq.monies[1]
}else{
tagMonies = currencyhq.monies[0]
}
if(tagMonies != undefined) {
var allowArr = [1,2,3,4,5,6,7,8,9,0,'1','2','3','4','5','6','7','8','9','0']
var toAmount =""
var returnAmount
for(var i=0; i=0; i--) {
if(allowArr.indexOf(toAmount[i]) == -1) {
firstSign = toAmount[i];
break;
}
}
if(firstSign == '.') {
returnAmount = toAmount.replace(',','')
}else if(firstSign == ','){
returnAmount = toAmount.replace('.','')
returnAmount = returnAmount.replace(',','.')
}else{
returnAmount = toAmount
}
}
return returnAmount;
}else if(window.PriceConvert != undefined) {
return window.PriceConvert(amount,to);
}else if(window.SalesRocket != undefined){
if(window.SalesRocket.CurrencyManager != undefined) {
if(window.SalesRocket.CurrencyManager.allCurrencies != undefined) {
var allCurrencies = SalesRocket.CurrencyManager.allCurrencies;
var MoneyRate = [];
for(var i in allCurrencies) {
MoneyRate[i] = allCurrencies[i]['r'];
};
var toRate = MoneyRate[to];
var fromRate = MoneyRate[from];
// 无小数点的特殊货币则不保留小数部分
if(hidden_point_arr.indexOf(to) === 0) {
return Math.round((amount * toRate) / fromRate);
}
return Math.round(((amount * toRate) / fromRate) * 100) /100;
}
}
return amount;
}
// console.log('---------------------------9---------------------------')
if(window.Currency!=undefined){
if(window.Currency.convert!=undefined){
return window.Currency.convert(amount,from,to);
}else{
return amount;
}
}else{
return amount;
}
}
function girafflyHiddenPoint(price){
if(hidden_point){
return parseInt(price).toLocaleString('en-US');
}else{
return formatCurrency(parseFloat(price).toFixed(2));
}
}
/**
* 函数名 : girafflyCurrencyAttributesObject
* 作用 : 获取变量中的货币数据
* 参数 : windowFirst ---> window 对象中的第一个属性
* 参数 : windowSecond ---> window 对象中的第二个属性
* 参数 : symbol ---> 获取到的数据是否只有符号,有符号则要去除符号
* 参数 : json ---> 获取到的数据是否为json格式
* 参数 : json_index ---> 如果是json,则需要填入json索引
* 参数 : html ---> 是否html类型
* 参数 : cookie ---> 是否在cookie获取数据
*/
function girafflyCurrencyAttributesObject(windowFirst,windowSecond,symbol=false,json=false,json_index='',html=false,cookie=false) {
var currencyStr1 = '';
var currencyStr2 = '';
if(cookie == true) {
if(window[windowFirst]!=undefined){
if(window[windowFirst][windowSecond]!=undefined){
var cookieArr = window[windowFirst][windowSecond].split(';')
cookieArr.map((item)=>{
if(item.split('=')[0].indexOf(json_index) != -1) {
currencyStr1 = item.split('=')[1]
}
})
return currencyStr1;
}
}
}else{
if(symbol == true) {
if(window[windowFirst]!=undefined){
if(window[windowFirst][windowSecond]!=undefined){
if(json == true) {
currencyStr1 = JSON.parse(window[windowFirst][windowSecond]);
currencyStr2 = currencyStr1[json_index];
return currencyStr2;
}else if(html == true) {
return jQuery(window[windowFirst][windowSecond]).text().trim();
}
else{
return JSON.parse(window[windowFirst][windowSecond]);
}
}
}
}else{
if(window[windowFirst]!=undefined){
if(window[windowFirst][windowSecond]!=undefined){
currencyStr1 = window[windowFirst][windowSecond];
if(json == true) {
currencyStr1 = JSON.parse(currencyStr1);
currencyStr2 = currencyStr1[json_index];
return currencyStr2;
}else{
currencyStr2 = ""
for(var i=0; i='A'&¤cyStr1[i]<='Z'){
currencyStr2 += currencyStr1[i];
}
}
return currencyStr2;
}
}
}
}
}
return false;
}
function girafflyCurrencyAttributesFunction(windowFirst,windowPath,functionName,param='') {
if(window[windowFirst] != undefined) {
windowData = window[windowFirst]
for(var i =0; i APP加载慢,导致进行后无法使用他们的函数获取Cookie,但是如果直接读取cookie的话,可能存在Cookie信息保留
// 用别人的函数读取cookie,好处是可以防止信息保留导致的信息冲突
girafflyCurrencyAttributesObject('document','cookie',false,false,'mc-currency',false,true)?currency.add(girafflyCurrencyAttributesObject('document','cookie',false,false,'mc-currency',false,true)):'';
girafflyCurrencyAttributesObject('document','cookie',false,false,'autoketing-currency',false,true)?currency.add(girafflyCurrencyAttributesObject('document','cookie',false,false,'autoketing-currency',false,true)):'';
// girafflyCurrencyAttributesFunction('window',[],'readCookie','mc-currency')?currency.add(girafflyCurrencyAttributesFunction('window',[''],'readCookie','mc-currency')):'';
// girafflyCurrencyAttributesObject('document','cookie',true,true,true,'mw_cs')?currency.add(girafflyCurrencyAttributesObject('document','cookie',true,true,true,'mw_cs')):'';
girafflyCurrencyAttributesFunction('mwSwitcher',['utils'],'getLocalCurrency','mw_cs')?currency.add(girafflyCurrencyAttributesFunction('mwSwitcher',['utils'],'getLocalCurrency','mw_cs')):'';
girafflyCurrencyAttributesFunction('Shoppad',['apps','coin'],'getLocalCurrency')?currency.add(girafflyCurrencyAttributesFunction('Shoppad',['apps','coin'],'getLocalCurrency')):'';
girafflyCurrencyAttributesFunction('window',[],'mcc_read_cookie','mcc_manual_currency')?currency.add(girafflyCurrencyAttributesFunction('window',[],'mcc_read_cookie','mcc_manual_currency')):'';
if(currency.size >= 2) {
currency.delete(window.Shopify.currency.active);
}
// 删除后应该只剩一个元素,如果还有多个的话,说明可能存在多个货币APP或者可能其他货币APP数据未完全清除,若是需要处理这个问题,可以从这想办法
if(currency.size >= 2) {
localStorage.clear();
sessionStorage.clear();
}
// console.log(currency)
// 默认取最后一个
to = currency.values().next()['value']
//转换价格
price = girafflyChangeCurrency(price,from,to,comparePrice);
// console.log(price,'price')
// console.log('---------girafflyChangeCurrency-----------end------------')
//货币符号
var before_format ="";
var after_format ="";
var change_format = girafflymoneyformat();
before_format=change_format.before_format;
after_format=change_format.after_format;
if(before_format === '$' && after_format === '') {
after_format = 'USD'
}
// if(notNeed){
// return ' $' + girafflyHiddenPoint(price) + ' '+after_format+'';
// }
return ''+before_format +''+ girafflyHiddenPoint(price) + ' ' +after_format +'';
}else{
var activeCurrency = 'USD';
if(Shopify.currency.active!=undefined){
activeCurrency=Shopify.currency.active;
}
return '$' + girafflyHiddenPoint(price) + ' ' +activeCurrency +'';
}
}
function formatCurrency(num){
if(num)
{
num = num.toString().replace(/\$|\,/g,'');
if(''==num || isNaN(num)){return;}
var sign = num.indexOf("-")> 0 ? '-' : '';
var cents = num.indexOf(".")> 0 ? num.substr(num.indexOf(".")) : '';
cents = cents.length>1 ? cents : '' ;
num = num.indexOf(".")>0 ? num.substring(0,(num.indexOf("."))) : num ;
if('' == cents){ if(num.length>1 && '0' == num.substr(0,1)){return;}}
else{if(num.length>1 && '0' == num.substr(0,1)){return ;}}
for (var i = 0; i < Math.floor((num.length-(1+i))/3); i++)
{
num = num.substring(0,num.length-(4*i+3))+','+num.substring(num.length-(4*i+3));
}
return (sign + num + cents);
}
}
function girafflyInitDom(json){
className = ['money','currency-converter-amount-box','mw-price','Magic-Currency','product__price','price-item'];
for(var i=0; i {
if(window.Currency!=undefined && giraffly_default_js!=1){
if(window.Currency.currentCurrency!=undefined){
if(hidden_point_arr.indexOf(window.Currency.currentCurrency)!=-1){
hidden_point=1;
}else{
hidden_point=0;
}
}
}else if(window.DoublyGlobalCurrency!=undefined){
if(window.DoublyGlobalCurrency.currentCurrency!=undefined){
if(hidden_point_arr.indexOf(window.DoublyGlobalCurrency.currentCurrency)!=-1){
hidden_point=1;
}else{
hidden_point=0;
}
}
}else if(window.KTCurrency!=undefined){
if(window.KTCurrency.currentCurrency!=undefined){
if(hidden_point_arr.indexOf(window.KTCurrency.currentCurrency)!=-1){
hidden_point=1;
}else{
hidden_point=0;
}
}
}
}, 500);
}
function Conversion(tagSelector,to){
if (tagSelector.attr("data-currency-original") === undefined) {
tagSelector.attr("data-currency-original", tagSelector.html());
tagSelector.attr("data-currency-shop-base", mcc_shop_base_currency)
} else if (mcc_ignore_original === true) {
tagSelector.attr("data-currency-original", tagSelector.html());
tagSelector.attr("data-currency-shop-base", mcc_shop_base_currency);
mcc_ignore_original = false;
mcc_manual_change = false
}
if (mcc_display_type === "with_currency_code") {
c = mcc_money_format_with_currency_code[mcc_shop_base_currency]
} else {
c = mcc_money_format[mcc_shop_base_currency]
}
if (c.indexOf('amount_no_decimals') != -1) {
d = parseInt(tagSelector.attr('data-currency-original').replace(/[^0-9]/g, ""), 10) * 100
} else {
if (mcc_shop_base_currency === "JOD" || mcc_shop_base_currency == "KWD" || mcc_shop_base_currency == "BHD" || mcc_shop_base_currency === "OMR") {
d = parseInt(tagSelector.attr('data-currency-original').replace(/[^0-9]/g, ""), 10) / 10
} else {
var g = /^[0-9][0-9]{0,2}(?:(\.|,)?[0-9]{3}){0,3}(?:(\.|,)[0-9]{0})?$/;
var h = /^[0-9][0-9]{0,2}(?:(\.|,)?[0-9]{3}){0,3}(?:(\.|,)[0-9]{1})?$/;
var i = /^[0-9][0-9]{0,2}(?:(\.|,)?[0-9]{3}){0,3}(?:(\.|,)[0-9]{2})?$/;
var j = tagSelector.attr('data-currency-original').replace(/[^0-9.,]/g, "").trim();
if (j[0] === "." || j[0] === ",") {
j = j.slice(1)
} else if (j.slice( - 1) === "." || j.slice( - 1) === ",") {
j = j.slice(0, -1)
}
if (g.test(j)) {
d = parseInt(j.replace(/[^0-9]/g, ""), 10) * 100
} else if (h.test(j)) {
d = parseInt(j.replace(/[^0-9]/g, ""), 10) * 10
} else if (i.test(j)) {
d = parseInt(j.replace(/[^0-9]/g, ""), 10)
} else {
d = parseInt(j.replace(/[^0-9]/g, ""), 10)
}
}
}
var k = mcc_manual_exchange_list[to] ? mcc_manual_exchange_list[to] : mcc_exchanged_rates[to];
var l = mcc_manual_exchange_list[mcc_shop_base_currency] ? mcc_manual_exchange_list[mcc_shop_base_currency] : mcc_exchanged_rates[mcc_shop_base_currency];
e = d * k / l;
if ((to === "JOD" || to == "KWD" || to == "BHD" || to === "OMR") && (mcc_rounded_whole_type === "without_00")) {
var m = to + "_nz"
} else {
var m = to
}
var money;
if (mcc_display_type === "with_currency_code") {
var e1 = /\{\{\s*(\w+)\s*\}\}/;
switch (mcc_money_format_with_currency_code[m].match(e1)[1]) {
case "amount":
money = mcc_floatToString(e / 100, 2, d);
break;
case "amount_no_decimals":
money = mcc_floatToString(e / 100, 0, d);
break;
case "amount_with_comma_separator":
money = mcc_floatToString(e / 100, 2, d).replace(/\./, ",");
break;
case "amount_no_decimals_with_comma_separator":
money = mcc_floatToString(e / 100, 0, d).replace(/\./, ",");
break
}
} else {
var e1 = /\{\{\s*(\w+)\s*\}\}/;
switch (mcc_money_format[m].match(e1)[1]) {
case "amount":
money = mcc_floatToString(e / 100, 2, d);
break;
case "amount_no_decimals":
money = mcc_floatToString(e / 100, 0, d);
break;
case "amount_with_comma_separator":
money = mcc_floatToString(e / 100, 2, d).replace(/\./, ",");
break;
case "amount_no_decimals_with_comma_separator":
money = mcc_floatToString(e / 100, 0, d).replace(/\./, ",");
break
}
}
return parseFloat(money);
}
function getCurrencyConverter() {
var xhr = new XMLHttpRequest();
xhr.open('GET', 'https://www.codeblackbelt.com/json/preferences/currency-converter-plus.json?countryCode=US&shop=www.latiendadelbillarista.com&activeCurrencyCode=USD&path=%2Fproducts%2Fsoldier', true);
xhr.send();
/**
* 获取数据后的处理程序
*/
var Rate;
xhr.onreadystatechange = function () {
if (xhr.readyState == 4 && xhr.status == 200) {
var res = JSON.parse(xhr.responseText);//获取到json字符串,解析
if(res.preferences){
Rate = res.preferences[0].currencies
for(var i=0; i div > div.nav-right-side.has-country-selector > a.cart.cart-icon--basket1 > div").text(quantity)
break
case 'Canopy':
jQuery(".inner-count").text(quantity)
break
case 'Boost':
jQuery(".header-cart__count").text(quantity)
break
case 'Blockshop':
case 'Fresh':
case 'Maker':
jQuery(".cart--external--total-items").text(quantity)
break
case 'Avenue':
jQuery(".cartCountSelector").text(quantity)
break
case 'District':
jQuery(".cart-button__count").text(quantity)
break
case 'Highlight':
jQuery(".menu-meta__count").text(quantity)
break
case 'Colors':
case 'Grid':
case 'Editorial':
case 'Avatar':
jQuery(".cart-count").text(quantity)
break
case 'Parallax':
jQuery("div.five-sixths.columns.nav.mobile_hidden > ul.header__secondary-navigation.menu.right > li.cart > a:nth-child(1) > span").text(quantity)
break
case 'Atlantic':
jQuery("span[data-cart-mini-count]").text(quantity)
break
case 'Galleria':
jQuery(".cart-counter").text(quantity)
break
case 'Responsive':
jQuery(".cart_count").text(quantity)
break
case 'Startup':
jQuery(".site-header__cart-count").text(quantity)
break
case 'Providence':
jQuery(".item-count").text(quantity)
break
case 'Sunrise':
jQuery("div.header-right.hide-mobile > div > div > a > em").text(quantity)
break
case 'Masonry':
jQuery(".numitems").text("("+quantity+")")
break
case 'Loft':
jQuery(".cart-item-count").text(quantity)
break
default:
break
}
//
// jQuery(".cart-count-bubble").find("span").text(quantity)
//
// jQuery('.js-cart-count').text(quantity)
//
// jQuery('#counter').attr('data-count',quantity)
// jQuery('#counter').find('span').text(quantity)
//
// jQuery(".jsccount").text(quantity)
//
// jQuery(".Header__CartCount").text(quantity)
//
// jQuery(".header__cart-count").text(quantity)
//
// jQuery(".cart-link__count").text(quantity)
//
// jQuery(".cart-link__bubble-num").text(quantity)
//
// if(Shopify.theme.name == "Capital" || Shopify.theme.name == "Retina") {
// jQuery("span[data-header-cart-count]").text(quantity)
// }else{
// jQuery("span[data-header-cart-count]").text("("+quantity+")")
// }
// jQuery("span[data-header-cart-count]").attr("data-header-cart-count", quantity)
//
// jQuery(".site-header-cart--count").attr("data-header-cart-count", quantity)
//
// jQuery(".cart-item-count-header--quantity").text(quantity)
//
// jQuery("#CartCount").text(quantity)
//
// jQuery("#site-control > div > div.nav-right-side.has-country-selector > a.cart.cart-icon--basket1 > div").text(quantity)
//
// jQuery(".inner-count").text(quantity)
//
// jQuery(".header-cart__count").text(quantity)
//
// jQuery(".cart--external--total-items").text(quantity)
//
// jQuery(".cartCountSelector").text(quantity)
//
// jQuery(".cart-button__count").text(quantity)
//
// jQuery(".menu-meta__count").text(quantity)
//
// jQuery(".cart-count").text(quantity)
//
// jQuery("div.five-sixths.columns.nav.mobile_hidden > ul.header__secondary-navigation.menu.right > li.cart > a:nth-child(1) > span").text(quantity)
//
// jQuery("span[data-cart-mini-count]").text(quantity)
//
// jQuery(".cart-counter").text(quantity)
//
// jQuery(".cart_count").text(quantity)
//
// jQuery(".site-header__cart-count").text(quantity)
//
// jQuery(".item-count").text(quantity)
//
// jQuery("div.header-right.hide-mobile > div > div > a > em").text(quantity)
//
// jQuery(".numitems").text("("+quantity+")")
//
// jQuery(".cart-item-count").text(quantity)
//
// jQuery("div.header-right.hide-mobile > div > div > a > em").text(quantity)
// jQuery("input[name*='updates']").attr("value",quantity)
}