fix: work around dataTransfer.getData limitation in agenda editor (#4553)

* fix: work around dataTransfer.getData limitation in agenda editor

* refactor: be slightly more careful checking dataTransfer type

* chore: remove debug statement
This commit is contained in:
Jennifer Richards 2022-10-10 10:48:23 -03:00 committed by GitHub
parent eed58c9753
commit 9709dbdf1c
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -312,7 +312,9 @@ $(function () {
// Was this drag started by dragging a session?
function isSessionDragEvent(event) {
return Boolean(event.originalEvent.dataTransfer.getData(dnd_mime_type));
return event.originalEvent.dataTransfer.types.some(
(item_type) => item_type.indexOf(dnd_mime_type) === 0
);
}
/**
@ -324,7 +326,7 @@ $(function () {
if (!isSessionDragEvent(event)) {
return null;
}
const sessionId = event.originalEvent.dataTransfer.getData(dnd_mime_type);
const sessionId = event.originalEvent.dataTransfer.types[0].slice(dnd_mime_type.length);
const sessionElements = sessions.filter("#" + sessionId);
if (sessionElements.length > 0) {
return sessionElements[0];
@ -357,7 +359,15 @@ $(function () {
// dragging
sessions.on("dragstart", function (event) {
if (canEditSession(this)) {
event.originalEvent.dataTransfer.setData(dnd_mime_type, this.id);
/* Bit of a hack here - per the w3c drag and drop spec, the data being dragged
* and dropped are only available during dragstart and drop events. Otherwise,
* only their count and type are guaranteed to be available. (See
* https://www.w3.org/TR/2011/WD-html5-20110113/dnd.html#drag-data-store-mode)
* To work around this, append the sessionId to the dnd_mime_type in the type we
* report for our event. The event handlers can then pull it out when needed.
* (At least Chrome v106 breaks if we try to peek at the payload.)
*/
event.originalEvent.dataTransfer.setData(dnd_mime_type + this.id, this.id);
jQuery(this).addClass("dragging");
selectSessionElement(this);
showPastTimeslotHints();