aboutsummaryrefslogtreecommitdiffstats
path: root/ui/ui.draggable.js
diff options
context:
space:
mode:
authorPaul Bakaus <paul.bakaus@googlemail.com>2008-07-17 16:13:10 +0000
committerPaul Bakaus <paul.bakaus@googlemail.com>2008-07-17 16:13:10 +0000
commit83f858aa286c6351c0a48004ca11f205b2833887 (patch)
treed3f60e2bc99849202beff0917b8712b49e1339a7 /ui/ui.draggable.js
parentdb258edf2a4411e888e13180ec60b4d56436808c (diff)
downloadjquery-ui-83f858aa286c6351c0a48004ca11f205b2833887.tar.gz
jquery-ui-83f858aa286c6351c0a48004ca11f205b2833887.zip
draggable: implemented more advanced features for the snap option - you can now pass in a object instead of a bolean into "snap", possible keys are the callbacks snap/release (which both receive ui.snapItem) and items (jQuery selector, defaults to :data(draggable))
Diffstat (limited to 'ui/ui.draggable.js')
-rw-r--r--ui/ui.draggable.js18
1 files changed, 15 insertions, 3 deletions
diff --git a/ui/ui.draggable.js b/ui/ui.draggable.js
index a4225093e..3ee2a46a6 100644
--- a/ui/ui.draggable.js
+++ b/ui/ui.draggable.js
@@ -379,7 +379,8 @@ $.ui.plugin.add("draggable", "snap", {
var inst = $(this).data("draggable");
inst.snapElements = [];
- $(ui.options.snap === true ? ':data(draggable)' : ui.options.snap).each(function() {
+
+ $(ui.options.snap.constructor != String ? ( ui.options.snap.items || ':data(draggable)' ) : ui.options.snap).each(function() {
var $t = $(this); var $o = $t.offset();
if(this != inst.element[0]) inst.snapElements.push({
item: this,
@@ -390,7 +391,7 @@ $.ui.plugin.add("draggable", "snap", {
},
drag: function(e, ui) {
-
+
var inst = $(this).data("draggable");
var d = ui.options.snapTolerance || 20;
var x1 = ui.absolutePosition.left, x2 = x1 + inst.helperProportions.width,
@@ -402,7 +403,11 @@ $.ui.plugin.add("draggable", "snap", {
t = inst.snapElements[i].top, b = t + inst.snapElements[i].height;
//Yes, I know, this is insane ;)
- if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) continue;
+ if(!((l-d < x1 && x1 < r+d && t-d < y1 && y1 < b+d) || (l-d < x1 && x1 < r+d && t-d < y2 && y2 < b+d) || (l-d < x2 && x2 < r+d && t-d < y1 && y1 < b+d) || (l-d < x2 && x2 < r+d && t-d < y2 && y2 < b+d))) {
+ if(inst.snapElements[i].snapping) (inst.options.snap.release && inst.options.snap.release.call(inst.element, null, $.extend(inst.uiHash(), { snapItem: inst.snapElements[i].item })));
+ inst.snapElements[i].snapping = false;
+ continue;
+ }
if(ui.options.snapMode != 'inner') {
var ts = Math.abs(t - y2) <= 20;
@@ -415,6 +420,8 @@ $.ui.plugin.add("draggable", "snap", {
if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r }).left;
}
+ var first = (ts || bs || ls || rs);
+
if(ui.options.snapMode != 'outer') {
var ts = Math.abs(t - y1) <= 20;
var bs = Math.abs(b - y2) <= 20;
@@ -426,7 +433,12 @@ $.ui.plugin.add("draggable", "snap", {
if(rs) ui.position.left = inst.convertPositionTo("relative", { top: 0, left: r - inst.helperProportions.width }).left;
}
+ if(!inst.snapElements[i].snapping && (ts || bs || ls || rs || first))
+ (inst.options.snap.snap && inst.options.snap.snap.call(inst.element, null, $.extend(inst.uiHash(), { snapItem: inst.snapElements[i].item })));
+ inst.snapElements[i].snapping = (ts || bs || ls || rs || first);
+
};
+
}
});