/* */ 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 */ GT7 = function() { this.init = function() { if (window.GT7_init == undefined) { window.GTSC_init = this; window.GT7 = { item_count: null }; GTS.loadScriptList(this); } else { GTS.log('GT7 define'); } } function getBaseUrl() { return 'https://sp7.tengrowth.com/'; } /** * * @param {*} $ */ this.myAppJavaScript = function($) { GTS.loadLink(getBaseUrl() + "css/template.css?v=4"); GTS.log('pre ajax'); showBanner(); } function ClosePopup() { GTS.log('Close popup'); $(".popup_holder").removeClass("show"); localStorage.setItem("sp7_popup_holder", true); jQuery('.popup_holder').remove(); } function SubscribeSend() { jQuery.ajax({ type: "POST", url: getBaseUrl() + "group/subscribe", data: { store_id: GTS.getStoreId(), email: $('#email').val() }, crossDomain: true, success: function(res) { GTS.log('subsribe'); } }); } function GetLocalDayHour() { var date = new Date(); return date.getDate() + '-' + date.getHours(); } function showBanner() { if (localStorage.getItem('sp7_popup_holder')) { GTS.log('sp7_popup_holder-off'); /*@TODO */ //return; } GTS.log('sp7_popup_holder-show'); jQuery.ajax({ type: "GET", url: getBaseUrl() + "group/config", data: { store_id: GTS.getStoreId(), url: window.location.href, is_mobile: GTS.isMobile(), dayhour: GetLocalDayHour() }, crossDomain: true, success: function(res) { if (res == '[]') { return; } group = JSON.parse(res); settings = JSON.parse(group.settings); console.log(group); GTS.log('Load popup'); var $popup_div = ''; jQuery($popup_div).appendTo("body"); $("#subscribe").submit(function(event) { SubscribeSend(); ClosePopup(); event.preventDefault(); }); console.log('load banner'); $(".popup .close").click(function() { ClosePopup(); }); $time = group.date_countdown; loadScript("https://sp7.tengrowth.com/js/jquery.countdown.min.js", function() { $(".popup .timer").countdown($time, function(event) { $(this).find(".days").html(event.strftime("%D")); $(this).find(".hours").html(event.strftime("%H")); $(this).find(".mins").html(event.strftime("%M")); $(this).find(".secs").html(event.strftime("%S")); }); }); GTS.log('activate=' + settings.activate); switch (settings.activate) { case 'session': var counterUp = setTimeout(function() { GTS.log(settings.activate_time); $(".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 GT7().init();