From 39cdaeb34dfe58cfd4a31b1f9e340bc906a918f1 Mon Sep 17 00:00:00 2001 From: Jermolene Date: Fri, 17 Mar 2017 14:54:30 +0000 Subject: [PATCH] Fix problem with tracking dragenter/leave events in Firefox Fixes #686 (hopefully!) --- core/modules/widgets/dropzone.js | 37 ++++++++++++++++---------------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index 4ac8e78f4..48c1b0368 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -50,32 +50,35 @@ DropZoneWidget.prototype.render = function(parent,nextSibling) { parent.insertBefore(domNode,nextSibling); this.renderChildren(domNode,null); this.domNodes.push(domNode); + // Stack of outstanding enter/leave events + this.currentlyEntered = []; }; -DropZoneWidget.prototype.enterDrag = function() { - // Check for this window being the source of the drag - if($tw.dragInProgress) { - return false; +DropZoneWidget.prototype.enterDrag = function(event) { + if(this.currentlyEntered.indexOf(event.target) === -1) { + this.currentlyEntered.push(event.target); } - // We count enter/leave events - this.dragEnterCount = (this.dragEnterCount || 0) + 1; // If we're entering for the first time we need to apply highlighting - if(this.dragEnterCount === 1) { - $tw.utils.addClass(this.domNodes[0],"tc-dragover"); - } + $tw.utils.addClass(this.domNodes[0],"tc-dragover"); }; -DropZoneWidget.prototype.leaveDrag = function() { - // Reduce the enter count - this.dragEnterCount = (this.dragEnterCount || 0) - 1; +DropZoneWidget.prototype.leaveDrag = function(event) { + var pos = this.currentlyEntered.indexOf(event.target); + if(pos !== -1) { + this.currentlyEntered.splice(pos,1); + } // Remove highlighting if we're leaving externally - if(this.dragEnterCount <= 0) { + if(this.currentlyEntered.length === 0) { $tw.utils.removeClass(this.domNodes[0],"tc-dragover"); } }; DropZoneWidget.prototype.handleDragEnterEvent = function(event) { - this.enterDrag(); + // Check for this window being the source of the drag + if($tw.dragInProgress) { + return false; + } + this.enterDrag(event); // Tell the browser that we're ready to handle the drop event.preventDefault(); // Tell the browser not to ripple the drag up to any parent drop handlers @@ -97,11 +100,11 @@ DropZoneWidget.prototype.handleDragOverEvent = function(event) { }; DropZoneWidget.prototype.handleDragLeaveEvent = function(event) { - this.leaveDrag(); + this.leaveDrag(event); }; DropZoneWidget.prototype.handleDropEvent = function(event) { - this.leaveDrag(); + this.leaveDrag(event); // Check for being over a TEXTAREA or INPUT if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) !== -1) { return false; @@ -112,8 +115,6 @@ DropZoneWidget.prototype.handleDropEvent = function(event) { } var self = this, dataTransfer = event.dataTransfer; - // Reset the enter count - this.dragEnterCount = 0; // Remove highlighting $tw.utils.removeClass(this.domNodes[0],"tc-dragover"); // Import any files in the drop