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(); },
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(); },
Share
Improve this question
edited May 23, 2017 at 4:17
K Scandrett
16.5k4 gold badges42 silver badges68 bronze badges
asked Aug 6, 2013 at 9:56
SauryabhattSauryabhatt
2692 silver badges14 bronze badges
6
|
Show 1 more comment
3 Answers
Reset to default 9Firefox 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.
ev.preventDefault();
toe.preventDefault();
since you name your event variablee
. – putvande Commented Aug 6, 2013 at 11:23