This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
2020-12-17 13:18:18 -08:00
|
|
|
export default {
|
|
|
|
methods: {
|
|
|
|
handleHash(namespace, callback, checkAnchor = true) {
|
|
|
|
if (!process.client || !window.location.hash) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const anchor = decodeURIComponent(window.location.hash.substr(1));
|
2021-04-01 09:45:27 -07:00
|
|
|
setTimeout(_ => {
|
2020-12-17 13:18:18 -08:00
|
|
|
const $anchor = document.getElementById(anchor);
|
|
|
|
if (checkAnchor && $anchor) {
|
|
|
|
$anchor.scrollIntoView();
|
|
|
|
} else if (!namespace) {
|
|
|
|
callback(anchor);
|
|
|
|
} else if (anchor.startsWith(namespace + '/')) {
|
|
|
|
callback(anchor.substring(namespace.length + 1));
|
|
|
|
}
|
2021-04-01 09:45:27 -07:00
|
|
|
}, 500);
|
2020-12-17 13:18:18 -08:00
|
|
|
},
|
|
|
|
setHash(namespace, value) {
|
|
|
|
if (!process.client) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
history.pushState(
|
|
|
|
'',
|
|
|
|
document.title,
|
|
|
|
window.location.pathname + window.location.search
|
|
|
|
+ (value ? '#' + (namespace ? namespace + '/' + value : value) : '')
|
|
|
|
);
|
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|