Draggable: Fixed coding style, moved properties out of prototype

This commit is contained in:
= 2011-10-01 12:05:36 -04:00
parent c10acecdd4
commit 1f23656fe2

View File

@ -19,31 +19,31 @@ $.widget( "ui.draggable", {
options: {
helper : false
helper: false
},
// Either initialized element or the helper
dragEl : false,
position : {},
offset : {},
// Start X/Y coords of mouse before drag
startCoords : {},
// Start position of element before drag
startPosition : {},
// Start offset of element before drag
startOffset : {},
// TODO: actually remove data
destroy: function() {
return this;
return this;
},
_create: function() {
// Either initialized element or the helper
this.dragEl = false,
this.position = {},
this.offset = {},
// Start X/Y coords of mouse before drag
this.startCoords = {},
// Start position of element before drag
this.startPosition = {},
// Start offset of element before drag
this.startOffset = {},
this.scrollParent = this.element.scrollParent();
@ -60,7 +60,7 @@ $.widget( "ui.draggable", {
},
_setPosition : function() {
_setPosition: function() {
var left, top, position, cssPosition;
@ -81,7 +81,7 @@ $.widget( "ui.draggable", {
}
// Take into account scrollbar for fixed position
position.top = position.top - this.scrollParent.scrollTop();
position.top = position.top - this.scrollParent.scrollTop();
position.left = position.left - this.scrollParent.scrollLeft();
return position;
@ -91,22 +91,22 @@ $.widget( "ui.draggable", {
/** When using relative, css values are checked **/
left = this.dragEl.css( "left" );
top = this.dragEl.css( "top" );
top = this.dragEl.css( "top" );
// Webkit will give back auto if there is nothing inline yet
left = ( left === "auto" ) ? 0 : parseInt( left, 10 );
top = ( top === "auto" ) ? 0 : parseInt( top, 10 );
left = ( left === "auto" ) ? 0: parseInt( left, 10 );
top = ( top === "auto" ) ? 0: parseInt( top, 10 );
return {
left : left,
top : top
left: left,
top: top
};
},
_mouseDown : function( event ) {
_mouseDown: function( event ) {
this.dragEl = this.element;
@ -120,8 +120,8 @@ $.widget( "ui.draggable", {
this.dragEl
.css({
position : "absolute",
display : "none"
position: "absolute",
display: "none"
})
.disableSelection()
.attr( "id", this.element.attr( "id" ) + "-" + this.widgetName );
@ -134,15 +134,15 @@ $.widget( "ui.draggable", {
// Cache starting absolute and relative positions
this.startPosition = this._setPosition();
this.startOffset = this.dragEl.offset();
this.startOffset = this.dragEl.offset();
// Cache current position and offset
this.position = $.extend( {}, this.startPosition );
this.offset = $.extend( {}, this.startOffset );
this.offset = $.extend( {}, this.startOffset );
this.startCoords = {
left : event.clientX,
top : event.clientY
left: event.clientX,
top: event.clientY
};
this._trigger( "start", event );
@ -158,30 +158,30 @@ $.widget( "ui.draggable", {
elOffset = this.element.offset();
this.dragEl.css({
display : "block",
top : elOffset.top + "px",
left : elOffset.left + "px"
display: "block",
top: elOffset.top + "px",
left: elOffset.left + "px"
});
} // this.options.height = true
},
_mouseMove : function( event ) {
_mouseMove: function( event ) {
var leftDiff = event.clientX - this.startCoords.left,
topDiff = event.clientY - this.startCoords.top,
newLeft = leftDiff + this.startPosition.left,
newTop = topDiff + this.startPosition.top;
topDiff = event.clientY - this.startCoords.top,
newLeft = leftDiff + this.startPosition.left,
newTop = topDiff + this.startPosition.top;
this.position = {
left : newLeft,
top : newTop
left: newLeft,
top: newTop
};
// Refresh offset cache with new positions
this.offset.left = this.startOffset.left + newLeft;
this.offset.top = this.startOffset.top + newTop;
this.offset.top = this.startOffset.top + newTop;
this._trigger( "drag", event );
@ -189,20 +189,20 @@ $.widget( "ui.draggable", {
if ( newLeft !== this.position.left || newTop !== this.position.top ) {
// refresh offset using slower functions
this.offset = this.dragEl.offset();
this.offset = this.dragEl.offset();
}
this.dragEl.css({
left : this.position.left + "px",
top : this.position.top + "px"
left: this.position.left + "px",
top: this.position.top + "px"
});
},
_mouseUp : function( event ) {
_mouseUp: function( event ) {
this._trigger( "stop", event );
@ -228,8 +228,8 @@ $.widget( "ui.draggable", {
_uiHash: function(event) {
return {
position : this.position,
offset : this.offset
position: this.position,
offset: this.offset
};
}