-
Notifications
You must be signed in to change notification settings - Fork 1
/
shell.js
48 lines (46 loc) · 1.79 KB
/
shell.js
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
(function setupShellCSS(){
document.querySelectorAll(".collapse").forEach(function (elem) {
elem.addEventListener("click", function (event) {
console.info("clicked");
var collapsable = document.getElementById(this.dataset.target);
if (collapsable.dataset.collapsed == "true") {
console.info("uncollapsing");
uncollapse(collapsable);
}
else {
console.info("collapsing");
collapse(collapsable);
}
});
document.getElementById("side-nav").addEventListener("touchstart", function (event) {
console.info("Swiping.");
this.touchStart = (event.touches[0].pageX);
});
document.getElementById("side-nav").addEventListener("touchend", function (event) {
var moved = this.touchStart - event.changedTouches[0].pageX;
var collapsable = this;
console.info(moved);
if (moved < 0) { //swipe left to right
console.info("L -> R");
console.info("uncollapsing");
uncollapse(collapsable);
}
else if (moved > 0) { //swipe right to left
console.info("L <- R");
console.info("collapsing");
collapse(collapsable);
}
});
});
function collapse(elem) {
elem.dataset.originalWidth = elem.getBoundingClientRect().width;
elem.style.width = '0px';
elem.style.minWidth = '0px';
elem.dataset.collapsed = "true";
}
function uncollapse(elem) {
elem.style.width = `${elem.dataset.originalWidth}px`;
elem.style.minWidth = `${elem.dataset.originalWidth}px`;
elem.dataset.collapsed = "false";
}
})();