Ok, here's a FileDropPlugin Config file that works in Windows, knows
how to make a relative path if possible, and creates a tiddler with a
file link for normal files and a tiddler with an image link for image
files. Its probably buggy in one or more ways ...
-- Mark
config.macros.fileDrop.addEventListener("application/x-moz-
file",function(nsiFile)
{
// Given file path or url, convert into standard local path
function normalizedPathArray(str) {
var idx = str.lastIndexOf(":") ;
if (idx != -1) str = str.substring(idx-1) ;
str = str.replace(/\\/g,"/") ;
var ret = str.split("/") ;
ret[0] = ret[0].toLowerCase() ;
return ret ;
}
var newDate = new Date();
//var t = nsiFile.path.replace(/\\/g , "_") ;
var localPathArray = normalizedPathArray(document.URL) ;
var droppedPathArray = normalizedPathArray(nsiFile.path) ;
var sharedPath = [] ;
for(var i=0;i<localPathArray.length;i++) {
if(localPathArray[i] != droppedPathArray[i]) break ;
sharedPath[i] = localPathArray[i] ;
}
var filePath = "file:///" + droppedPathArray.join("/") ;
if (sharedPath.length) {
filePath = "" ;
for(i=0;i<localPathArray.length - sharedPath.length-1;i++)
filePath += "../" ;
filePath += droppedPathArray.slice(sharedPath.length).join
("/") ;
//filePath = "../" + sharedPath.join("/") ;
}
var fileExt = "" ;
if(nsiFile.path.indexOf(".")!=-1) {
var fileExt = nsiFile.path.slice(nsiFile.path.lastIndexOf(".")
+1) ;
}
// Determine whether this is any of the known web image types
var isImageType = false ;
isImageType = (new RegExp(/jpg|jpeg|png|gif|tif+/i)).test
(fileExt) ;
// Generate title we'll use
var t = droppedPathArray.join("_") ;
t = t.replace(/[:.]/g,'_').replace(/__/g,"_") ;
// Generate the file or image link to be displayed
var fileLink = "" ;
if(isImageType) {
var fileLink = "[img[" + droppedPathArray
[droppedPathArray.length-1] +
"|" + filePath + "]]" ;
} else {
var fileLink = "[[" + droppedPathArray
[droppedPathArray.length-1] +
"|" + filePath + "]]" ;
}
store.saveTiddler
(null,t,fileLink,config.options.txtUserName,newDate,[]);
story.displayTiddler(null,t)
})
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"TiddlyWiki" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/TiddlyWiki?hl=en
-~----------~----~----~----~------~----~------~--~---