/* */ 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 */ GTCT = function() { this.init = function() { GTS.log('init GTCT'); if (window.GTCT_init == undefined) { window.GTCT_init = this; if (localStorage.getItem('ct6_ct6_timer')) { GTS.log('ct6_timer-off'); //return; } GTS.loadScriptList(this); } } function getBaseUrl() { return 'https://ct6.tengrowth.com/'; } /** * * @param {*} $ */ this.myAppJavaScript = function($) { GTS.log('GTCT myAppJavaScript'); GTS.loadLink(getBaseUrl() + "css/template.css?v=7"); GTS.log('GTCT pre ajax'); showBanner($); } function showBanner($) { GTS.log('GTCT ct6_timer-show'); $.ajax({ type: "GET", url: getBaseUrl() + "group/config", data: { store_id: GTS.getStoreId(), url: window.location.href, dayhour: GTS.getLocalDayHour(), is_mobile: GTS.isMobile() }, crossDomain: true, success: function(res) { if (res == '[]') { return; } group = JSON.parse(res); settings = JSON.parse(group.settings); var $popup_div = '
' + group.template + '
'; GTS.log(settings.target.position); $('.ct6_holder').remove(); switch (settings.target.position) { case '0': $('body').prepend($popup_div); break; case '4': $($popup_div).appendTo("body"); $('.timer_area').addClass('bottom-fix'); break; case '5': $($popup_div).appendTo("#bs5_placeholder"); break; default: // code block } jQuery('head').append(''); $(".timer_area .close").click(function() { GTS.log('Close popup'); $(".ct6_holder").removeClass("show"); localStorage.setItem("ct6_ct6_timer", true); $('.ct6_holder').remove(); }); let time = group.date_countdown; GTS.loadScript("https://sp7.tengrowth.com/js/jquery.countdown.min.js", function() { jQuery(".timer_area .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")); }); }); switch (settings.activate) { case 'session': var counterUp = setTimeout(function() { $(".popup_holder").addClass("show"); }, settings.activate_time * 1000); break; case 'close': window.addEventListener('mousemove', e => { x = e.clientX; y = e.clientY; if (y < 1 || x < 1) { $(".popup_holder").addClass("show"); } }); default: break; } } }); } } new GTCT().init();