How to add more callbacks to Sortable class
Posted by Sandro Paganotti in
Web 2.0 -
comments are closed
The Scriptacolous Sortable class contains istances of Draggable and Droppable; after a quick look I discover that there are very useful callbacks (onStart , onEnd) that you can’t trigger from Sortable.
Enabling these callbacks require just a few minutes and three (maybe four :) lines of code; to do this you need to open ‘dragdrop.js’ (I’m currently using Scriptacolous 1.8), go to line 652 and modify as follow:
// Around Line 652
onChange: Prototype.emptyFunction,
onUpdate: Prototype.emptyFunction,
onStart: Prototype.emptyFunction, // prepare an onStart function
onEnd: Prototype.emptyFunction // prepare an onEnd function
}, arguments[1] || { });
// clear any old sortable with same element
this.destroy(element);
// build options for the draggables
var options_for_draggable = {
revert: true,
quiet: options.quiet,
scroll: options.scroll,
scrollSpeed: options.scrollSpeed,
scrollSensitivity: options.scrollSensitivity,
delay: options.delay,
ghosting: options.ghosting,
constraint: options.constraint,
handle: options.handle,
onStart: options.onStart, // apply the onStart function to the draggable istance
onEnd: options.onEnd // apply the onEnd function to the draggable istance
};
In the same way you can implement also the callbacks related to the Droppable class. Hope this may be useful.
Sandro

