/* */ if (typeof GTS === 'undefined') { console.log("%c init GTS ", "background: #1960bc; color: #fff", ); window.GTS = class GTS { static publicLog(text) { console.log("%c " + text, "background: #1960bc; color: #fff", ); } static getStoreId() { return Shopify.shop; } /** * * @param {number} amount */ static moneyFormat(money_format, amount) { var price = amount / 100; return String(money_format).replace('{{amount}}', price.toFixed(2)) + ''; } static log(text) { var debug = localStorage.getItem("debug"); if (debug == true) { console.log(text); } } static warn(text) { var debug = localStorage.getItem("debug"); if (debug == true) { console.warn(text); } } static debug(val = true) { localStorage.setItem("debug", val); } static getIterateChild(lastElement) { var lastChild = lastElement.find('div,span'); if (lastChild.length) { lastElement = this.getIterateChild(lastChild); } return lastElement; } static isMobile() { if (window.innerWidth <= 800 && window.innerHeight <= 800) { return true; } else { return false; } } static loadLink(url) { jQuery('head').append(''); } static loadScriptList(app) { GTS.log('loadScriptList'); if ((typeof jQuery === 'undefined')) { GTS.loadScript('https://cdn.shopify.com/s/files/1/0020/7624/6127/t/8/assets/jquery-2.2.3.min.js', function() { //window.GTS.jQuery191 = jQuery.noConflict(true); // GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js'); // GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/cart.min.js'); // GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/rivets-cart.min.js'); // GTS.loadScript('//rafaelcastrocouto.github.io/jQuery.DomOutline/demo/jquery.dom-outline-1.0.js'); app.myAppJavaScript(jQuery); }); } else if ((parseFloat(jQuery.fn.jquery) < 1.7)) { GTS.loadScript('https://cdn.shopify.com/s/files/1/0020/7624/6127/t/8/assets/jquery-2.2.3.min.js', function() { window.GTS.jQuery191 = jQuery.noConflict(true); // GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/jquery-modal/0.9.1/jquery.modal.min.js'); // GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/cart.min.js'); // GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/rivets-cart.min.js'); // GTS.loadScript('//rafaelcastrocouto.github.io/jQuery.DomOutline/demo/jquery.dom-outline-1.0.js'); app.myAppJavaScript(window.GTS.jQuery191); }); } else { GTS.loadScript('//code.jquery.com/ui/1.12.1/jquery-ui.min.js'); GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/cart.min.js'); GTS.loadScript('//cdnjs.cloudflare.com/ajax/libs/shopify-cartjs/0.4.1/rivets-cart.min.js'); GTS.loadScript('//rafaelcastrocouto.github.io/jQuery.DomOutline/demo/jquery.dom-outline-1.0.js'); app.myAppJavaScript(jQuery); } } static loadScript(url, callback) { if (callback == undefined) { callback = function() {} } var script = document.createElement('script'); script.type = 'text/javascript'; // If the browser is Internet Explorer. if (script.readyState) { script.onreadystatechange = function() { if (script.readyState === 'loaded' || script.readyState === 'complete') { script.onreadystatechange = null; callback(); } }; // For any other browser. } else { script.onload = function() { callback(); }; } script.src = url; document.getElementsByTagName('head')[0].appendChild(script); } static getLocalDayHour() { var date = new Date(); return date.getDate() + '-' + date.getHours(); } static checkCart() { if (window.GTS.cart != undefined) { return; } $("head").append(''); var elem = $('meta[name="gts_cart:count"]'); window.GTS.cart = { item_count: 0 }; setInterval(function() { jQuery.getJSON('/cart.js', function(cart) { if (window.GTS.cart.item_count != cart.item_count) { window.GTS.cart = cart; elem.attr('content', cart.item_count); } }); }, 1000); } } } function po9_goToCart() { document.location.href = "/cart"; } /** * main obj */ GTPO = function() { this.init = function() { GTS.log('GTPO init'); if (window.GTPO_init == undefined) { GTS.log('GTPO define'); window.GTPO_init = this; window.po9 = {}; GTS.loadScriptList(this); } else { GTS.log('GTPO define'); } } function getBaseUrl() { return 'https://po9.tengrowth.com/'; } /** * * @param {*} $ */ this.myAppJavaScript = function($) { GTS.log('GTPO myAppJavaScript'); if (meta.page.pageType == 'product') { showBtn(); } } function showBtn() { GTS.log('GTPO showCart'); jQuery.ajax({ type: "GET", url: getBaseUrl() + "api/config", data: { store_id: GTS.getStoreId(), pid: meta.product.id, theme: Shopify.theme.name, customer: getCustomerId() }, crossDomain: true, success: function(res) { group = JSON.parse(res); if (typeof group.error !== 'undefined') { console.log(group.error); return; } group = JSON.parse(res); window.po9.data = group; jQuery('head').append(''); if (group.timer.show) { jQuery('head').append(''); } if (group.popup.show) { jQuery('head').append(''); } let $btn = jQuery(group.path); window.po9.base_name = $btn.text(); window.po9.base_val = $btn.val(); window.po9.variant_id = null; /* if (localStorage.getItem("openCart") == 1) { localStorage.setItem("openCart", 0); //eval(window.po9.data.js_add_button); jQuery(window.po9.data.placement_cart)[0].click(); } */ jQuery(document).change(switchBtn); switchBtn(); //jQuery("select[name='id']").change(switchBtn); } }); } /* function addToCart(id) { GTS.log('addToCart'); let quantity = jQuery("input[name='quantity']").val(); jQuery.post('/cart/add.js', { items: [{ id: id, quantity: quantity }] }).always(function() { localStorage.setItem("openCart", 1); eval(window.po9.data.js_add_button); jQuery(window.po9.data.placement_cart)[0].click(); }); eval(window.po9.data.js_add_button); } */ function addPreOrder(id) { GTS.log('addPreOrder'); let name = window.po9.data.prop_text; const entries = new Map([ ['Comment', name] ]); const props = Object.fromEntries(entries); let quantity = jQuery("input[name='quantity']").val(); GTS.log(props); GTS.log(id); jQuery.post('/cart/add.js', { items: [{ id: id, quantity: quantity, properties: props }] }).always(function(json) { if (window.po9.data.popup.show) { po9_PopUpShow(); } else if (window.po9.data.js_add_button != '') { eval(window.po9.data.js_add_button); } else { po9_goToCart(); } }); } function getVariantId() { let variant_id = jQuery("select[name='id']").children("option:selected").val(); if (window.po9.data.placement_variant) { variant_id = jQuery(window.po9.data.placement_variant).val(); } else if (variant_id == undefined) { variant_id = jQuery("input[name='id']").val(); if (variant_id == undefined) { return; } } return variant_id; } function switchBtn() { //console.log("switchBtn"); let group = window.po9.data; let variant_id = getVariantId(); if (window.po9.variant_id == variant_id) { //console.log("switchBtn exit"); return; } //jQuery("#gd3_copy_checkout").remove(); window.po9.variant_id = variant_id; let $btn = jQuery(group.path).not("#gd3_copy_checkout").show(); // let copyBtn = $btn.next('#gd3_copy_checkout').hide(); let copyBtn = jQuery("#gd3_copy_checkout").hide(); let btn_text = $btn.text(); if (copyBtn.length == 0) { jQuery("").insertAfter(group.path); copyBtn = jQuery('#gd3_copy_checkout'); let val_text = $btn.val(); if (val_text != '') { copyBtn.val(val_text); } } if (group.comming_soon.show == 1) { btn_text = group.comming_soon.text; copyBtn.val(btn_text); } copyBtn.text(btn_text); let variant_data = group.product[variant_id]; GTS.log(variant_data); GTS.log(variant_id); GTS.log('btn:' + group.path); jQuery('.pre_order_comment').remove(); jQuery('.pre_order_lost').remove(); jQuery("#ct_timer_po9").remove(); if (variant_data !== undefined && variant_data.policy == 'continue' && group.quantity_stop != null && variant_data.quantity <= group.quantity_stop) { GTS.log('PO9 - hide'); $btn.hide(); copyBtn.attr("disabled", 'disabled'); copyBtn.text("Out of Stock"); copyBtn.show(); paymentButtons(true); } else if (variant_data !== undefined && variant_data.policy == 'continue' && variant_data.quantity <= group.quantity_start) { GTS.log('PO9 - show pre order'); $btn.hide(); paymentButtons(true); if (group.comming_soon.show == 0) { copyBtn.attr("disabled", false); copyBtn.text(group.name); copyBtn.val(group.name); copyBtn.unbind('click').click(function(e) { e.preventDefault(); addPreOrder(variant_id); }); } else { copyBtn.text(group.comming_soon.text); copyBtn.val(group.comming_soon.text); copyBtn.attr("disabled", true); } copyBtn.show(); if (group.comment != '' && group.comment != null && jQuery(".pre_order_comment").length == 0) { jQuery('.pre_order_comment').remove(); jQuery('' + group.comment + "
").insertAfter('#gd3_copy_checkout'); } if (group.left_wessage.show && group.quantity_stop != null && jQuery(".pre_order_lost").length == 0) { jQuery('.pre_order_lost').remove(); let cnt = variant_data.quantity - group.quantity_stop; let lost_text = group.left_wessage.template.replace("{{cnt}}", cnt); jQuery('' + lost_text + "
").insertAfter('#gd3_copy_checkout'); } if (group.timer.show && jQuery("#ct_timer_po9").length == 0) { let timer_html = getTimerHtml(group.timer.text); let time = group.timer.date_countdown; jQuery(timer_html).insertAfter('#gd3_copy_checkout'); GTS.loadScript("https://sp7.tengrowth.com/js/jquery.countdown.min.js", function() { jQuery("#ct_timer_po9 .timer").countdown(time, function(event) { jQuery(this).find(".days").html(event.strftime("%D")); jQuery(this).find(".hours").html(event.strftime("%H")); jQuery(this).find(".mins").html(event.strftime("%M")); jQuery(this).find(".secs").html(event.strftime("%S")); }); }); } if (group.popup.show && jQuery("#po9_popup").length == 0) { let html = getPopupHtml(group.popup.text); jQuery("body").append(html); jQuery(document).click(po9_PopUpHide); } } } function getTimerHtml(text) { return '
' + '
' + '

' + text.topText + '

' + '
' + '
' + '

' + '

' + text.days + '

' + '
' + '
' + '

' + '

' + text.hrs + '

' + '
' + '
' + '

' + '

' + text.mins + '

' + '
' + '
' + '

' + '

' + text.secs + '

' + '
' + '
' + '
' + '
'; } function getPopupHtml(text) { return ''; } function getCustomerId() { let customer = null; if (meta.page.customerId != undefined) { customer = meta.page.customerId; } return customer; } function paymentButtons(hide) { if (hide) { jQuery('.shopify-payment-button').hide(); } else { jQuery('.shopify-payment-button').show(); } } } function po9_PopUpShow() { jQuery("#po9_popup").show(); } function po9_PopUpHide() { jQuery("#po9_popup").hide(); } new GTPO().init();