views:

365

answers:

1

Hi-

I'm trying to make a group of objects draggable as you can see below - easy enough. But I'd like to configure things so that if any one of these items gets dragged, the others automatically cease to be draggable. Does anyone know how to do this?

var products = document.getElementsByClassName('box');
for (var i = 0; i < products.length; i++) {
  new Draggable(products[i].id, {ghosting:true})
}

Also, is it possible, after you've made an object draggable, to selectively and individually trigger its 'onStart', 'onEnd', or 'Revert' sequences through code, not using the mouse?

Thanks very much.

A: 

Save the Draggables in a collection and call destroy() on them when one of them is dragged (ie, onEnd is fired):

var draggables = [];
var products = document.getElementsByClassName('box');
for (var i = 0; i < products.length; i++) {
    var draggable = new Draggable(products[i].id, {
        ghosting:true,
        onEnd: function () {
            draggables.invoke('destroy');
        }
    });
    draggables.push(draggable)
}
Crescent Fresh
Thanks for following up...I tried this code but it doesn't seem to work. Everything seems to work normally except the statement "draggables.invoke('destroy')".It seems to have no effect. I've tried other variations such as: [1] for (var d in draggables) draggables.pop(d); [2] draggables.each(function(draggable) { alert(item) });
echobase
...sorry that comment got messed up. I also tried: draggables.each(function(draggable) { draggable.destroy(); }but none of this seems to work.
echobase
crescentfresh:I finally did it. Here's what I did: onEnd: function(d) { Draggables.drags.each(function(draggable) { draggable.destroy(); } }Thanks for helping the wheels turn in my head. },
echobase
If you provide a full-blown minimal example, we might try it out.
nes1983