1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-12-24 00:50:28 +00:00

Tidying up drag and drop

This commit is contained in:
Jeremy Ruston 2013-04-10 16:55:25 +01:00
parent e39d246317
commit 94287c9ac3
3 changed files with 11 additions and 9 deletions

View File

@ -28,7 +28,6 @@ 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"];
@ -132,7 +131,7 @@ ImportWidget.prototype.handlePasteEvent = function(event) {
title: self.generateTitle("Untitled"),
text: str
};
self.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(fields));
self.storeTiddler(fields);
self.openTiddler(fields.title);
});
}
@ -160,7 +159,7 @@ ImportWidget.prototype.importData = function(dataTransfer) {
if(!fields.title) {
fields.title = this.generateTitle("Untitled");
}
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(fields));
this.storeTiddler(fields);
this.openTiddler(fields.title);
return;
}
@ -212,7 +211,7 @@ ImportWidget.prototype.importFiles = function(files) {
var commaPos = event.target.result.indexOf(",");
if(commaPos !== -1) {
fields.text = event.target.result.substr(commaPos+1);
self.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(fields));
self.storeTiddler(fields);
self.openTiddler(fields.title);
}
} else {
@ -221,8 +220,8 @@ ImportWidget.prototype.importFiles = function(files) {
console.log("No tiddlers found in file ",file.name);
} else {
$tw.utils.each(tiddlers,function(tiddlerFields) {
var title = self.generateTitle(tiddlerFields.title);
self.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(tiddlerFields,{title: title}));
tiddlerFields.title = self.generateTitle(tiddlerFields.title);
self.storeTiddler(tiddlerFields);
self.openTiddler(title);
});
}
@ -239,6 +238,10 @@ ImportWidget.prototype.importFiles = function(files) {
};
};
ImportWidget.prototype.storeTiddler = function(fields) {
this.renderer.renderTree.wiki.addTiddler(new $tw.Tiddler(fields));
};
ImportWidget.prototype.generateTitle = function(baseTitle) {
var c = 0;
do {

View File

@ -4,7 +4,7 @@ title: $:/templates/ControlPanel
---
Import: <$import mutate="sidebar importer" class="tw-drop-zone">
Import: <$import class="tw-drop-zone">
Drop files here

View File

@ -3,8 +3,7 @@ title: $:/templates/PageTemplate
<!-- The navigator catches navigation events and updates the story and history tiddlers -->
<$navigator story="$:/StoryList" history="$:/HistoryList">
<$import browse="no" mutate="global importer" class="tw-drop-zone-fullscreen">
<$import browse="no" class="tw-drop-zone-fullscreen">
<!-- The sidebar header -->
<header class="sidebar-header">