var daURL = window.location.href;
console.log('URL '+daURL);
// Helper function to get an element's exact position
function getPosition(el) {
var xPos = 0;
var yPos = 0;
while (el) {
if (el.tagName == "BODY") {
// deal with browser quirks with body/window/document and page scroll
var xScroll = el.scrollLeft || document.documentElement.scrollLeft;
var yScroll = el.scrollTop || document.documentElement.scrollTop;
xPos += (el.offsetLeft - xScroll + el.clientLeft);
yPos += (el.offsetTop - yScroll + el.clientTop);
} else {
// for all other non-BODY elements
xPos += (el.offsetLeft - el.scrollLeft + el.clientLeft);
yPos += (el.offsetTop - el.scrollTop + el.clientTop);
}
el = el.offsetParent;
}
return {
x: xPos,
y: yPos
};
}
// deal with the page getting resized or scrolled
window.addEventListener("scroll", updatePosition, false);
window.addEventListener("resize", updatePosition, false);
function updatePosition() {
// add your code to update the position when your browser
// is resized or scrolled
}
var myElement = document.querySelector("#destini_container");
var position = getPosition(myElement);
locatorOffset = position.y;
console.log('locatorOffset is '+position.y);
if (locatorOffset > 0) {} else {var locatorOffset = 0;}
destini = {
elementId: '',
APO: false,
WLAB: false,
APOG: false,
};
destini.loadIframe = function(elementId){
var host = 'destinilocators.com';
var client = 'pepsicrossbrand';
var clientIteration = 'a';
var systemParameters = 'ACODE=pffwidget&APOG=00028400372985';
var locator = host + '/' + client + '/' + clientIteration + '/locator.php';
var referrer = '?RFR=' + window.location.protocol + '//' + window.location.hostname + window.location.pathname;
var customParameters = '';
if(destini.wlab !== 'undefined'){
customParameters += '&WLAB=' + destini.wlab;
}
if(destini.apog !== 'undefined'){
customParameters += '&APOG=' + destini.wlab;
}
if (typeof destini.APO !== 'undefined') {
customParameters += '&APO=' + destini.APO;
}
if (typeof destini.APOG !== 'undefined') {
customParameters += '&APOG=' + destini.APOG;
}
var search = location.search.substring(1);
var getQuery = false;
try {
var getQuery = JSON.parse('{"' + decodeURI(search).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
} catch(e) {
}
var systemParametersQuery = false;
try {
var systemParametersQuery = JSON.parse('{"' + decodeURI(systemParameters).replace(/"/g, '\\"').replace(/&/g, '","').replace(/=/g,'":"') + '"}');
} catch(e) {
}
if(systemParametersQuery!==false && getQuery !== false){
for(var k in getQuery){
systemParametersQuery[k] = getQuery[k];
}
} else if (getQuery!==false){
systemParametersQuery = getQuery;
}
function serialize(obj) {
return obj!==false ? ''+Object.keys(obj).reduce(function(a,k){a.push(k+'='+encodeURIComponent(obj[k]));return a},[]).join('&') : '';
}
systemParameters = serialize(systemParametersQuery);
if (customParameters.indexOf('ASSC') != -1) {
document.getElementById(destini.elementId).innerHTML = '';
console.log('loadIframe() done');
}
else {
document.getElementById(destini.elementId).innerHTML = '';
console.log('loadIframe() done');
}
}
// destini.loadIframe();
destini.destroyIframe = function(){
document.getElementById(destini.elementId).innerHTML = '';
};
destini.init = function(containerId){
destini.elementId = containerId;
};
destini.loadWidget = function(wlab, APO, APOG){
destini.wlab = wlab;
destini.APO = APO;
destini.APOG = APOG;
destini.loadIframe();
};
function loadScript(url, callback){
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = url;
script.onreadystatechange = callback;
script.onload = callback;
head.appendChild(script);
}
var destiniSVal = "";
var destiniCurrHeight = 0;
var ecHeight = 0;
var ecType = 0;
function destiniSend() {
if (document.getElementById("destini")) {
document.getElementById("destini").contentWindow.postMessage(destiniSVal, "https://destinilocators.com");
}
}
function destiniLocKeypress(e) {
if (document.getElementById("destiniLocation")) {
var key;
if (window.event) {
key = window.event.keyCode;
} else {
key = e.which;
}
if (key == 13) {
destiniSVal = "DLOC:" + document.getElementById('destiniLocation').value;
destiniSend();
return false;
}
}
}
function destiniLocSubmit() {
if (document.getElementById("destiniLocation")) {
destiniSVal = "DLOC:" + document.getElementById('destiniLocation').value;
destiniSend();
}
}
function destiniSetRange() {
if (document.getElementById("destiniRange")) {
var selIndex = document.getElementById('destiniRange').selectedIndex;
destiniSVal = "RNGE:" + document.getElementById('destiniRange').options[selIndex].value;
destiniSend();
}
}
function destiniAddProducts(upc, subFlag) {
if (subFlag) {
sendFlag = subFlag;
} else {
sendFlag = 0;
}
if (document.getElementById("destini")) {
destiniSVal = "PROD:" + sendFlag + "|" + upc;
destiniSend();
}
}
function destiniReset(upc) {
if (upc) {
sendUpc = upc;
} else {
sendUpc = "|";
}
if (document.getElementById("destini")) {
destiniSVal = "RSET:" + sendUpc;
destiniSend();
}
}
function getPoint(el) {
const bound = el.getBoundingClientRect();
return {
left: bound.left + window.scrollX,
top: bound.top + window.scrollY
};
}
function destiniScrollPoint(whatPoint,offVal) {
var theOff = 0;
if (offVal) {
if (!isNaN(offVal)) {
theOff = offVal;
}
}
console.log("destiniScrollPoint",whatPoint,ecHeight,ecType,theOff);
if (document.getElementById("destini")) {
var offset = getPoint(document.getElementById("destini")).top;
if (whatPoint == "top") {window.scrollTo(0,(offset+theOff));}
else if (whatPoint == "bot") {window.scrollTo(0,(offset+destiniCurrHeight+theOff));}
else if (whatPoint == "mid") {
if (ecType == 1){window.scrollTo(0,(offset+(offset+ecHeight)+theOff));}
else if (ecType == 2){window.scrollTo(0,(offset+(destiniCurrHeight-ecHeight)+theOff));}
}
}
}window.addEventListener("message", function(event) {
var checkOr = 0;
if (event.origin) {
console.log("addEventListener (event.origin)",event.origin);
orVal = String(event.origin);
let parser = document.createElement('a');
parser.href = orVal;
let r2 = RegExp('(^destini[.]co$|.+[.]destini[.]co$)', 'gi').test(parser.hostname);
checkOr = r2 === true ? 1 : checkOr;
}
if (checkOr == 1) {
var checkVal = "";
var setVal = "";
if (event.data) {
var baseVal = String(event.data);
console.log('baseVal:'+ baseVal);
checkVal = baseVal.substring(0, 5);
setVal = baseVal.substring(5);
}
if (checkVal === "labelListViewClear") {
document.body.scrollTop = locatorOffset;
document.documentElement.scrollTop = locatorOffset;
}
if (checkVal === "RSIZ:" || checkVal === "/atlantis_templates/") {
console.log('RSIZ detected');
if (document.getElementById("destini")) {
// console.log('destini element found');
// console.log('previous iFrameHeight = '+ destiniCurrHeight);
var newSize = parseInt(setVal);
// if (newSize != destiniCurrHeight) {
if (newSize > 950) {
document.getElementById('destini').style.height = newSize + "px";
// document.body.scrollTop = locatorOffset;
// document.documentElement.scrollTop = locatorOffset;
console.log("Resizer event.data/newSize = " + checkVal + " / " + newSize);
}
else {
if (screen.width > 785) {
// document.getElementById('destini').style.height = "950px";
// document.getElementById('destini').style.height = "7100px";
document.getElementById('destini').style.height = newSize + "px";
console.log("Resizer event.data/newSize = " + checkVal + " / " + newSize);
// document.body.scrollTop = locatorOffset;
// document.documentElement.scrollTop = locatorOffset;
}
else {
document.getElementById('destini').style.height = newSize + "px";
console.log("Resizer event.data/newSize = " + checkVal + " / " + newSize);
// document.body.scrollTop = locatorOffset;
// document.documentElement.scrollTop = locatorOffset;
}
}
destiniCurrHeight = newSize;
// }
}
} else if (checkVal === "ECHT:") {
if (document.getElementById("destini")) {
var subPos = setVal.indexOf("|");
var thisSet = setVal.substring(0, subPos);
var thisType = setVal.substring(subPos + 1);
ecHeight = parseInt(thisSet);
ecType = parseInt(thisType);
}
} else if (checkVal === "SCRL:") {
if (document.getElementById("destini")) {
document.getElementById('destini').scrollTop = 0;
document.body.scrollTop = locatorOffset;
document.documentElement.scrollTop = locatorOffset;
}
} else if (checkVal === "SZIP:") {
if (document.getElementById("destiniLocation")) {
var setZip = setVal;
document.getElementById('destiniLocation').value = setZip;
}
} else if (checkVal === "LCTN:") {
if (document.getElementById("destini")) {
document.getElementById('destini').contentWindow.location.replace(setVal);
}
}
}
}, false);
function loadResizeScript(){
loadScript('//destinilocators.com/control/gtm.js', function(){ });
if(window.location.protocol=='http:'){
loadScript('//destinilocators.com/control/pscript.js', function(){ });
}else{
loadScript('//destinilocators.com/control/pscript_s.js', function(){ });
}
}
// loadResizeScript();