console.log('JWT blank. Not taking any login action.');
//************************************************
//********** GLOBAL PD/ONE VARIABLES *************
//************************************************
var pdCategoryId = "932";
//************************************************
//************ JS/CSS FILE ROUTINES *************
//************************************************
function pdLoadJsCssFile(filename, filetype){
if (filetype=="js") {
var fileref=document.createElement('script');
fileref.setAttribute("type","text/javascript");
fileref.setAttribute("async",true);
fileref.setAttribute("src", filename);
}
else if (filetype=="css") {
var fileref=document.createElement("link");
fileref.setAttribute("rel", "stylesheet");
fileref.setAttribute("type", "text/css");
fileref.setAttribute("href", filename);
}
if (typeof fileref!="undefined")
document.getElementsByTagName("head")[0].appendChild(fileref);
}
//************************************************
//*** UTILITY TO EXECUTE SCRIPTS IN A CONTAINER ***
//************************************************
function pdRunScriptsIn(element) {
if (!element) return;
if (!window.__pdExecutedScriptsSet) window.__pdExecutedScriptsSet = new Set();
var scripts = element.querySelectorAll('script');
console.log('pdRunScriptsIn: found', scripts.length, 'script tag(s) inside injected content.');
scripts.forEach(function(originalScript, idx) {
var signature = originalScript.src ? 'src:' + originalScript.src : 'inline:' + (originalScript.textContent || '').trim();
if (window.__pdExecutedScriptsSet.has(signature)) {
console.log('pdRunScriptsIn: skipping already executed script #' + (idx + 1));
originalScript.remove();
return;
}
// Skip known inline definitions if the global already exists (prevents duplicate var errors)
if (!originalScript.src && originalScript.textContent && originalScript.textContent.indexOf('EmailInputManager') !== -1 && typeof window.EmailInputManager !== 'undefined') {
console.log('pdRunScriptsIn: skipping inline EmailInputManager because it already exists.');
originalScript.remove();
return;
}
var newScript = document.createElement('script');
// Preserve external vs inline scripts
if (originalScript.src) {
newScript.src = originalScript.src;
newScript.async = originalScript.async;
newScript.defer = originalScript.defer;
} else {
newScript.textContent = originalScript.textContent;
}
// Move over type/attrs in case module/type is used
if (originalScript.type) newScript.type = originalScript.type;
// Append to head to ensure execution in most browsers
window.__pdExecutedScriptsSet.add(signature);
document.head.appendChild(newScript);
console.log('pdRunScriptsIn: executed script #' + (idx + 1) + (originalScript.src ? ' src=' + originalScript.src : ' (inline)'));
originalScript.remove();
});
}
//************************************************
//*** UTILITY TO NORMALIZE MODULE NAMES **********
//************************************************
function pdNormalizeModuleName(raw) {
if (!raw) return '';
var name = String(raw);
if (name.indexOf('?') !== -1) name = name.split('?')[0];
if (name.indexOf('&') !== -1) name = name.split('&')[0];
if (name.indexOf('#') !== -1) name = name.split('#')[0];
if (name.indexOf('/') !== -1) {
var parts = name.split('/').filter(function(p){ return p; });
var lastMod = parts.find(function(p){ return p.indexOf('mod_') === 0; });
if (lastMod) name = lastMod;
else name = parts[parts.length - 1] || name;
}
return name.trim();
}
//************************************************
//*** UTILITY TO PULL MODULE NAME FROM A URL *****
//************************************************
function pdGetModuleFromUrl(url) {
try {
var parsed = new URL(url, window.location.origin);
return pdNormalizeModuleName(parsed.searchParams.get('module') || '');
} catch (e) {
return '';
}
}
//************************************************
//****** PD/ONE FEATURE SPECIFIC CSS/JS *********
//************************************************
pdLoadJsCssFile("https://cdn.practicaldatacore.com/my-justforjeeps-com/mod_bigcommerce/pdCompiledScript.js?cb=1971653", "js");
pdLoadJsCssFile("https://cdn.practicaldatacore.com/my-justforjeeps-com/mod_pdOneStyleEditor/pdPublicStyle.css?cb=492913", "css");
//*** CATEGORY ID:932****
//*** PRODUCT ID:****
//*** PRODUCT ID LIST CSV:****
//**** INCLUDE CATEGORY PAGE JAVASCRIPT ****
var pdStarsRefreshFlag = true;
function pdDisplayCategoryStars() {
if(pdStarsRefreshFlag == true) {
document.querySelectorAll("div[productId='6258'], div[data-itemid='6258'], .pdRatingStarsWrapper[data-itemid='6258']").forEach(function(element) {
element.innerHTML = "
";
});
document.querySelectorAll("div[productId='6327'], div[data-itemid='6327'], .pdRatingStarsWrapper[data-itemid='6327']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6330'], div[data-itemid='6330'], .pdRatingStarsWrapper[data-itemid='6330']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6426'], div[data-itemid='6426'], .pdRatingStarsWrapper[data-itemid='6426']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6427'], div[data-itemid='6427'], .pdRatingStarsWrapper[data-itemid='6427']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6428'], div[data-itemid='6428'], .pdRatingStarsWrapper[data-itemid='6428']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6453'], div[data-itemid='6453'], .pdRatingStarsWrapper[data-itemid='6453']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6454'], div[data-itemid='6454'], .pdRatingStarsWrapper[data-itemid='6454']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6687'], div[data-itemid='6687'], .pdRatingStarsWrapper[data-itemid='6687']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6736'], div[data-itemid='6736'], .pdRatingStarsWrapper[data-itemid='6736']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6758'], div[data-itemid='6758'], .pdRatingStarsWrapper[data-itemid='6758']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6775'], div[data-itemid='6775'], .pdRatingStarsWrapper[data-itemid='6775']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6780'], div[data-itemid='6780'], .pdRatingStarsWrapper[data-itemid='6780']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='6785'], div[data-itemid='6785'], .pdRatingStarsWrapper[data-itemid='6785']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7046'], div[data-itemid='7046'], .pdRatingStarsWrapper[data-itemid='7046']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7047'], div[data-itemid='7047'], .pdRatingStarsWrapper[data-itemid='7047']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7154'], div[data-itemid='7154'], .pdRatingStarsWrapper[data-itemid='7154']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7156'], div[data-itemid='7156'], .pdRatingStarsWrapper[data-itemid='7156']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7157'], div[data-itemid='7157'], .pdRatingStarsWrapper[data-itemid='7157']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7158'], div[data-itemid='7158'], .pdRatingStarsWrapper[data-itemid='7158']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7159'], div[data-itemid='7159'], .pdRatingStarsWrapper[data-itemid='7159']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7164'], div[data-itemid='7164'], .pdRatingStarsWrapper[data-itemid='7164']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7187'], div[data-itemid='7187'], .pdRatingStarsWrapper[data-itemid='7187']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7207'], div[data-itemid='7207'], .pdRatingStarsWrapper[data-itemid='7207']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7208'], div[data-itemid='7208'], .pdRatingStarsWrapper[data-itemid='7208']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7214'], div[data-itemid='7214'], .pdRatingStarsWrapper[data-itemid='7214']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7226'], div[data-itemid='7226'], .pdRatingStarsWrapper[data-itemid='7226']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7229'], div[data-itemid='7229'], .pdRatingStarsWrapper[data-itemid='7229']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7318'], div[data-itemid='7318'], .pdRatingStarsWrapper[data-itemid='7318']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7359'], div[data-itemid='7359'], .pdRatingStarsWrapper[data-itemid='7359']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7365'], div[data-itemid='7365'], .pdRatingStarsWrapper[data-itemid='7365']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7370'], div[data-itemid='7370'], .pdRatingStarsWrapper[data-itemid='7370']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7371'], div[data-itemid='7371'], .pdRatingStarsWrapper[data-itemid='7371']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7372'], div[data-itemid='7372'], .pdRatingStarsWrapper[data-itemid='7372']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7373'], div[data-itemid='7373'], .pdRatingStarsWrapper[data-itemid='7373']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7378'], div[data-itemid='7378'], .pdRatingStarsWrapper[data-itemid='7378']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7379'], div[data-itemid='7379'], .pdRatingStarsWrapper[data-itemid='7379']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7460'], div[data-itemid='7460'], .pdRatingStarsWrapper[data-itemid='7460']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7467'], div[data-itemid='7467'], .pdRatingStarsWrapper[data-itemid='7467']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7485'], div[data-itemid='7485'], .pdRatingStarsWrapper[data-itemid='7485']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7822'], div[data-itemid='7822'], .pdRatingStarsWrapper[data-itemid='7822']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7893'], div[data-itemid='7893'], .pdRatingStarsWrapper[data-itemid='7893']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7931'], div[data-itemid='7931'], .pdRatingStarsWrapper[data-itemid='7931']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='7953'], div[data-itemid='7953'], .pdRatingStarsWrapper[data-itemid='7953']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8142'], div[data-itemid='8142'], .pdRatingStarsWrapper[data-itemid='8142']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8243'], div[data-itemid='8243'], .pdRatingStarsWrapper[data-itemid='8243']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8244'], div[data-itemid='8244'], .pdRatingStarsWrapper[data-itemid='8244']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8285'], div[data-itemid='8285'], .pdRatingStarsWrapper[data-itemid='8285']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8341'], div[data-itemid='8341'], .pdRatingStarsWrapper[data-itemid='8341']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8374'], div[data-itemid='8374'], .pdRatingStarsWrapper[data-itemid='8374']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8516'], div[data-itemid='8516'], .pdRatingStarsWrapper[data-itemid='8516']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8730'], div[data-itemid='8730'], .pdRatingStarsWrapper[data-itemid='8730']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8731'], div[data-itemid='8731'], .pdRatingStarsWrapper[data-itemid='8731']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8819'], div[data-itemid='8819'], .pdRatingStarsWrapper[data-itemid='8819']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='8825'], div[data-itemid='8825'], .pdRatingStarsWrapper[data-itemid='8825']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9085'], div[data-itemid='9085'], .pdRatingStarsWrapper[data-itemid='9085']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9238'], div[data-itemid='9238'], .pdRatingStarsWrapper[data-itemid='9238']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9317'], div[data-itemid='9317'], .pdRatingStarsWrapper[data-itemid='9317']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9372'], div[data-itemid='9372'], .pdRatingStarsWrapper[data-itemid='9372']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9390'], div[data-itemid='9390'], .pdRatingStarsWrapper[data-itemid='9390']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9469'], div[data-itemid='9469'], .pdRatingStarsWrapper[data-itemid='9469']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9489'], div[data-itemid='9489'], .pdRatingStarsWrapper[data-itemid='9489']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9591'], div[data-itemid='9591'], .pdRatingStarsWrapper[data-itemid='9591']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9592'], div[data-itemid='9592'], .pdRatingStarsWrapper[data-itemid='9592']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9599'], div[data-itemid='9599'], .pdRatingStarsWrapper[data-itemid='9599']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9631'], div[data-itemid='9631'], .pdRatingStarsWrapper[data-itemid='9631']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9662'], div[data-itemid='9662'], .pdRatingStarsWrapper[data-itemid='9662']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9733'], div[data-itemid='9733'], .pdRatingStarsWrapper[data-itemid='9733']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9917'], div[data-itemid='9917'], .pdRatingStarsWrapper[data-itemid='9917']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9924'], div[data-itemid='9924'], .pdRatingStarsWrapper[data-itemid='9924']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9925'], div[data-itemid='9925'], .pdRatingStarsWrapper[data-itemid='9925']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9927'], div[data-itemid='9927'], .pdRatingStarsWrapper[data-itemid='9927']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9928'], div[data-itemid='9928'], .pdRatingStarsWrapper[data-itemid='9928']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9929'], div[data-itemid='9929'], .pdRatingStarsWrapper[data-itemid='9929']").forEach(function(element) {
element.innerHTML = "";
});
document.querySelectorAll("div[productId='9937'], div[data-itemid='9937'], .pdRatingStarsWrapper[data-itemid='9937']").forEach(function(element) {
element.innerHTML = "";
});
pdStarsRefreshFlag = false;
}
}
pdDisplayCategoryStars();
function pdRefreshCategoryStarsDelayed() {
pdStarsRefreshFlag = true;
setTimeout(pdDisplayCategoryStars, 500);
}
try {
document.getElementById('product-listing-container').addEventListener('DOMSubtreeModified', function() {
pdRefreshCategoryStarsDelayed();
});
} catch(e){};
//*** public_mod_structuredData_renderJsonByItemId found
//*** public_mod_structuredData enabled
var script = document.createElement('script');
script.setAttribute('type', 'application/ld+json');
script.innerHTML = "{\"@context\":\"http:\\/\\/schema.org\",\"@type\":\"Organization\",\"sameAs\":[\"https://www.facebook.com/JustForJeeps\",\"https://twitter.com/JustForJeeps\",\"https://www.instagram.com/justforjeeps/\",\"https://www.pinterest.com/justforjeeps/\"],\"name\":\"JustForJeeps.com\",\"url\":\"https:\\/\\/www.justforjeeps.com\\/\",\"address\":{\"@type\":\"PostalAddress\",\"streetAddress\":\"56 Boston Providence Tpke\",\"addressLocality\":\"Norwood\",\"addressRegion\":\"MA\",\"addressCountry\":\"US\",\"postalCode\":\"02062\"},\"founders\":[{\"@type\":\"Person\",\"name\":\"Peter Catanese\"}],\"logo\":\"https:\\/\\/my.justforjeeps.com\\/pd_custom\\/core\\/structuredData\\/images\\/imageCompanyLogo.jpg\",\"foundingDate\":\"2004\",\"contactPoint\":{\"@type\":\"ContactPoint\",\"email\":\"support@justforjeeps.com\",\"telephone\":\"+1-888-651-5337\",\"contactType\":\"Customer Support\"}}"
document.getElementsByTagName('head')[0].appendChild(script); ;
var script = document.createElement('script');
script.setAttribute('type', 'application/ld+json');
script.innerHTML = "{\"@context\":\"http:\\/\\/schema.org\",\"@type\":\"LocalBusiness\",\"address\":{\"@type\":\"PostalAddress\"},\"priceRange\":\"0.6700-3465.9900\"}"
document.getElementsByTagName('head')[0].appendChild(script); ;
function pdGetAccountNavRoot() {
var navRoot = document.querySelector('.navBar-section');
if (navRoot) return navRoot;
navRoot = document.querySelector('.navBar.navBar--sub.navBar--account .navBar-section');
if (navRoot) return navRoot;
navRoot = document.querySelector('.navBar.navBar--sub.navBar--account');
if (navRoot) return navRoot;
navRoot = document.querySelector('.account-nav');
if (navRoot) return navRoot;
navRoot = document.querySelector('.b2b-account-nav, .b2b-side-nav, .b2b-sidebar nav, .b2b-sidebar, .b3-side-nav, .b3-nav, .b3-sidebar nav, .b3-sidebar, .b2b-portal__nav, .b3-portal__nav');
return navRoot;
}
function pdGetAccountNavItem(root, hrefFragment, fallbackSelector) {
if (!root) return null;
var link = hrefFragment ? root.querySelector('a[href*="' + hrefFragment + '"]') : null;
if (link && link.closest) {
var item = link.closest('li');
if (item) return item;
}
return fallbackSelector ? root.querySelector(fallbackSelector) : null;
}
function pdInjectAccountLinkModifications() {
//***** INJECT REWARDS LINK ****
var navRoot = pdGetAccountNavRoot();
var navItem = pdGetAccountNavItem(navRoot, "account.php?action=order_status", "li:nth-child(2)");
if (navItem) { navItem.insertAdjacentHTML("afterend", 'Rewards'); }
//***** INJECT OLDER ORDER HISTORY LINK ****
var navRoot = pdGetAccountNavRoot();
var navItem = pdGetAccountNavItem(navRoot, "account.php?action=order_status", "li:nth-child(1)");
if (navItem) { navItem.insertAdjacentHTML("afterend", 'Older Orders'); }
}
pdInjectAccountLinkModifications();var pdPublicUrl = 'https://my.justforjeeps.com/';
var pdUseLegacyRewardsPage = true;
function pdShouldUseRewards2025() {
return !pdUseLegacyRewardsPage;
}
function insertDivUnderH1(divClass = "inserted-under-h1") {
var pageName = window.location.pathname.split("/").pop();
if (pageName !== "login.php" && pageName !== "cart.php" && pageName !== "checkout") return;
var params = new URLSearchParams(window.location.search || "");
var action = params.get("action") || "login";
if (pageName === "login.php" && action === "reset_password") return;
var bannerHtml = "";
var bannerTemplateData = {"rewardsPercentageBack":3.33,"pointsAwardedForNewSignUp":0};
if (!bannerHtml) return;
if (pageName === "login.php" && action === "login" && !true) return;
if (pageName === "login.php" && action === "create_account" && !true) return;
if (pageName === "cart.php" && !true) return;
if (pageName === "checkout" && !true) return;
function pdRenderBannerTemplate(template, data) {
if (!template || !data) return template || '';
template = template.replace(/\{\{#if\s+(\w+)\}\}([\s\S]*?)\{\{\/if\}\}/g, function(_, key, inner) {
var val = data[key];
if (val === undefined || val === null) return '';
if (typeof val === 'number' && val === 0) return '';
if (typeof val === 'string' && val.trim() === '') return '';
return inner;
});
template = template.replace(/\{\{(\w+)\}\}/g, function(_, key) {
var val = data[key];
return (val === undefined || val === null) ? '' : String(val);
});
return template;
}
bannerHtml = pdRenderBannerTemplate(bannerHtml, bannerTemplateData);
var div = document.createElement("div");
div.className = divClass;
div.innerHTML = bannerHtml;
if (pageName === "checkout") {
var checkoutPrimary = document.querySelector(".layout.optimizedCheckout-contentPrimary");
if (checkoutPrimary) {
checkoutPrimary.insertAdjacentElement("afterbegin", div);
return;
}
}
var h1 = document.querySelector("h1.page-heading");
if (!h1) return;
if (pageName === "cart.php") {
h1.insertAdjacentElement("afterend", div);
return;
}
if (action === "login") {
var loginRow = document.querySelector(".login-row");
if (loginRow) {
loginRow.insertAdjacentElement("afterbegin", div);
return;
}
}
if (action === "create_account") {
var accountBody = document.querySelector(".account-body");
if (accountBody) {
accountBody.insertAdjacentElement("afterbegin", div);
return;
}
}
h1.insertAdjacentElement("afterend", div);
}
function pdInitAccountModuleContent(){
console.log('pdPageScript2025: DOMContentLoaded fired');
const urlParams = new URLSearchParams(location.search);
var activeNavItem = document.querySelector('.navBar-section .is-active');
var prevLinkElem = activeNavItem ? activeNavItem.dataset.pdLinkElem : null;
var prevLinkTarget = activeNavItem ? activeNavItem.dataset.pdLinkElemTarget : null;
if (prevLinkElem && prevLinkTarget) {
var prevTargetElem = document.querySelector(prevLinkTarget);
if (prevTargetElem) {
prevTargetElem.innerHTML = prevLinkElem;
}
delete activeNavItem.dataset.pdLinkElem;
delete activeNavItem.dataset.pdLinkElemTarget;
}
if (urlParams.has('pd_module_content')){
console.log('pdPageScript2025: pd_module_content detected:', urlParams.get('pd_module_content'));
console.log('pdPageScript2025: pd_module_subNav:', urlParams.get('pd_module_subNav'));
var module = urlParams.get('pd_module_content');
var subNav = urlParams.get('pd_module_subNav');
var moduleLink = document.querySelector('#pdContent_'+module+' a');
var moduleTitle = moduleLink ? moduleLink.innerHTML : '';
var currentUrl = window.location.href;
var currentUrlNoQuery = currentUrl.substring(0, currentUrl.indexOf('?'));
console.log(currentUrlNoQuery);
activeNavItem = document.querySelector('.navBar-section .is-active');
var currentTab = activeNavItem ? activeNavItem.innerHTML : '';
if (activeNavItem && activeNavItem.classList.contains('pdLinkEvent') == false){
if(activeNavItem.querySelector('.navBar-action')){
}
else {
activeNavItem.innerHTML = ''+currentTab+'';
}
}
if (activeNavItem) {
activeNavItem.dataset.pdLinkElemTarget = '#pdContent_'+module;
var moduleItem = document.querySelector('#pdContent_'+module);
activeNavItem.dataset.pdLinkElem = moduleItem ? moduleItem.innerHTML : '';
}
var moduleItem = document.querySelector('#pdContent_'+module);
if (moduleItem) {
moduleItem.innerHTML = moduleLink ? moduleLink.textContent : '';
}
if (activeNavItem) {
activeNavItem.classList.remove('is-active');
}
if (moduleItem) {
moduleItem.classList.add('is-active');
}
var pageHeading = document.querySelector('.page-heading');
if (pageHeading) {
pageHeading.innerHTML = moduleTitle;
}
if (subNav !== '' && subNav !== null){
url = pdPublicUrl+'/'+module+'/'+subNav+'.php?module='+module;
}
else {
url = pdPublicUrl+'/'+module+'/index.php?module='+module;
}
console.log('pdPageScript2025: calling pdOneAjaxLinkHandler with URL:', url);
pdOneAjaxLinkHandler(url);
}
insertDivUnderH1();
}
if (document.readyState === 'loading') {
document.addEventListener('DOMContentLoaded', pdInitAccountModuleContent);
} else {
pdInitAccountModuleContent();
}
document.addEventListener('submit', function(e) {
var form = e.target.closest('.pdModal form');
if (!form) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
pdOneAjaxFormHandler(form);
}, true);
document.addEventListener('submit', function(e) {
var form = e.target.closest('#pdModuleContent form');
if (!form) {
return;
}
e.preventDefault();
e.stopImmediatePropagation();
pdOneAjaxFormHandler(form);
}, true);
document.addEventListener('click', function(e) {
var link = e.target.closest('.pdLinkEvent');
if (!link) {
return;
}
var currentUrl = window.location.href;
activeNavItem = document.querySelector('.navBar-section .is-active');
var activeNavAction = activeNavItem ? activeNavItem.querySelector('.navBar-action') : null;
var currentTab = activeNavAction ? activeNavAction.innerHTML : (activeNavItem ? activeNavItem.innerHTML : '');
console.log(link.innerHTML);
if (activeNavItem && activeNavItem.classList.contains('pdLinkEvent') == false){
activeNavItem.innerHTML = ''+currentTab+'';
}
if (activeNavItem) {
activeNavItem.classList.remove('is-active');
}
if (link.parentElement) {
link.parentElement.classList.add('is-active');
}
var url = link.getAttribute('href');
e.preventDefault();
e.stopImmediatePropagation();
pdOneAjaxLinkHandler(url);
});
document.addEventListener('click', function(e) {
var link = e.target.closest('#pdModuleContent a');
if (!link) {
return;
}
var url = link.getAttribute('href');
link.setAttribute("href", "#");
e.preventDefault();
pdOneAjaxLinkHandler(url);
});
function pdShowRewardsLoadError(message){
var accountContent = document.querySelector('.account-content');
if (!accountContent) {
return;
}
var safeMessage = message || 'Rewards could not be loaded.';
accountContent.innerHTML = '' + safeMessage + '
';
}
var pdRewardsForceLegacy = false;
function pdLoadRewardsLegacyFallback(options){
options = options || {};
pdRewardsForceLegacy = true;
var url = pdPublicUrl + '/mod_myRewards/index.php?module=mod_myRewards';
var method = (options.method || 'GET').toUpperCase();
var queryString = options.queryString || '';
if (!queryString && options.body) {
queryString = options.body.toString();
}
if (queryString) {
url += (url.indexOf('?') !== -1 ? '&' : '?') + queryString;
}
console.log('pdLoadRewardsLegacyFallback:', url, 'method:', method);
if (method === 'GET') {
pdOneAjaxLinkHandler(url);
return;
}
var fetchOptions = {
method: method,
credentials: 'include'
};
if (options.body) {
fetchOptions.headers = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
};
fetchOptions.body = options.body;
}
fetch(url, fetchOptions)
.then(function(response) { return response.text(); })
.then(function(result) {
console.log('pdLoadRewardsLegacyFallback success; length:', (result || '').length);
var accountContent = document.querySelector('.account-content');
if (accountContent) {
accountContent.innerHTML = result;
}
if (typeof pdRunScriptsIn === 'function') {
pdRunScriptsIn(document.querySelector('.account-content'));
}
})
.catch(function(errMsg) {
console.log('pdLoadRewardsLegacyFallback error', errMsg && errMsg['statusText'] ? errMsg['statusText'] : errMsg);
pdShowRewardsLoadError('Rewards could not be loaded.');
});
}
function pdLoadRewards2025Ajax(options){
options = options || {};
var endpoint = pdPublicUrl + '/mod_myRewards/ajax/renderRewardsPage2025.php';
var method = (options.method || 'GET').toUpperCase();
var queryString = options.queryString || '';
if (!queryString && options.body && method === 'GET') {
queryString = options.body.toString();
}
if (queryString) {
endpoint += (endpoint.indexOf('?') !== -1 ? '&' : '?') + queryString;
}
var fetchOptions = {
method: method,
credentials: 'include',
headers: {
'Accept': 'application/json'
}
};
if (method != 'GET' && options.body) {
fetchOptions.headers['Content-Type'] = 'application/x-www-form-urlencoded; charset=UTF-8';
fetchOptions.body = options.body;
}
var accountContent = document.querySelector('.account-content');
if (accountContent) {
accountContent.innerHTML = 'Loading rewards...
';
}
console.log('pdLoadRewards2025Ajax:', endpoint, 'method:', method);
return fetch(endpoint, fetchOptions)
.then(function(response) {
if (!response.ok) {
throw new Error('HTTP ' + response.status);
}
return response.json();
})
.then(function(data) {
console.log('pdLoadRewards2025Ajax success; html length:', (data.html || '').length);
if (data && data.success === false) {
pdShowRewardsLoadError(data.message || 'Rewards could not be loaded.');
return;
}
if (data.redirectUrl) {
window.location.href = data.redirectUrl;
return;
}
var accountContent = document.querySelector('.account-content');
if (accountContent) {
accountContent.innerHTML = data.html || '';
}
if (!data.html) {
pdLoadRewardsLegacyFallback(options);
return;
}
if (data.js) {
document.querySelectorAll('script[data-pd-rewards-ajax="true"]').forEach(function(script) {
if (script.parentNode) script.parentNode.removeChild(script);
});
var script = document.createElement('script');
script.type = 'text/javascript';
script.setAttribute('data-pd-rewards-ajax', 'true');
script.text = data.js;
document.body.appendChild(script);
try { document.dispatchEvent(new Event('DOMContentLoaded', { bubbles: true })); } catch(e) {}
}
})
.catch(function(errMsg) {
console.log('pdLoadRewards2025Ajax error', errMsg && errMsg['statusText'] ? errMsg['statusText'] : errMsg);
pdLoadRewardsLegacyFallback(options);
});
}
function pdOneAjaxLinkHandler(url){
console.log('pdOneAjaxLinkHandler entry:', url);
console.log("pdOneAjaxLinkHandler:" + url);
var contentElem = document.querySelector('#pdModuleContent');
var dataElem = document.querySelector('#pdModuleData');
var currModule = contentElem ? contentElem.getAttribute('data-currmodule') : null;
if (!currModule || currModule === '' || currModule === undefined) {
currModule = dataElem ? dataElem.getAttribute('data-currmodule') : null;
}
currModule = pdNormalizeModuleName(currModule);
var externalLink = false;
var targetModule = pdGetModuleFromUrl(url);
if (!targetModule && currModule) {
targetModule = currModule;
}
if (!targetModule) {
// As a last resort, try to parse the path portion (e.g., /mod_myRewards/)
try {
var tmpUrl = new URL(url, window.location.origin);
var parts = tmpUrl.pathname.split('/').filter(function(p){ return p; });
var maybeMod = parts.find(function(p){ return p.indexOf('mod_') === 0; });
if (maybeMod) targetModule = maybeMod;
} catch(e) {}
}
console.log('pdOneAjaxLinkHandler: targetModule =', targetModule, 'currModule =', currModule);
console.log('pdOneAjaxLinkHandler: targetModule decision point; targetModule=', targetModule);
if (targetModule === 'mod_myRewards' && pdShouldUseRewards2025() && !pdRewardsForceLegacy) {
var queryString = '';
try {
var tmpUrl = new URL(url, window.location.origin);
queryString = tmpUrl.search ? tmpUrl.search.substring(1) : '';
} catch(e) {}
console.log('pdOneAjaxLinkHandler: routing to pdLoadRewards2025Ajax with query:', queryString);
pdLoadRewards2025Ajax({ method: 'GET', queryString: queryString });
return;
}
//assume http or https is external link
var testUrl = url;
var testUrlNoQuery = url.substring(0, testUrl.indexOf('?'));
if (testUrlNoQuery !== ''){
if ((url.includes('https://') || url.includes('http://')) && !testUrlNoQuery.includes('mod_')){
externalLink = true;
}
}
if (!externalLink && currModule !== '' && currModule !== undefined) {
testUrl = testUrl.replace('https://', '');
testUrl = testUrl.replace('http://', '');
replaceStart = testUrl.indexOf('/');
if (replaceStart == -1){
replaceStart = 0;
}
testurl = testUrl.substring(replaceStart);
//If no 'mod_' present assume reference path to current module and create absolute path
if (!url.includes('mod_')){
url = pdPublicUrl+'/'+currModule+'/'+testurl;
}
//Else assume link to other module and create absolute path
else {
url = pdPublicUrl+'/'+testurl;
}
if (currModule) {
url += (url.indexOf('?') !== -1 ? '&' : '?') + 'module=' + currModule;
}
}
//Perform ajax if not linking to external site
if (!externalLink){
if (url.includes('?')){
url += '&mode=inject';
}
else {
url += '?mode=inject';
}
fetch(url, {
method: 'POST',
credentials: 'include'
})
.then(function(response) {
return response.text();
})
.then(function(result) {
console.log('pdOneAjaxLinkHandler success; length:', (result || '').length);
var accountContent = document.querySelector('.account-content');
if (accountContent) {
accountContent.innerHTML = result;
}
if (targetModule === 'mod_myRewards') {
console.log('pdOneAjaxLinkHandler: running pdRunScriptsIn for mod_myRewards.');
pdRunScriptsIn(document.querySelector('.account-content'));
}
})
.catch(function(errMsg) {
console.log('pdOneAjaxLinkHandler error', errMsg && errMsg['statusText']);
});
}
else {
// window.location.href = url;
}
}
function pdOneAjaxFormHandler(form, module){
var dataElem = document.querySelector('#pdModuleData');
var contentElem = document.querySelector('#pdModuleContent');
var currModule = dataElem ? dataElem.getAttribute('data-currmodule') : null;
if (currModule == undefined){
currModule = contentElem ? contentElem.getAttribute('data-currmodule') : null;
}
currModule = pdNormalizeModuleName(currModule);
if (currModule === 'mod_myRewards' && pdShouldUseRewards2025()) {
var method = (form.getAttribute('method') || 'GET').toUpperCase();
var formParams = new URLSearchParams(new FormData(form));
if (method === 'GET') {
pdLoadRewards2025Ajax({ method: 'GET', queryString: formParams.toString() });
} else {
pdLoadRewards2025Ajax({ method: method, body: formParams });
}
return;
}
var formData = new FormData(form);
console.log(Array.from(formData.entries()));
var method = form.getAttribute('method') || 'GET';
var url = form.getAttribute('action') || '';
replaceStart = url.indexOf('/');
if (replaceStart == -1){
replaceStart = 0;
}
url = url.substring(replaceStart);
url = pdPublicUrl+'/'+currModule+'/'+url+'?module='+currModule;
if (url.includes('?')){
url += '&mode=inject';
}
else {
url += '?mode=inject';
}
if (url.includes('?')){
url += '&module='+currModule;
}
else {
url += '?module='+currModule;
}
var formParams = new URLSearchParams(formData);
var fetchUrl = url;
var fetchOptions = {
method: method.toUpperCase(),
credentials: 'include'
};
if (fetchOptions.method === 'GET') {
if (formParams.toString()) {
fetchUrl += (fetchUrl.includes('?') ? '&' : '?') + formParams.toString();
}
} else {
fetchOptions.headers = {
'Content-Type': 'application/x-www-form-urlencoded; charset=UTF-8'
};
fetchOptions.body = formParams;
}
fetch(fetchUrl, fetchOptions)
.then(function(response) {
return response.text();
})
.then(function(result) {
console.log('pdOneAjaxFormHandler success; length:', (result || '').length);
var moduleContainerSelector = '#pdModuleContent';
var moduleContainer = form.closest(moduleContainerSelector);
if (moduleContainer) {
moduleContainer.outerHTML = result;
}
if (currModule === 'mod_myRewards' && pdShouldUseRewards2025() && !pdRewardsForceLegacy) {
console.log('pdOneAjaxFormHandler: running pdRunScriptsIn for mod_myRewards.');
pdRunScriptsIn(document.querySelector(moduleContainerSelector));
}
})
.catch(function(errMsg) {
console.log('pdOneAjaxFormHandler error', errMsg);
});
}var script = document.createElement('style');
script.setAttribute('type', 'text/css');
script.innerHTML = ``;
document.getElementsByTagName('head')[0].appendChild(script);
var pdOneBannerEl = document.getElementById('pd_pdOneBanner');
if (pdOneBannerEl) {
//*** BANNER ALREADY EXISTS, DO NOT RE-INSERT
} else {
pdOneBannerEl = document.createElement('div');
pdOneBannerEl.id = 'pd_pdOneBanner';
if (document.body && document.body.firstChild) {
document.body.insertBefore(pdOneBannerEl, document.body.firstChild);
} else if (document.body) {
document.body.appendChild(pdOneBannerEl);
}
}
if (pdOneBannerEl) { pdOneBannerEl.innerHTML = ""; }
//*** COMPLETION CALLBACK
try{pdContentRenderCompleted()}catch(e){};
//*** done.