mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-24 17:10:29 +00:00
Coding style and layout tweaks
This commit is contained in:
parent
3e2f475324
commit
066a4d9fbc
@ -100,12 +100,19 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
|
||||
};
|
||||
|
||||
DropZoneWidget.prototype.importData = function(dataTransfer) {
|
||||
// Try each provided data type in turn
|
||||
for(var t=0; t<this.importDataTypes.length; t++) {
|
||||
// Get the data
|
||||
var dataType = this.importDataTypes[t];
|
||||
try {
|
||||
var data = dataTransfer.getData(dataType.type);
|
||||
} catch(e) { if(e.description !== "Invalid argument.") throw e; } // deal with formats that IE doesn't support
|
||||
if(data !== "" && data != null) {
|
||||
} catch(e) {
|
||||
if(e.description !== "Invalid argument.") {
|
||||
throw e; // Deal with formats that IE doesn't support
|
||||
}
|
||||
}
|
||||
// Import the tiddlers in the data
|
||||
if(data !== "" && data !== null) {
|
||||
var tiddlerFields = dataType.convertToFields(data);
|
||||
if(!tiddlerFields.title) {
|
||||
tiddlerFields.title = this.wiki.generateNewTitle("Untitled");
|
||||
@ -121,12 +128,12 @@ DropZoneWidget.prototype.importDataTypes = [
|
||||
return JSON.parse(data);
|
||||
}},
|
||||
{type: "URL", convertToFields: function(data) {
|
||||
// check for tiddler data URI
|
||||
// Check for tiddler data URI
|
||||
var match = decodeURI(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
||||
if(match) {
|
||||
return JSON.parse(match[1]);
|
||||
} else {
|
||||
return { // as URL string
|
||||
return { // As URL string
|
||||
text: data
|
||||
};
|
||||
}
|
||||
|
@ -124,17 +124,22 @@ LinkWidget.prototype.handleDragStartEvent = function(event) {
|
||||
this.dragImage.appendChild(cover);
|
||||
// Set the data transfer properties
|
||||
var dataTransfer = event.dataTransfer;
|
||||
// First the image
|
||||
dataTransfer.effectAllowed = "copy";
|
||||
if(dataTransfer.setDragImage) {
|
||||
dataTransfer.setDragImage(this.dragImage.firstChild,-16,-16);
|
||||
}
|
||||
// Then the data
|
||||
dataTransfer.clearData();
|
||||
var jsonData = this.wiki.getTiddlerAsJson(this.to),
|
||||
textData = this.wiki.getTiddlerText(this.to,"");
|
||||
// IE doesn't like these content types
|
||||
if(!(/msie|trident/i.test(navigator.userAgent))) {
|
||||
dataTransfer.setData("text/vnd.tiddler",this.wiki.getTiddlerAsJson(this.to));
|
||||
dataTransfer.setData("text/plain",this.wiki.getTiddlerText(this.to,""));
|
||||
dataTransfer.setData("text/vnd.tiddler",jsonData);
|
||||
dataTransfer.setData("text/plain",textData);
|
||||
}
|
||||
dataTransfer.setData("URL","data:text/vnd.tiddler," + encodeURI(this.wiki.getTiddlerAsJson(this.to)));
|
||||
dataTransfer.setData("Text",this.wiki.getTiddlerText(this.to,""));
|
||||
dataTransfer.setData("URL","data:text/vnd.tiddler," + encodeURI(jsonData));
|
||||
dataTransfer.setData("Text",textData);
|
||||
event.stopPropagation();
|
||||
} else {
|
||||
event.preventDefault();
|
||||
|
Loading…
Reference in New Issue
Block a user