| 1 |
(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) {
|
| 22 |
return this.each(function() {
|
| 23 |
if(!$(this).is(".ui-draggable")) new $.ui.draggable(this, o);
|
| 24 |
});
|
| 25 |
}
|
| 26 |
|
| 27 |
$.ui.ddmanager = {
|
| 28 |
current: null,
|
| 29 |
droppables: [],
|
| 30 |
prepareOffsets: function(t, e) {
|
| 31 |
var dropTop = $.ui.ddmanager.dropTop = [];
|
| 32 |
var dropLeft = $.ui.ddmanager.dropLeft;
|
| 33 |
var m = $.ui.ddmanager.droppables;
|
| 34 |
for (var i = 0; i < m.length; i++) {
|
| 35 |
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
|
| 38 |
m[i].item.activate.call(m[i].item, e);
|
| 39 |
}
|
| 40 |
},
|
| 41 |
fire: function(oDrag, e) {
|
| 42 |
|
| 43 |
var oDrops = $.ui.ddmanager.droppables;
|
| 44 |
var oOvers = $.grep(oDrops, function(oDrop) {
|
| 45 |
if (!!oDrop && !oDrop.item.disabled && $.ui.intersect(oDrag, oDrop, oDrop.item.options.tolerance))
|
| 46 |
oDrop.item.drop.call(oDrop.item, e);
|
| 47 |
});
|
| 48 |
$.each(oDrops, function(i, oDrop) {
|
| 49 |
if (!oDrop.item.disabled && oDrop.item.options.accept(oDrag.element)) {
|
| 50 |
oDrop.out = 1; oDrop.over = 0;
|
| 51 |
oDrop.item.deactivate.call(oDrop.item, e);
|
| 52 |
}
|
| 53 |
});
|
| 54 |
},
|
| 55 |
update: function(oDrag, e) {
|
| 56 |
|
| 57 |
if(oDrag.options.refreshPositions) $.ui.ddmanager.prepareOffsets();
|
| 58 |
|
| 59 |
var oDrops = $.ui.ddmanager.droppables;
|
| 60 |
var oOvers = $.grep(oDrops, function(oDrop) {
|
| 61 |
if(oDrop.item.disabled) return false;
|
| 62 |
var isOver = $.ui.intersect(oDrag, oDrop, oDrop.item.options.tolerance)
|
| 63 |
if (!isOver && oDrop.over == 1) {
|
| 64 |
oDrop.out = 1; oDrop.over = 0;
|
| 65 |
oDrop.item.out.call(oDrop.item, e);
|
| 66 |
}
|
| 67 |
return isOver;
|
| 68 |
});
|
| 69 |
$.each(oOvers, function(i, oOver) {
|
| 70 |
if (oOver.over == 0) {
|
| 71 |
oOver.out = 0; oOver.over = 1;
|
| 72 |
oOver.item.over.call(oOver.item, e);
|
| 73 |
}
|
| 74 |
});
|
| 75 |
}
|
| 76 |
};
|
| 77 |
|
| 78 |
$.ui.draggable = function(el, o) {
|
| 79 |
|
| 80 |
var options = {};
|
| 81 |
$.extend(options, o);
|
| 82 |
var self = this;
|
| 83 |
$.extend(options, {
|
| 84 |
_start: function(h, p, c, t, e) {
|
| 85 |
self.start.apply(t, [self, e]); // Trigger the start callback
|
| 86 |
},
|
| 87 |
_beforeStop: function(h, p, c, t, e) {
|
| 88 |
self.stop.apply(t, [self, e]); // Trigger the start callback
|
| 89 |
},
|
| 90 |
_drag: function(h, p, c, t, e) {
|
| 91 |
self.drag.apply(t, [self, e]); // Trigger the start callback
|
| 92 |
},
|
| 93 |
startCondition: function(e) {
|
| 94 |
return !(e.target.className.indexOf("ui-resizable-handle") != -1 || self.disabled);
|
| 95 |
}
|
| 96 |
});
|
| 97 |
|
| 98 |
$.data(el, "ui-draggable", this);
|
| 99 |
|
| 100 |
if (options.ghosting == true) options.helper = 'clone'; //legacy option check
|
| 101 |
$(el).addClass("ui-draggable");
|
| 102 |
this.interaction = new $.ui.mouseInteraction(el, options);
|
| 103 |
|
| 104 |
}
|
| 105 |
|
| 106 |
$.extend($.ui.draggable.prototype, {
|
| 107 |
plugins: {},
|
| 108 |
currentTarget: null,
|
| 109 |
lastTarget: null,
|
| 110 |
destroy: function() {
|
| 111 |
$(this.interaction.element).removeClass("ui-draggable").removeClass("ui-draggable-disabled");
|
| 112 |
this.interaction.destroy();
|
| 113 |
},
|
| 114 |
enable: function() {
|
| 115 |
$(this.interaction.element).removeClass("ui-draggable-disabled");
|
| 116 |
this.disabled = false;
|
| 117 |
},
|
| 118 |
disable: function() {
|
| 119 |
$(this.interaction.element).addClass("ui-draggable-disabled");
|
| 120 |
this.disabled = true;
|
| 121 |
},
|
| 122 |
prepareCallbackObj: function(self) {
|
| 123 |
return {
|
| 124 |
helper: self.helper,
|
| 125 |
position: { left: self.pos[0], top: self.pos[1] },
|
| 126 |
offset: self.options.cursorAt,
|
| 127 |
draggable: self,
|
| 128 |
options: self.options
|
| 129 |
}
|
| 130 |
},
|
| 131 |
start: function(that, e) {
|
| 132 |
|
| 133 |
var o = this.options;
|
| 134 |
$.ui.ddmanager.current = this;
|
| 135 |
|
| 136 |
$.ui.plugin.call(that, 'start', [e, that.prepareCallbackObj(this)]);
|
| 137 |
$(this.element).triggerHandler("dragstart", [e, that.prepareCallbackObj(this)], o.start);
|
| 138 |
|
| 139 |
if (this.slowMode && $.ui.droppable && !o.dropBehaviour)
|
| 140 |
$.ui.ddmanager.prepareOffsets(this, e);
|
| 141 |
|
| 142 |
return false;
|
| 143 |
|
| 144 |
},
|
| 145 |
stop: function(that, e) {
|
| 146 |
|
| 147 |
var o = this.options;
|
| 148 |
|
| 149 |
$.ui.plugin.call(that, 'stop', [e, that.prepareCallbackObj(this)]);
|
| 150 |
$(this.element).triggerHandler("dragstop", [e, that.prepareCallbackObj(this)], o.stop);
|
| 151 |
|
| 152 |
if (this.slowMode && $.ui.droppable && !o.dropBehaviour) //If cursorAt is within the helper, we must use our drop manager
|
| 153 |
$.ui.ddmanager.fire(this, e);
|
| 154 |
|
| 155 |
$.ui.ddmanager.current = null;
|
| 156 |
$.ui.ddmanager.last = this;
|
| 157 |
|
| 158 |
return false;
|
| 159 |
|
| 160 |
},
|
| 161 |
drag: function(that, e) {
|
| 162 |
|
| 163 |
var o = this.options;
|
| 164 |
|
| 165 |
$.ui.ddmanager.update(this, e);
|
| 166 |
|
| 167 |
this.pos = [this.pos[0]-o.cursorAt.left, this.pos[1]-o.cursorAt.top];
|
| 168 |
|
| 169 |
$.ui.plugin.call(that, 'drag', [e, that.prepareCallbackObj(this)]);
|
| 170 |
var nv = $(this.element).triggerHandler("drag", [e, that.prepareCallbackObj(this)], o.drag);
|
| 171 |
|
| 172 |
var nl = (nv && nv.left) ? nv.left : this.pos[0];
|
| 173 |
var nt = (nv && nv.top) ? nv.top : this.pos[1];
|
| 174 |
|
| 175 |
$(this.helper).css('left', nl+'px').css('top', nt+'px'); // Stick the helper to the cursor
|
| 176 |
return false;
|
| 177 |
|
| 178 |
}
|
| 179 |
});
|
| 180 |
|
| 181 |
})(jQuery);
|