| 1 |
(function($) { |
(function($) { |
| 2 |
|
|
| 3 |
|
//Make nodes selectable by expression |
| 4 |
|
$.extend($.expr[':'], { draggable: "(' '+a.className+' ').indexOf(' ui-draggable ')" }); |
| 5 |
|
|
| 6 |
|
|
| 7 |
|
//Macros for external methods that support chaining |
| 8 |
|
var methods = "destroy,enable,disable".split(","); |
| 9 |
|
for(var i=0;i<methods.length;i++) { |
| 10 |
|
var cur = methods[i], f; |
| 11 |
|
eval('f = function() { var a = arguments; return this.each(function() { if(jQuery(this).is(".ui-draggable")) jQuery.data(this, "ui-draggable")["'+cur+'"](a); }); }'); |
| 12 |
|
$.fn["draggable"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f; |
| 13 |
|
}; |
| 14 |
|
|
| 15 |
|
//get instance method |
| 16 |
|
$.fn.draggableInstance = function() { |
| 17 |
|
if($(this[0]).is(".ui-draggable")) return $.data(this[0], "ui-draggable"); |
| 18 |
|
return false; |
| 19 |
|
}; |
| 20 |
|
|
| 21 |
$.fn.draggable = function(o) { |
$.fn.draggable = function(o) { |
| 22 |
return this.each(function() { |
return this.each(function() { |
| 23 |
new $.ui.draggable(this, o); |
new $.ui.draggable(this, o); |
| 24 |
}); |
}); |
| 25 |
} |
} |
| 26 |
|
|
|
$.fn.undraggable = function() { |
|
|
|
|
|
} |
|
|
|
|
| 27 |
$.ui.ddmanager = { |
$.ui.ddmanager = { |
| 28 |
current: null, |
current: null, |
| 29 |
droppables: [], |
droppables: [], |
| 32 |
var dropLeft = $.ui.ddmanager.dropLeft; |
var dropLeft = $.ui.ddmanager.dropLeft; |
| 33 |
var m = $.ui.ddmanager.droppables; |
var m = $.ui.ddmanager.droppables; |
| 34 |
for (var i = 0; i < m.length; i++) { |
for (var i = 0; i < m.length; i++) { |
| 35 |
m[i].offset = $(m[i].item.element).offset({ border: false }); |
if(m[i].item.disabled) continue; |
| 36 |
|
m[i].offset = $(m[i].item.element).offset(); |
| 37 |
if (t && m[i].item.options.accept(t.element)) //Activate the droppable if used directly from draggables |
if (t && m[i].item.options.accept(t.element)) //Activate the droppable if used directly from draggables |
| 38 |
m[i].item.activate.call(m[i].item); |
m[i].item.activate.call(m[i].item); |
| 39 |
} |
} |
| 42 |
|
|
| 43 |
var oDrops = $.ui.ddmanager.droppables; |
var oDrops = $.ui.ddmanager.droppables; |
| 44 |
var oOvers = $.grep(oDrops, function(oDrop) { |
var oOvers = $.grep(oDrops, function(oDrop) { |
| 45 |
if ($.ui.intersect(oDrag, oDrop, oDrop.item.options.tolerance)) |
|
| 46 |
|
if (!oDrop.item.disabled && $.ui.intersect(oDrag, oDrop, oDrop.item.options.tolerance)) |
| 47 |
oDrop.item.drop.call(oDrop.item); |
oDrop.item.drop.call(oDrop.item); |
| 48 |
}); |
}); |
| 49 |
$.each(oDrops, function(i, oDrop) { |
$.each(oDrops, function(i, oDrop) { |
| 50 |
if (oDrop.item.options.accept(oDrag.element)) { |
if (!oDrop.item.disabled && oDrop.item.options.accept(oDrag.element)) { |
| 51 |
oDrop.out = 1; oDrop.over = 0; |
oDrop.out = 1; oDrop.over = 0; |
| 52 |
oDrop.item.deactivate.call(oDrop.item); |
oDrop.item.deactivate.call(oDrop.item); |
| 53 |
} |
} |
| 59 |
|
|
| 60 |
var oDrops = $.ui.ddmanager.droppables; |
var oDrops = $.ui.ddmanager.droppables; |
| 61 |
var oOvers = $.grep(oDrops, function(oDrop) { |
var oOvers = $.grep(oDrops, function(oDrop) { |
| 62 |
|
if(oDrop.item.disabled) return false; |
| 63 |
var isOver = $.ui.intersect(oDrag, oDrop, oDrop.item.options.tolerance) |
var isOver = $.ui.intersect(oDrag, oDrop, oDrop.item.options.tolerance) |
| 64 |
if (!isOver && oDrop.over == 1) { |
if (!isOver && oDrop.over == 1) { |
| 65 |
oDrop.out = 1; oDrop.over = 0; |
oDrop.out = 1; oDrop.over = 0; |
| 80 |
|
|
| 81 |
var options = {}; |
var options = {}; |
| 82 |
$.extend(options, o); |
$.extend(options, o); |
| 83 |
|
var self = this; |
| 84 |
$.extend(options, { |
$.extend(options, { |
| 85 |
_start: function(h, p, c, t, e) { |
_start: function(h, p, c, t, e) { |
| 86 |
self.start.apply(t, [self, e]); // Trigger the start callback |
self.start.apply(t, [self, e]); // Trigger the start callback |
| 90 |
}, |
}, |
| 91 |
_drag: function(h, p, c, t, e) { |
_drag: function(h, p, c, t, e) { |
| 92 |
self.drag.apply(t, [self, e]); // Trigger the start callback |
self.drag.apply(t, [self, e]); // Trigger the start callback |
| 93 |
|
}, |
| 94 |
|
startCondition: function(e) { |
| 95 |
|
return !(e.target.className.indexOf("ui-resizable-handle") != -1 || self.disabled); |
| 96 |
} |
} |
| 97 |
}); |
}); |
| 98 |
var self = this; |
|
| 99 |
|
$.data(el, "ui-draggable", this); |
| 100 |
|
|
| 101 |
if (options.ghosting == true) options.helper = 'clone'; //legacy option check |
if (options.ghosting == true) options.helper = 'clone'; //legacy option check |
| 102 |
|
$(el).addClass("ui-draggable"); |
| 103 |
this.interaction = new $.ui.mouseInteraction(el, options); |
this.interaction = new $.ui.mouseInteraction(el, options); |
| 104 |
|
|
| 105 |
} |
} |
| 108 |
plugins: {}, |
plugins: {}, |
| 109 |
currentTarget: null, |
currentTarget: null, |
| 110 |
lastTarget: null, |
lastTarget: null, |
| 111 |
|
destroy: function() { |
| 112 |
|
$(this.interaction.element).removeClass("ui-draggable").removeClass("ui-draggable-disabled"); |
| 113 |
|
this.interaction.destroy(); |
| 114 |
|
}, |
| 115 |
|
enable: function() { |
| 116 |
|
$(this.interaction.element).removeClass("ui-draggable-disabled"); |
| 117 |
|
this.disabled = false; |
| 118 |
|
}, |
| 119 |
|
disable: function() { |
| 120 |
|
$(this.interaction.element).addClass("ui-draggable-disabled"); |
| 121 |
|
this.disabled = true; |
| 122 |
|
}, |
| 123 |
prepareCallbackObj: function(self) { |
prepareCallbackObj: function(self) { |
| 124 |
return { |
return { |
| 125 |
helper: self.helper, |
helper: self.helper, |
| 134 |
var o = this.options; |
var o = this.options; |
| 135 |
$.ui.ddmanager.current = this; |
$.ui.ddmanager.current = this; |
| 136 |
|
|
| 137 |
$.ui.plugin.call('start', that, this); |
$.ui.plugin.call(that, 'start', [e, that.prepareCallbackObj(this)]); |
| 138 |
$(this.element).triggerHandler("dragstart", [e, that.prepareCallbackObj(this)], o.start); |
$(this.element).triggerHandler("dragstart", [e, that.prepareCallbackObj(this)], o.start); |
| 139 |
|
|
| 140 |
if (this.slowMode && $.ui.droppable && !o.dropBehaviour) |
if (this.slowMode && $.ui.droppable && !o.dropBehaviour) |
| 147 |
|
|
| 148 |
var o = this.options; |
var o = this.options; |
| 149 |
|
|
| 150 |
$.ui.plugin.call('stop', that, this); |
$.ui.plugin.call(that, 'stop', [e, that.prepareCallbackObj(this)]); |
| 151 |
$(this.element).triggerHandler("dragstop", [e, that.prepareCallbackObj(this)], o.stop); |
$(this.element).triggerHandler("dragstop", [e, that.prepareCallbackObj(this)], o.stop); |
| 152 |
|
|
| 153 |
if (this.slowMode && $.ui.droppable && !o.dropBehaviour) //If cursorAt is within the helper, we must use our drop manager |
if (this.slowMode && $.ui.droppable && !o.dropBehaviour) //If cursorAt is within the helper, we must use our drop manager |
| 167 |
|
|
| 168 |
this.pos = [this.pos[0]-o.cursorAt.left, this.pos[1]-o.cursorAt.top]; |
this.pos = [this.pos[0]-o.cursorAt.left, this.pos[1]-o.cursorAt.top]; |
| 169 |
|
|
| 170 |
$.ui.plugin.call('drag', that, this); |
$.ui.plugin.call(that, 'drag', [e, that.prepareCallbackObj(this)]); |
| 171 |
var nv = $(this.element).triggerHandler("drag", [e, that.prepareCallbackObj(this)], o.drag); |
var nv = $(this.element).triggerHandler("drag", [e, that.prepareCallbackObj(this)], o.drag); |
| 172 |
|
|
| 173 |
var nl = (nv && nv.left) ? nv.left : this.pos[0]; |
var nl = (nv && nv.left) ? nv.left : this.pos[0]; |