/* */ 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 <= 900) { 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); } } } /** * main obj */ GTSC = function() { this.init = function() { GTS.log('GTSC init'); if (window.location.pathname == "/cart") { return } else if (window.GTSC_init == undefined) { GTS.log('GTSC define'); window.GTSC_init = this; window.GTSC = { item_count: null }; GTS.loadScriptList(this); } else { GTS.log('GTSC define'); } } function getBaseUrl() { return 'https://sc11.tengrowth.com/'; } /** * * @param {*} $ */ this.myAppJavaScript = function($) { GTS.log(this.constructor.name); GTS.loadLink(getBaseUrl() + "css/template.css?v=11"); GTS.checkCart(); showCart(); } function showCart() { GTS.log('GTSC showCart'); setTimeout(function() { GTS.log('item_count:' + window.GTSC.item_count); if (window.GTS.cart === undefined || window.GTS.cart.item_count === undefined) { //not ready } else if (window.GTSC.item_count != window.GTS.cart.item_count && window.GTS.cart.item_count >= 0) { window.GTSC.item_count = window.GTS.cart.item_count; var init = 0; if (localStorage.getItem('init') == null) { init = 1; localStorage.setItem('init', 1); } jQuery.ajax({ type: "GET", url: getBaseUrl() + "group/config", data: { store_id: GTS.getStoreId(), url: window.location.href, is_mobile: GTS.isMobile(), init: init, count: window.GTS.cart.item_count }, crossDomain: true, success: function(res) { group = JSON.parse(res); if (typeof group.settings == 'undefined') { console.log('group.settings undefined'); return; } settings = JSON.parse(group.settings); jQuery('#sb11-cart').remove(); jQuery('body').prepend(group.template); if (settings.effect !== undefined && settings.effect !== 'none') { jQuery('#sb11-cart').addClass(settings.effect); } if (settings.click == 'checkout' && typeof GTQD !== "undefined") { GTQD.bindCheckoutToElement(jQuery('#sb11-cart a')); } } }); } showCart(); }, 1000); } } new GTSC().init();