mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-12-25 01:20:30 +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) {
|
DropZoneWidget.prototype.importData = function(dataTransfer) {
|
||||||
|
// Try each provided data type in turn
|
||||||
for(var t=0; t<this.importDataTypes.length; t++) {
|
for(var t=0; t<this.importDataTypes.length; t++) {
|
||||||
|
// Get the data
|
||||||
var dataType = this.importDataTypes[t];
|
var dataType = this.importDataTypes[t];
|
||||||
try {
|
try {
|
||||||
var data = dataTransfer.getData(dataType.type);
|
var data = dataTransfer.getData(dataType.type);
|
||||||
} catch(e) { if(e.description !== "Invalid argument.") throw e; } // deal with formats that IE doesn't support
|
} catch(e) {
|
||||||
if(data !== "" && data != null) {
|
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);
|
var tiddlerFields = dataType.convertToFields(data);
|
||||||
if(!tiddlerFields.title) {
|
if(!tiddlerFields.title) {
|
||||||
tiddlerFields.title = this.wiki.generateNewTitle("Untitled");
|
tiddlerFields.title = this.wiki.generateNewTitle("Untitled");
|
||||||
@ -121,12 +128,12 @@ DropZoneWidget.prototype.importDataTypes = [
|
|||||||
return JSON.parse(data);
|
return JSON.parse(data);
|
||||||
}},
|
}},
|
||||||
{type: "URL", convertToFields: function(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);
|
var match = decodeURI(data).match(/^data\:text\/vnd\.tiddler,(.*)/i);
|
||||||
if(match) {
|
if(match) {
|
||||||
return JSON.parse(match[1]);
|
return JSON.parse(match[1]);
|
||||||
} else {
|
} else {
|
||||||
return { // as URL string
|
return { // As URL string
|
||||||
text: data
|
text: data
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -124,17 +124,22 @@ LinkWidget.prototype.handleDragStartEvent = function(event) {
|
|||||||
this.dragImage.appendChild(cover);
|
this.dragImage.appendChild(cover);
|
||||||
// Set the data transfer properties
|
// Set the data transfer properties
|
||||||
var dataTransfer = event.dataTransfer;
|
var dataTransfer = event.dataTransfer;
|
||||||
|
// First the image
|
||||||
dataTransfer.effectAllowed = "copy";
|
dataTransfer.effectAllowed = "copy";
|
||||||
if(dataTransfer.setDragImage) {
|
if(dataTransfer.setDragImage) {
|
||||||
dataTransfer.setDragImage(this.dragImage.firstChild,-16,-16);
|
dataTransfer.setDragImage(this.dragImage.firstChild,-16,-16);
|
||||||
}
|
}
|
||||||
|
// Then the data
|
||||||
dataTransfer.clearData();
|
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))) {
|
if(!(/msie|trident/i.test(navigator.userAgent))) {
|
||||||
dataTransfer.setData("text/vnd.tiddler",this.wiki.getTiddlerAsJson(this.to));
|
dataTransfer.setData("text/vnd.tiddler",jsonData);
|
||||||
dataTransfer.setData("text/plain",this.wiki.getTiddlerText(this.to,""));
|
dataTransfer.setData("text/plain",textData);
|
||||||
}
|
}
|
||||||
dataTransfer.setData("URL","data:text/vnd.tiddler," + encodeURI(this.wiki.getTiddlerAsJson(this.to)));
|
dataTransfer.setData("URL","data:text/vnd.tiddler," + encodeURI(jsonData));
|
||||||
dataTransfer.setData("Text",this.wiki.getTiddlerText(this.to,""));
|
dataTransfer.setData("Text",textData);
|
||||||
event.stopPropagation();
|
event.stopPropagation();
|
||||||
} else {
|
} else {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
Loading…
Reference in New Issue
Block a user