From 78735cde961c100f8fc79b9e012f739c3084413c Mon Sep 17 00:00:00 2001 From: Jermolene Date: Tue, 11 Nov 2014 11:44:00 +0000 Subject: [PATCH] Refactor dropzone I want to start figuring out #686 --- core/modules/widgets/dropzone.js | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index edda8fa50..42b75b1fe 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -52,13 +52,26 @@ DropZoneWidget.prototype.render = function(parent,nextSibling) { this.domNodes.push(domNode); }; -DropZoneWidget.prototype.handleDragEnterEvent = function(event) { +DropZoneWidget.prototype.enterDrag = function() { // 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"); } +}; + +DropZoneWidget.prototype.leaveDrag = function() { + // Reduce the enter count + this.dragEnterCount = (this.dragEnterCount || 0) - 1; + // Remove highlighting if we're leaving externally + if(this.dragEnterCount <= 0) { + $tw.utils.removeClass(this.domNodes[0],"tc-dragover"); + } +}; + +DropZoneWidget.prototype.handleDragEnterEvent = function(event) { + this.enterDrag(); // 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 @@ -76,15 +89,11 @@ DropZoneWidget.prototype.handleDragOverEvent = function(event) { }; DropZoneWidget.prototype.handleDragLeaveEvent = function(event) { - // Reduce the enter count - this.dragEnterCount = (this.dragEnterCount || 0) - 1; - // Remove highlighting if we're leaving externally - if(this.dragEnterCount <= 0) { - $tw.utils.removeClass(this.domNodes[0],"tc-dragover"); - } + this.leaveDrag(); }; DropZoneWidget.prototype.handleDropEvent = function(event) { + this.leaveDrag(); // Check for being over a TEXTAREA or INPUT if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) !== -1) { return false;