(hash)
| 24 | } |
| 25 | |
| 26 | export function scrollToHash(hash) { |
| 27 | let selector = `[name="${hash}"]`; |
| 28 | let element = |
| 29 | document.getElementById(hash) || document.querySelector(selector); |
| 30 | |
| 31 | if (!element) { |
| 32 | warn( |
| 33 | `Tried to scroll to element with id or name "${hash}", but it was not found`, |
| 34 | { |
| 35 | id: 'no-hash-target', |
| 36 | }, |
| 37 | ); |
| 38 | |
| 39 | return; |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * NOTE: the ember router does not support hashes in the URL |
| 44 | * https://github.com/emberjs/rfcs/issues/709 |
| 45 | * |
| 46 | * this means that when testing hash changes in the URL, |
| 47 | * we have to assert against the window.location, rather than |
| 48 | * the self-container currentURL helper |
| 49 | * |
| 50 | * NOTE: other ways of changing the URL, but without the smoothness: |
| 51 | * - window[.top].location.replace |
| 52 | */ |
| 53 | |
| 54 | element.scrollIntoView({ behavior: 'smooth' }); |
| 55 | |
| 56 | if (hash !== window.location.hash) { |
| 57 | let withoutHash = location.href.split('#')[0]; |
| 58 | let nextUrl = `${withoutHash}#${hash}`; |
| 59 | // most browsers ignore the title param of pushState |
| 60 | let titleWithoutHash = document.title.split(' | #')[0]; |
| 61 | let nextTitle = `${titleWithoutHash} | #${hash}`; |
| 62 | |
| 63 | history.pushState({}, nextTitle, nextUrl); |
| 64 | document.title = nextTitle; |
| 65 | } |
| 66 | } |
| 67 | |
| 68 | function isLoadingRoute(routeName) { |
| 69 | return routeName.endsWith('_loading') || routeName.endsWith('.loading'); |
no outgoing calls
no test coverage detected