I need to fix a few things here:
The delete button does not work after the drop event. The delete only works on items not in the dropzone. Not sure what is wrong here. also, it would be better to add the delete button to each dropped item instead of cloning it.
I need to be able sort the dropped items. sortable is not included in the current demo below.
HTML:
<div id="items">
<div class="item"><span>Item 111111</span>
<span class="delete"><button>Delete Line</button></span>
</div>
<div class="item"><span>Item 222222</span>
<span class="delete"><button>Delete Line</button></span>
</div>
<div class="item"><span>Item 333333</span>
<span class="delete"><button>Delete Line</button></span>
</div>
</div>
<div style="" id="cart">
<div class="info">Drag Items Here</div>
</div>
<div class=""><span>test delete works here but not after a drag event</span>
<span class="delete"><button>Delete Line</button></span>
</div>
Here is the DomReady event:
$$('.item').addEvent('mousedown', function (event) {
event.stop();
// `this` refers to the element with the .item class
var item = this;
var clone = item.clone().setStyles(item.getCoordinates()).setStyles({
opacity: 0.7,
position: 'absolute'
}).inject(document.body);
var drag = new Drag.Move(clone, {
droppables: $('cart'),
onDrop: function (dragging, cart) {
dragging.destroy();
item.removeClass('item');
item.addClass('item_dz');
if (cart != null) {
item.clone().inject(cart);
cart.highlight('#4679BD', '#FFF');
item.removeClass('item_dz');
item.addClass('item');
}
},
onEnter: function (dragging, cart) {
cart.tween('background-color', '#FFF04F');
},
onLeave: function (dragging, cart) {
cart.tween('background-color', '#FFF');
},
onCancel: function (dragging) {
dragging.destroy();
}
});
drag.start(event);
});
$$('.delete').addEvents({
click: function () {
this.getParent().destroy();
this.destroy();
},
mouseover: function () {
this.tween('opacity', '1');
this.getPrevious(['.item_dz']).fade(0.3);
this.getPrevious(['.item_dz']).tween('background-color', '#fff', '#f00');
},
mouseleave: function () {
this.tween('opacity', '0.5');
this.getPrevious(['.item_dz']).fade(1);
this.getPrevious(['.item_dz']).tween('background-color', '#f00', '#fff');
}
});
Please help...