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