-
Notifications
You must be signed in to change notification settings - Fork 434
Expand file tree
/
Copy pathutils.js
More file actions
32 lines (27 loc) · 940 Bytes
/
utils.js
File metadata and controls
32 lines (27 loc) · 940 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
const pushHash = (hash) => {
hash = hash
? hash.indexOf('#') === 0
? hash
: '#' + hash
: '';
if(history.replaceState) {
let loc = window.location;
history.replaceState(null, null, hash ? loc.pathname + loc.search + hash
// remove hash
: loc.pathname + loc.search);
} else {
location.hash = hash;
}
}
const getHash = () => {
return window.location.hash.replace(/^#/, '');
}
const filterElementInContainer = (container) => (element) => container.contains ? container != element && container.contains(element) : !!(container.compareDocumentPosition(element) & 16)
const scrollOffset = (c, t) => c === document ?
t.getBoundingClientRect().top + (window.scrollY || window.pageYOffset) : getComputedStyle(c).position === "relative" ? t.offsetTop : (t.getBoundingClientRect().top + c.scrollTop)
export default {
pushHash,
getHash,
filterElementInContainer,
scrollOffset
};