diff --git a/core/modules/widgets/import.js b/core/modules/widgets/import.js index ed32334ec..63b0128dd 100644 --- a/core/modules/widgets/import.js +++ b/core/modules/widgets/import.js @@ -28,6 +28,7 @@ var ImportWidget = function(renderer) { ImportWidget.prototype.generate = function() { // Get the parameters from the attributes this.browse = this.renderer.getAttribute("browse","yes"); + this.mutate = this.renderer.getAttribute("mutate","yes"); this["class"] = this.renderer.getAttribute("class"); // Compute classes var classes = ["tw-import"]; @@ -69,52 +70,76 @@ ImportWidget.prototype.handleChangeEvent = function(event) { }; ImportWidget.prototype.handleDragEnterEvent = function(event) { - this.renderer.domNode.classList.add("tw-dragover"); + // 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.renderer.domNode,"tw-dragover"); + } + // 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 + event.stopPropagation(); }; ImportWidget.prototype.handleDragOverEvent = function(event) { - event.stopPropagation(); + // Tell the browser that we're still interested in the drop event.preventDefault(); - event.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy. + event.dataTransfer.dropEffect = 'copy'; // Explicitly show this is a copy }; ImportWidget.prototype.handleDragLeaveEvent = function(event) { - this.renderer.domNode.classList.remove("tw-dragover"); + // 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.renderer.domNode,"tw-dragover"); + } }; ImportWidget.prototype.handleDropEvent = function(event) { - this.renderer.domNode.classList.remove("tw-dragover"); - event.stopPropagation(); + var dataTransfer = event.dataTransfer; + // Reset the enter count + this.dragEnterCount = 0; + // Remove highlighting + $tw.utils.removeClass(this.renderer.domNode,"tw-dragover"); + // Try to import the various data types we understand + this.importData(dataTransfer); + // Import any files in the drop + this.importFiles(dataTransfer.files); + // Tell the browser that we handled the drop event.preventDefault(); - this.importFiles(event.dataTransfer.files); - return false; + // Stop the drop ripple up to any parent handlers + event.stopPropagation(); }; ImportWidget.prototype.handlePasteEvent = function(event) { - if(["TEXTAREA","INPUT"].indexOf(event.srcElement.tagName) == -1) { + // Let the browser handle it if we're in a textarea or input box + if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) == -1) { var self = this, items = event.clipboardData.items; + // Enumerate the clipboard items for(var t = 0; t> +} + .btn-invisible { padding: 0; margin: 0; @@ -376,13 +390,30 @@ embed { height: 20em; } -.tw-dragover .tw-drag-target { - display: block; - background: red; - position: absolute; +.tw-import { + position: relative; } -.tw-drag-target { - display: none; - position: absolute; +.tw-drop-zone-fullscreen.tw-dragover:before { + z-index: 10000; + display: block; + position: fixed; + top: 0; + left: 0; + right: 0; + background: rgba(0,200,0,0.7); + text-align: center; + content: "Drop here"; +} + +.tw-drop-zone.tw-dragover:before { + z-index: 10000; + display: block; + position: absolute; + top: 0; + left: 0; + right: 0; + background: rgba(0,200,0,0.7); + text-align: center; + content: "Drop here"; } diff --git a/core/templates/ControlPanel.tid b/core/templates/ControlPanel.tid index d78575e9c..6f86fbc85 100644 --- a/core/templates/ControlPanel.tid +++ b/core/templates/ControlPanel.tid @@ -4,7 +4,11 @@ title: $:/templates/ControlPanel --- -Import: <$import/> +Import: <$import mutate="sidebar importer" class="tw-drop-zone"> + +Drop files here + + --- diff --git a/core/templates/PageTemplate.tid b/core/templates/PageTemplate.tid index 6ee5d5279..fd11f0c27 100644 --- a/core/templates/PageTemplate.tid +++ b/core/templates/PageTemplate.tid @@ -4,11 +4,7 @@ title: $:/templates/PageTemplate <$navigator story="$:/StoryList" history="$:/HistoryList"> -<$import browse="no"> - -
-Drop files here to import them as tiddlers -
+<$import browse="no" mutate="global importer" class="tw-drop-zone-fullscreen">