mirror of
https://github.com/Jermolene/TiddlyWiki5
synced 2024-10-06 02:40:44 +00:00
Merge pull request #299 from davidjade/master
Better drag/drop for Firefox/Chrome and improved IE support
This commit is contained in:
commit
ce13548884
@ -130,6 +130,7 @@ exports.convertEventName = function(eventName) {
|
|||||||
|
|
||||||
// Setup constants for the current browser
|
// Setup constants for the current browser
|
||||||
exports.getBrowserInfo = function(info) {
|
exports.getBrowserInfo = function(info) {
|
||||||
|
info.isIE = (/msie|trident/i.test(navigator.userAgent));
|
||||||
};
|
};
|
||||||
|
|
||||||
})();
|
})();
|
||||||
|
@ -102,15 +102,10 @@ DropZoneWidget.prototype.handleDropEvent = function(event) {
|
|||||||
DropZoneWidget.prototype.importData = function(dataTransfer) {
|
DropZoneWidget.prototype.importData = function(dataTransfer) {
|
||||||
// Try each provided data type in turn
|
// 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++) {
|
||||||
|
if(!$tw.browser.isIE || this.importDataTypes[t].IECompatible) {
|
||||||
// Get the data
|
// Get the data
|
||||||
var dataType = this.importDataTypes[t];
|
var dataType = this.importDataTypes[t];
|
||||||
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
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Import the tiddlers in the data
|
// Import the tiddlers in the data
|
||||||
if(data !== "" && data !== null) {
|
if(data !== "" && data !== null) {
|
||||||
var tiddlerFields = dataType.convertToFields(data);
|
var tiddlerFields = dataType.convertToFields(data);
|
||||||
@ -120,14 +115,15 @@ DropZoneWidget.prototype.importData = function(dataTransfer) {
|
|||||||
this.dispatchEvent({type: "tw-import-tiddlers", param: JSON.stringify([tiddlerFields])});
|
this.dispatchEvent({type: "tw-import-tiddlers", param: JSON.stringify([tiddlerFields])});
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
|
|
||||||
DropZoneWidget.prototype.importDataTypes = [
|
DropZoneWidget.prototype.importDataTypes = [
|
||||||
{type: "text/vnd.tiddler", convertToFields: function(data) {
|
{type: "text/vnd.tiddler", IECompatible: false, convertToFields: function(data) {
|
||||||
return JSON.parse(data);
|
return JSON.parse(data);
|
||||||
}},
|
}},
|
||||||
{type: "URL", convertToFields: function(data) {
|
{type: "URL", IECompatible: true, 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) {
|
||||||
@ -138,17 +134,28 @@ DropZoneWidget.prototype.importDataTypes = [
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}},
|
}},
|
||||||
{type: "text/plain", convertToFields: function(data) {
|
{type: "text/x-moz-url", IECompatible: false, convertToFields: function(data) {
|
||||||
|
// 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
|
||||||
|
text: data
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}},
|
||||||
|
{type: "text/plain", IECompatible: false, convertToFields: function(data) {
|
||||||
return {
|
return {
|
||||||
text: data
|
text: data
|
||||||
};
|
};
|
||||||
}},
|
}},
|
||||||
{type: "Text", convertToFields: function(data) {
|
{type: "Text", IECompatible: true, convertToFields: function(data) {
|
||||||
return {
|
return {
|
||||||
text: data
|
text: data
|
||||||
};
|
};
|
||||||
}},
|
}},
|
||||||
{type: "text/uri-list", convertToFields: function(data) {
|
{type: "text/uri-list", IECompatible: false, convertToFields: function(data) {
|
||||||
return {
|
return {
|
||||||
text: data
|
text: data
|
||||||
};
|
};
|
||||||
|
@ -133,9 +133,10 @@ LinkWidget.prototype.handleDragStartEvent = function(event) {
|
|||||||
var jsonData = this.wiki.getTiddlerAsJson(this.to),
|
var jsonData = this.wiki.getTiddlerAsJson(this.to),
|
||||||
textData = this.wiki.getTiddlerText(this.to,"");
|
textData = this.wiki.getTiddlerText(this.to,"");
|
||||||
// IE doesn't like these content types
|
// IE doesn't like these content types
|
||||||
if(!(/msie|trident/i.test(navigator.userAgent))) {
|
if(!$tw.browser.isIE) {
|
||||||
dataTransfer.setData("text/vnd.tiddler",jsonData);
|
dataTransfer.setData("text/vnd.tiddler",jsonData);
|
||||||
dataTransfer.setData("text/plain",textData);
|
dataTransfer.setData("text/plain",textData);
|
||||||
|
dataTransfer.setData("text/x-moz-url","data:text/vnd.tiddler," + encodeURI(jsonData));
|
||||||
}
|
}
|
||||||
dataTransfer.setData("URL","data:text/vnd.tiddler," + encodeURI(jsonData));
|
dataTransfer.setData("URL","data:text/vnd.tiddler," + encodeURI(jsonData));
|
||||||
dataTransfer.setData("Text",textData);
|
dataTransfer.setData("Text",textData);
|
||||||
|
Loading…
Reference in New Issue
Block a user