2019-02-22 14:21:32 +00:00
|
|
|
<template>
|
2019-08-05 14:35:53 +00:00
|
|
|
<aside id="sidebar" ref="sidebar">
|
|
|
|
<div class="scrollable-area">
|
|
|
|
<div class="logo-container">
|
|
|
|
<img
|
|
|
|
:src="`img/logo-${isPublic() ? 'horizontal-' : ''}transparent-bg.svg`"
|
|
|
|
class="logo"
|
|
|
|
alt="The Lounge"
|
|
|
|
/>
|
|
|
|
<img
|
|
|
|
:src="`img/logo-${isPublic() ? 'horizontal-' : ''}transparent-bg-inverted.svg`"
|
|
|
|
class="logo-inverted"
|
|
|
|
alt="The Lounge"
|
|
|
|
/>
|
2019-02-22 14:21:32 +00:00
|
|
|
</div>
|
2019-11-02 19:40:59 +00:00
|
|
|
<NetworkList />
|
2019-08-05 14:35:53 +00:00
|
|
|
</div>
|
|
|
|
<footer id="footer">
|
|
|
|
<span
|
|
|
|
class="tooltipped tooltipped-n tooltipped-no-touch"
|
|
|
|
aria-label="Connect to network"
|
2019-10-20 16:17:21 +00:00
|
|
|
><router-link
|
|
|
|
to="/connect"
|
|
|
|
tag="button"
|
|
|
|
active-class="active"
|
|
|
|
:class="['icon', 'connect']"
|
2019-03-01 14:18:16 +00:00
|
|
|
aria-label="Connect to network"
|
2019-08-05 14:35:53 +00:00
|
|
|
role="tab"
|
|
|
|
aria-controls="connect"
|
2019-11-11 19:18:55 +00:00
|
|
|
:aria-selected="$route.name === 'Connect'"
|
2019-08-05 14:35:53 +00:00
|
|
|
/></span>
|
|
|
|
<span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Settings"
|
2019-10-20 16:17:21 +00:00
|
|
|
><router-link
|
|
|
|
to="/settings"
|
|
|
|
tag="button"
|
|
|
|
active-class="active"
|
|
|
|
:class="['icon', 'settings']"
|
2019-08-05 14:35:53 +00:00
|
|
|
aria-label="Settings"
|
|
|
|
role="tab"
|
|
|
|
aria-controls="settings"
|
2019-11-11 19:18:55 +00:00
|
|
|
:aria-selected="$route.name === 'Settings'"
|
2019-08-05 14:35:53 +00:00
|
|
|
/></span>
|
|
|
|
<span class="tooltipped tooltipped-n tooltipped-no-touch" aria-label="Help"
|
2019-10-20 16:17:21 +00:00
|
|
|
><router-link
|
|
|
|
to="/help"
|
|
|
|
tag="button"
|
|
|
|
active-class="active"
|
|
|
|
:class="['icon', 'help']"
|
2019-08-05 14:35:53 +00:00
|
|
|
aria-label="Help"
|
|
|
|
role="tab"
|
|
|
|
aria-controls="help"
|
2019-11-11 19:18:55 +00:00
|
|
|
:aria-selected="$route.name === 'Help'"
|
2019-08-05 14:35:53 +00:00
|
|
|
/></span>
|
|
|
|
</footer>
|
|
|
|
</aside>
|
2019-02-22 14:21:32 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
|
|
|
import NetworkList from "./NetworkList.vue";
|
|
|
|
|
|
|
|
export default {
|
|
|
|
name: "Sidebar",
|
|
|
|
components: {
|
|
|
|
NetworkList,
|
|
|
|
},
|
|
|
|
props: {
|
2019-08-05 14:35:53 +00:00
|
|
|
overlay: HTMLElement,
|
2019-02-22 14:21:32 +00:00
|
|
|
},
|
2019-08-05 12:24:44 +00:00
|
|
|
mounted() {
|
|
|
|
this.touchStartPos = null;
|
|
|
|
this.touchCurPos = null;
|
|
|
|
this.touchStartTime = 0;
|
|
|
|
this.menuWidth = 0;
|
|
|
|
this.menuIsMoving = false;
|
|
|
|
this.menuIsAbsolute = false;
|
|
|
|
|
|
|
|
this.onTouchStart = (e) => {
|
|
|
|
this.touchStartPos = this.touchCurPos = e.touches.item(0);
|
|
|
|
|
|
|
|
if (e.touches.length !== 1) {
|
|
|
|
this.onTouchEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const styles = window.getComputedStyle(this.$refs.sidebar);
|
|
|
|
|
|
|
|
this.menuWidth = parseFloat(styles.width);
|
|
|
|
this.menuIsAbsolute = styles.position === "absolute";
|
|
|
|
|
|
|
|
if (!this.$store.state.sidebarOpen || this.touchStartPos.screenX > this.menuWidth) {
|
|
|
|
this.touchStartTime = Date.now();
|
|
|
|
|
|
|
|
document.body.addEventListener("touchmove", this.onTouchMove, {passive: true});
|
|
|
|
document.body.addEventListener("touchend", this.onTouchEnd, {passive: true});
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
this.onTouchMove = (e) => {
|
|
|
|
const touch = (this.touchCurPos = e.touches.item(0));
|
|
|
|
let distX = touch.screenX - this.touchStartPos.screenX;
|
|
|
|
const distY = touch.screenY - this.touchStartPos.screenY;
|
|
|
|
|
|
|
|
if (!this.menuIsMoving) {
|
|
|
|
// tan(45°) is 1. Gestures in 0°-45° (< 1) are considered horizontal, so
|
|
|
|
// menu must be open; gestures in 45°-90° (>1) are considered vertical, so
|
|
|
|
// chat windows must be scrolled.
|
|
|
|
if (Math.abs(distY / distX) >= 1) {
|
|
|
|
this.onTouchEnd();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
const devicePixelRatio = window.devicePixelRatio || 2;
|
|
|
|
|
|
|
|
if (Math.abs(distX) > devicePixelRatio) {
|
|
|
|
this.$store.commit("sidebarDragging", true);
|
|
|
|
this.menuIsMoving = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Do not animate the menu on desktop view
|
|
|
|
if (!this.menuIsAbsolute) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.$store.state.sidebarOpen) {
|
|
|
|
distX += this.menuWidth;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (distX > this.menuWidth) {
|
|
|
|
distX = this.menuWidth;
|
|
|
|
} else if (distX < 0) {
|
|
|
|
distX = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
this.$refs.sidebar.style.transform = "translate3d(" + distX + "px, 0, 0)";
|
2019-08-05 14:35:53 +00:00
|
|
|
this.overlay.style.opacity = distX / this.menuWidth;
|
2019-08-05 12:24:44 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
this.onTouchEnd = () => {
|
|
|
|
const diff = this.touchCurPos.screenX - this.touchStartPos.screenX;
|
|
|
|
const absDiff = Math.abs(diff);
|
|
|
|
|
|
|
|
if (
|
|
|
|
absDiff > this.menuWidth / 2 ||
|
|
|
|
(Date.now() - this.touchStartTime < 180 && absDiff > 50)
|
|
|
|
) {
|
|
|
|
this.toggle(diff > 0);
|
|
|
|
}
|
|
|
|
|
|
|
|
document.body.removeEventListener("touchmove", this.onTouchMove);
|
|
|
|
document.body.removeEventListener("touchend", this.onTouchEnd);
|
|
|
|
this.$store.commit("sidebarDragging", false);
|
|
|
|
|
|
|
|
this.$refs.sidebar.style.transform = null;
|
2019-08-05 14:35:53 +00:00
|
|
|
this.overlay.style.opacity = null;
|
2019-08-05 12:24:44 +00:00
|
|
|
|
|
|
|
this.touchStartPos = null;
|
|
|
|
this.touchCurPos = null;
|
|
|
|
this.touchStartTime = 0;
|
|
|
|
this.menuIsMoving = false;
|
|
|
|
};
|
|
|
|
|
|
|
|
this.toggle = (state) => {
|
|
|
|
this.$store.commit("sidebarOpen", state);
|
|
|
|
};
|
|
|
|
|
|
|
|
document.body.addEventListener("touchstart", this.onTouchStart, {passive: true});
|
|
|
|
},
|
2019-02-22 14:21:32 +00:00
|
|
|
methods: {
|
|
|
|
isPublic: () => document.body.classList.contains("public"),
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|