@kth/style 1.14.2 → 1.15.0-alpha.1
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.
- package/README.md +76 -4
- package/dist/backtotop.js +57 -0
- package/dist/cjs/index.js +276 -0
- package/dist/cjs/types/index.d.ts +2 -0
- package/dist/consent/klaro-no-css.js +6324 -0
- package/dist/consent/klaro.css +820 -0
- package/dist/consent/kth-klaro.scss +286 -0
- package/dist/esm/index.js +276 -0
- package/dist/icons/legacy/scss/_svg_data.scss +194 -0
- package/dist/icons/legacy/svg/arrow-back-black.svg +5 -0
- package/dist/icons/legacy/svg/arrow-back-blue.svg +5 -0
- package/dist/icons/legacy/svg/arrow-back-white.svg +5 -0
- package/dist/icons/legacy/svg/arrow-collapse-black.svg +1 -0
- package/dist/icons/legacy/svg/arrow-collapse-blue.svg +5 -0
- package/dist/icons/legacy/svg/arrow-collapse-white.svg +5 -0
- package/dist/icons/legacy/svg/arrow-expand-black.svg +5 -0
- package/dist/icons/legacy/svg/arrow-expand-blue.svg +5 -0
- package/dist/icons/legacy/svg/arrow-expand-white.svg +5 -0
- package/dist/icons/legacy/svg/arrow-maximize-blue.svg +5 -0
- package/dist/icons/legacy/svg/arrow-minimize-blue.svg +5 -0
- package/dist/icons/legacy/svg/arrow-next-black.svg +5 -0
- package/dist/icons/legacy/svg/arrow-next-white.svg +5 -0
- package/dist/icons/legacy/svg/arrow-up-down-black.svg +5 -0
- package/dist/icons/legacy/svg/arrow-up-down-white.svg +5 -0
- package/dist/icons/legacy/svg/asterisk-black.svg +5 -0
- package/dist/icons/legacy/svg/audio-blue.svg +5 -0
- package/dist/icons/legacy/svg/audio-white.svg +5 -0
- package/dist/icons/legacy/svg/back-to-top-blue.svg +6 -0
- package/dist/icons/legacy/svg/calculate-blue.svg +5 -0
- package/dist/icons/legacy/svg/check-black.svg +5 -0
- package/dist/icons/legacy/svg/close-black.svg +5 -0
- package/dist/icons/legacy/svg/close-white.svg +1 -0
- package/dist/icons/legacy/svg/code-blue.svg +5 -0
- package/dist/icons/legacy/svg/code-white.svg +5 -0
- package/dist/icons/legacy/svg/compressed-blue.svg +13 -0
- package/dist/icons/legacy/svg/compressed-white.svg +13 -0
- package/dist/icons/legacy/svg/copy-blue.svg +5 -0
- package/dist/icons/legacy/svg/date-black.svg +5 -0
- package/dist/icons/legacy/svg/date-blue.svg +5 -0
- package/dist/icons/legacy/svg/date-white.svg +5 -0
- package/dist/icons/legacy/svg/delete-blue.svg +5 -0
- package/dist/icons/legacy/svg/doc-blue.svg +5 -0
- package/dist/icons/legacy/svg/doc-white.svg +5 -0
- package/dist/icons/legacy/svg/download-blue.svg +5 -0
- package/dist/icons/legacy/svg/download-white.svg +5 -0
- package/dist/icons/legacy/svg/edit-blue.svg +5 -0
- package/dist/icons/legacy/svg/email-white.svg +5 -0
- package/dist/icons/legacy/svg/error-black.svg +5 -0
- package/dist/icons/legacy/svg/eye-black.svg +5 -0
- package/dist/icons/legacy/svg/eye-blue.svg +5 -0
- package/dist/icons/legacy/svg/eye-off-black.svg +5 -0
- package/dist/icons/legacy/svg/eye-off-blue.svg +5 -0
- package/dist/icons/legacy/svg/favorite-active-blue.svg +5 -0
- package/dist/icons/legacy/svg/favorite-blue.svg +5 -0
- package/dist/icons/legacy/svg/file-blue.svg +5 -0
- package/dist/icons/legacy/svg/file-white.svg +5 -0
- package/dist/icons/legacy/svg/filter-blue.svg +5 -0
- package/dist/icons/legacy/svg/folder-blue.svg +5 -0
- package/dist/icons/legacy/svg/folder-white.svg +5 -0
- package/dist/icons/legacy/svg/gallery-active-black.svg +5 -0
- package/dist/icons/legacy/svg/gallery-back-black.svg +5 -0
- package/dist/icons/legacy/svg/gallery-next-black.svg +5 -0
- package/dist/icons/legacy/svg/gallery-passive-black.svg +5 -0
- package/dist/icons/legacy/svg/gallery-pause-black.svg +5 -0
- package/dist/icons/legacy/svg/gallery-play-black.svg +5 -0
- package/dist/icons/legacy/svg/image-blue.svg +5 -0
- package/dist/icons/legacy/svg/image-white.svg +5 -0
- package/dist/icons/legacy/svg/information-black.svg +5 -0
- package/dist/icons/legacy/svg/language-black.svg +5 -0
- package/dist/icons/legacy/svg/language-white.svg +1 -0
- package/dist/icons/legacy/svg/link-black.svg +5 -0
- package/dist/icons/legacy/svg/link-blue.svg +1 -0
- package/dist/icons/legacy/svg/menu-black.svg +8 -0
- package/dist/icons/legacy/svg/message-white.svg +5 -0
- package/dist/icons/legacy/svg/notification-white.svg +5 -0
- package/dist/icons/legacy/svg/open-modal-blue.svg +5 -0
- package/dist/icons/legacy/svg/open-window-black.svg +5 -0
- package/dist/icons/legacy/svg/open-window-blue.svg +5 -0
- package/dist/icons/legacy/svg/open-window-white.svg +5 -0
- package/dist/icons/legacy/svg/page-first-black.svg +5 -0
- package/dist/icons/legacy/svg/page-last-black.svg +5 -0
- package/dist/icons/legacy/svg/pdf-blue.svg +6 -0
- package/dist/icons/legacy/svg/pdf-white.svg +6 -0
- package/dist/icons/legacy/svg/ppt-blue.svg +5 -0
- package/dist/icons/legacy/svg/ppt-white.svg +5 -0
- package/dist/icons/legacy/svg/print-blue.svg +5 -0
- package/dist/icons/legacy/svg/quote-black.svg +5 -0
- package/dist/icons/legacy/svg/quote-white.svg +5 -0
- package/dist/icons/legacy/svg/scale-blue.svg +5 -0
- package/dist/icons/legacy/svg/search-blue.svg +5 -0
- package/dist/icons/legacy/svg/settings-blue.svg +5 -0
- package/dist/icons/legacy/svg/sort-ascending-white.svg +5 -0
- package/dist/icons/legacy/svg/sort-descending-white.svg +5 -0
- package/dist/icons/legacy/svg/success-black.svg +5 -0
- package/dist/icons/legacy/svg/text-blue.svg +5 -0
- package/dist/icons/legacy/svg/text-white.svg +5 -0
- package/dist/icons/legacy/svg/thumb-down-blue.svg +5 -0
- package/dist/icons/legacy/svg/thumb-up-blue.svg +5 -0
- package/dist/icons/legacy/svg/upload-blue.svg +5 -0
- package/dist/icons/legacy/svg/upload-white.svg +5 -0
- package/dist/icons/legacy/svg/user-management-blue.svg +5 -0
- package/dist/icons/legacy/svg/video-blue.svg +5 -0
- package/dist/icons/legacy/svg/video-white.svg +5 -0
- package/dist/icons/legacy/svg/xls-blue.svg +5 -0
- package/dist/icons/legacy/svg/xls-white.svg +5 -0
- package/dist/menus.js +227 -0
- package/package.json +3 -1
- package/scss/components/backtotop.scss +24 -0
- package/scss/components/commonStyle.scss +91 -0
package/README.md
CHANGED
|
@@ -22,7 +22,79 @@ Documentation available in the [KTH Style website](https://intra.kth.se/style)
|
|
|
22
22
|
```
|
|
23
23
|
|
|
24
24
|
- `scss` contains all CSS. Those can be imported as they are
|
|
25
|
-
- `src` contains source for JavaScript components
|
|
26
|
-
- `src/components`
|
|
27
|
-
- `index.ts`
|
|
28
|
-
- `assets`
|
|
25
|
+
- `src` contains TypeScript source for JavaScript components
|
|
26
|
+
- `src/components` contains the package components
|
|
27
|
+
- `index.ts` defines the package's public JavaScript exports
|
|
28
|
+
- `assets` contains static assets such as fonts and the logotype. These assets can be exposed by applications using KTH Style
|
|
29
|
+
|
|
30
|
+
## Installation
|
|
31
|
+
|
|
32
|
+
Install the package with npm:
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install @kth/style
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
## Usage
|
|
39
|
+
|
|
40
|
+
Import JavaScript components from the package:
|
|
41
|
+
|
|
42
|
+
```ts
|
|
43
|
+
import { MenuPanel } from "@kth/style";
|
|
44
|
+
```
|
|
45
|
+
|
|
46
|
+
Import SCSS files directly when needed:
|
|
47
|
+
|
|
48
|
+
```scss
|
|
49
|
+
@use "@kth/style/scss/components/button";
|
|
50
|
+
@use "@kth/style/scss/tokens/colors";
|
|
51
|
+
```
|
|
52
|
+
|
|
53
|
+
## Development
|
|
54
|
+
|
|
55
|
+
Run package commands from the repository root with npm workspaces:
|
|
56
|
+
|
|
57
|
+
```bash
|
|
58
|
+
npm install
|
|
59
|
+
npm run dev -w @kth/style
|
|
60
|
+
npm test -w @kth/style
|
|
61
|
+
npm run build -w @kth/style
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Alternatively, run the package scripts from this directory:
|
|
65
|
+
|
|
66
|
+
```bash
|
|
67
|
+
cd @kth/style
|
|
68
|
+
npm run dev
|
|
69
|
+
npm test
|
|
70
|
+
npm run build
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
The package exposes JavaScript components through the package root and SCSS files through the `scss` export. Refer to the source and the [KTH Style website](https://intra.kth.se/style) for the complete component documentation.
|
|
74
|
+
|
|
75
|
+
## Release process
|
|
76
|
+
|
|
77
|
+
Before creating the release, it is recommended to run the checks locally:
|
|
78
|
+
|
|
79
|
+
```bash
|
|
80
|
+
npm test
|
|
81
|
+
npm run build
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
Run the release command from the repository root:
|
|
85
|
+
|
|
86
|
+
```bash
|
|
87
|
+
npm run lerna:version
|
|
88
|
+
```
|
|
89
|
+
|
|
90
|
+
Lerna updates the package version, creates the release commit, and creates a Git tag. It does not push the changes or publish the package. The package must have changes since the previous release, but those changes do not need to be pushed before running this command.
|
|
91
|
+
|
|
92
|
+
After `lerna:version` completes, push the release commit and tag:
|
|
93
|
+
|
|
94
|
+
```bash
|
|
95
|
+
git push --follow-tags
|
|
96
|
+
```
|
|
97
|
+
|
|
98
|
+
Publishing to npm is handled by the CI pipeline when a version tag, such as `@kth/style@1.14.3`, is pushed. Do not run `npm publish` manually unless the pipeline documentation instructs you to do so.
|
|
99
|
+
|
|
100
|
+
Finally, create a release note and announce the release in the Developer channel on Slack.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
(function () {
|
|
2
|
+
'use strict';
|
|
3
|
+
|
|
4
|
+
/* eslint-disable func-names */ /* eslint-disable no-var */ window.addEventListener(
|
|
5
|
+
"load",
|
|
6
|
+
() => {
|
|
7
|
+
/**
|
|
8
|
+
* Back to top link
|
|
9
|
+
*/ var lastKnownScrollPosition = 0;
|
|
10
|
+
var ticking = false;
|
|
11
|
+
var backToTopButton = document.querySelector("#back-to-top");
|
|
12
|
+
if (!backToTopButton) {
|
|
13
|
+
backToTopButton = document.createElement("div");
|
|
14
|
+
backToTopButton = document.body.appendChild(backToTopButton);
|
|
15
|
+
backToTopButton.id = "back-to-top";
|
|
16
|
+
backToTopButton.setAttribute("role", "link");
|
|
17
|
+
backToTopButton.setAttribute("aria-hidden", "true");
|
|
18
|
+
if (document.documentElement.lang === "sv-SE") {
|
|
19
|
+
backToTopButton.innerText = "Till sidans topp";
|
|
20
|
+
} else {
|
|
21
|
+
backToTopButton.innerText = "To page top";
|
|
22
|
+
}
|
|
23
|
+
if (document.querySelector("footer")) {
|
|
24
|
+
document.body.insertBefore(
|
|
25
|
+
backToTopButton,
|
|
26
|
+
document.querySelector("footer"),
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
backToTopButton.addEventListener("click", function () {
|
|
31
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
32
|
+
this.classList.toggle("show");
|
|
33
|
+
this.setAttribute("aria-hidden", true);
|
|
34
|
+
});
|
|
35
|
+
function handleBackToTop(scrollPos) {
|
|
36
|
+
if (scrollPos > 200) {
|
|
37
|
+
backToTopButton.classList.add("show");
|
|
38
|
+
backToTopButton.removeAttribute("aria-hidden");
|
|
39
|
+
} else {
|
|
40
|
+
backToTopButton.classList.remove("show");
|
|
41
|
+
backToTopButton.setAttribute("aria-hidden", true);
|
|
42
|
+
}
|
|
43
|
+
}
|
|
44
|
+
window.addEventListener("scroll", () => {
|
|
45
|
+
lastKnownScrollPosition = window.scrollY;
|
|
46
|
+
if (!ticking) {
|
|
47
|
+
window.requestAnimationFrame(() => {
|
|
48
|
+
handleBackToTop(lastKnownScrollPosition);
|
|
49
|
+
ticking = false;
|
|
50
|
+
});
|
|
51
|
+
ticking = true;
|
|
52
|
+
}
|
|
53
|
+
});
|
|
54
|
+
},
|
|
55
|
+
);
|
|
56
|
+
|
|
57
|
+
})();
|
package/dist/cjs/index.js
CHANGED
|
@@ -124,4 +124,280 @@ class MenuPanel {
|
|
|
124
124
|
}
|
|
125
125
|
}
|
|
126
126
|
|
|
127
|
+
/* eslint-disable func-names */ /* eslint-disable no-var */ window.addEventListener(
|
|
128
|
+
"load",
|
|
129
|
+
() => {
|
|
130
|
+
/**
|
|
131
|
+
* Back to top link
|
|
132
|
+
*/ var lastKnownScrollPosition = 0;
|
|
133
|
+
var ticking = false;
|
|
134
|
+
var backToTopButton = document.querySelector("#back-to-top");
|
|
135
|
+
if (!backToTopButton) {
|
|
136
|
+
backToTopButton = document.createElement("div");
|
|
137
|
+
backToTopButton = document.body.appendChild(backToTopButton);
|
|
138
|
+
backToTopButton.id = "back-to-top";
|
|
139
|
+
backToTopButton.setAttribute("role", "link");
|
|
140
|
+
backToTopButton.setAttribute("aria-hidden", "true");
|
|
141
|
+
if (document.documentElement.lang === "sv-SE") {
|
|
142
|
+
backToTopButton.innerText = "Till sidans topp";
|
|
143
|
+
} else {
|
|
144
|
+
backToTopButton.innerText = "To page top";
|
|
145
|
+
}
|
|
146
|
+
if (document.querySelector("footer")) {
|
|
147
|
+
document.body.insertBefore(
|
|
148
|
+
backToTopButton,
|
|
149
|
+
document.querySelector("footer"),
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
backToTopButton.addEventListener("click", function () {
|
|
154
|
+
window.scrollTo({ top: 0, behavior: "smooth" });
|
|
155
|
+
this.classList.toggle("show");
|
|
156
|
+
this.setAttribute("aria-hidden", true);
|
|
157
|
+
});
|
|
158
|
+
function handleBackToTop(scrollPos) {
|
|
159
|
+
if (scrollPos > 200) {
|
|
160
|
+
backToTopButton.classList.add("show");
|
|
161
|
+
backToTopButton.removeAttribute("aria-hidden");
|
|
162
|
+
} else {
|
|
163
|
+
backToTopButton.classList.remove("show");
|
|
164
|
+
backToTopButton.setAttribute("aria-hidden", true);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
window.addEventListener("scroll", () => {
|
|
168
|
+
lastKnownScrollPosition = window.scrollY;
|
|
169
|
+
if (!ticking) {
|
|
170
|
+
window.requestAnimationFrame(() => {
|
|
171
|
+
handleBackToTop(lastKnownScrollPosition);
|
|
172
|
+
ticking = false;
|
|
173
|
+
});
|
|
174
|
+
ticking = true;
|
|
175
|
+
}
|
|
176
|
+
});
|
|
177
|
+
},
|
|
178
|
+
);
|
|
179
|
+
|
|
180
|
+
/* eslint-disable no-var */ /* eslint-disable vars-on-top */ /* eslint-disable no-use-before-define */ function klaroOnload() {
|
|
181
|
+
var klaro = document.querySelector("#klaro div.klaro");
|
|
182
|
+
function noVisibleKlaro() {
|
|
183
|
+
return (
|
|
184
|
+
!klaro ||
|
|
185
|
+
window.getComputedStyle(klaro).display === "none" ||
|
|
186
|
+
klaro.querySelector("a") === null
|
|
187
|
+
);
|
|
188
|
+
}
|
|
189
|
+
if (noVisibleKlaro()) {
|
|
190
|
+
return;
|
|
191
|
+
}
|
|
192
|
+
if (klaro !== document.body.firstElementChild) {
|
|
193
|
+
document.body.insertBefore(klaro, document.body.firstElementChild);
|
|
194
|
+
}
|
|
195
|
+
const getNextFocusableElement = function _getNextFocusableElement(
|
|
196
|
+
element,
|
|
197
|
+
step,
|
|
198
|
+
) {
|
|
199
|
+
var elements = Array.prototype.slice.call(
|
|
200
|
+
klaro.querySelectorAll(
|
|
201
|
+
"a:not([disabled]), button:not([disabled]), input:not([disabled])",
|
|
202
|
+
),
|
|
203
|
+
);
|
|
204
|
+
if (!elements) return null;
|
|
205
|
+
elements = elements.filter(
|
|
206
|
+
(e) => window.getComputedStyle(e).display !== "none",
|
|
207
|
+
);
|
|
208
|
+
for (var i = 0; i < elements.length; i++) {
|
|
209
|
+
if (elements[i] === element) {
|
|
210
|
+
if (i < elements.length - step) {
|
|
211
|
+
return elements[i + step];
|
|
212
|
+
}
|
|
213
|
+
return elements[0];
|
|
214
|
+
}
|
|
215
|
+
}
|
|
216
|
+
return elements[0];
|
|
217
|
+
};
|
|
218
|
+
const resetActiveLI = function _resetActiveLI() {
|
|
219
|
+
var elements = Array.prototype.slice.call(
|
|
220
|
+
klaro.querySelectorAll("li.active"),
|
|
221
|
+
);
|
|
222
|
+
if (!elements) return;
|
|
223
|
+
elements.forEach((e) => e.classList.remove("active"));
|
|
224
|
+
}; // eslint-disable-next-line no-shadow
|
|
225
|
+
const handleKeydown = (event) => {
|
|
226
|
+
if (noVisibleKlaro()) {
|
|
227
|
+
window.removeEventListener("keydown", handleKeydown);
|
|
228
|
+
return;
|
|
229
|
+
}
|
|
230
|
+
if (event.key === "Tab") {
|
|
231
|
+
const nextElement = getNextFocusableElement(
|
|
232
|
+
event.target,
|
|
233
|
+
event.shiftKey ? -1 : 1,
|
|
234
|
+
);
|
|
235
|
+
if (nextElement) {
|
|
236
|
+
event.preventDefault();
|
|
237
|
+
nextElement.focus();
|
|
238
|
+
resetActiveLI();
|
|
239
|
+
if (nextElement.tagName === "INPUT") {
|
|
240
|
+
nextElement.parentElement.closest("li").classList.add("active");
|
|
241
|
+
}
|
|
242
|
+
}
|
|
243
|
+
} else if (event.key === "Escape") {
|
|
244
|
+
const closeButton = klaro.querySelector(
|
|
245
|
+
"div.klaro .cookie-modal button.hide",
|
|
246
|
+
);
|
|
247
|
+
if (closeButton) {
|
|
248
|
+
closeButton.click();
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
};
|
|
252
|
+
window.addEventListener("keydown", handleKeydown);
|
|
253
|
+
const config = { childList: true, subtree: true, attributes: true };
|
|
254
|
+
const callback = function _callback(mutationsList) {
|
|
255
|
+
for (const mutation of mutationsList) {
|
|
256
|
+
if (mutation.type === "childList") {
|
|
257
|
+
if (mutation.addedNodes.length > 0) {
|
|
258
|
+
for (const node of mutation.addedNodes) {
|
|
259
|
+
if (node.nodeType === 1) {
|
|
260
|
+
if (node.classList.contains("cookie-modal")) {
|
|
261
|
+
var inputs = Array.prototype.slice.call(
|
|
262
|
+
node.querySelectorAll("input"),
|
|
263
|
+
);
|
|
264
|
+
for (const input of inputs) {
|
|
265
|
+
input.setAttribute("tabindex", "0");
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
}
|
|
269
|
+
}
|
|
270
|
+
} else if (mutation.removedNodes.length > 0) {
|
|
271
|
+
for (const node of mutation.removedNodes) {
|
|
272
|
+
if (node.nodeType === 1) {
|
|
273
|
+
if (
|
|
274
|
+
node.classList.contains("cn-body") ||
|
|
275
|
+
node.classList.contains("cookie-modal")
|
|
276
|
+
) {
|
|
277
|
+
window.removeEventListener("keydown", handleKeydown);
|
|
278
|
+
}
|
|
279
|
+
}
|
|
280
|
+
}
|
|
281
|
+
}
|
|
282
|
+
} else if (mutation.attributeName === "style") {
|
|
283
|
+
if (
|
|
284
|
+
window.getComputedStyle(klaro).getPropertyValue("display") === "none"
|
|
285
|
+
) {
|
|
286
|
+
window.removeEventListener("keydown", handleKeydown);
|
|
287
|
+
}
|
|
288
|
+
}
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const observer = new MutationObserver(callback);
|
|
292
|
+
observer.observe(klaro, config);
|
|
293
|
+
}
|
|
294
|
+
window.addEventListener("load", () => {
|
|
295
|
+
klaroOnload();
|
|
296
|
+
});
|
|
297
|
+
window.addEventListener("load", () => {
|
|
298
|
+
// If no mobile menu containers are present, skip it all togehter
|
|
299
|
+
if (
|
|
300
|
+
!document.getElementById("mobileMenuWrapper") ||
|
|
301
|
+
!document.getElementById("mobileMenuList") ||
|
|
302
|
+
!document.getElementById("mobileMenuContent") ||
|
|
303
|
+
!document.getElementById("nav-icon")
|
|
304
|
+
) {
|
|
305
|
+
return;
|
|
306
|
+
}
|
|
307
|
+
var mainMenu = document.getElementById("mainMenu"); // Get main menu
|
|
308
|
+
var megaMenu = document.getElementById("megaMenu"); // Get mega menu
|
|
309
|
+
var secondaryMenu = document.querySelector(".secondaryMenu"); // Get secondary menu
|
|
310
|
+
if (!mainMenu && !megaMenu && !secondaryMenu) {
|
|
311
|
+
document.getElementById("mobileMenuWrapper").style.display = "none"; // Hide mobile menu wrapper/container if there is no menus
|
|
312
|
+
}
|
|
313
|
+
if (mainMenu) {
|
|
314
|
+
// For main menu items, copy a link if it exists, otherwise copy the link content
|
|
315
|
+
createMobileMenuItems(mainMenu.querySelectorAll("li"), true);
|
|
316
|
+
} else if (megaMenu) {
|
|
317
|
+
// For mega menu items, copy only the the first alinks
|
|
318
|
+
createMobileMenuItems(megaMenu.querySelectorAll("li"), false);
|
|
319
|
+
}
|
|
320
|
+
if (secondaryMenu) {
|
|
321
|
+
createMobileMenuItemsForSecondaryMenu(
|
|
322
|
+
secondaryMenu.querySelectorAll("li a"),
|
|
323
|
+
);
|
|
324
|
+
}
|
|
325
|
+
function createMobileMenuItems(menuItems, includeInline) {
|
|
326
|
+
for (var i = 0; i < menuItems.length; i++) {
|
|
327
|
+
var linkToCopy = menuItems[i].querySelector("a");
|
|
328
|
+
if (linkToCopy || includeInline) {
|
|
329
|
+
var listItem = document.createElement("li");
|
|
330
|
+
listItem.className =
|
|
331
|
+
menuItems[i].className !== "" ? menuItems[i].className : "nav-item";
|
|
332
|
+
if (linkToCopy) {
|
|
333
|
+
var link = document.createElement("a");
|
|
334
|
+
link.href = linkToCopy.href;
|
|
335
|
+
link.text = linkToCopy.text;
|
|
336
|
+
link.className = linkToCopy.className;
|
|
337
|
+
listItem.appendChild(link);
|
|
338
|
+
} else if (includeInline) {
|
|
339
|
+
listItem.innerHTML = menuItems[i].innerHTML;
|
|
340
|
+
}
|
|
341
|
+
document.getElementById("mobileMenuList").appendChild(listItem);
|
|
342
|
+
}
|
|
343
|
+
}
|
|
344
|
+
}
|
|
345
|
+
function createMobileMenuItemsForSecondaryMenu(menuItems) {
|
|
346
|
+
var secondaryMenuWrapper = document.createElement("li");
|
|
347
|
+
secondaryMenuWrapper.className = "secondaryMenuWrap";
|
|
348
|
+
var secondaryMenuContainer = document.createElement("ul");
|
|
349
|
+
secondaryMenuContainer.className = "secondaryMenuContainer";
|
|
350
|
+
for (var i = 0; i < menuItems.length; i++) {
|
|
351
|
+
var link = document.createElement("a");
|
|
352
|
+
link.className = "secondaryMenu";
|
|
353
|
+
link.href = menuItems[i].href;
|
|
354
|
+
link.text = menuItems[i].text;
|
|
355
|
+
if (menuItems[i].hreflang) {
|
|
356
|
+
link.hreflang = menuItems[i].hreflang;
|
|
357
|
+
}
|
|
358
|
+
var secondaryMenuListItem = document.createElement("li");
|
|
359
|
+
secondaryMenuListItem.className = "item nav-item secondaryItem";
|
|
360
|
+
secondaryMenuListItem.appendChild(link);
|
|
361
|
+
secondaryMenuContainer.appendChild(secondaryMenuListItem);
|
|
362
|
+
}
|
|
363
|
+
secondaryMenuWrapper.appendChild(secondaryMenuContainer);
|
|
364
|
+
document.getElementById("mobileMenuList").appendChild(secondaryMenuWrapper);
|
|
365
|
+
} // Mega menu icon toggler.
|
|
366
|
+
document.getElementById("nav-icon").onclick = function _onclick() {
|
|
367
|
+
if (document.body.style.overflow !== "hidden") {
|
|
368
|
+
document.body.style.overflow = "hidden";
|
|
369
|
+
} else {
|
|
370
|
+
document.body.style.overflow = "initial";
|
|
371
|
+
}
|
|
372
|
+
document.getElementById("mobileMenuContent").classList.toggle("show");
|
|
373
|
+
this.classList.toggle("open");
|
|
374
|
+
};
|
|
375
|
+
});
|
|
376
|
+
function stickyMainMenu() {
|
|
377
|
+
if (!document.querySelector("#mainMenu ul.nav.nav-list")) return;
|
|
378
|
+
function isInViewport(element) {
|
|
379
|
+
if (!element) return false;
|
|
380
|
+
const rect = element.getBoundingClientRect();
|
|
381
|
+
return (
|
|
382
|
+
rect.top >= 0 &&
|
|
383
|
+
rect.left >= 0 &&
|
|
384
|
+
rect.bottom <=
|
|
385
|
+
(window.innerHeight || document.documentElement.clientHeight) &&
|
|
386
|
+
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
|
|
387
|
+
);
|
|
388
|
+
}
|
|
389
|
+
if (
|
|
390
|
+
isInViewport(
|
|
391
|
+
document.querySelector("#mainMenu ul.nav.nav-list:last-of-type")
|
|
392
|
+
?.lastElementChild,
|
|
393
|
+
)
|
|
394
|
+
) {
|
|
395
|
+
document.querySelector("#mainMenu").classList.add("sticky-menu");
|
|
396
|
+
} else {
|
|
397
|
+
document.querySelector("#mainMenu").classList.remove("sticky-menu");
|
|
398
|
+
}
|
|
399
|
+
}
|
|
400
|
+
window.addEventListener("load", stickyMainMenu);
|
|
401
|
+
window.addEventListener("resize", stickyMainMenu);
|
|
402
|
+
|
|
127
403
|
exports.MenuPanel = MenuPanel;
|