From 09afa8297a81fbe48dec7ef376db04077ce949c8 Mon Sep 17 00:00:00 2001 From: Tobias Beer Date: Mon, 9 Feb 2015 23:49:04 +0100 Subject: [PATCH 1/3] prevents drag and drop import in same window MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit fixes #592 Introduces and preserves **_origin** field when using drag-and-drop — bad idea? discard? different field name? demo http://592.tiddlyspot.com --- core/modules/widgets/dropzone.js | 21 ++++++++++++++------- core/modules/widgets/link.js | 2 +- core/modules/wiki.js | 13 ++++++++----- 3 files changed, 23 insertions(+), 13 deletions(-) diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index b0f7510fe..c1441175e 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -27,14 +27,14 @@ DropZoneWidget.prototype = new Widget(); Render this widget into the DOM */ DropZoneWidget.prototype.render = function(parent,nextSibling) { - var self = this; + var domNode; // Remember parent this.parentDomNode = parent; // Compute attributes and execute state this.computeAttributes(); this.execute(); // Create element - var domNode = this.document.createElement("div"); + domNode = this.document.createElement("div"); domNode.className = "tc-dropzone"; // Add event handlers $tw.utils.addEventListeners(domNode,[ @@ -119,20 +119,27 @@ DropZoneWidget.prototype.handleDropEvent = function(event) { }; DropZoneWidget.prototype.importData = function(dataTransfer) { + var data, dataType, origin, t, tiddlerFields, title; // Try each provided data type in turn - for(var t=0; t Date: Tue, 10 Feb 2015 23:33:19 +0100 Subject: [PATCH 2/3] Revert "prevents drag and drop import in same window" This reverts commit 09afa8297a81fbe48dec7ef376db04077ce949c8. --- core/modules/widgets/dropzone.js | 21 +++++++-------------- core/modules/widgets/link.js | 2 +- core/modules/wiki.js | 13 +++++-------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index c1441175e..b0f7510fe 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -27,14 +27,14 @@ DropZoneWidget.prototype = new Widget(); Render this widget into the DOM */ DropZoneWidget.prototype.render = function(parent,nextSibling) { - var domNode; + var self = this; // Remember parent this.parentDomNode = parent; // Compute attributes and execute state this.computeAttributes(); this.execute(); // Create element - domNode = this.document.createElement("div"); + var domNode = this.document.createElement("div"); domNode.className = "tc-dropzone"; // Add event handlers $tw.utils.addEventListeners(domNode,[ @@ -119,27 +119,20 @@ DropZoneWidget.prototype.handleDropEvent = function(event) { }; DropZoneWidget.prototype.importData = function(dataTransfer) { - var data, dataType, origin, t, tiddlerFields, title; // Try each provided data type in turn - for(t=0; t Date: Tue, 10 Feb 2015 23:34:37 +0100 Subject: [PATCH 3/3] using $tw.dragging to prevent dnd in same window Anything missing? --- core/modules/widgets/dropzone.js | 4 ++++ core/modules/widgets/link.js | 2 ++ 2 files changed, 6 insertions(+) diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index b0f7510fe..34ae850d8 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -134,6 +134,10 @@ DropZoneWidget.prototype.importData = function(dataTransfer) { if(!tiddlerFields.title) { tiddlerFields.title = this.wiki.generateNewTitle("Untitled"); } + if($tw.dragging) { + $tw.dragging = false; + return false; + } this.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify([tiddlerFields])}); return; } diff --git a/core/modules/widgets/link.js b/core/modules/widgets/link.js index eac53a050..c4439ecbb 100755 --- a/core/modules/widgets/link.js +++ b/core/modules/widgets/link.js @@ -126,6 +126,7 @@ LinkWidget.prototype.handleClickEvent = function(event) { LinkWidget.prototype.handleDragStartEvent = function(event) { if(event.target === this.domNodes[0]) { if(this.to) { + $tw.dragging = true; // Set the dragging class on the element being dragged $tw.utils.addClass(event.target,"tc-tiddlylink-dragging"); // Create the drag image elements @@ -173,6 +174,7 @@ LinkWidget.prototype.handleDragStartEvent = function(event) { LinkWidget.prototype.handleDragEndEvent = function(event) { if(event.target === this.domNodes[0]) { + $tw.dragging = false; // Remove the dragging class on the element being dragged $tw.utils.removeClass(event.target,"tc-tiddlylink-dragging"); // Delete the drag image element