Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 21 additions & 2 deletions packages/pxweb2/index.html
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
<!DOCTYPE html>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title>Pxweb2</title>
<title>Statistikkbanken – SSB</title>
<base href="/" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<link rel="icon" type="image/svg+xml" href="./images/favicon.svg" />
Expand All @@ -14,6 +14,7 @@
/>
<link rel="stylesheet" href="src/styles.scss" />
<link rel="stylesheet" href="./theme/variables.css?v=__BUILD_DATE__" />

<link
rel="preload"
href="./fonts/PxWeb-font-500.ttf"
Expand Down Expand Up @@ -56,7 +57,25 @@
crossorigin="anonymous"
type="font/ttf"
/>

<script src="./config/config.js?v=__BUILD_DATE__"></script>
<!-- <script
nonce="d2901284faf3e34fd9ce916ebd2a0271"
type="module"
crossorigin
src="./assets/index-DrUrJEPE.js"
></script> -->
<link rel="stylesheet" crossorigin href="./assets/index-DCpT_v70.css" />
<link
rel="stylesheet"
href="./theme/variables.css?v=2026-06-22T10:48:59.880Z"
/>
<link rel="stylesheet" href="./ssbstyle.css" />
<script
nonce="d2901284faf3e34fd9ce916ebd2a0271"
src="./ssbscript.js"
type="module"
></script>
</head>
<body>
<div id="root"></div>
Expand Down
47 changes: 37 additions & 10 deletions packages/pxweb2/public/config/config.js
Original file line number Diff line number Diff line change
@@ -1,28 +1,55 @@
globalThis.PxWeb2Config = {
window.PxWeb2Config = {
language: {
supportedLanguages: [
{ shorthand: 'no', languageName: 'Norsk' },
{ shorthand: 'en', languageName: 'English' },
{ shorthand: 'sv', languageName: 'Svenska' },
],
defaultLanguage: 'en',
defaultLanguage: 'no',
fallbackLanguage: 'en',
showDefaultLanguageInPath: true,
positionInPath: 'after',
showDefaultLanguageInPath: false,
positionInPath: 'before',
},
baseApplicationPath: '/',
apiUrl: 'https://api.scb.se/OV0104/v2beta/api/v2',
apiUrl: 'https://data.ssb.no/api/pxwebapi/v2',
maxDataCells: 150000,
useDynamicContentInTitle: false,
showBreadCrumbOnStartPage: false,
showBreadCrumbOnStartPage: true,
specialCharacters: ['.', '..', ':', '-', '...', '*'],
variableFilterExclusionList: {
no: [
'statistikkvariabel',
'år',
'kvartal',
'måned',
'uke',
'driftsår',
'enkeltår',
'intervall (år)',
'halvår',
'kvartal (u)',
'termin',
'toårlig',
'fireårlig',
'femårlig',
],
en: [
'observations',
'year',
'quarter',
'month',
'every other year',
'every fifth year',
'contents',
'half year',
'quarter (u)',
'termin',
'week',
'single years',
'biannual',
'every 4th year',
'every 5th year',
'interval (year)',
'driftsår',
'every ten years',
],
sv: [
'tabellinnehåll',
Expand All @@ -35,7 +62,7 @@ globalThis.PxWeb2Config = {
],
},
homePage: {
sv: '', // Set to your Swedish homepage URL
en: '', // Set to your English homepage URL
no: '/',
en: '/en/',
},
};
148 changes: 148 additions & 0 deletions packages/pxweb2/ssbscript.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,148 @@
(function () {
const WIP_STATUS_TEXT = {
en: {
before:
"Welcome to the new Statbank! We're still fine-tuning things. If something is missing, you can still ",
linkText: 'access the old version',
},
no: {
before:
'Velkommen til nye Statistikkbanken! Vi jobber med de siste detaljene. Skulle du savne noe, kan du fortsatt ',
linkText: 'bruke den gamle løsningen',
},
};

function checkLanguage() {
const url = new URL(globalThis.location.href);
if (url.pathname.includes('/en/')) {
return 'en';
} else {
return 'no';
}
}
/**
* Fires update() on initial load and on every SPA navigation:
* - history.pushState / replaceState (programmatic navigation)
* - popstate (back/forward)
*/
function computeTransformedUrl() {
const url = new URL(globalThis.location.href);
const newUrl = url.pathname.replace('/statbank', '/statbank1');
return newUrl.toString();
}
// ---------------------------------------------
// Track last language to detect language changes
// ---------------------------------------------
let lastLang = null;

function update() {
const bodyLong = document.querySelector(
'#wip-status-message div[class*="bodylong"]',
);
if (!bodyLong) {
return;
}

const language = checkLanguage();
const content = WIP_STATUS_TEXT[language] || WIP_STATUS_TEXT.no;
const before = document.createTextNode(content.before);
const newUrl = computeTransformedUrl();
const linkId = 'myLink';

const link = document.createElement('a');
link.id = linkId;
link.className = 'oldLinkClass';
link.href = newUrl;
link.textContent = content.linkText;
link.target = '_blank'; // open in new tab
link.rel = 'noopener noreferrer'; // safe when target=_blank

const after = document.createTextNode('.');
bodyLong.textContent = '';

bodyLong.appendChild(before);
bodyLong.appendChild(link);
bodyLong.appendChild(after);
// ---------------------------------------------
// Cookie Banner Language Sync
// ---------------------------------------------
if (language !== lastLang) {
// Language changed => reinitialize banner content
const content = bannerContent[language];
initCookieConsent(content);
lastLang = language;
}
}

function scheduleUpdate() {
update();
requestAnimationFrame(update);
setTimeout(update, 400);
}

// Patch pushState / replaceState to emit a custom event
['pushState', 'replaceState'].forEach((method) => {
const original = history[method];
history[method] = function () {
const ret = original.apply(this, arguments);
globalThis.dispatchEvent(new Event('rr-nav')); // custom event for SPA navigation
return ret;
};
});

// --- Persistent link binder setup ---
let boundResetLink = null;

function onResetConsentClick(e) {
e.preventDefault();
if (typeof resetCookieConsent === 'function') {
resetCookieConsent();
}
}

function bindResetConsentLink() {
const language = checkLanguage();
const link = document.querySelector(
`a[href$="change-cookie-consent-${language}"]`,
);

if (boundResetLink && !boundResetLink.isConnected) {
boundResetLink = null;
}

if (link && link !== boundResetLink) {
boundResetLink = link;
link.addEventListener('click', onResetConsentClick);
}

if (!link) {
boundResetLink = null;
}
}

// --- No observer: rebind on known lifecycle/navigation points ---
function scheduleBindResetConsentLink() {
// immediate attempt
bindResetConsentLink();
// after paint (for SPA updates that render slightly later)
requestAnimationFrame(bindResetConsentLink);
// delayed fallback (for async content loading)
setTimeout(bindResetConsentLink, 600);
}

function onNavigationUpdate() {
scheduleBindResetConsentLink();
scheduleUpdate();
}

// --- Bind on initial DOM load ---
document.addEventListener('DOMContentLoaded', () => {
scheduleBindResetConsentLink();
scheduleUpdate();
});

// --- Bind on SPA navigation & back/forward ---
globalThis.addEventListener('rr-nav', onNavigationUpdate);

globalThis.addEventListener('popstate', onNavigationUpdate);
})();
Loading
Loading