2008-06-04 02:34:33 +00:00
|
|
|
/*
|
2008-09-04 22:03:30 +00:00
|
|
|
* jQuery UI Droppable @VERSION
|
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-20 04:10:34 +00:00
|
|
|
*
|
2008-06-04 02:34:33 +00:00
|
|
|
* http://docs.jquery.com/UI/Droppables
|
|
|
|
*
|
|
|
|
* Depends:
|
2009-09-17 10:39:12 +00:00
|
|
|
* jquery.ui.core.js
|
2010-01-07 03:19:50 +00:00
|
|
|
* jquery.ui.widget.js
|
2010-02-03 23:19:48 +00:00
|
|
|
* jquery.ui.draggable.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
|
|
|
|
|
|
|
$.widget("ui.droppable", {
|
2011-05-28 19:39:55 +00:00
|
|
|
version: "@VERSION",
|
2010-02-05 03:03:50 +00:00
|
|
|
widgetEventPrefix: "drop",
|
2011-11-13 23:41:29 +00:00
|
|
|
allowedTolerance: ["touch","intersect"],
|
2010-01-07 03:19:50 +00:00
|
|
|
options: {
|
2011-11-13 22:28:56 +00:00
|
|
|
// accept: '*',
|
|
|
|
// activeClass: false,
|
|
|
|
// addClasses: true,
|
|
|
|
// greedy: false,
|
|
|
|
// hoverClass: false,
|
|
|
|
// scope: 'default',
|
2011-11-13 23:39:04 +00:00
|
|
|
tolerance: 'intersect'
|
2010-01-07 03:19:50 +00:00
|
|
|
},
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
// draggableProportions: width and height of currently dragging draggable
|
2011-11-13 22:42:05 +00:00
|
|
|
// over: whether or not a draggable is currently over droppable
|
2011-11-13 22:28:56 +00:00
|
|
|
// proportions: width and height of droppable
|
2011-11-13 23:39:04 +00:00
|
|
|
|
|
|
|
|
2011-11-13 22:49:37 +00:00
|
|
|
refreshPosition: function() {
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
// Store current location
|
|
|
|
this.offset = this.element.offset();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
//Store the droppable's proportions
|
2008-07-02 17:38:34 +00:00
|
|
|
this.proportions = { width: this.element[0].offsetWidth, height: this.element[0].offsetHeight };
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:49:37 +00:00
|
|
|
},
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:49:37 +00:00
|
|
|
_create: function() {
|
|
|
|
|
|
|
|
this.refreshPosition();
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
// TODO: Use $.Callbacks or .on from 1.7
|
|
|
|
$('*').live( "drag", $.proxy( this._drag, this ) );
|
|
|
|
$('*').live( "dragstart", $.proxy( this._dragStart, this ) );
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
this._bind( this.document, {
|
|
|
|
mouseup: "_mouseUp"
|
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
_drag: function( event, ui ) {
|
2011-11-13 23:39:04 +00:00
|
|
|
|
|
|
|
var handleFunc, edges,
|
|
|
|
tolerance = this.options.tolerance,
|
|
|
|
over = false;
|
|
|
|
|
|
|
|
switch ( tolerance ) {
|
|
|
|
|
|
|
|
case "intersect":
|
|
|
|
case "touch":
|
|
|
|
|
|
|
|
edges = {
|
|
|
|
right: ( this.offset.left + this.proportions.width ),
|
|
|
|
bottom: ( this.offset.top + this.proportions.height ),
|
|
|
|
draggableRight: ( ui.offset.left + this.draggableProportions.width ),
|
|
|
|
draggableBottom: ( ui.offset.top + this.draggableProportions.height )
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
handleFunc = "_handle" + tolerance.substr(0, 1 ).toUpperCase() + tolerance.substr( 1 );
|
|
|
|
over = this[ handleFunc ]( edges, ui );
|
2011-11-13 22:28:56 +00:00
|
|
|
|
|
|
|
break;
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
default:
|
2011-11-13 23:39:04 +00:00
|
|
|
throw( "Invalid tolerance passed: " + this.options.tolerance + ". Allowed: " + this.allowedTolerance.join( ", " ) );
|
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
}
|
|
|
|
|
2011-11-13 23:39:04 +00:00
|
|
|
// If there is sufficient overlap as deemed by tolerance
|
|
|
|
if ( over === true ) {
|
|
|
|
|
|
|
|
this._trigger( "over", event, this._uiHash() );
|
|
|
|
this.over = true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
// If there isn't enough overlap and droppable was previously flagged as over
|
|
|
|
else if ( this.over === true ) {
|
|
|
|
|
|
|
|
this.over = false;
|
|
|
|
this._trigger( "out", event, this._uiHash() );
|
|
|
|
|
|
|
|
}
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
},
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
_dragStart: function( event, ui ) {
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
var draggable = $( event.target );
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
// TODO: Possibly move into draggable hash, so if there are multiple droppables, it's not recalculating all the time
|
2011-11-13 22:28:56 +00:00
|
|
|
this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight };
|
2008-11-18 02:55:25 +00:00
|
|
|
|
|
|
|
|
2011-11-13 23:39:04 +00:00
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
// Determines if draggable is over droppable based on intersect tolerance
|
|
|
|
_handleIntersect: function( edges, ui ) {
|
|
|
|
|
|
|
|
var xDiff = edges.draggableRight - this.offset.left,
|
|
|
|
yDiff = edges.draggableBottom - this.offset.top,
|
|
|
|
xHalfway = Math.round( this.proportions.width / 2 ),
|
|
|
|
yHalfway = Math.round( this.proportions.height / 2 ),
|
|
|
|
xHalfOverlap = false;
|
|
|
|
yHalfOverlap = false;
|
|
|
|
|
|
|
|
|
|
|
|
// If Coming from left or right
|
|
|
|
xHalfOverlap = ( ui.offset.left < this.offset.left ) ?
|
|
|
|
( xDiff >= xHalfway ) :
|
|
|
|
( xDiff <= xHalfway + this.proportions.width );
|
|
|
|
|
|
|
|
// If Coming from top or bottom
|
|
|
|
yHalfOverlap = ( ui.offset.top < this.offset.top ) ?
|
|
|
|
( yDiff >= yHalfway ) :
|
|
|
|
( yDiff <= yHalfway + this.proportions.height );
|
|
|
|
|
|
|
|
return ( xHalfOverlap && yHalfOverlap );
|
|
|
|
|
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
},
|
|
|
|
|
2011-11-13 23:39:04 +00:00
|
|
|
// Determines if draggable is over droppable based on touch tolerance
|
|
|
|
_handleTouch: function( edges, ui ) {
|
2011-11-13 22:42:05 +00:00
|
|
|
|
2011-11-13 23:39:04 +00:00
|
|
|
var xOverlap = ( edges.draggableRight >= this.offset.left && ui.offset.left <= edges.right ),
|
|
|
|
yOverlap = ( edges.draggableBottom >= this.offset.top && ui.offset.top <= edges.bottom );
|
|
|
|
|
|
|
|
return ( xOverlap && yOverlap );
|
|
|
|
|
|
|
|
},
|
|
|
|
|
|
|
|
_mouseUp: function( event ) {
|
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
if ( this.over ) {
|
|
|
|
this._trigger( "drop", event, this._uiHash() );
|
|
|
|
}
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
this.over = false;
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
},
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
// TODO: fill me out
|
|
|
|
_uiHash: function() {
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2011-11-13 22:42:05 +00:00
|
|
|
return {};
|
2011-11-13 23:39:04 +00:00
|
|
|
|
2008-06-04 02:34:33 +00:00
|
|
|
}
|
2008-11-21 04:01:33 +00:00
|
|
|
|
2008-11-18 02:55:25 +00:00
|
|
|
|
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
});
|
2008-11-18 02:55:25 +00:00
|
|
|
|
2011-11-13 22:28:56 +00:00
|
|
|
})(jQuery);
|
2008-11-18 02:55:25 +00:00
|
|
|
|
|
|
|
|