Roster-page
(function () {
if (window.__vh_modal_initialized) return;
window.__vh_modal_initialized = true;
var SKATER_PAGE = ‘https://virtualhockeyassociation.com/player-history/’;
var GOALIE_PAGE = ‘https://virtualhockeyassociation.com/goalie-history/’;
var modal = document.getElementById(‘vh-modal’);
var frame = document.getElementById(‘vh-frame’);
var titleEl = document.getElementById(‘vh-title’);
var loading = document.getElementById(‘vh-loading’);
var closeEl = document.getElementById(‘vh-close’);
if (!modal || !frame || !titleEl || !loading) {
console.warn(‘[VH modal] Missing modal shell.’);
return;
}
function buildUrl(type, first, last, name) {
var base = (String(type).toLowerCase() === ‘goalie’) ? GOALIE_PAGE : SKATER_PAGE;
var qs = new URLSearchParams();
if (first) qs.set(‘wdt_var2’, first.trim());
if (last) qs.set(‘wdt_var3’, last.trim());
if (name) qs.set(‘wdt_var4’, name.trim());
qs.set(‘t’, Date.now().toString()); // defeat caches
return base + ‘?’ + qs.toString();
}
function resolve(a){
var type = (a.getAttribute(‘data-type’) || ‘skater’).trim().toLowerCase();
var name = (a.getAttribute(‘data-player’) || a.textContent).trim();
var first = (a.getAttribute(‘data-first’) || ”).trim();
var last = (a.getAttribute(‘data-last’) || ”).trim();
if ((!first || !last) && name) {
var parts = name.split(/\s+/);
if (parts.length >= 2) { last = last || parts.pop(); first = first || parts.join(‘ ‘); }
}
// Prefer a valid href that already points to a history page
var href = a.getAttribute(‘href’) || ”;
if (/\/(player|goalie)-history\//.test(href)) {
try { var u = new URL(href, location.origin); u.searchParams.set(‘t’, Date.now()); href = u.toString(); }
catch(e){ href = href + (href.indexOf(‘?’)===-1?’?’:’&’) + ‘t=’ + Date.now(); }
return { url: href, type: type, name: name };
}
// Otherwise, build it from the data-*
return { url: buildUrl(type, first, last, name), type: type, name: name };
}
function openModal(res){
titleEl.textContent = ‘Previous seasons for ‘ + res.name + (res.type === ‘goalie’ ? ‘ (G)’ : ”);
loading.style.display = ‘flex’;
frame.src = res.url;
modal.style.display = ‘block’;
document.documentElement.style.overflow = ‘hidden’;
console.log(‘[VH modal] →’, res.url);
}
document.addEventListener(‘click’, function(e){
var a = e.target.closest(‘a.md-open’);
if (!a) return;
e.preventDefault();
e.stopPropagation();
e.stopImmediatePropagation();
openModal(resolve(a));
});
function closeModal(){
modal.style.display=’none’;
frame.src=”;
document.documentElement.style.overflow=”;
}
if (closeEl) closeEl.addEventListener(‘click’, closeModal);
modal.addEventListener(‘click’, function(e){ if (e.target === modal) closeModal(); });
document.addEventListener(‘keydown’, function(e){ if (e.key === ‘Escape’) closeModal(); });
frame.addEventListener(‘load’, function(){ loading.style.display=’none’; });
})();
// Force correct hrefs on all roster links (even if the template didn’t render them)
document.addEventListener(‘DOMContentLoaded’, function () {
var SKATER_PAGE = ‘https://virtualhockeyassociation.com/player-history/’;
var GOALIE_PAGE = ‘https://virtualhockeyassociation.com/goalie-history/’;
document.querySelectorAll(‘a.md-open’).forEach(function (a) {
var type = (a.getAttribute(‘data-type’) || ‘skater’).toLowerCase();
var first = (a.getAttribute(‘data-first’) || ”).trim();
var last = (a.getAttribute(‘data-last’) || ”).trim();
var name = (a.getAttribute(‘data-player’) || a.textContent).trim();
// fallback: split full name if first/last missing
if ((!first || !last) && name) {
var parts = name.split(/\s+/);
if (parts.length >= 2) { last = last || parts.pop(); first = first || parts.join(‘ ‘); }
}
var base = (type === ‘goalie’) ? GOALIE_PAGE : SKATER_PAGE;
var url = base + ‘?wdt_var2=’ + encodeURIComponent(first)
+ ‘&wdt_var3=’ + encodeURIComponent(last)
+ ‘&wdt_var4=’ + encodeURIComponent(name);
a.setAttribute(‘href’, url); // ✅ now hover shows the right URL
a.style.cursor = ‘pointer’;
});
});