/* */ 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 */ GTPP = function() { this.init = function() { GTS.publicLog(this.constructor.name); if (window.GTPP_init == undefined) { window.GTPP_init = this; GTS.loadScriptList(this); } else { GTS.log(this.constructor.name + ' define'); } } function getBaseUrl() { return 'https://pp13.tengrowth.com/'; } /** * * @param {*} $ */ this.myAppJavaScript = function($) { loadGoogleFonts(); loadSettings(); } function loadSettings() { const xhttp = new XMLHttpRequest(); xhttp.onreadystatechange = function() { if (this.readyState == 4 && this.status == 200) { showCookies(JSON.parse(xhttp.responseText)); } }; xhttp.open( "GET", getBaseUrl() + `/api/config?store_id=${window.Shopify.shop}`, true ); xhttp.send(); } function loadGoogleFonts() { const googleFontLink = "https://fonts.googleapis.com/css?family=Abril+Fatface|Anton|Barlow+Condensed|Cabin|Cairo|Dancing+Script|Exo+2|Indie+Flower|Josefin+Sans|Lato|Lobster|Merriweather+Sans|Modak|Montserrat|Noto+Sans|Open+Sans|Oxygen|Pacifico|Poppins|Prociono|Raleway|Roboto|Roboto+Mono|Roboto+Slab|Shadows+Into+Light|Source+Sans+Pro|Source+Serif+Pro|Teko|Titillium+Web|Yanone+Kaffeesatz&display=swap" const link = document.createElement('link'); link.rel = 'stylesheet'; link.href = googleFontLink; document.head.appendChild(link); } function htmlToElements(html) { const template = document.createElement("template"); template.innerHTML = html; return template.content.childNodes; } this.acceptCookieOption = function() { if (window.location.search !== "?isPreview=true") { localStorage.setItem("pp-cookie-bar-accepted-url", window.Shopify.shop); } const element = document.getElementById("coupo-cookie-bar-container"); element.parentNode.removeChild(element); } function showCookies(settings) { GTS.log(settings); const settingsDictionary = { MESSAGE: "message", PRIVACY_POLICY_URL: "privacy_policy_url", OK_BUTTON_TEXT: "ok_button_text", INFO_LINK_TEXT: "info_link_text", BANNER_COLOR: "banner_color", BANNER_TEXT_COLOR: "banner_text_color", BANNER_LINK_COLOR: "banner_link_color", BUTTON_COLOR: "button_color", BUTTON_TEXT_COLOR: "button_text_color", BUTTON_BORDER_COLOR: "button_border_color" }; const STYLES = ` ` const PRIVACY_POLICY = ` INFO_LINK_TEXT ` let cookieHtml = ` `; if ( window.location.search === "?isPreview=true" || (localStorage.getItem("pp-cookie-bar-accepted-url") !== window.Shopify.shop && settings.show_banner) ) { if (!settings.privacy_policy_url) cookieHtml = cookieHtml.replace(PRIVACY_POLICY, '') Object.keys(settingsDictionary).forEach(setting => { const stringToReplace = new RegExp(setting, 'g') cookieHtml = cookieHtml.replace( stringToReplace, settings[settingsDictionary[setting]] ); }); document.body.appendChild(htmlToElements(cookieHtml)[0]); // Do this if window has not yet loaded window.onload = () => document.body.appendChild(htmlToElements(cookieHtml)[0]); } } } new GTPP().init();