diff --git a/boot/boot.js b/boot/boot.js index d9719ed50..284d58db9 100644 --- a/boot/boot.js +++ b/boot/boot.js @@ -1220,10 +1220,14 @@ $tw.Wiki.prototype.processSafeMode = function() { /* Extracts tiddlers from a typed block of text, specifying default field values */ -$tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields) { +$tw.Wiki.prototype.deserializeTiddlers = function(type,text,srcFields,options) { srcFields = srcFields || Object.create(null); - var deserializer = $tw.Wiki.tiddlerDeserializerModules[type], + options = options || {}; + var deserializer = $tw.Wiki.tiddlerDeserializerModules[options.deserializer], fields = Object.create(null); + if(!deserializer) { + deserializer = $tw.Wiki.tiddlerDeserializerModules[type]; + } if(!deserializer && $tw.utils.getFileExtensionInfo(type)) { // If we didn't find the serializer, try converting it from an extension to a content type type = $tw.utils.getFileExtensionInfo(type).type; diff --git a/core/modules/widgets/dropzone.js b/core/modules/widgets/dropzone.js index 08d875c39..d732fb97d 100644 --- a/core/modules/widgets/dropzone.js +++ b/core/modules/widgets/dropzone.js @@ -104,7 +104,10 @@ DropZoneWidget.prototype.handleDragLeaveEvent = function(event) { }; DropZoneWidget.prototype.handleDropEvent = function(event) { - var self = this; + var self = this, + readFileCallback = function(tiddlerFieldsArray) { + self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)}); + }; this.leaveDrag(event); // Check for being over a TEXTAREA or INPUT if(["TEXTAREA","INPUT"].indexOf(event.target.tagName) !== -1) { @@ -121,15 +124,14 @@ DropZoneWidget.prototype.handleDropEvent = function(event) { // Import any files in the drop var numFiles = 0; if(dataTransfer.files) { - numFiles = this.wiki.readFiles(dataTransfer.files,function(tiddlerFieldsArray) { - self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)}); + numFiles = this.wiki.readFiles(dataTransfer.files,{ + callback: readFileCallback, + deserializer: this.dropzoneDeserializer }); } // Try to import the various data types we understand if(numFiles === 0) { - $tw.utils.importDataTransfer(dataTransfer,this.wiki.generateNewTitle("Untitled"),function(fieldsArray) { - self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(fieldsArray)}); - }); + $tw.utils.importDataTransfer(dataTransfer,this.wiki.generateNewTitle("Untitled"),readFileCallback); } // Tell the browser that we handled the drop event.preventDefault(); @@ -138,6 +140,10 @@ DropZoneWidget.prototype.handleDropEvent = function(event) { }; DropZoneWidget.prototype.handlePasteEvent = function(event) { + var self = this, + readFileCallback = function(tiddlerFieldsArray) { + self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)}); + }; // 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, @@ -147,8 +153,9 @@ DropZoneWidget.prototype.handlePasteEvent = function(event) { var item = items[t]; if(item.kind === "file") { // Import any files - this.wiki.readFile(item.getAsFile(),function(tiddlerFieldsArray) { - self.dispatchEvent({type: "tm-import-tiddlers", param: JSON.stringify(tiddlerFieldsArray)}); + this.wiki.readFile(item.getAsFile(),{ + callback: readFileCallback, + deserializer: this.dropzoneDeserializer }); } else if(item.kind === "string") { // Create tiddlers from string items @@ -176,6 +183,7 @@ DropZoneWidget.prototype.handlePasteEvent = function(event) { Compute the internal state of the widget */ DropZoneWidget.prototype.execute = function() { + this.dropzoneDeserializer = this.getAttribute("deserializer"); // Make child widgets this.makeChildWidgets(); }; diff --git a/core/modules/wiki.js b/core/modules/wiki.js index 1d077fd67..b2dbed5c9 100755 --- a/core/modules/wiki.js +++ b/core/modules/wiki.js @@ -1125,16 +1125,24 @@ exports.checkTiddlerText = function(title,targetText,options) { /* Read an array of browser File objects, invoking callback(tiddlerFieldsArray) once they're all read */ -exports.readFiles = function(files,callback) { +exports.readFiles = function(files,options) { + var callback; + if(typeof options === "function") { + callback = options; + options = {}; + } else { + callback = options.callback; + } var result = [], - outstanding = files.length; - for(var f=0; f