mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2025-05-06 09:24:10 +00:00
Fix problem with tracking dragenter/leave events in Firefox
Fixes #686 (hopefully!)
This commit is contained in:
parent
d778bc9a21
commit
39cdaeb34d
@ -50,32 +50,35 @@ DropZoneWidget.prototype.render = function(parent,nextSibling) {
|
|||||||
parent.insertBefore(domNode,nextSibling);
|
parent.insertBefore(domNode,nextSibling);
|
||||||
this.renderChildren(domNode,null);
|
this.renderChildren(domNode,null);
|
||||||
this.domNodes.push(domNode);
|
this.domNodes.push(domNode);
|
||||||
|
// Stack of outstanding enter/leave events
|
||||||
|
this.currentlyEntered = [];
|
||||||
};
|
};
|
||||||
|
|
||||||
DropZoneWidget.prototype.enterDrag = function() {
|
DropZoneWidget.prototype.enterDrag = function(event) {
|
||||||
// Check for this window being the source of the drag
|
if(this.currentlyEntered.indexOf(event.target) === -1) {
|
||||||
if($tw.dragInProgress) {
|
this.currentlyEntered.push(event.target);
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
// 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 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() {
|
DropZoneWidget.prototype.leaveDrag = function(event) {
|
||||||
// Reduce the enter count
|
var pos = this.currentlyEntered.indexOf(event.target);
|
||||||
this.dragEnterCount = (this.dragEnterCount || 0) - 1;
|
if(pos !== -1) {
|
||||||
|
this.currentlyEntered.splice(pos,1);
|
||||||
|
}
|
||||||
// Remove highlighting if we're leaving externally
|
// Remove highlighting if we're leaving externally
|
||||||
if(this.dragEnterCount <= 0) {
|
if(this.currentlyEntered.length === 0) {
|
||||||
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
|
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
DropZoneWidget.prototype.handleDragEnterEvent = function(event) {
|
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
|
// Tell the browser that we're ready to handle the drop
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
// Tell the browser not to ripple the drag up to any parent drop handlers
|
// 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) {
|
DropZoneWidget.prototype.handleDragLeaveEvent = function(event) {
|
||||||
this.leaveDrag();
|
this.leaveDrag(event);
|
||||||
};
|
};
|
||||||
|
|
||||||
DropZoneWidget.prototype.handleDropEvent = function(event) {
|
DropZoneWidget.prototype.handleDropEvent = function(event) {
|
||||||
this.leaveDrag();
|
this.leaveDrag(event);
|
||||||
// Check for being over a TEXTAREA or INPUT
|
// Check for being over a TEXTAREA or INPUT
|
||||||
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) !== -1) {
|
if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) !== -1) {
|
||||||
return false;
|
return false;
|
||||||
@ -112,8 +115,6 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
|
|||||||
}
|
}
|
||||||
var self = this,
|
var self = this,
|
||||||
dataTransfer = event.dataTransfer;
|
dataTransfer = event.dataTransfer;
|
||||||
// Reset the enter count
|
|
||||||
this.dragEnterCount = 0;
|
|
||||||
// Remove highlighting
|
// Remove highlighting
|
||||||
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
|
$tw.utils.removeClass(this.domNodes[0],"tc-dragover");
|
||||||
// Import any files in the drop
|
// Import any files in the drop
|
||||||
|
Loading…
x
Reference in New Issue
Block a user