Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add mouse side-buttons navigation #256 #257

Draft
wants to merge 2 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -133,3 +133,6 @@ package-lock.json

# This gets generated post install
app/version.js

# This gets generated when I open in a Container
.devcontainer
42 changes: 41 additions & 1 deletion app/ui/omni-box.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,46 @@ class OmniBox extends HTMLElement {
this.forwardButton.addEventListener('click', () => {
this.dispatchEvent(new CustomEvent('forward'))
})

// mouse side-buttons for navigating
window.addEventListener("mouseup", (e) => {
e.preventDefault()

if(e.button === 3) {
this.dispatchEvent(new CustomEvent('back'))
} else if(e.button === 4) {
this.dispatchEvent(new CustomEvent('forward'))
}
})

// mouse gestures for navigating
let isMouseDown = false
let startX = 0
let startY = 0

window.addEventListener('mousedown', (e) => {
isMouseDown = true
startX = e.clientX
startY = e.clientY
})
window.addEventListener('mousemove', (e) => {
if (isMouseDown) {
const distX = e.clientX - startX
const distY = e.clientY - startY

if (Math.abs(distX) > Math.abs(distY)) {
if (distX > 0) {
this.dispatchEvent(new CustomEvent('forward'))
} else {
this.dispatchEvent(new CustomEvent('back'))
}
}
isMouseDown = false
}
})
window.addEventListener('mouseup', () => {
isMouseDown = false
})
}

clearOptions () {
Expand Down Expand Up @@ -342,4 +382,4 @@ function makeIPNS (path) {
return `ipns://${path.slice(IPNS_PREFIX.length)}`
}

customElements.define('omni-box', OmniBox)
customElements.define('omni-box', OmniBox)