Classes
- API Home
- _global_
- Array
- Jelo
- Jelo.Ajax
- Jelo.Anim
- Jelo.Core
- Jelo.CSS
- Jelo.Dom
- Jelo.DragDrop
- Jelo.Env
- Jelo.Event
- Jelo.JSON
- Jelo.Widget
Namespace Jelo.DragDrop
Provides element drag and drop detection.
Defined in: Jelo.DragDrop.js.
| Constructor Attributes | Constructor Name and Description |
|---|---|
| Method Attributes | Method Name and Description |
|---|---|
| <static> |
Jelo.DragDrop.disable()
Stop listening for drag and drop events.
|
| <static> |
Jelo.DragDrop.enable()
Start listening for drag and drop events.
|
| <static> |
Jelo.DragDrop.getTarget()
|
| <static> |
Jelo.DragDrop.getThreshold()
|
| <static> |
Jelo.DragDrop.isDragging(compare)
Determines whether a drag event is occurring.
|
| <static> |
Jelo.DragDrop.setDraggable(element, fn, handle)
NOTE: Inside
fn.before, fn.drag, and fn.after,
you can access the drag target using "this":
Jelo.DragDrop.setDraggable(element, {
before: function(event) {
// the element currently being dragged
var target = this;
// all normal event properties and methods are available
var x = event.clientX;
var y = event.clientY;
// this will avoid executing mousedown events on this element or its ancestors
event.preventDefault();
event.stopPropagation();
}
});
You can use default drag behaviors while overriding them:
Jelo.DragDrop.setDraggable(element, {
before: function(event) {
// default setup behavior
Jelo.DragDrop.getBehavior('before').call(this, e);
// any additional initialization you require
$(this).addClass('dragging');
},
after: function(event) {
Jelo.DragDrop.getBehavior('after').call(this, e);
$(this).removeClass('dragging');
}
});
|
| <static> |
Jelo.DragDrop.setDroppable(element, fn, handle)
NOTE: Inside
fn.enter, fn.over, fn.leave, and fn.drop,
you can access the drag target using the supplied event object:
Jelo.DragDrop.setDroppable(element, {
enter: function(event) {
// the element currently being dragged
var target = event.dragTarget;
// all normal event properties and methods are available
var x = event.clientX;
var y = event.clientY;
event.stopPropagation();
}
});
You can use default drop behaviors while overriding them:
Jelo.DragDrop.setDroppable(element, {
drop: function(event) {
if ($(event.dragTarget).hasClass('my-element')) {
// only apply default behavior to elements that pass the above check
Jelo.DragDrop.getBehavior('drop').call(this, e);
}
}
});
|
| <static> |
Jelo.DragDrop.setThreshold(n)
|
Method Detail
<static>
Jelo.DragDrop.disable()
Stop listening for drag and drop events.
<static>
Jelo.DragDrop.enable()
Start listening for drag and drop events.
<static>
{HTMLElement}
Jelo.DragDrop.getTarget()
- Returns:
- {HTMLElement} The element currently being dragged, or null if unavailable.
<static>
{Number}
Jelo.DragDrop.getThreshold()
- Returns:
- {Number} How many pixels an element must be dragged before its drag behavior actually "kicks in".
<static>
{Boolean}
Jelo.DragDrop.isDragging(compare)
Determines whether a drag event is occurring. If an element is passed as the
compare argument,
this function determines whether the dragged element is identical to the supplied element.
- Parameters:
- {HTMLElement} compare Optional
- An element to examine.
- Returns:
- {Boolean} If
compareis null, this function returns true if any element is currently being dragged. Ifcompareis supplied, this function returns true if the supplied element is currently being dragged.
<static>
Jelo.DragDrop.setDraggable(element, fn, handle)
NOTE: Inside
fn.before, fn.drag, and fn.after,
you can access the drag target using "this":
Jelo.DragDrop.setDraggable(element, {
before: function(event) {
// the element currently being dragged
var target = this;
// all normal event properties and methods are available
var x = event.clientX;
var y = event.clientY;
// this will avoid executing mousedown events on this element or its ancestors
event.preventDefault();
event.stopPropagation();
}
});
You can use default drag behaviors while overriding them:
Jelo.DragDrop.setDraggable(element, {
before: function(event) {
// default setup behavior
Jelo.DragDrop.getBehavior('before').call(this, e);
// any additional initialization you require
$(this).addClass('dragging');
},
after: function(event) {
Jelo.DragDrop.getBehavior('after').call(this, e);
$(this).removeClass('dragging');
}
});
- Parameters:
- {HTMLElement|Array} element
- One or more elements.
- {Function|Object} fn Optional
- If this argument is a function, it will be used as
fn.drag(see below). If it is literallyfalse, it will turn off all drag behavior forelement. - {Function} fn.before Optional
- Code to execute immediately before a drag operation takes place. Note that this is not called until the drag meets or exceeds the threshold.
- {Function} fn.drag Optional
- Code to execute while an element is being dragged. By default, it positions the element at the mouse cursor.
- {Function} fn.after Optional
- Code to execute when an element is dropped. This function runs before the drop
target's
drophandler. - {HTMLElement} handle Optional, Default: element
- The "drag handle", meaning the element you actually use to drag
elementBy default, the handle is the entire target element, but you may wish to specify a different element (for example, a panel might be dragged by only its title bar).
<static>
Jelo.DragDrop.setDroppable(element, fn, handle)
NOTE: Inside
fn.enter, fn.over, fn.leave, and fn.drop,
you can access the drag target using the supplied event object:
Jelo.DragDrop.setDroppable(element, {
enter: function(event) {
// the element currently being dragged
var target = event.dragTarget;
// all normal event properties and methods are available
var x = event.clientX;
var y = event.clientY;
event.stopPropagation();
}
});
You can use default drop behaviors while overriding them:
Jelo.DragDrop.setDroppable(element, {
drop: function(event) {
if ($(event.dragTarget).hasClass('my-element')) {
// only apply default behavior to elements that pass the above check
Jelo.DragDrop.getBehavior('drop').call(this, e);
}
}
});
- Parameters:
- {HTMLElement|Array} element
- One or more elements.
- {Function|Object} fn Optional
- If this argument is a function, it will be used as
fn.drop(see below). If it is literallyfalse, it will turn off all drop behavior forelement. - {Function} fn.enter Optional
- Code to execute once a draggable element begins to hover over
element. Typically used to changeelement's styles to indicate valid or invalid drops. - {Function} fn.over Optional
- Code to execute constantly while an element is dragged over
element. - {Function} fn.leave Optional
- Code to execute once a draggable element stops hovering over
element. - {Function} fn.drop Optional
- Code to execute after a draggable element is dropped on
element. By default, the drag target becomes a child ofelement. - {HTMLElement} handle Optional, Default: element
- The "drop handle", meaning the element you actually want to listen to drop events. By default, the handle is the entire target element, but you may wish to specify a different element depending on your intended behavior.
<static>
Jelo.DragDrop.setThreshold(n)
- Parameters:
- {Number} n
- How many pixels an element must be dragged before its drag behavior actually "kicks in".
- recent changes — (see all)
-
- Sep 14, 2010 — Simplified DragDrop.
- Jul 19, 2010 — Fixed typo preventing reliably aborting pending Ajax requests.
- Jun 17, 2010 — Fixed a conflict preventing Easing.SWINGOUT and Easing.SWINGBOTH from running simultaneously.
- Apr 22, 2010 — Added Array support to CSS.toggleClass.
- random jelo shots — (see all)
