Skip to content

Commit ec9c1cf

Browse files
committed
Draggable: Proper use of ._trigger for detecting preventDefault. _uiHash now returns position and helper - removed offset.
1 parent 1337573 commit ec9c1cf

File tree

1 file changed

+23
-16
lines changed

1 file changed

+23
-16
lines changed

ui/jquery.ui.draggable.js

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ $.widget( "ui.draggable", {
124124
},
125125

126126
_mouseDown: function( event ) {
127-
var newLeft, newTop;
127+
var newLeft, newTop, allowed;
128128

129129
// Prevent text selection, among other things
130130
event.preventDefault();
@@ -183,11 +183,10 @@ $.widget( "ui.draggable", {
183183

184184
this._preparePosition( event );
185185

186-
this._trigger( "start", event, this._uiHash() );
186+
allowed = this._trigger( "start", event, this._uiHash() );
187187

188-
// TODO: should user be able to change position of draggable, if event stopped?
189188
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
190-
if ( event.cancelBubble === true ) {
189+
if ( allowed !== true ) {
191190
this.doc.unbind( "." + this.widgetName );
192191
return;
193192
}
@@ -201,15 +200,15 @@ $.widget( "ui.draggable", {
201200
},
202201

203202
_mouseMove: function( event ) {
204-
var newLeft, newTop;
205-
203+
var newLeft, newTop, allowed;
204+
206205
this._preparePosition( event );
207206

208-
this._trigger( "drag", event, this._uiHash() );
209-
210-
// TODO: should user be able to change position of draggable, if event stopped?
207+
allowed = this._trigger( "drag", event, this._uiHash() );
208+
209+
211210
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
212-
if ( event.cancelBubble === true ) {
211+
if ( allowed !== true ) {
213212
this.doc.unbind( "." + this.widgetName );
214213
return;
215214
}
@@ -221,14 +220,15 @@ $.widget( "ui.draggable", {
221220
},
222221

223222
_mouseUp: function( event ) {
223+
224+
var allowed;
224225

225226
this._preparePosition( event );
226227

227-
this._trigger( "stop", event, this._uiHash() );
228+
allowed = this._trigger( "stop", event, this._uiHash() );
228229

229-
// TODO: should user be able to change position of draggable, if event stopped?
230230
// If user stops propagation, leave helper there, disallow any CSS changes
231-
if ( event.cancelBubble !== true ) {
231+
if ( allowed === true ) {
232232

233233
this._setCss( event );
234234

@@ -293,10 +293,17 @@ $.widget( "ui.draggable", {
293293
},
294294

295295
_uiHash: function( event ) {
296-
return {
297-
position: this.position,
298-
offset: this.offset
296+
var ret = {
297+
position: this.position
298+
// offset: this.offset
299299
};
300+
301+
if ( this.options.helper ) {
302+
ret.helper = this.dragEl;
303+
}
304+
305+
return ret;
306+
300307
}
301308
});
302309

0 commit comments

Comments
 (0)