Skip to content

Commit 9cde172

Browse files
committed
Draggable: Only apply touch-action attr to handle and update handle demo
1 parent b58dc21 commit 9cde172

File tree

2 files changed

+9
-15
lines changed

2 files changed

+9
-15
lines changed

demos/draggable/handle.html

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<script src="../../jquery-1.9.1.js"></script>
88
<script src="../../ui/jquery.ui.core.js"></script>
99
<script src="../../ui/jquery.ui.widget.js"></script>
10+
<script src="../../external/pointerevents.js"></script>
1011
<script src="../../ui/jquery.ui.interaction.js"></script>
1112
<script src="../../ui/jquery.ui.draggable.js"></script>
1213
<link rel="stylesheet" href="../demos.css">
@@ -15,22 +16,9 @@
1516
#draggable p { cursor: move; }
1617
</style>
1718
<script>
18-
$.widget( "ui.draggable", $.ui.draggable, {
19-
options: {
20-
cancel: null
21-
},
22-
_isValidTarget: function( element ) {
23-
var valid = this._super( element );
24-
if ( valid && this.options.cancel ) {
25-
valid = !element.is( this.options.cancel );
26-
}
27-
return valid;
28-
}
29-
});
30-
3119
$(function() {
3220
$( "#draggable" ).draggable({ handle: "p" });
33-
$( "#draggable2" ).draggable({ cancel: "p.ui-widget-header" });
21+
$( "#draggable2" ).draggable({ exclude: "p.ui-widget-header" });
3422
});
3523
</script>
3624
</head>

ui/jquery.ui.draggable.js

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,8 @@ $.widget( "ui.draggable", $.ui.interaction, {
6161
scrollSpeed: 5,
6262

6363
_create: function() {
64+
var handle;
65+
6466
this._super();
6567

6668
// Static position elements can't be moved with top/left
@@ -69,7 +71,11 @@ $.widget( "ui.draggable", $.ui.interaction, {
6971
}
7072

7173
// Add touch-action attribute for pointer events to prevent view panning when dragging
72-
this.element.attr("touch-action", "none");
74+
handle = this.element.find( this.options.handle ).eq(0);
75+
if ( !handle.length ) {
76+
handle = this.element;
77+
}
78+
handle.attr("touch-action", "none");
7379

7480
this.element.addClass( "ui-draggable" );
7581
},

0 commit comments

Comments
 (0)