Skip to content
(function () {
/* ---------- 1) Rewrite chip hrefs to pretty URL ---------- */
function cityFromPath() {
var segs = location.pathname.split('/').filter(Boolean);
return segs[0] || 'nyc';
}
function buildUrl(city, slug) { return '/' + city + '/' + slug + '/'; }
function rewriteChipLinks(scope) {
var city = cityFromPath();
var sel = '.wpgb-card a[href*="/jewish-events/category/"], .wpgb-card .event-chips a';
var chips = (scope || document).querySelectorAll(sel);
chips.forEach(function (a) {
var href = a.getAttribute('href') || '';
var parts = href.split('/').filter(Boolean);
var slug = parts[parts.length - 1];
if (!slug) return;
a.setAttribute('href', buildUrl(city, slug));
});
}
function onDomReady(cb){
if (document.readyState !== 'loading') return cb();
document.addEventListener('DOMContentLoaded', cb);
}
onDomReady(function(){ rewriteChipLinks(); });
document.addEventListener('wpgbRefreshed', function(e){ rewriteChipLinks(e.target); });
/* ---------- 2) Prefilter grid on /{city}/{term}/ ---------- */
// term = second path segment (e.g., /nyc/speed-dating/)
var pathSegs = location.pathname.split('/').filter(Boolean);
var term = (pathSegs.length >= 2) ? pathSegs[1] : null;
if (!term) return; // normal city page
var FACET_SELECTOR =
'.wpgb-facet[data-facet="event_type"], .wpgb-facet[data-taxonomy="tribe_events_cat"], .wpgb-facet--taxonomy';
function tryPreselect() {
var facet = document.querySelector(FACET_SELECTOR);
if (!facet) return false;
// Try several ways facets store the slug
var input =
facet.querySelector('input[value="' + term + '"]') ||
facet.querySelector('[data-slug="' + term + '"]') ||
facet.querySelector('input[value$="/' + term + '"]');
if (!input) return false;
// Select & trigger filter
if ((input.type === 'checkbox' || input.type === 'radio')) {
if (!input.checked) input.checked = true;
input.dispatchEvent(new Event('change', { bubbles: true }));
} else {
var li = input.closest('li, .wpgb-choice'); if (li) li.click();
}
return true;
}
// Wait for WPGB markup; poll briefly + re-run after WPGB signals refresh/ready
var attempts = 0, maxAttempts = 20;
function poll() {
if (tryPreselect() || attempts++ >= maxAttempts) return;
setTimeout(poll, 150);
}
onDomReady(poll);
document.addEventListener('wpgbReady', poll);
document.addEventListener('wpgbRefreshed', poll);
})();