Skip to content

Commit 9709dbd

Browse files
fix: work around dataTransfer.getData limitation in agenda editor (ietf-tools#4553)
* fix: work around dataTransfer.getData limitation in agenda editor * refactor: be slightly more careful checking dataTransfer type * chore: remove debug statement
1 parent eed58c9 commit 9709dbd

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

ietf/static/js/edit-meeting-schedule.js

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,9 @@ $(function () {
312312

313313
// Was this drag started by dragging a session?
314314
function isSessionDragEvent(event) {
315-
return Boolean(event.originalEvent.dataTransfer.getData(dnd_mime_type));
315+
return event.originalEvent.dataTransfer.types.some(
316+
(item_type) => item_type.indexOf(dnd_mime_type) === 0
317+
);
316318
}
317319

318320
/**
@@ -324,7 +326,7 @@ $(function () {
324326
if (!isSessionDragEvent(event)) {
325327
return null;
326328
}
327-
const sessionId = event.originalEvent.dataTransfer.getData(dnd_mime_type);
329+
const sessionId = event.originalEvent.dataTransfer.types[0].slice(dnd_mime_type.length);
328330
const sessionElements = sessions.filter("#" + sessionId);
329331
if (sessionElements.length > 0) {
330332
return sessionElements[0];
@@ -357,7 +359,15 @@ $(function () {
357359
// dragging
358360
sessions.on("dragstart", function (event) {
359361
if (canEditSession(this)) {
360-
event.originalEvent.dataTransfer.setData(dnd_mime_type, this.id);
362+
/* Bit of a hack here - per the w3c drag and drop spec, the data being dragged
363+
* and dropped are only available during dragstart and drop events. Otherwise,
364+
* only their count and type are guaranteed to be available. (See
365+
* https://www.w3.org/TR/2011/WD-html5-20110113/dnd.html#drag-data-store-mode)
366+
* To work around this, append the sessionId to the dnd_mime_type in the type we
367+
* report for our event. The event handlers can then pull it out when needed.
368+
* (At least Chrome v106 breaks if we try to peek at the payload.)
369+
*/
370+
event.originalEvent.dataTransfer.setData(dnd_mime_type + this.id, this.id);
361371
jQuery(this).addClass("dragging");
362372
selectSessionElement(this);
363373
showPastTimeslotHints();

0 commit comments

Comments
 (0)