Draggable: Proper use of ._trigger for detecting preventDefault. _uiHash now returns position and helper - removed offset.

This commit is contained in:
Dave Stein 2011-11-06 16:20:56 -05:00
parent 1337573adc
commit ec9c1cf6f4

View File

@ -124,7 +124,7 @@ $.widget( "ui.draggable", {
}, },
_mouseDown: function( event ) { _mouseDown: function( event ) {
var newLeft, newTop; var newLeft, newTop, allowed;
// Prevent text selection, among other things // Prevent text selection, among other things
event.preventDefault(); event.preventDefault();
@ -183,11 +183,10 @@ $.widget( "ui.draggable", {
this._preparePosition( event ); this._preparePosition( event );
this._trigger( "start", event, this._uiHash() ); allowed = this._trigger( "start", event, this._uiHash() );
// TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes // If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( event.cancelBubble === true ) { if ( allowed !== true ) {
this.doc.unbind( "." + this.widgetName ); this.doc.unbind( "." + this.widgetName );
return; return;
} }
@ -201,15 +200,15 @@ $.widget( "ui.draggable", {
}, },
_mouseMove: function( event ) { _mouseMove: function( event ) {
var newLeft, newTop; var newLeft, newTop, allowed;
this._preparePosition( event ); this._preparePosition( event );
this._trigger( "drag", event, this._uiHash() ); allowed = this._trigger( "drag", event, this._uiHash() );
// TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes // If user stops propagation, leave helper there ( if there's one ), disallow any CSS changes
if ( event.cancelBubble === true ) { if ( allowed !== true ) {
this.doc.unbind( "." + this.widgetName ); this.doc.unbind( "." + this.widgetName );
return; return;
} }
@ -221,14 +220,15 @@ $.widget( "ui.draggable", {
}, },
_mouseUp: function( event ) { _mouseUp: function( event ) {
var allowed;
this._preparePosition( event ); this._preparePosition( event );
this._trigger( "stop", event, this._uiHash() ); allowed = this._trigger( "stop", event, this._uiHash() );
// TODO: should user be able to change position of draggable, if event stopped?
// If user stops propagation, leave helper there, disallow any CSS changes // If user stops propagation, leave helper there, disallow any CSS changes
if ( event.cancelBubble !== true ) { if ( allowed === true ) {
this._setCss( event ); this._setCss( event );
@ -293,10 +293,17 @@ $.widget( "ui.draggable", {
}, },
_uiHash: function( event ) { _uiHash: function( event ) {
return { var ret = {
position: this.position, position: this.position
offset: this.offset // offset: this.offset
}; };
if ( this.options.helper ) {
ret.helper = this.dragEl;
}
return ret;
} }
}); });