I am making some changes on drag start and want to revert them if drop fails. I wrote this logic in a function triggered by dragend. This works perfect in Chrome but in firefox 'Dragend' event is not fired.
Can anyone tell me something about this behaviour? I am using firefox 22.0 on ubantu.
Code is as below
$(".view-controller").on("dragover", that.dragOverMain);
$(".view-controller").on("dragenter", that.dragEnterMain);
$(".view-controller").on("dragexit dragleave", that.dragExitMain);
$(".view-controller").on("dragend", that.dragEndMain);
$(".view-controller").on("drop", that.dropMain);
$(".view-controller").children().on("dragstart", function(e) {
that.dragStartChild(e);
});
$(".view-controller").children().on("dragend", function(e) {
that.dragEndMain(e);
});
dragStartChild: function(e) { console.log('dragStartChild'); },
dragEndMain: function(e) { console.log('dragEndMain'); e.preventDefault(); },
dropMain: function(e) { console.log('dropMain'); e.preventDefault(); },
dragExitMain: function(e) { console.log('dragExitMain'); e.preventDefault(); },
dragEnterMain: function(e) { console.log('dragEnterMain'); e.preventDefault(); },
dragOverMain: function(e) { console.log('dragOverMain'); e.preventDefault(); },
Firefox requires drag data to be set (event.dataTransfer.setData(...)
) in the dragstart
event. Without setting this data the dragstart
event will fire, but the dragend
event won't.
https://developer.mozilla.org/en-US/docs/Web/API/HTML_Drag_and_Drop_API/Drag_operations#dragstart:
To make another HTML element draggable, three things must be done:
- Set the draggable attribute to true on the element that you wish to make draggable.
- Add a listener for the dragstart event
- Set the drag data within the listener defined above.
Example:
<div draggable="true" ondragstart="event.dataTransfer.setData('text/plain', 'This text may be dragged')">
This text <strong>may</strong> be dragged.
</div>
Try this instead.
<div ondragend="dragEndMain(event)" class="viewcontroller">
<!-- some html -->
</div>
Basically bind the javascript event in html itself.
Worth adding here that Firefox has a bug that causes dragend to not fire if you're moving or deleting DOM elements as a part of your Drag and Drop functionality.
https://bugzilla.mozilla.org/show_bug.cgi?id=460801
Moving the DOM manipulations into my method called on dragend solved this problem for me.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With