2018-04-02 05:34:16 +00:00
|
|
|
import TouchController from "./TouchController"
|
|
|
|
import Diff from "./Diff"
|
2017-10-02 00:02:07 +00:00
|
|
|
|
2018-04-02 05:34:16 +00:00
|
|
|
export default class SideBar {
|
2017-10-02 00:02:07 +00:00
|
|
|
element: HTMLElement
|
|
|
|
touchController: TouchController
|
|
|
|
|
|
|
|
constructor(element) {
|
|
|
|
this.element = element
|
|
|
|
|
2019-04-22 09:06:50 +00:00
|
|
|
document.body.addEventListener("click", _ => {
|
2019-04-19 13:12:33 +00:00
|
|
|
if(document.activeElement && document.activeElement.id === "search") {
|
|
|
|
return
|
|
|
|
}
|
2017-10-02 00:02:07 +00:00
|
|
|
|
|
|
|
this.hide()
|
|
|
|
})
|
|
|
|
|
|
|
|
this.touchController = new TouchController()
|
|
|
|
this.touchController.leftSwipe = () => this.hide()
|
|
|
|
this.touchController.rightSwipe = () => this.show()
|
|
|
|
}
|
|
|
|
|
|
|
|
show() {
|
2018-03-29 09:36:54 +00:00
|
|
|
Diff.mutations.queue(() => this.element.classList.add("sidebar-visible"))
|
2017-10-02 00:02:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
hide() {
|
2018-03-29 09:36:54 +00:00
|
|
|
Diff.mutations.queue(() => this.element.classList.remove("sidebar-visible"))
|
2017-10-02 00:02:07 +00:00
|
|
|
}
|
2018-03-07 13:52:56 +00:00
|
|
|
|
|
|
|
toggle() {
|
2019-11-17 09:25:14 +00:00
|
|
|
const visible = this.element.style.display !== "none"
|
2018-03-07 13:52:56 +00:00
|
|
|
|
|
|
|
if(visible) {
|
|
|
|
this.element.style.display = "none"
|
|
|
|
} else {
|
|
|
|
this.element.style.display = "flex"
|
|
|
|
}
|
|
|
|
}
|
2019-11-17 09:44:30 +00:00
|
|
|
}
|