|
|
|
@ -1,12 +1,12 @@
|
|
|
|
|
// script.aculo.us dragdrop.js v1.7.0, Fri Jan 19 19:16:36 CET 2007
|
|
|
|
|
// script.aculo.us dragdrop.js v1.8.1, Thu Jan 03 22:07:12 -0500 2008
|
|
|
|
|
|
|
|
|
|
// Copyright (c) 2005, 2006 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
|
|
|
|
// (c) 2005, 2006 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
|
|
|
|
|
// Copyright (c) 2005-2007 Thomas Fuchs (http://script.aculo.us, http://mir.aculo.us)
|
|
|
|
|
// (c) 2005-2007 Sammi Williams (http://www.oriontransfer.co.nz, sammi@oriontransfer.co.nz)
|
|
|
|
|
//
|
|
|
|
|
// script.aculo.us is freely distributable under the terms of an MIT-style license.
|
|
|
|
|
// For details, see the script.aculo.us web site: http://script.aculo.us/
|
|
|
|
|
|
|
|
|
|
if(typeof Effect == 'undefined')
|
|
|
|
|
if(Object.isUndefined(Effect))
|
|
|
|
|
throw("dragdrop.js requires including script.aculo.us' effects.js library");
|
|
|
|
|
|
|
|
|
|
var Droppables = {
|
|
|
|
@ -22,14 +22,13 @@ var Droppables = {
|
|
|
|
|
greedy: true,
|
|
|
|
|
hoverclass: null,
|
|
|
|
|
tree: false
|
|
|
|
|
}, arguments[1] || {});
|
|
|
|
|
}, arguments[1] || { });
|
|
|
|
|
|
|
|
|
|
// cache containers
|
|
|
|
|
if(options.containment) {
|
|
|
|
|
options._containers = [];
|
|
|
|
|
var containment = options.containment;
|
|
|
|
|
if((typeof containment == 'object') &&
|
|
|
|
|
(containment.constructor == Array)) {
|
|
|
|
|
if(Object.isArray(containment)) {
|
|
|
|
|
containment.each( function(c) { options._containers.push($(c)) });
|
|
|
|
|
} else {
|
|
|
|
|
options._containers.push($(containment));
|
|
|
|
@ -89,21 +88,23 @@ var Droppables = {
|
|
|
|
|
|
|
|
|
|
show: function(point, element) {
|
|
|
|
|
if(!this.drops.length) return;
|
|
|
|
|
var affected = [];
|
|
|
|
|
var drop, affected = [];
|
|
|
|
|
|
|
|
|
|
if(this.last_active) this.deactivate(this.last_active);
|
|
|
|
|
this.drops.each( function(drop) {
|
|
|
|
|
if(Droppables.isAffected(point, element, drop))
|
|
|
|
|
affected.push(drop);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
if(affected.length>0) {
|
|
|
|
|
if(affected.length>0)
|
|
|
|
|
drop = Droppables.findDeepestChild(affected);
|
|
|
|
|
|
|
|
|
|
if(this.last_active && this.last_active != drop) this.deactivate(this.last_active);
|
|
|
|
|
if (drop) {
|
|
|
|
|
Position.within(drop.element, point[0], point[1]);
|
|
|
|
|
if(drop.onHover)
|
|
|
|
|
drop.onHover(element, drop.element, Position.overlap(drop.overlap, drop.element));
|
|
|
|
|
|
|
|
|
|
Droppables.activate(drop);
|
|
|
|
|
if (drop != this.last_active) Droppables.activate(drop);
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
@ -112,8 +113,10 @@ var Droppables = {
|
|
|
|
|
Position.prepare();
|
|
|
|
|
|
|
|
|
|
if (this.isAffected([Event.pointerX(event), Event.pointerY(event)], element, this.last_active))
|
|
|
|
|
if (this.last_active.onDrop)
|
|
|
|
|
if (this.last_active.onDrop) {
|
|
|
|
|
this.last_active.onDrop(element, this.last_active.element, event);
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
reset: function() {
|
|
|
|
@ -221,10 +224,7 @@ var Draggables = {
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
var Draggable = Class.create();
|
|
|
|
|
Draggable._dragging = {};
|
|
|
|
|
|
|
|
|
|
Draggable.prototype = {
|
|
|
|
|
var Draggable = Class.create({
|
|
|
|
|
initialize: function(element) {
|
|
|
|
|
var defaults = {
|
|
|
|
|
handle: false,
|
|
|
|
@ -235,7 +235,7 @@ Draggable.prototype = {
|
|
|
|
|
});
|
|
|
|
|
},
|
|
|
|
|
endeffect: function(element) {
|
|
|
|
|
var toOpacity = typeof element._opacity == 'number' ? element._opacity : 1.0;
|
|
|
|
|
var toOpacity = Object.isNumber(element._opacity) ? element._opacity : 1.0;
|
|
|
|
|
new Effect.Opacity(element, {duration:0.2, from:0.7, to:toOpacity,
|
|
|
|
|
queue: {scope:'_draggable', position:'end'},
|
|
|
|
|
afterFinish: function(){
|
|
|
|
@ -245,6 +245,7 @@ Draggable.prototype = {
|
|
|
|
|
},
|
|
|
|
|
zindex: 1000,
|
|
|
|
|
revert: false,
|
|
|
|
|
quiet: false,
|
|
|
|
|
scroll: false,
|
|
|
|
|
scrollSensitivity: 20,
|
|
|
|
|
scrollSpeed: 15,
|
|
|
|
@ -252,7 +253,7 @@ Draggable.prototype = {
|
|
|
|
|
delay: 0
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
if(!arguments[1] || typeof arguments[1].endeffect == 'undefined')
|
|
|
|
|
if(!arguments[1] || Object.isUndefined(arguments[1].endeffect))
|
|
|
|
|
Object.extend(defaults, {
|
|
|
|
|
starteffect: function(element) {
|
|
|
|
|
element._opacity = Element.getOpacity(element);
|
|
|
|
@ -261,11 +262,11 @@ Draggable.prototype = {
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var options = Object.extend(defaults, arguments[1] || {});
|
|
|
|
|
var options = Object.extend(defaults, arguments[1] || { });
|
|
|
|
|
|
|
|
|
|
this.element = $(element);
|
|
|
|
|
|
|
|
|
|
if(options.handle && (typeof options.handle == 'string'))
|
|
|
|
|
if(options.handle && Object.isString(options.handle))
|
|
|
|
|
this.handle = this.element.down('.'+options.handle, 0);
|
|
|
|
|
|
|
|
|
|
if(!this.handle) this.handle = $(options.handle);
|
|
|
|
@ -278,7 +279,6 @@ Draggable.prototype = {
|
|
|
|
|
|
|
|
|
|
Element.makePositioned(this.element); // fix IE
|
|
|
|
|
|
|
|
|
|
this.delta = this.currentDelta();
|
|
|
|
|
this.options = options;
|
|
|
|
|
this.dragging = false;
|
|
|
|
|
|
|
|
|
@ -300,7 +300,7 @@ Draggable.prototype = {
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
initDrag: function(event) {
|
|
|
|
|
if(typeof Draggable._dragging[this.element] != 'undefined' &&
|
|
|
|
|
if(!Object.isUndefined(Draggable._dragging[this.element]) &&
|
|
|
|
|
Draggable._dragging[this.element]) return;
|
|
|
|
|
if(Event.isLeftClick(event)) {
|
|
|
|
|
// abort on form elements, fixes a Firefox issue
|
|
|
|
@ -323,6 +323,8 @@ Draggable.prototype = {
|
|
|
|
|
|
|
|
|
|
startDrag: function(event) {
|
|
|
|
|
this.dragging = true;
|
|
|
|
|
if(!this.delta)
|
|
|
|
|
this.delta = this.currentDelta();
|
|
|
|
|
|
|
|
|
|
if(this.options.zindex) {
|
|
|
|
|
this.originalZ = parseInt(Element.getStyle(this.element,'z-index') || 0);
|
|
|
|
@ -331,7 +333,9 @@ Draggable.prototype = {
|
|
|
|
|
|
|
|
|
|
if(this.options.ghosting) {
|
|
|
|
|
this._clone = this.element.cloneNode(true);
|
|
|
|
|
Position.absolutize(this.element);
|
|
|
|
|
this.element._originallyAbsolute = (this.element.getStyle('position') == 'absolute');
|
|
|
|
|
if (!this.element._originallyAbsolute)
|
|
|
|
|
Position.absolutize(this.element);
|
|
|
|
|
this.element.parentNode.insertBefore(this._clone, this.element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -353,8 +357,12 @@ Draggable.prototype = {
|
|
|
|
|
|
|
|
|
|
updateDrag: function(event, pointer) {
|
|
|
|
|
if(!this.dragging) this.startDrag(event);
|
|
|
|
|
Position.prepare();
|
|
|
|
|
Droppables.show(pointer, this.element);
|
|
|
|
|
|
|
|
|
|
if(!this.options.quiet){
|
|
|
|
|
Position.prepare();
|
|
|
|
|
Droppables.show(pointer, this.element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
Draggables.notify('onDrag', this, event);
|
|
|
|
|
|
|
|
|
|
this.draw(pointer);
|
|
|
|
@ -382,7 +390,7 @@ Draggable.prototype = {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// fix AppleWebKit rendering
|
|
|
|
|
if(navigator.appVersion.indexOf('AppleWebKit')>0) window.scrollBy(0,0);
|
|
|
|
|
if(Prototype.Browser.WebKit) window.scrollBy(0,0);
|
|
|
|
|
|
|
|
|
|
Event.stop(event);
|
|
|
|
|
},
|
|
|
|
@ -390,22 +398,36 @@ Draggable.prototype = {
|
|
|
|
|
finishDrag: function(event, success) {
|
|
|
|
|
this.dragging = false;
|
|
|
|
|
|
|
|
|
|
if(this.options.quiet){
|
|
|
|
|
Position.prepare();
|
|
|
|
|
var pointer = [Event.pointerX(event), Event.pointerY(event)];
|
|
|
|
|
Droppables.show(pointer, this.element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(this.options.ghosting) {
|
|
|
|
|
Position.relativize(this.element);
|
|
|
|
|
if (!this.element._originallyAbsolute)
|
|
|
|
|
Position.relativize(this.element);
|
|
|
|
|
delete this.element._originallyAbsolute;
|
|
|
|
|
Element.remove(this._clone);
|
|
|
|
|
this._clone = null;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if(success) Droppables.fire(event, this.element);
|
|
|
|
|
var dropped = false;
|
|
|
|
|
if(success) {
|
|
|
|
|
dropped = Droppables.fire(event, this.element);
|
|
|
|
|
if (!dropped) dropped = false;
|
|
|
|
|
}
|
|
|
|
|
if(dropped && this.options.onDropped) this.options.onDropped(this.element);
|
|
|
|
|
Draggables.notify('onEnd', this, event);
|
|
|
|
|
|
|
|
|
|
var revert = this.options.revert;
|
|
|
|
|
if(revert && typeof revert == 'function') revert = revert(this.element);
|
|
|
|
|
if(revert && Object.isFunction(revert)) revert = revert(this.element);
|
|
|
|
|
|
|
|
|
|
var d = this.currentDelta();
|
|
|
|
|
if(revert && this.options.reverteffect) {
|
|
|
|
|
this.options.reverteffect(this.element,
|
|
|
|
|
d[1]-this.delta[1], d[0]-this.delta[0]);
|
|
|
|
|
if (dropped == 0 || revert != 'failure')
|
|
|
|
|
this.options.reverteffect(this.element,
|
|
|
|
|
d[1]-this.delta[1], d[0]-this.delta[0]);
|
|
|
|
|
} else {
|
|
|
|
|
this.delta = d;
|
|
|
|
|
}
|
|
|
|
@ -453,15 +475,15 @@ Draggable.prototype = {
|
|
|
|
|
}.bind(this));
|
|
|
|
|
|
|
|
|
|
if(this.options.snap) {
|
|
|
|
|
if(typeof this.options.snap == 'function') {
|
|
|
|
|
if(Object.isFunction(this.options.snap)) {
|
|
|
|
|
p = this.options.snap(p[0],p[1],this);
|
|
|
|
|
} else {
|
|
|
|
|
if(this.options.snap instanceof Array) {
|
|
|
|
|
if(Object.isArray(this.options.snap)) {
|
|
|
|
|
p = p.map( function(v, i) {
|
|
|
|
|
return Math.round(v/this.options.snap[i])*this.options.snap[i] }.bind(this))
|
|
|
|
|
return (v/this.options.snap[i]).round()*this.options.snap[i] }.bind(this))
|
|
|
|
|
} else {
|
|
|
|
|
p = p.map( function(v) {
|
|
|
|
|
return Math.round(v/this.options.snap)*this.options.snap }.bind(this))
|
|
|
|
|
return (v/this.options.snap).round()*this.options.snap }.bind(this))
|
|
|
|
|
}
|
|
|
|
|
}}
|
|
|
|
|
|
|
|
|
@ -545,12 +567,13 @@ Draggable.prototype = {
|
|
|
|
|
}
|
|
|
|
|
return { top: T, left: L, width: W, height: H };
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
Draggable._dragging = { };
|
|
|
|
|
|
|
|
|
|
/*--------------------------------------------------------------------------*/
|
|
|
|
|
|
|
|
|
|
var SortableObserver = Class.create();
|
|
|
|
|
SortableObserver.prototype = {
|
|
|
|
|
var SortableObserver = Class.create({
|
|
|
|
|
initialize: function(element, observer) {
|
|
|
|
|
this.element = $(element);
|
|
|
|
|
this.observer = observer;
|
|
|
|
@ -566,12 +589,12 @@ SortableObserver.prototype = {
|
|
|
|
|
if(this.lastValue != Sortable.serialize(this.element))
|
|
|
|
|
this.observer(this.element)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
var Sortable = {
|
|
|
|
|
SERIALIZE_RULE: /^[^_\-](?:[A-Za-z0-9\-\_]*)[_](.*)$/,
|
|
|
|
|
|
|
|
|
|
sortables: {},
|
|
|
|
|
sortables: { },
|
|
|
|
|
|
|
|
|
|
_findRootElement: function(element) {
|
|
|
|
|
while (element.tagName.toUpperCase() != "BODY") {
|
|
|
|
@ -614,13 +637,20 @@ var Sortable = {
|
|
|
|
|
delay: 0,
|
|
|
|
|
hoverclass: null,
|
|
|
|
|
ghosting: false,
|
|
|
|
|
quiet: false,
|
|
|
|
|
scroll: false,
|
|
|
|
|
scrollSensitivity: 20,
|
|
|
|
|
scrollSpeed: 15,
|
|
|
|
|
format: this.SERIALIZE_RULE,
|
|
|
|
|
|
|
|
|
|
// these take arrays of elements or ids and can be
|
|
|
|
|
// used for better initialization performance
|
|
|
|
|
elements: false,
|
|
|
|
|
handles: false,
|
|
|
|
|
|
|
|
|
|
onChange: Prototype.emptyFunction,
|
|
|
|
|
onUpdate: Prototype.emptyFunction
|
|
|
|
|
}, arguments[1] || {});
|
|
|
|
|
}, arguments[1] || { });
|
|
|
|
|
|
|
|
|
|
// clear any old sortable with same element
|
|
|
|
|
this.destroy(element);
|
|
|
|
@ -628,6 +658,7 @@ var Sortable = {
|
|
|
|
|
// build options for the draggables
|
|
|
|
|
var options_for_draggable = {
|
|
|
|
|
revert: true,
|
|
|
|
|
quiet: options.quiet,
|
|
|
|
|
scroll: options.scroll,
|
|
|
|
|
scrollSpeed: options.scrollSpeed,
|
|
|
|
|
scrollSensitivity: options.scrollSensitivity,
|
|
|
|
@ -681,10 +712,9 @@ var Sortable = {
|
|
|
|
|
options.droppables.push(element);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
(this.findElements(element, options) || []).each( function(e) {
|
|
|
|
|
// handles are per-draggable
|
|
|
|
|
var handle = options.handle ?
|
|
|
|
|
$(e).down('.'+options.handle,0) : e;
|
|
|
|
|
(options.elements || this.findElements(element, options) || []).each( function(e,i) {
|
|
|
|
|
var handle = options.handles ? $(options.handles[i]) :
|
|
|
|
|
(options.handle ? $(e).select('.' + options.handle)[0] : e);
|
|
|
|
|
options.draggables.push(
|
|
|
|
|
new Draggable(e, Object.extend(options_for_draggable, { handle: handle })));
|
|
|
|
|
Droppables.add(e, options_for_droppable);
|
|
|
|
@ -844,7 +874,7 @@ var Sortable = {
|
|
|
|
|
only: sortableOptions.only,
|
|
|
|
|
name: element.id,
|
|
|
|
|
format: sortableOptions.format
|
|
|
|
|
}, arguments[1] || {});
|
|
|
|
|
}, arguments[1] || { });
|
|
|
|
|
|
|
|
|
|
var root = {
|
|
|
|
|
id: null,
|
|
|
|
@ -868,7 +898,7 @@ var Sortable = {
|
|
|
|
|
|
|
|
|
|
sequence: function(element) {
|
|
|
|
|
element = $(element);
|
|
|
|
|
var options = Object.extend(this.options(element), arguments[1] || {});
|
|
|
|
|
var options = Object.extend(this.options(element), arguments[1] || { });
|
|
|
|
|
|
|
|
|
|
return $(this.findElements(element, options) || []).map( function(item) {
|
|
|
|
|
return item.id.match(options.format) ? item.id.match(options.format)[1] : '';
|
|
|
|
@ -877,9 +907,9 @@ var Sortable = {
|
|
|
|
|
|
|
|
|
|
setSequence: function(element, new_sequence) {
|
|
|
|
|
element = $(element);
|
|
|
|
|
var options = Object.extend(this.options(element), arguments[2] || {});
|
|
|
|
|
var options = Object.extend(this.options(element), arguments[2] || { });
|
|
|
|
|
|
|
|
|
|
var nodeMap = {};
|
|
|
|
|
var nodeMap = { };
|
|
|
|
|
this.findElements(element, options).each( function(n) {
|
|
|
|
|
if (n.id.match(options.format))
|
|
|
|
|
nodeMap[n.id.match(options.format)[1]] = [n, n.parentNode];
|
|
|
|
@ -897,7 +927,7 @@ var Sortable = {
|
|
|
|
|
|
|
|
|
|
serialize: function(element) {
|
|
|
|
|
element = $(element);
|
|
|
|
|
var options = Object.extend(Sortable.options(element), arguments[1] || {});
|
|
|
|
|
var options = Object.extend(Sortable.options(element), arguments[1] || { });
|
|
|
|
|
var name = encodeURIComponent(
|
|
|
|
|
(arguments[1] && arguments[1].name) ? arguments[1].name : element.id);
|
|
|
|
|
|
|
|
|
|