var contextPath = "" // Set the window for goantiques if (window.goantiques == undefined) window.goantiques = {}; if (window.goantiques.embeds == undefined) window.goantiques.embeds = {}; // Embed the function window.goantiques.embed = function(host) { // variables for the page // currentPath : our current path past the hash // id : random id to use below // embedUrl : Url that is calling this piece var currentPath = window.location.hash.substr(1), id = Math.floor((Math.random()) * 100000).toString(), embedUrl = window.location.href.split('#')[0]; host = findHostPathIfUndefined(host, embedUrl); goantiquesUrl = function(path) { if (host.indexOf('?') >= 0) { path = path.replace('?', '&'); } return 'http://' + host + path + '&remote=' + encodeURIComponent(embedUrl); } // embed the onMessage. This is used so that when the code on our side // calls back to the server it can process the message if (window.postMessage) { onMessage = processMessage; // Add in the listeners to process it // IE + other compatible event handlers if (window.addEventListener) window.addEventListener("message", onMessage, false); else window.attachEvent("onmessage", onMessage); } // Print out the iframe reference var goaPath = goantiquesUrl(currentPath); //alert(goaPath) document.write(''); }; /** * This will process the message that comes back from the server. * This will mainly be used to alter the URL at the top of the page. * There are really a few things it could happen : * 1. Height Change * 2. location update the top * 3. Unload, go back to the previous page */ function processMessage(e) { var message = e.data.split(':'); // make sure this message comes from the frame var frame = document.getElementById('goantiquesEmededPage'); if (frame.contentWindow != e.source) return; // Now process for each type if (message[0] == 'height') { setHeight(message[1]); } else if (message[0] == 'location') { // Update the locatioin bar window.location.hash = '#' + message[1]; } else if (message[0] == 'unload') { // console.log("unload-----------" + message); // console.log(" loc : " + window.location); // console.log(" hash : " + window.location.hash.substr(1)); } else if (message[0] == 'load') { // Update the location, this also helps well with the redirects // then also send the parent URL back window.location.hash = '#' + message[1]; frame.contentWindow.postMessage( "currentLocation:" + document.URL, "*" ); } else if (message[0] == 'launchZipPopup') { launchZipPopup(); } } // Heights for the parent frame // this is so we can change the frame based on the size of the iframe coming back minHeight = 300; currentHeight= 100; function setHeight(newHeight) { if (newHeight < minHeight) newHeight = minHeight; if (newHeight != currentHeight) { currentHeight = newHeight; $("#goantiquesEmededPage").height(currentHeight) } } /** * Find the host path if its not passed in */ function findHostPathIfUndefined(host, embedUrl) { if (typeof(host) == 'undefined') { var scripts = document.getElementsByTagName('script'), jsPath = contextPath+'/embed/just-looking/remote'; host = ''; for (i = 0; i < scripts.length; i++) { if (scripts[i].src.indexOf(jsPath) > 0) { host = scripts[i].src; host = host.replace('http://', '').replace('https://', ''); host = host.substr(0, host.indexOf(jsPath)); host += contextPath+'/embed/just-looking/index?p='; } } } return host; } // Now run the embedding try { window.goantiques.embed(); } catch(e) { // Failed to embed document.write("
Failed to embed goantiques: " + e + "
"); } /** * Get current URL at the # and replace it with the ending. */ function createForwardURL(ending) { var url = document.URL; var front = url.substr(0, url.indexOf('#')); return front + '#' + ending; } // The modal CSS embeding document.write(''); document.write(''); // Used for zip code popup document.write(''); document.write(''); document.write(''); document.write(''); /** Hard coded from postal code check.js **/ // TODO dont copy get for realzie function isValidUKPostcode(p) { var postCodeRegEx = /[A-Z]{1,2}[A-Z0-9]{1,2} ?[0-9][A-Z]{2}/i; return postCodeRegEx.test(p); } // Oh canada function isValidCanadianPostcode(p) { var postCodeRegEx = /^([a-ceghj-npr-tv-z]){1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}[a-ceghj-npr-tv-z]{1}[0-9]{1}$/i; return postCodeRegEx.test(p); } // http://stackoverflow.com/questions/160550/zip-code-us-postal-code-validation function isValidUSPostcode(p) {63135 var postCodeRegEx = /(^\d{5}$)|(^\d{5}-\d{4}$)/i; return postCodeRegEx.test(p); } function whatCountryPostalCode(p) { if (isValidUSPostcode(p)) { return "US"; } if (isValidUKPostcode(p)) { return "GB"; } if (isValidCanadianPostcode(p.toLowerCase())) { return "CA"; } return ""; } // PUT SOME PLACE ELSE $(document).ready(function() { $("#anonymousContactInfoForm").submit(function() { // If the zip code is unknown // and the country has not been set var countryZip = whatCountryPostalCode($("#zipCodeInput").val()); var inputCountry = $("#inputCountryId").val(); if (countryZip == "" && inputCountry == "") { //console.log("We dont knwo the country"); $("#zipInput").hide(); $("#countryList").show(); return false; } else if (countryZip != "") { $("#countryCode").val(countryZip); } else if (inputCountry != "") { $("#countryCode").val(inputCountry); } // now submit it through the post message? var frame = document.getElementById('goantiquesEmededPage'); frame.contentWindow.postMessage( "zipCode:" + $("#zipCodeInput").val() + ":" + $("#countryCode").val(), "*" ); // now close the window $.modal.close() return false; }); }); function launchZipPopup() { $("#anonymousContactInfo").modal({ containerId:'anon-zip', overlayId:'anon-zip-overlay', persist:true }); } // This is needed to do the popups on the page: $(document).ready(function() { $(".categorySwitch").click(function (event) { window.location.hash = '/embed/just-looking/category/' + $(event.target).attr("href"); window.location.reload(true); return false; }); $(".categoryChange").change(function (event) { window.location.hash = '/embed/just-looking/category/' + $(event.target).val(); window.location.reload(true); return false; }); });