jquery-ui/ui/jquery.ui.droppable.js

94 lines
2.3 KiB
JavaScript
Raw Normal View History

2008-06-04 02:34:33 +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)
* Dual licensed under the MIT or GPL Version 2 licenses.
* http://jquery.org/license
*
2008-06-04 02:34:33 +00:00
* http://docs.jquery.com/UI/Droppables
*
* Depends:
* jquery.ui.core.js
* jquery.ui.widget.js
2010-02-03 23:19:48 +00:00
* jquery.ui.draggable.js
2008-06-04 02:34:33 +00:00
*/
(function( $, undefined ) {
2008-06-04 02:34:33 +00:00
$.widget("ui.droppable", {
version: "@VERSION",
widgetEventPrefix: "drop",
2011-11-13 22:28:56 +00:00
allowedTolerance: ['touch'],
options: {
2011-11-13 22:28:56 +00:00
// accept: '*',
// activeClass: false,
// addClasses: true,
// greedy: false,
// hoverClass: false,
// scope: 'default',
tolerance: 'touch' //'intersect'
},
2011-11-13 22:28:56 +00:00
// draggableProportions: width and height of currently dragging draggable
// proportions: width and height of droppable
_create: function() {
2011-11-13 22:28:56 +00:00
// Store current location
this.offset = this.element.offset();
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 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 ) );
2008-06-04 02:34:33 +00:00
},
2011-11-13 22:28:56 +00:00
_drag: function( event, ui ) {
var rightEdge, bottomEdge, draggableRightEdge, draggableBottomEdge, xOverlap, yOverlap;
switch ( this.options.tolerance ) {
case 'touch':
rightEdge = ( this.offset.left + this.proportions.width ),
bottomEdge = ( this.offset.top + this.proportions.height ),
draggableRightEdge = ( ui.offset.left + this.draggableProportions.width ),
draggableBottomEdge = ( ui.offset.top + this.draggableProportions.height ),
xOverlap = ( draggableRightEdge >= this.offset.left && ui.offset.left <= rightEdge ),
yOverlap = ( draggableBottomEdge >= this.offset.top && ui.offset.top <= bottomEdge );
if ( xOverlap && yOverlap ) {
// TODO: properly fill out uiHash
this._trigger( "over", event, {} );
}
break;
default:
throw( "Invalid tolerance passed: " + this.options.tolerance + ". Allowed: " + this.allowedTolerance.join( ', ' ) );
break;
}
2008-06-04 02:34:33 +00:00
},
2011-11-13 22:28:56 +00:00
_dragStart: function( event, ui ) {
var draggable = $( event.target );
this.draggableProportions = { width: draggable[0].offsetWidth, height: draggable[0].offsetHeight };
2008-06-04 02:34:33 +00:00
}
2011-11-13 22:28:56 +00:00
});
2011-11-13 22:28:56 +00:00
})(jQuery);