// get the URL from the current script tag var scripts = document.getElementsByTagName('script'); var currScriptTag = scripts[scripts.length - 1]; var url = currScriptTag.getAttribute('url'); var img = currScriptTag.getAttribute('img'); console.log('url init: ' + url) if (typeof GatemasterEmbed == 'undefined') { console.log('LOAD GatemasterEmbed') var GatemasterEmbed = { //GatemasterEmbedExists: false, CurrentScriptTag: currScriptTag, // hold the reference to the current script tag that holds GatemasterEmbed //EmbedScripts: [], GetBaseURL: function(url) { var protocol=url.split('/')[0]; var hostname = url.split('/')[2] + '/' + url.split('/')[3]; return protocol + '//' + hostname; }, GetURLParameterByName: function(name) { return GatemasterEmbed.GetURLParameterByNameWithGivenURL(name, location.search); }, GetURLParameterByNameWithGivenURL: function(name, url) { name = name.replace(/[\[]/, "\\\[").replace(/[\]]/, "\\\]"); var regex = new RegExp("[\\?&]" + name + "=([^&#]*)"), results = regex.exec(url); return results == null ? "" : decodeURIComponent(results[1].replace(/\+/g, " ")); }, GetRand: function(min, max) { var min=0, max=10000; return Math.floor(Math.random() * (max - min + 1) ) + min; }, CycleUser: function(url) { var compID = GatemasterEmbed.GetURLParameterByNameWithGivenURL('CompanyID', url); console.log('CycleUser: ' + url); console.log('compID: ' + compID); // send the user to the ecommerce to set cookie and cycle back to orignal page, we need to have gmreturn in the URL so we know that it cycled through the ecommerce and not to cycle again var gmURL = GatemasterEmbed.GetBaseURL(url); var returnURL = window.top.location.href; if(returnURL.indexOf('?') >= 0) returnURL += '&'; else returnURL += '?'; returnURL += 'gmreturn=' + url; // hold the name of the URL of this embedded script so we know which one to pop the modal for in case multiple are embedded var urlCycle = gmURL + '/InitUser.aspx?CompanyID=' + compID + '&ReturnURL=' + encodeURIComponent(returnURL) + '&rand=' + GatemasterEmbed.GetRand(); console.log(urlCycle) // cycle the user through the ecommerce window.top.location.href = urlCycle }, OpenModal: function (url) { console.log('window.jQuery == undefined: ' + (window.jQuery == undefined)); console.log('!jQuery().colorbox: ' + (!jQuery().colorbox)); // make sure jquery is loaded //if(window.jQuery == undefined || !jQuery().colorbox) { // alert('The site needs a few more seconds to load. Please try again.'); // return; //} parent.document.body.style.overflow ='hidden'; // take the scrollbar off the parent // var width = $(window).width() * .98; // var height = $(window).height() * .98; // NOTE: the parent window must have at the top of the page for the height to work var width = window.innerWidth * .98; var height = window.innerHeight * .98; height = height-70, // give room on top for the close icon console.log('modal width: ' + width); console.log('modal height: ' + height); $.colorbox({ onLoad: function() { $('#cboxClose').show(); // show the close button $('#cboxOverlay').append($('#cboxClose')); // append the close button to the overlay so it shows outside of the iframe }, iframe: true, width: width, height: height, fastIframe: false, href: url, preventoverlayclose: true, // don't allow close of modal window on overlay click close: '' }); }, ModalOpen: function () { var colorboxOpen = $("#colorbox").css("display") == "block"; return colorboxOpen; }, // function to do dynamic loading of scripts LoadScript: function(url, callback, checkExistsFunc) { console.log('LoadScript ' + url); var libExists = false; // load the library by default if(checkExistsFunc !== undefined) { libExists = checkExistsFunc(); } if(!libExists) { var script = document.createElement("script") script.type = "text/javascript"; if (script.readyState){ //IE script.onreadystatechange = function(){ if (script.readyState == "loaded" || script.readyState == "complete"){ script.onreadystatechange = null; callback(); } }; } else { //Others script.onload = function(){ callback(); }; } script.src = url; //document.getElementsByTagName("head")[0].appendChild(script); GatemasterEmbed.CurrentScriptTag.insertAdjacentElement("beforebegin", script); } else { callback(); } }, WriteLine: function(val){ // write the HTML next to the current embedded script currScriptTag.insertAdjacentHTML("beforebegin", val); }, Init: function() { // setup to pop the modal after the page loads $(function(){ console.log('Init - gmReturn: ' + gmReturn) // user has cycled back from the Gatemaster domain to allow for 3rd party cookies so open the ecommerce - only pop the modal if the return URL is the same as the embedded url if(gmReturn) { GatemasterEmbed.OpenModal(gmReturn); } }); } } // END - var GatemasterEmbed var css = document.createElement('link'); // Create a new script element css.href='https://www.gatemastertickets.com/POS/css/colorbox.css'; css.rel='stylesheet'; GatemasterEmbed.CurrentScriptTag.insertAdjacentElement("beforebegin", css); // load the scripts and CSS GatemasterEmbed.LoadScript("https://www.gatemastertickets.com/POS/js/lib/jquery.min.js", function(){ GatemasterEmbed.LoadScript("https://www.gatemastertickets.com/POS/js/lib/jquery.colorbox.js", function(){ // call init code to be called after JS is loaded GatemasterEmbed.Init(); }); }, function(){ return (window.jQuery !== undefined); }); document.addEventListener('click', function (e) { if (GatemasterEmbed.ModalOpen()) { console.log('close store'); parent.document.body.style.overflow ='auto'; // add the scrollbar back to the parent // ask the user if the block is clicked on outside of the window // if (GatemasterEmbed.ModalOpen() && confirm("Do you want to exit the store?")) { // GatemasterEmbed.CloseModal(); // }; } }); //GatemasterEmbed.GatemasterEmbedExists = true; // don't let the alert get wired more than once } // END - if (typeof GatemasterEmbed == 'undefined') var gmReturn = GatemasterEmbed.GetURLParameterByName("gmreturn"); // if "gmreturn" is in the URL then we know that it cycled through ecommerce var br = navigator.platform.toLowerCase(); var isMac = (br == "ipad" || br == "iphone" || br == "ipod" || br.indexOf("mac") >= 0); // if on a mac then we have to cycle the user through the ecommerce to set a cookie before allowing ecommerce to open - this is due to the limitation Apple has put on setting 3rd party cookies (cookies in iframes) console.log('br: ' + br) console.log('isMac: ' + isMac) console.log('gmReturn: ' + gmReturn) if (isMac && !gmReturn) { console.log(url) console.log("safari: " + window.top.location.href); // when user presses the buy now button it will send them through the ecommerce GatemasterEmbed.WriteLine(''); } else { // user is not mac or the user has been cycled through the GM server GatemasterEmbed.WriteLine(''); }