Skip to content

Commit ec87754

Browse files
authored
Merge pull request #2009 from adumesny/master
mobile resizing
2 parents 1a52ba8 + 0bb53bf commit ec87754

File tree

4 files changed

+28
-5
lines changed

4 files changed

+28
-5
lines changed

demo/mobile.html

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,21 @@
77
<title>Simple mobile demo</title>
88

99
<link rel="stylesheet" href="demo.css"/>
10-
<script src="../dist/gridstack-jq.js"></script>
10+
<link rel="stylesheet" href="../dist/gridstack-extra.css"/>
11+
<script src="../dist/gridstack-h5.js"></script>
1112

1213
</head>
1314
<body>
1415
<h1>Simple mobile demo</h1>
15-
<p>uses gridstack-jq.js which includes jquery.ui.touch-punch by default (minimum v3.2+, small 2k)</p>
16+
<p>shows resize handle on mobile and support native touch events</p>
1617
<div class="grid-stack"></div>
1718
<script type="text/javascript">
1819
let grid = GridStack.init({
19-
// column: 1, // will auto switch on smaller screens
20-
cellHeight: 150, // make sure we have a decent height and not width/12 for 1 column
20+
column: 3,
21+
disableOneColumnMode: true,
2122
alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent)
2223
});
23-
grid.load([{x:0, y:0, content: '1'}, {x:0, y:1, h:2, content: '2'}, {x:0, y:3, content: '3'}])
24+
grid.load([{x:0, y:0, content: '1'}, {x:1, y:0, h:2, content: '2'}, {x:2, y:0, content: '3'}])
2425
</script>
2526
</body>
2627
</html>

demo/nested.html

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,9 @@ <h1>Nested grids demo</h1>
6565
cellHeight: 50,
6666
margin: 5,
6767
minRow: 2, // don't collapse when empty
68+
disableOneColumnMode: true,
6869
acceptWidgets: true,
70+
alwaysShowResizeHandle: /Android|webOS|iPhone|iPad|iPod|BlackBerry|IEMobile|Opera Mini/i.test(navigator.userAgent),
6971
id: 'main',
7072
children: [
7173
{x:0, y:0, content: 'regular item'},

src/h5/dd-draggable.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ export class DDDraggable extends DDBaseImplement implements HTMLElementExtendOpt
9999
this.dragEl.removeEventListener('mousedown', this._mouseDown);
100100
if (isTouch) {
101101
this.dragEl.removeEventListener('touchstart', touchstart);
102+
this.dragEl.removeEventListener('pointerdown', pointerdown);
102103
}
103104
this.el.classList.remove('ui-draggable');
104105
if (!forDestroy) this.el.classList.add('ui-draggable-disabled');

src/h5/dd-resizable-handle.ts

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
* Copyright (c) 2021-2022 Alain Dumesny - see GridStack root license
44
*/
55

6+
import { isTouch, pointerdown, touchend, touchmove, touchstart } from './touch';
7+
68
export 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

Comments
 (0)