@onsvisual/svelte-components 1.1.47 → 1.1.49
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -64,7 +64,7 @@
|
|
|
64
64
|
*/
|
|
65
65
|
export let legacy = false;
|
|
66
66
|
/**
|
|
67
|
-
* Optional: Pass the "page"
|
|
67
|
+
* Optional: Pass the "page" state from "$app/state" in SvelteKit (gets read from context by default if it exists)
|
|
68
68
|
* @type {any}
|
|
69
69
|
*/
|
|
70
70
|
export let page = getContext("page");
|
|
@@ -87,8 +87,9 @@
|
|
|
87
87
|
let path = "";
|
|
88
88
|
let activeLink = null;
|
|
89
89
|
|
|
90
|
-
function setPaths() {
|
|
91
|
-
|
|
90
|
+
function setPaths(page) {
|
|
91
|
+
if (!page) return;
|
|
92
|
+
const url = page.url;
|
|
92
93
|
lang = url.host.startsWith("cy") ? "cy" : "en";
|
|
93
94
|
baseurl = lang === "cy" ? "https://cy.ons.gov.uk" : "https://www.ons.gov.uk";
|
|
94
95
|
baseother = lang === "cy" ? "https://www.ons.gov.uk" : "https://cy.ons.gov.uk";
|
|
@@ -115,24 +116,22 @@
|
|
|
115
116
|
Cymraeg: "English",
|
|
116
117
|
"Newid iaith i": "Change language to"
|
|
117
118
|
};
|
|
118
|
-
|
|
119
119
|
$: i18n = (text) => (lang === "cy" && texts[text] ? texts[text] : text);
|
|
120
120
|
|
|
121
121
|
onMount(() => {
|
|
122
|
-
setPaths();
|
|
122
|
+
setPaths(page || { url: document?.location });
|
|
123
123
|
|
|
124
124
|
if ((!compact && !legacy) || (title && Array.isArray(navLinks))) {
|
|
125
|
-
const hasBodyClass = "className" in document
|
|
126
|
-
const bodyClassString = document
|
|
125
|
+
const hasBodyClass = "className" in document?.body || {};
|
|
126
|
+
const bodyClassString = document?.body?.className || "";
|
|
127
127
|
if (hasBodyClass && !bodyClassString.includes("ons-js-enabled"))
|
|
128
128
|
document.body.className = bodyClassString + " ons-js-enabled";
|
|
129
129
|
initNav(el?.parentElement || document);
|
|
130
130
|
}
|
|
131
131
|
});
|
|
132
|
+
$: setPaths(page);
|
|
132
133
|
</script>
|
|
133
134
|
|
|
134
|
-
<svelte:window onpopstate={setPaths} />
|
|
135
|
-
|
|
136
135
|
<header
|
|
137
136
|
class="ons-header"
|
|
138
137
|
class:ons-header--basic={!compact && !legacy}
|