@qtoggle/qui 1.20.0-beta.1 → 1.20.0-beta.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/js/widgets/widgets.js +41 -0
- package/package.json +1 -1
- package/pyproject.toml +1 -1
package/js/widgets/widgets.js
CHANGED
|
@@ -29,6 +29,46 @@ function initButtons() {
|
|
|
29
29
|
})
|
|
30
30
|
}
|
|
31
31
|
|
|
32
|
+
function initLongPress() {
|
|
33
|
+
/* A touch press held long enough to become a long press ends without a click, so the release looked like a
|
|
34
|
+
* tap that did nothing. Treat that release as a click, except in text fields and links, which have their own
|
|
35
|
+
* long-press menus. */
|
|
36
|
+
let longPressTarget = null
|
|
37
|
+
|
|
38
|
+
document.addEventListener('contextmenu', function (e) {
|
|
39
|
+
let ownMenu = e.target.closest('input, textarea, select, [contenteditable], a[href]')
|
|
40
|
+
longPressTarget = (e.pointerType === 'touch' && !ownMenu) ? e.target : null
|
|
41
|
+
if (longPressTarget) {
|
|
42
|
+
e.preventDefault()
|
|
43
|
+
}
|
|
44
|
+
}, {capture: true})
|
|
45
|
+
|
|
46
|
+
document.addEventListener('pointerup', function (e) {
|
|
47
|
+
let target = longPressTarget
|
|
48
|
+
longPressTarget = null
|
|
49
|
+
if (!target || e.pointerType !== 'touch') {
|
|
50
|
+
return
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/* Touch pointers stay captured by the pressed element, so find where the finger actually left. Like a real
|
|
54
|
+
* click, the target is the closest element holding both the press and the release. */
|
|
55
|
+
let released = document.elementFromPoint(e.clientX, e.clientY)
|
|
56
|
+
while (target && !target.contains(released)) {
|
|
57
|
+
target = target.parentElement
|
|
58
|
+
}
|
|
59
|
+
if (!target || target === document.body || target === document.documentElement) {
|
|
60
|
+
return
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/* Let the release finish first, like a real click does */
|
|
64
|
+
setTimeout(() => target.click())
|
|
65
|
+
}, {capture: true, passive: true})
|
|
66
|
+
|
|
67
|
+
document.addEventListener('pointercancel', function () {
|
|
68
|
+
longPressTarget = null
|
|
69
|
+
}, {capture: true, passive: true})
|
|
70
|
+
}
|
|
71
|
+
|
|
32
72
|
/**
|
|
33
73
|
* Create a caption made of an icon and a text.
|
|
34
74
|
* @alias qui.widgets.makeIconTextCaption
|
|
@@ -54,4 +94,5 @@ export function makeIconTextCaption(icon, text) {
|
|
|
54
94
|
|
|
55
95
|
export function init() {
|
|
56
96
|
initButtons()
|
|
97
|
+
initLongPress()
|
|
57
98
|
}
|
package/package.json
CHANGED