2008-06-04 02:34:33 +00:00
|
|
|
/*
|
2011-09-28 01:10:59 +00:00
|
|
|
* jQuery UI Draggable 2.0.0
|
2008-06-04 02:34:33 +00:00
|
|
|
*
|
2011-01-17 14:13:18 +00:00
|
|
|
* Copyright 2011, AUTHORS.txt (http://jqueryui.com/about)
|
2010-07-09 13:01:04 +00:00
|
|
|
* Dual licensed under the MIT or GPL Version 2 licenses.
|
|
|
|
* http://jquery.org/license
|
2008-11-10 05:18:20 +00:00
|
|
|
*
|
2008-06-04 02:34:33 +00:00
|
|
|
* http://docs.jquery.com/UI/Draggables
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.ui.core.js
|
2009-12-22 19:51:24 +00:00
|
|
|
* jquery.ui.widget.js
|
2008-06-04 02:34:33 +00:00
|
|
|
*/
|
2010-07-13 13:57:58 +00:00
|
|
|
(function( $, undefined ) {
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
$.widget("ui.draggable", {
|
2010-02-05 03:03:50 +00:00
|
|
|
widgetEventPrefix: "drag",
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
helper : false
|
2009-04-15 02:33:28 +00:00
|
|
|
|
2008-11-21 04:01:33 +00:00
|
|
|
},
|
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
drag_el : false, // either element or the helper
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
position : {},
|
|
|
|
offset : {},
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_start_coords : {}, // start X/Y coords of mouse before drag
|
|
|
|
_start_position : {}, // start position of element before drag
|
|
|
|
_start_offset : {}, // start offset of element before drag
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_create: function() {
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this.scrollParent = this.element.scrollParent();
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Static position elements can't be moved with top/left
|
|
|
|
if ( this.element.css( "position" ) === "static" ) {
|
|
|
|
this.element.css( "position", "relative" );
|
|
|
|
}
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Prevent browser from hijacking drag
|
|
|
|
this.element.disableSelection();
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Using proxy to avoid anon functions using self to pass "this" along
|
|
|
|
this.element.bind( "mousedown." + this.widgetName, $.proxy( this._mouseDown, this ) );
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
}, // _create
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
destroy: function() {
|
2010-01-28 16:35:59 +00:00
|
|
|
return this;
|
2011-09-28 01:10:59 +00:00
|
|
|
}, // destroy
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_setPosition : function() {
|
2008-11-23 17:42:24 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
var left, top, position, css_position;
|
2008-11-23 17:42:24 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Helper is appended to body so offset of element is all that's needed
|
|
|
|
if ( this.options.helper === true ) {
|
|
|
|
return this.element.offset();
|
|
|
|
}
|
2008-11-23 17:42:24 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
css_position = this.drag_el.css( "position" );;
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// If fixed or absolute
|
|
|
|
if ( css_position !== "relative" ) {
|
2008-11-23 17:42:24 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
position = this.drag_el.position();
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
if ( css_position === "absolute" ) {
|
|
|
|
return position;
|
|
|
|
}
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Take into account scrollbar for fixed position
|
|
|
|
position.top = position.top - this.scrollParent.scrollTop();
|
|
|
|
position.left = position.left - this.scrollParent.scrollLeft();
|
2008-11-23 17:42:24 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
return position;
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
} // css_position !+== absolute
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
/** When using relative, css values are checked **/
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
left = this.drag_el.css( "left" );
|
|
|
|
top = this.drag_el.css( "top" );
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// 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 );
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
return {
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
left : left,
|
|
|
|
top : top
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
};
|
2009-01-08 12:37:15 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
}, // _setPosition
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_mouseDown : function( event ) {
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
var el_position;
|
|
|
|
|
|
|
|
this.drag_el = this.element;
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Helper required, so clone, hide, and set reference
|
|
|
|
if ( this.options.helper === true ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this.drag_el = this.element.clone();
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// If source element has an ID, change ID of helper to avoid overlap
|
|
|
|
if ( this.element.attr( 'id' ) ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this.drag_el
|
|
|
|
.css({
|
|
|
|
position : 'absolute',
|
|
|
|
display : 'none'
|
|
|
|
})
|
|
|
|
.disableSelection()
|
|
|
|
.attr( 'id', this.element.attr( 'id' ) + '-' + this.widgetName );
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
} // id
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
$('body').append( this.drag_el );
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
} // if this.options.helper = true
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Cache starting absolute and relative positions
|
|
|
|
this._start_position = this._setPosition();
|
|
|
|
this._start_offset = this.drag_el.offset();
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Cache current position and offset
|
|
|
|
this.position = $.extend( {}, this._start_position );
|
|
|
|
this.offset = $.extend( {}, this._start_offset );
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this._start_coords = {
|
|
|
|
left : event.clientX,
|
|
|
|
top : event.clientY
|
|
|
|
};
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this._trigger( "start", event );
|
2009-01-22 13:10:18 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
$(document).bind( "mousemove." + this.widgetName, $.proxy( this._mouseMove, this ) );
|
|
|
|
$(document).bind( "mouseup." + this.widgetName, $.proxy( this._mouseUp, this ) );
|
2009-01-22 13:10:18 +00:00
|
|
|
|
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Set the helper up by actual element
|
|
|
|
if ( this.options.helper === true ) {
|
2008-12-31 08:22:11 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// get the absolute position of element so that helper will know where to go
|
|
|
|
el_offset = this.element.offset();
|
2008-12-30 16:34:23 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this.drag_el.css({
|
|
|
|
display : 'block',
|
|
|
|
top : el_offset.top + 'px',
|
|
|
|
left : el_offset.left + 'px'
|
|
|
|
});
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
} // this.options.height = true
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
}, // _mouseDown
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_mouseMove : function( event ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
var left_diff = event.clientX - this._start_coords.left,
|
|
|
|
top_diff = event.clientY - this._start_coords.top,
|
|
|
|
new_left = left_diff + this._start_position.left,
|
|
|
|
new_top = top_diff + this._start_position.top;
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this.position = {
|
|
|
|
left : new_left,
|
|
|
|
top : new_top
|
|
|
|
};
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// Refresh offset cache with new positions
|
|
|
|
this.offset.left = this._start_offset.left + new_left;
|
|
|
|
this.offset.top = this._start_offset.top + new_top;
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this._trigger( "drag", event );
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// User overriding left/top so shortcut math is no longer valid
|
|
|
|
if ( new_left !== this.position.left || new_top !== this.position.top ) {
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
// refresh offset using slower functions
|
|
|
|
this.offset = this.drag_el.offset();
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
}
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this.drag_el.css({
|
2008-11-23 17:42:24 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
left : this.position.left + 'px',
|
|
|
|
top : this.position.top + 'px'
|
2009-01-24 01:36:22 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
});
|
2008-11-28 15:43:32 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
}, // _mouseMove
|
2009-01-24 01:36:22 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_mouseUp : function( event ) {
|
2009-01-24 01:36:22 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this._trigger( "stop", event );
|
2009-01-24 01:36:22 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
this._start_coords = {};
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
if ( this.options.helper === true ) {
|
|
|
|
this.drag_el.remove();
|
|
|
|
}
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
$(document).unbind( "mousemove." + this.widgetName );
|
|
|
|
$(document).unbind( "mouseup." + this.widgetName );
|
2008-06-04 02:34:33 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
}, // _mouseUp
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_trigger: function(type, event, ui) {
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
ui = ui || this._uiHash();
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
return $.Widget.prototype._trigger.call(this, type, event, ui);
|
|
|
|
}, // _trigger
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
_uiHash: function(event) {
|
|
|
|
return {
|
|
|
|
position : this.position,
|
|
|
|
offset : this.offset
|
2008-06-04 02:34:33 +00:00
|
|
|
};
|
2011-09-28 01:10:59 +00:00
|
|
|
} // _uiHash
|
2008-11-10 05:18:20 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2011-09-28 01:10:59 +00:00
|
|
|
$.extend($.ui.draggable, {
|
|
|
|
version: "2.0.0"
|
2008-06-04 02:34:33 +00:00
|
|
|
});
|
|
|
|
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
})(jQuery);
|