-
FEATURED COMPONENTS
First time here? Check out the FAQ!
Hi, I have 3 divs that are related. I want that when the user drags one of this items the other 2 are drag automatically (so the user can see that they are being dragged too!). How can I do this???? There's no onDrag event to do it by java code....
Thanks!
EDIT: I use the code provided by Cor3000 and it works fine. To continue using the default drag for all the divs that havn't got the data-related attribute use the following code:
var superdiv = {};
zk.override(zul.wgt.Div.prototype, superdiv, {
cloneDrag_: function (drag, ofs) {
if(drag.node.dataset.related == undefined || drag.node.dataset.related == ''){
//superdiv.cloneDrag_.apply(drag,ofs);
return superdiv.cloneDrag_.apply(this,arguments);
}else{
var dragContainer = document.createElement("div");
dragContainer.style.position = 'absolute';
//dragContainer.innerText = 'Dragging related nodes'; /*e.g. add a text*/
jq('[data-related=' + drag.node.dataset.related + ']').each(function(index, related) {
var comp = related.cloneNode(true);
if(index!=0){
comp.style.marginLeft = '100px';
}
dragContainer.appendChild(comp);
})
document.body.appendChild(dragContainer);
return dragContainer;
}
}
});
Hi Neus.
since drag and drop initially happens on the client side you can override a number of client side functions to customize this behavior (http://books.zkoss.org/wiki/ZKClient-sideReference/Customization/Drag-and-Drop_Effects)
I created a small example to show the basic principle http://zkfiddle.org/sample/1rbom3p/1-custom-drag-and-drop
It uses data-attributes to identify related divs to clone them into the same dragContainer. But any mechanism will work.
I use the client/attribute namespace to set the data attributes. To assign these values from java you can use setClientDataAttribute (or in ZK <=7 setWidgetAttribute)
Robert
Asked: 2015-12-10 10:03:27 +0800
Seen: 40 times
Last updated: Dec 24 '15