Skip to content

Commit 77c3a33

Browse files
committed
allow continous size change per button
1 parent 8c6b252 commit 77c3a33

2 files changed

Lines changed: 28 additions & 4 deletions

File tree

‎app/assets/stylesheets/feature.css‎

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -637,6 +637,9 @@ body:not(.map-mode-rw) .feature-section-card:has(#map-description-view:empty) {
637637
line-height: 1;
638638
cursor: pointer;
639639
flex-shrink: 0;
640+
touch-action: none;
641+
user-select: none;
642+
-webkit-touch-callout: none;
640643
}
641644

642645
.stepper-btn:active {

‎app/javascript/helpers/stepper.js‎

Lines changed: 25 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { isTouchDevice } from 'helpers/functions'
1+
import { isTouchDevice, debounce } from 'helpers/functions'
22

33
const formatters = {
44
opacity: v => (v * 10) + '%',
@@ -28,11 +28,31 @@ export function initSteppers () {
2828
const decBtn = stepper.querySelector('.stepper-btn-dec')
2929
const incBtn = stepper.querySelector('.stepper-btn-inc')
3030

31-
decBtn.addEventListener('click', () => adjustValue(input, -step, stepper))
32-
incBtn.addEventListener('click', () => adjustValue(input, step, stepper))
31+
initRepeatButton(decBtn, () => adjustValue(input, -step, stepper))
32+
initRepeatButton(incBtn, () => adjustValue(input, step, stepper))
3333
})
3434
}
3535

36+
function initRepeatButton (button, action) {
37+
let timer
38+
const stop = () => clearTimeout(timer)
39+
const repeat = (delay) => {
40+
action()
41+
timer = setTimeout(() => repeat(80), delay)
42+
}
43+
button.addEventListener('pointerdown', (event) => {
44+
if (event.button !== 0) return
45+
button.setPointerCapture(event.pointerId)
46+
repeat(400)
47+
})
48+
button.addEventListener('pointerup', stop)
49+
button.addEventListener('pointercancel', stop)
50+
button.addEventListener('lostpointercapture', stop)
51+
// pointerdown already handled mouse and touch, only keyboard activation (detail 0) is left
52+
button.addEventListener('click', (event) => { if (event.detail === 0) action() })
53+
button.addEventListener('contextmenu', (event) => event.preventDefault())
54+
}
55+
3656
function adjustValue (input, delta, stepper) {
3757
const min = Number(input.min)
3858
const max = Number(input.max)
@@ -43,7 +63,8 @@ function adjustValue (input, delta, stepper) {
4363
input.value = newValue
4464
stepper.querySelector('.stepper-val').textContent = formatValue(input.id, newValue)
4565
input.dispatchEvent(new Event('input', { bubbles: true }))
46-
input.dispatchEvent(new Event('change', { bubbles: true }))
66+
// change handlers save to the server, so send only the final value of a click series
67+
debounce(() => input.dispatchEvent(new Event('change', { bubbles: true })), 'stepper-' + input.id, 500)
4768
}
4869

4970
export function syncStepperValues () {

0 commit comments

Comments
 (0)