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 ) {
var newLeft, newTop;
var newLeft, newTop, allowed;
// Prevent text selection, among other things
event.preventDefault();
@ -183,11 +183,10 @@ $.widget( "ui.draggable", {
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 ( event.cancelBubble === true ) {
if ( allowed !== true ) {
this.doc.unbind( "." + this.widgetName );
return;
}
@ -201,15 +200,15 @@ $.widget( "ui.draggable", {
},
_mouseMove: function( event ) {
var newLeft, newTop;
var newLeft, newTop, allowed;
this._preparePosition( event );
this._trigger( "drag", event, this._uiHash() );
// TODO: should user be able to change position of draggable, if event stopped?
allowed = this._trigger( "drag", event, this._uiHash() );
// 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 );
return;
}
@ -221,14 +220,15 @@ $.widget( "ui.draggable", {
},
_mouseUp: function( event ) {
var allowed;
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 ( event.cancelBubble !== true ) {
if ( allowed === true ) {
this._setCss( event );
@ -293,10 +293,17 @@ $.widget( "ui.draggable", {
},
_uiHash: function( event ) {
return {
position: this.position,
offset: this.offset
var ret = {
position: this.position
// offset: this.offset
};
if ( this.options.helper ) {
ret.helper = this.dragEl;
}
return ret;
}
});