| 1 |
(function($) { |
(function($) { |
| 2 |
|
|
| 3 |
|
//Make nodes selectable by expression |
| 4 |
|
$.extend($.expr[':'], { droppable: "(' '+a.className+' ').indexOf(' ui-droppable ')" }); |
| 5 |
|
|
| 6 |
|
//Macros for external methods that support chaining |
| 7 |
|
var methods = "destroy,enable,disable".split(","); |
| 8 |
|
for(var i=0;i<methods.length;i++) { |
| 9 |
|
var cur = methods[i], f; |
| 10 |
|
eval('f = function() { var a = arguments; return this.each(function() { if(jQuery(this).is(".ui-droppable")) jQuery.data(this, "ui-droppable")["'+cur+'"](a); }); }'); |
| 11 |
|
$.fn["droppable"+cur.substr(0,1).toUpperCase()+cur.substr(1)] = f; |
| 12 |
|
}; |
| 13 |
|
|
| 14 |
|
//get instance method |
| 15 |
|
$.fn.droppableInstance = function() { |
| 16 |
|
if($(this[0]).is(".ui-droppable")) return $.data(this[0], "ui-droppable"); |
| 17 |
|
return false; |
| 18 |
|
}; |
| 19 |
|
|
| 20 |
$.fn.droppable = function(o) { |
$.fn.droppable = function(o) { |
| 21 |
return this.each(function() { |
return this.each(function() { |
| 22 |
new $.ui.droppable(this,o); |
new $.ui.droppable(this,o); |
| 23 |
}); |
}); |
| 24 |
} |
} |
| 25 |
|
|
|
$.fn.undroppable = function() { |
|
|
|
|
|
} |
|
|
|
|
| 26 |
$.ui.droppable = function(el,o) { |
$.ui.droppable = function(el,o) { |
| 27 |
|
|
| 28 |
if(!o) var o = {}; |
if(!o) var o = {}; |
| 29 |
this.element = el; if($.browser.msie) el.droppable = 1; |
this.element = el; if($.browser.msie) el.droppable = 1; |
| 30 |
|
$.data(el, "ui-droppable", this); |
| 31 |
|
|
| 32 |
this.options = {}; |
this.options = {}; |
| 33 |
$.extend(this.options, o); |
$.extend(this.options, o); |
| 42 |
o = this.options; |
o = this.options; |
| 43 |
var self = this; |
var self = this; |
| 44 |
|
|
| 45 |
$(this.element).bind("mousemove", function(e) { return self.move.apply(self, [e]); }); |
this.mouseBindings = [function(e) { return self.move.apply(self, [e]); },function(e) { return self.drop.apply(self, [e]); }]; |
| 46 |
$(this.element).bind("mouseup", function(e) { return self.drop.apply(self, [e]); }); |
$(this.element).bind("mousemove", this.mouseBindings[0]); |
| 47 |
|
$(this.element).bind("mouseup", this.mouseBindings[1]); |
| 48 |
|
|
| 49 |
$.ui.ddmanager.droppables.push({ item: this, over: 0, out: 1 }); // Add the reference and positions to the manager |
$.ui.ddmanager.droppables.push({ item: this, over: 0, out: 1 }); // Add the reference and positions to the manager |
| 50 |
|
$(this.element).addClass("ui-droppable"); |
| 51 |
|
|
| 52 |
}; |
}; |
| 53 |
|
|
| 58 |
draggable: c, |
draggable: c, |
| 59 |
droppable: this, |
droppable: this, |
| 60 |
element: c.element, |
element: c.element, |
| 61 |
helper: c.helper |
helper: c.helper, |
| 62 |
|
options: this.options |
| 63 |
} |
} |
| 64 |
}, |
}, |
| 65 |
destroy: function() { |
destroy: function() { |
| 66 |
|
$(this.element).removeClass("ui-droppable").removeClass("ui-droppable-disabled"); |
| 67 |
|
$(this.element).unbind("mousemove", this.mouseBindings[0]); |
| 68 |
|
$(this.element).unbind("mouseup", this.mouseBindings[1]); |
| 69 |
|
|
| 70 |
|
for(var i=0;i<$.ui.ddmanager.droppables.length;i++) { |
| 71 |
|
if($.ui.ddmanager.droppables[i].item == this) $.ui.ddmanager.droppables.splice(i,1); |
| 72 |
|
} |
| 73 |
|
}, |
| 74 |
|
enable: function() { |
| 75 |
|
$(this.element).removeClass("ui-droppable-disabled"); |
| 76 |
|
this.disabled = false; |
| 77 |
|
}, |
| 78 |
|
disable: function() { |
| 79 |
|
$(this.element).addClass("ui-droppable-disabled"); |
| 80 |
|
this.disabled = true; |
| 81 |
}, |
}, |
| 82 |
move: function(e) { |
move: function(e) { |
| 83 |
|
|
| 105 |
|
|
| 106 |
var o = this.options; |
var o = this.options; |
| 107 |
if (o.accept(c.element)) { |
if (o.accept(c.element)) { |
| 108 |
$.ui.plugin.call('over', this); |
$.ui.plugin.call(this, 'over', [e, this.prepareCallbackObj(c)]); |
| 109 |
$(this.element).triggerHandler("dropover", [e, this.prepareCallbackObj(c)], o.over); |
$(this.element).triggerHandler("dropover", [e, this.prepareCallbackObj(c)], o.over); |
| 110 |
} |
} |
| 111 |
|
|
| 117 |
|
|
| 118 |
var o = this.options; |
var o = this.options; |
| 119 |
if (o.accept(c.element)) { |
if (o.accept(c.element)) { |
| 120 |
$.ui.plugin.call('out', this); |
$.ui.plugin.call(this, 'out', [e, this.prepareCallbackObj(c)]); |
| 121 |
$(this.element).triggerHandler("dropout", [e, this.prepareCallbackObj(c)], o.out); |
$(this.element).triggerHandler("dropout", [e, this.prepareCallbackObj(c)], o.out); |
| 122 |
} |
} |
| 123 |
|
|
| 131 |
if(o.accept(c.element)) { // Fire callback |
if(o.accept(c.element)) { // Fire callback |
| 132 |
if(o.greedy && !c.slowMode) { |
if(o.greedy && !c.slowMode) { |
| 133 |
if(c.currentTarget == this.element) { |
if(c.currentTarget == this.element) { |
| 134 |
$.ui.plugin.call('drop', this); |
$.ui.plugin.call(this, 'drop', [e, { |
| 135 |
|
draggable: c, |
| 136 |
|
droppable: this, |
| 137 |
|
element: c.element, |
| 138 |
|
helper: c.helper |
| 139 |
|
}]); |
| 140 |
$(this.element).triggerHandler("drop", [e, { |
$(this.element).triggerHandler("drop", [e, { |
| 141 |
draggable: c, |
draggable: c, |
| 142 |
droppable: this, |
droppable: this, |
| 145 |
}], o.drop); |
}], o.drop); |
| 146 |
} |
} |
| 147 |
} else { |
} else { |
| 148 |
$.ui.plugin.call('drop', this); |
$.ui.plugin.call(this, 'drop', [e, this.prepareCallbackObj(c)]); |
| 149 |
$(this.element).triggerHandler("drop", [e, this.prepareCallbackObj(c)], o.drop); |
$(this.element).triggerHandler("drop", [e, this.prepareCallbackObj(c)], o.drop); |
| 150 |
} |
} |
| 151 |
} |
} |
| 153 |
}, |
}, |
| 154 |
activate: function(e) { |
activate: function(e) { |
| 155 |
var c = $.ui.ddmanager.current; |
var c = $.ui.ddmanager.current; |
| 156 |
$.ui.plugin.call('activate', this); |
$.ui.plugin.call(this, 'activate', [e, this.prepareCallbackObj(c)]); |
| 157 |
if(c) $(this.element).triggerHandler("dropactivate", [e, this.prepareCallbackObj(c)], this.options.activate); |
if(c) $(this.element).triggerHandler("dropactivate", [e, this.prepareCallbackObj(c)], this.options.activate); |
| 158 |
}, |
}, |
| 159 |
deactivate: function(e) { |
deactivate: function(e) { |
| 160 |
var c = $.ui.ddmanager.current; |
var c = $.ui.ddmanager.current; |
| 161 |
$.ui.plugin.call('deactivate', this); |
$.ui.plugin.call(this, 'deactivate', [e, this.prepareCallbackObj(c)]); |
| 162 |
if(c) $(this.element).triggerHandler("dropdeactivate", [e, this.prepareCallbackObj(c)], this.options.deactivate); |
if(c) $(this.element).triggerHandler("dropdeactivate", [e, this.prepareCallbackObj(c)], this.options.deactivate); |
| 163 |
} |
} |
| 164 |
}); |
}); |