33 * Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44 */
55
6+ import { isTouch , pointerdown , touchend , touchmove , touchstart } from './touch' ;
7+
68export interface DDResizableHandleOpt {
79 start ?: ( event ) => void ;
810 move ?: ( event ) => void ;
@@ -47,13 +49,22 @@ export class DDResizableHandle {
4749 this . el = el ;
4850 this . host . appendChild ( this . el ) ;
4951 this . el . addEventListener ( 'mousedown' , this . _mouseDown ) ;
52+ if ( isTouch ) {
53+ this . el . addEventListener ( 'touchstart' , touchstart ) ;
54+ this . el . addEventListener ( 'pointerdown' , pointerdown ) ;
55+ // this.el.style.touchAction = 'none'; // not needed unlike pointerdown doc comment
56+ }
5057 return this ;
5158 }
5259
5360 /** call this when resize handle needs to be removed and cleaned up */
5461 public destroy ( ) : DDResizableHandle {
5562 if ( this . moving ) this . _mouseUp ( this . mouseDownEvent ) ;
5663 this . el . removeEventListener ( 'mousedown' , this . _mouseDown ) ;
64+ if ( isTouch ) {
65+ this . el . removeEventListener ( 'touchstart' , touchstart ) ;
66+ this . el . removeEventListener ( 'pointerdown' , pointerdown ) ;
67+ }
5768 this . host . removeChild ( this . el ) ;
5869 delete this . el ;
5970 delete this . host ;
@@ -66,6 +77,10 @@ export class DDResizableHandle {
6677 this . mouseDownEvent = e ;
6778 document . addEventListener ( 'mousemove' , this . _mouseMove , true ) ; // capture, not bubble
6879 document . addEventListener ( 'mouseup' , this . _mouseUp ) ;
80+ if ( isTouch ) {
81+ this . el . addEventListener ( 'touchmove' , touchmove ) ;
82+ this . el . addEventListener ( 'touchend' , touchend ) ;
83+ }
6984 }
7085
7186 /** @internal */
@@ -87,6 +102,10 @@ export class DDResizableHandle {
87102 }
88103 document . removeEventListener ( 'mousemove' , this . _mouseMove , true ) ;
89104 document . removeEventListener ( 'mouseup' , this . _mouseUp ) ;
105+ if ( isTouch ) {
106+ this . el . removeEventListener ( 'touchmove' , touchmove ) ;
107+ this . el . removeEventListener ( 'touchend' , touchend ) ;
108+ }
90109 delete this . moving ;
91110 delete this . mouseDownEvent ;
92111 }
0 commit comments