|
31 | 31 | export let percentOf = undefined; |
32 | 32 | export let moveHandle = undefined; |
33 | 33 | export let fixFloat = undefined; |
| 34 | + export let normalisedClient = undefined; |
| 35 | +
|
| 36 | + let clientStart; |
34 | 37 |
|
35 | 38 | $: pipStep = pipstep || ((max - min) / step >= ( vertical ? 50 : 100 ) ? (max - min) / ( vertical ? 10 : 20 ) : 1); |
36 | 39 |
|
|
54 | 57 | } |
55 | 58 | }; |
56 | 59 |
|
57 | | - function labelClick(val) { |
| 60 | + /** |
| 61 | + * function to run when the user clicks on a label |
| 62 | + * we store the original client position so we can check if the user has moved the mouse/finger |
| 63 | + * @param {event} e the event from browser |
| 64 | + **/ |
| 65 | + function labelDown(e) { |
| 66 | + e = normalisedClient(e); |
| 67 | + clientStart = { x: e.clientX, y: e.clientY }; |
| 68 | + } |
| 69 | +
|
| 70 | + /** |
| 71 | + * function to run when the user releases the mouse/finger |
| 72 | + * we check if the user has moved the mouse/finger, if not we "click" the label |
| 73 | + * and move the handle it to the label position |
| 74 | + * @param {number} val the value of the label |
| 75 | + * @param {event} e the event from browser |
| 76 | + */ |
| 77 | + function labelUp(val,e) { |
| 78 | + e = normalisedClient(e); |
58 | 79 | if ( !disabled ) { |
59 | | - moveHandle( undefined, val ); |
| 80 | + const distanceMoved = Math.sqrt( Math.pow( clientStart.x - e.clientX, 2 ) + Math.pow( clientStart.y - e.clientY, 2 ) ); |
| 81 | + if ( clientStart && ( distanceMoved <= 5 ) ) { |
| 82 | + moveHandle( undefined, val ); |
| 83 | + } |
60 | 84 | } |
61 | 85 | } |
62 | 86 | </script> |
|
181 | 205 | class:selected={isSelected(min)} |
182 | 206 | class:in-range={inRange(min)} |
183 | 207 | style="{orientationStart}: 0%;" |
184 | | - on:click={labelClick(min)} |
185 | | - on:touchend|preventDefault={labelClick(min)} |
| 208 | + on:pointerdown={(e)=>{labelDown(e)}} |
| 209 | + on:pointerup={(e)=>{labelUp(pipVal(min),e)}} |
186 | 210 | > |
187 | 211 | {#if all === 'label' || first === 'label'} |
188 | 212 | <span class="pipVal"> |
|
200 | 224 | class:selected={isSelected(pipVal(i))} |
201 | 225 | class:in-range={inRange(pipVal(i))} |
202 | 226 | style="{orientationStart}: {percentOf(pipVal(i))}%;" |
203 | | - on:click={labelClick(pipVal(i))} |
204 | | - on:touchend|preventDefault={labelClick(pipVal(i))} |
| 227 | + on:pointerdown={(e)=>{labelDown(e)}} |
| 228 | + on:pointerup={(e)=>{labelUp(pipVal(i),e)}} |
205 | 229 | > |
206 | 230 | {#if all === 'label' || rest === 'label'} |
207 | 231 | <span class="pipVal"> |
|
219 | 243 | class:selected={isSelected(max)} |
220 | 244 | class:in-range={inRange(max)} |
221 | 245 | style="{orientationStart}: 100%;" |
222 | | - on:click={labelClick(max)} |
223 | | - on:touchend|preventDefault={labelClick(max)} |
| 246 | + on:pointerdown={(e)=>{labelDown(e)}} |
| 247 | + on:pointerup={(e)=>{labelUp(pipVal(max),e)}} |
224 | 248 | > |
225 | 249 | {#if all === 'label' || last === 'label'} |
226 | 250 | <span class="pipVal"> |
|
0 commit comments