@onsvisual/svelte-components 1.1.46 → 1.1.48
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");
|
|
@@ -81,18 +81,21 @@
|
|
|
81
81
|
|
|
82
82
|
let el; // Header HTML element
|
|
83
83
|
|
|
84
|
-
let
|
|
84
|
+
let _page;
|
|
85
85
|
let lang = "en";
|
|
86
86
|
let baseurl = "https://www.ons.gov.uk";
|
|
87
87
|
let baseother = "https://cy.ons.gov.uk";
|
|
88
88
|
let path = "";
|
|
89
|
+
let activeLink = null;
|
|
89
90
|
|
|
90
|
-
function setPaths() {
|
|
91
|
-
|
|
91
|
+
function setPaths(page) {
|
|
92
|
+
if (!page) return;
|
|
93
|
+
const url = page.url;
|
|
92
94
|
lang = url.host.startsWith("cy") ? "cy" : "en";
|
|
93
95
|
baseurl = lang === "cy" ? "https://cy.ons.gov.uk" : "https://www.ons.gov.uk";
|
|
94
96
|
baseother = lang === "cy" ? "https://www.ons.gov.uk" : "https://cy.ons.gov.uk";
|
|
95
97
|
path = url.pathname;
|
|
98
|
+
activeLink = Array.isArray(navLinks) ? getActiveLink(navLinks, path) : null;
|
|
96
99
|
}
|
|
97
100
|
|
|
98
101
|
function getActiveLink(navLinks, path) {
|
|
@@ -114,22 +117,21 @@
|
|
|
114
117
|
Cymraeg: "English",
|
|
115
118
|
"Newid iaith i": "Change language to"
|
|
116
119
|
};
|
|
117
|
-
|
|
118
120
|
$: i18n = (text) => (lang === "cy" && texts[text] ? texts[text] : text);
|
|
119
|
-
$: activeLink =
|
|
120
|
-
Array.isArray(navLinks) && url?.pathname ? getActiveLink(navLinks, url.pathname) : null;
|
|
121
121
|
|
|
122
122
|
onMount(() => {
|
|
123
|
+
_page = page || { url: document?.location };
|
|
123
124
|
setPaths();
|
|
124
125
|
|
|
125
126
|
if ((!compact && !legacy) || (title && Array.isArray(navLinks))) {
|
|
126
|
-
const hasBodyClass = "className" in document
|
|
127
|
-
const bodyClassString = document
|
|
127
|
+
const hasBodyClass = "className" in document?.body || {};
|
|
128
|
+
const bodyClassString = document?.body?.className || "";
|
|
128
129
|
if (hasBodyClass && !bodyClassString.includes("ons-js-enabled"))
|
|
129
130
|
document.body.className = bodyClassString + " ons-js-enabled";
|
|
130
131
|
initNav(el?.parentElement || document);
|
|
131
132
|
}
|
|
132
133
|
});
|
|
134
|
+
$: setPaths(_page);
|
|
133
135
|
</script>
|
|
134
136
|
|
|
135
137
|
<header
|