@qtoggle/qui 1.20.2 → 1.20.3
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/utils/css.js
CHANGED
|
@@ -238,3 +238,18 @@ export function px2em(px, elem = Window.$body) {
|
|
|
238
238
|
|
|
239
239
|
return width
|
|
240
240
|
}
|
|
241
|
+
|
|
242
|
+
/**
|
|
243
|
+
* Convert a length from visual pixels to CSS pixels.
|
|
244
|
+
*
|
|
245
|
+
* Pointer event coordinates and `getBoundingClientRect()` values (so also jQuery's `offset()` and `position()`) are
|
|
246
|
+
* visual pixels -- they include the scaling factor applied to the body. CSS lengths, *em* units, `offsetWidth` and
|
|
247
|
+
* jQuery's `width()` are CSS pixels. Mixing the two is only safe when the scaling factor is `1`.
|
|
248
|
+
*
|
|
249
|
+
* @alias qui.utils.css.unscalePx
|
|
250
|
+
* @param {Number} px
|
|
251
|
+
* @returns {Number}
|
|
252
|
+
*/
|
|
253
|
+
export function unscalePx(px) {
|
|
254
|
+
return px / Window.getScalingFactor()
|
|
255
|
+
}
|
package/js/utils/gestures.js
CHANGED
|
@@ -4,6 +4,7 @@
|
|
|
4
4
|
|
|
5
5
|
import $ from '$qui/lib/jquery.module.js'
|
|
6
6
|
|
|
7
|
+
import * as CSS from '$qui/utils/css.js'
|
|
7
8
|
import * as Window from '$qui/window.js'
|
|
8
9
|
|
|
9
10
|
|
|
@@ -44,6 +45,10 @@ const LONG_PRESS_DATA_KEY = 'qui.utils.gestures.longPress'
|
|
|
44
45
|
|
|
45
46
|
/**
|
|
46
47
|
* Setup an HTML element for dragging.
|
|
48
|
+
*
|
|
49
|
+
* All coordinates passed to the callbacks are CSS pixels, so they can be compared or combined with *em* units and CSS
|
|
50
|
+
* lengths directly. Use {@link qui.utils.css.unscalePx} on any `offset()` or `position()` value measured against them.
|
|
51
|
+
*
|
|
47
52
|
* @alias qui.utils.gestures.enableDragging
|
|
48
53
|
* @param {jQuery} element the dragged element
|
|
49
54
|
* @param {qui.utils.gestures.DragMoveCallback} onMove
|
|
@@ -81,12 +86,11 @@ export function enableDragging(element, onMove, onBegin, onEnd, direction) {
|
|
|
81
86
|
|
|
82
87
|
function pointerDown(e) {
|
|
83
88
|
let elemOffset = element.offset()
|
|
84
|
-
beginElemX = elemOffset.left
|
|
85
|
-
beginElemY = elemOffset.top
|
|
89
|
+
beginElemX = CSS.unscalePx(elemOffset.left)
|
|
90
|
+
beginElemY = CSS.unscalePx(elemOffset.top)
|
|
86
91
|
|
|
87
|
-
|
|
88
|
-
e.
|
|
89
|
-
e.pageY /= scalingFactor
|
|
92
|
+
e.pageX = CSS.unscalePx(e.pageX)
|
|
93
|
+
e.pageY = CSS.unscalePx(e.pageY)
|
|
90
94
|
|
|
91
95
|
beginPageX = e.pageX
|
|
92
96
|
beginPageY = e.pageY
|
|
@@ -109,9 +113,8 @@ export function enableDragging(element, onMove, onBegin, onEnd, direction) {
|
|
|
109
113
|
* where the pointer actually was, before it is told the drag is over */
|
|
110
114
|
flushMove()
|
|
111
115
|
|
|
112
|
-
|
|
113
|
-
e.
|
|
114
|
-
e.pageY /= scalingFactor
|
|
116
|
+
e.pageX = CSS.unscalePx(e.pageX)
|
|
117
|
+
e.pageY = CSS.unscalePx(e.pageY)
|
|
115
118
|
|
|
116
119
|
if (direction === 'x') { /* Constrain moving to horizontal axis */
|
|
117
120
|
e.pageY = beginPageY
|
|
@@ -135,9 +138,8 @@ export function enableDragging(element, onMove, onBegin, onEnd, direction) {
|
|
|
135
138
|
}
|
|
136
139
|
|
|
137
140
|
function pointerMove(e) {
|
|
138
|
-
|
|
139
|
-
e.
|
|
140
|
-
e.pageY /= scalingFactor
|
|
141
|
+
e.pageX = CSS.unscalePx(e.pageX)
|
|
142
|
+
e.pageY = CSS.unscalePx(e.pageY)
|
|
141
143
|
|
|
142
144
|
if (direction === 'x') { /* Constrain moving to horizontal axis */
|
|
143
145
|
e.pageY = beginPageY
|
|
@@ -3,6 +3,7 @@ import $ from '$qui/lib/jquery.module.js'
|
|
|
3
3
|
|
|
4
4
|
import {gettext} from '$qui/base/i18n.js'
|
|
5
5
|
import * as Theme from '$qui/theme.js'
|
|
6
|
+
import * as CSS from '$qui/utils/css.js'
|
|
6
7
|
import {asap} from '$qui/utils/misc.js'
|
|
7
8
|
import * as ObjectUtils from '$qui/utils/object.js'
|
|
8
9
|
import * as PromiseUtils from '$qui/utils/promise.js'
|
|
@@ -370,7 +371,7 @@ $.widget('qui.combo', $.qui.basewidget, {
|
|
|
370
371
|
this._prevItemDiv = this._itemContainer.children('div.qui-combo-item.selected')
|
|
371
372
|
|
|
372
373
|
if (this._prevItemDiv.length) {
|
|
373
|
-
let scrollTop = this._prevItemDiv.offset().top - this._itemContainer.offset().top +
|
|
374
|
+
let scrollTop = CSS.unscalePx(this._prevItemDiv.offset().top - this._itemContainer.offset().top) +
|
|
374
375
|
this._itemContainer.scrollTop()
|
|
375
376
|
this._itemContainer.scrollTop(scrollTop)
|
|
376
377
|
}
|
|
@@ -534,7 +535,7 @@ $.widget('qui.combo', $.qui.basewidget, {
|
|
|
534
535
|
if (itemDiv) {
|
|
535
536
|
itemDiv.addClass('selected')
|
|
536
537
|
if (scroll) {
|
|
537
|
-
let scrollTop = itemDiv.offset().top - this._itemContainer.offset().top +
|
|
538
|
+
let scrollTop = CSS.unscalePx(itemDiv.offset().top - this._itemContainer.offset().top) +
|
|
538
539
|
this._itemContainer.scrollTop()
|
|
539
540
|
this._itemContainer.scrollTop(scrollTop)
|
|
540
541
|
}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
|
|
2
2
|
import $ from '$qui/lib/jquery.module.js'
|
|
3
3
|
|
|
4
|
+
import * as CSS from '$qui/utils/css.js'
|
|
4
5
|
import * as Gestures from '$qui/utils/gestures.js'
|
|
5
6
|
|
|
6
7
|
import * as BaseWidget from '../base-widget.js' /* Needed */
|
|
@@ -68,8 +69,8 @@ $.widget('qui.slider', $.qui.basewidget, {
|
|
|
68
69
|
return
|
|
69
70
|
}
|
|
70
71
|
|
|
71
|
-
let
|
|
72
|
-
let pos = pageX -
|
|
72
|
+
let barLeft = CSS.unscalePx(widget._bar.offset().left)
|
|
73
|
+
let pos = pageX - barLeft
|
|
73
74
|
pos = pos / widget._getWidth()
|
|
74
75
|
pos = widget._bestPos(pos)
|
|
75
76
|
|
|
@@ -233,7 +234,9 @@ $.widget('qui.slider', $.qui.basewidget, {
|
|
|
233
234
|
},
|
|
234
235
|
|
|
235
236
|
_getPos: function () {
|
|
236
|
-
|
|
237
|
+
/* Deduced from the current value, rather than measured: the cursor is placed with a percentage and a negative
|
|
238
|
+
* margin, which no measurement reads back cleanly under a scaling factor */
|
|
239
|
+
return this._valToPos(this._curVal)
|
|
237
240
|
},
|
|
238
241
|
|
|
239
242
|
_setPos: function (pos) {
|
package/package.json
CHANGED