|
1 | 1 | <script> |
2 | | -// @ts-nocheck |
3 | | -
|
| 2 | + // @ts-nocheck |
4 | 3 | import { onMount, afterUpdate } from 'svelte'; |
5 | | - import 'overlayscrollbars/overlayscrollbars.css'; |
6 | | - import { OverlayScrollbars } from 'overlayscrollbars'; |
7 | | - import Link from 'svelte-link'; |
8 | | - import { page } from '$app/stores'; |
9 | 4 | import { browser } from '$app/environment'; |
| 5 | + import { goto } from '$app/navigation'; |
| 6 | + import { page } from '$app/stores'; |
10 | 7 | import { _ } from 'svelte-i18n'; |
| 8 | + import Link from 'svelte-link'; |
| 9 | + import 'overlayscrollbars/overlayscrollbars.css'; |
| 10 | + import { OverlayScrollbars } from 'overlayscrollbars'; |
11 | 11 | import { globalEventStore } from '$lib/helpers/store'; |
| 12 | + import { getCleanUrl } from '$lib/helpers/utils/common'; |
12 | 13 |
|
13 | 14 | /** @type {import('$pluginTypes').PluginMenuDefModel[]} */ |
14 | 15 | export let menu; |
15 | 16 |
|
16 | 17 | // after routing complete call afterUpdate function |
17 | 18 | afterUpdate(() => { |
18 | 19 | removeActiveDropdown(); |
19 | | - const curUrl = getPathUrl(); |
| 20 | + const curUrl = getCleanUrl($page.url.pathname); |
20 | 21 | if (curUrl) { |
21 | | - let item = document.querySelector(".vertical-menu a[href='" + curUrl + "']"); |
| 22 | + const item = document.querySelector(".vertical-menu a[id='" + curUrl + "']"); |
22 | 23 | if (item) { |
23 | 24 | item.classList.add('mm-active'); |
24 | 25 | const parent1 = item.parentElement; |
|
62 | 63 |
|
63 | 64 | onMount(async () => { |
64 | 65 | const menuElement = document.querySelector('#vertical-menu'); |
| 66 | + // @ts-ignore |
65 | 67 | OverlayScrollbars(menuElement, options); |
66 | 68 | activeMenu(); |
67 | 69 |
|
68 | | - const curUrl = getPathUrl(); |
| 70 | + const curUrl = getCleanUrl($page.url.pathname); |
69 | 71 | if (curUrl) { |
70 | | - let item = document.querySelector(".vertical-menu a[href='" + curUrl + "']"); |
| 72 | + const item = document.querySelector(".vertical-menu a[id='" + curUrl + "']"); |
71 | 73 | if (item) { |
72 | 74 | item.classList.add('mm-active'); |
73 | 75 | item.scrollIntoView({ behavior: 'smooth', block: 'center' }); |
|
183 | 185 |
|
184 | 186 | const menuItemScroll = () => { |
185 | 187 | if (browser) { |
186 | | - const curUrl = getPathUrl(); |
187 | | - let item = document.querySelector(".vertical-menu a[href='" + curUrl + "']")?.offsetTop; |
188 | | - if (item && item > 300) { |
189 | | - item = item - 300; |
| 188 | + const curUrl = getCleanUrl($page.url.pathname); |
| 189 | + const item = document.querySelector(".vertical-menu a[id='" + curUrl + "']"); |
| 190 | + // @ts-ignore |
| 191 | + let offset = item?.offsetTop; |
| 192 | + if (offset && offset > 300) { |
| 193 | + offset = offset - 300; |
190 | 194 | const menuElement = document.getElementById('vertical-menu'); |
191 | 195 | menuElement?.scrollTo({ |
192 | | - top: item, |
| 196 | + top: offset, |
193 | 197 | behavior: 'smooth' |
194 | 198 | }); |
195 | 199 | } |
196 | 200 | } |
197 | 201 | }; |
198 | 202 |
|
199 | | - const getPathUrl = () => { |
200 | | - const path = $page.url.pathname; |
201 | | - return path?.startsWith('/') ? path.substring(1) : path; |
202 | | - }; |
| 203 | + /** @param {string} url */ |
| 204 | + const goToPage = (url) => { |
| 205 | + if (!url) return; |
203 | 206 |
|
204 | | - const goToPage = () => { |
| 207 | + url = getCleanUrl(url); |
205 | 208 | globalEventStore.reset(); |
| 209 | + goto(url); |
206 | 210 | } |
207 | 211 | </script> |
208 | 212 |
|
|
217 | 221 | <li class="menu-title" key="t-menu">{$_(item.label)}</li> |
218 | 222 | {:else if item.subMenu} |
219 | 223 | <li> |
220 | | - <Link href={null} class="has-arrow waves-effect"> |
| 224 | + <Link class="has-arrow waves-effect clickable" href={null}> |
221 | 225 | <i class={item.icon} /> |
222 | 226 | <span>{$_(item.label)}</span> |
223 | 227 | </Link> |
224 | 228 | <ul class="sub-menu mm-collapse"> |
225 | 229 | {#each item.subMenu as subMenu} |
226 | 230 | {#if subMenu.isChildItem} |
227 | 231 | <li> |
228 | | - <Link href="#" class="has-arrow waves-effect"> |
| 232 | + <Link class="has-arrow waves-effect clickable" href={null}> |
229 | 233 | <span>{$_(subMenu.label)}</span> |
230 | 234 | </Link> |
231 | 235 | <ul class="sub-menu mm-collapse"> |
232 | 236 | {#each subMenu.childItems as childItem} |
233 | | - <li><Link href={childItem.link} on:click={() => goToPage()}>{$_(childItem.label)}</Link></li> |
| 237 | + <li> |
| 238 | + <Link class="clickable" id={getCleanUrl(childItem.link)} href={null} on:click={() => goToPage(childItem.link)}> |
| 239 | + {$_(childItem.label)} |
| 240 | + </Link> |
| 241 | + </li> |
234 | 242 | {/each} |
235 | 243 | </ul> |
236 | 244 | </li> |
237 | 245 | {:else} |
238 | | - <li><Link href={subMenu.link} on:click={() => goToPage()}>{$_(subMenu.label)}</Link></li> |
| 246 | + <li> |
| 247 | + <Link class="clickable" id={getCleanUrl(subMenu.link)} href={null} on:click={() => goToPage(subMenu.link)}> |
| 248 | + {$_(subMenu.label)} |
| 249 | + </Link> |
| 250 | + </li> |
239 | 251 | {/if} |
240 | 252 | {/each} |
241 | 253 | </ul> |
242 | 254 | </li> |
243 | 255 | {:else} |
244 | 256 | <li> |
245 | | - <Link class="waves-effect" href={item.link} on:click={() => goToPage()} > |
246 | | - <i class={item.icon} /> <span>{$_(item.label)}</span> |
| 257 | + <Link class="waves-effect clickable" id={getCleanUrl(item.link)} href={null} on:click={() => goToPage(item.link)} > |
| 258 | + <i class={item.icon} /> |
| 259 | + <span>{$_(item.label)}</span> |
247 | 260 | </Link> |
248 | 261 | </li> |
249 | 262 | {/if} |
|
0 commit comments