2012-08-29 21:40:58 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/savers/tiddlyfox.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: saver
|
|
|
|
|
|
|
|
Handles saving changes via the TiddlyFox file extension
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false, netscape: false, Components: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var TiddlyFoxSaver = function(wiki) {
|
|
|
|
};
|
|
|
|
|
2013-11-27 20:51:08 +00:00
|
|
|
TiddlyFoxSaver.prototype.save = function(text,method,callback) {
|
2012-08-29 21:40:58 +00:00
|
|
|
var messageBox = document.getElementById("tiddlyfox-message-box");
|
|
|
|
if(messageBox) {
|
2013-05-10 17:14:01 +00:00
|
|
|
// Get the pathname of this document
|
2014-05-05 12:30:31 +00:00
|
|
|
var pathname = document.location.toString().split("#")[0];
|
2014-04-17 21:30:14 +00:00
|
|
|
// Replace file://localhost/ with file:///
|
2014-08-30 19:44:26 +00:00
|
|
|
if(pathname.indexOf("file://localhost/") === 0) {
|
2014-04-17 21:30:14 +00:00
|
|
|
pathname = "file://" + pathname.substr(16);
|
|
|
|
}
|
|
|
|
// Windows path file:///x:/blah/blah --> x:\blah\blah
|
|
|
|
if(/^file\:\/\/\/[A-Z]\:\//i.test(pathname)) {
|
|
|
|
// Remove the leading slash and convert slashes to backslashes
|
|
|
|
pathname = pathname.substr(8).replace(/\//g,"\\");
|
|
|
|
// Firefox Windows network path file://///server/share/blah/blah --> //server/share/blah/blah
|
|
|
|
} else if(pathname.indexOf("file://///") === 0) {
|
|
|
|
pathname = "\\\\" + unescape(pathname.substr(10)).replace(/\//g,"\\");
|
|
|
|
// Mac/Unix local path file:///path/path --> /path/path
|
2014-08-30 19:44:26 +00:00
|
|
|
} else if(pathname.indexOf("file:///") === 0) {
|
2014-04-17 21:30:14 +00:00
|
|
|
pathname = unescape(pathname.substr(7));
|
|
|
|
// Mac/Unix local path file:/path/path --> /path/path
|
2014-08-30 19:44:26 +00:00
|
|
|
} else if(pathname.indexOf("file:/") === 0) {
|
2014-04-17 21:30:14 +00:00
|
|
|
pathname = unescape(pathname.substr(5));
|
|
|
|
// Otherwise Windows networth path file://server/share/path/path --> \\server\share\path\path
|
|
|
|
} else {
|
|
|
|
pathname = "\\\\" + unescape(pathname.substr(7)).replace(new RegExp("/","g"),"\\");
|
2013-05-10 17:14:01 +00:00
|
|
|
}
|
2012-08-29 21:40:58 +00:00
|
|
|
// Create the message element and put it in the message box
|
|
|
|
var message = document.createElement("div");
|
2013-05-10 17:14:01 +00:00
|
|
|
message.setAttribute("data-tiddlyfox-path",decodeURIComponent(pathname));
|
2012-11-17 20:17:29 +00:00
|
|
|
message.setAttribute("data-tiddlyfox-content",text);
|
2012-08-29 21:40:58 +00:00
|
|
|
messageBox.appendChild(message);
|
2013-05-07 17:09:15 +00:00
|
|
|
// Add an event handler for when the file has been saved
|
|
|
|
message.addEventListener("tiddlyfox-have-saved-file",function(event) {
|
|
|
|
callback(null);
|
|
|
|
}, false);
|
2012-08-29 21:40:58 +00:00
|
|
|
// Create and dispatch the custom event to the extension
|
|
|
|
var event = document.createEvent("Events");
|
|
|
|
event.initEvent("tiddlyfox-save-file",true,false);
|
|
|
|
message.dispatchEvent(event);
|
|
|
|
return true;
|
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Information about this saver
|
|
|
|
*/
|
|
|
|
TiddlyFoxSaver.prototype.info = {
|
|
|
|
name: "tiddlyfox",
|
2014-02-04 21:21:01 +00:00
|
|
|
priority: 1500,
|
|
|
|
capabilities: ["save", "autosave"]
|
2012-08-29 21:40:58 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static method that returns true if this saver is capable of working
|
|
|
|
*/
|
|
|
|
exports.canSave = function(wiki) {
|
|
|
|
return (window.location.protocol === "file:");
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create an instance of this saver
|
|
|
|
*/
|
|
|
|
exports.create = function(wiki) {
|
|
|
|
return new TiddlyFoxSaver(wiki);
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|