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-05-07 17:09:15 +00:00
|
|
|
TiddlyFoxSaver.prototype.save = function(text,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
|
|
|
|
var pathname = document.location.pathname;
|
|
|
|
// Test for a Windows path of the form /x:/blah/blah
|
2013-09-19 12:50:28 +00:00
|
|
|
if(/^\/[A-Z]\:\//i.test(pathname)) {
|
2013-05-10 17:14:01 +00:00
|
|
|
// Remove the leading slash
|
|
|
|
pathname = pathname.substr(1);
|
|
|
|
// Convert slashes to backslashes
|
|
|
|
pathname = pathname.replace(/\//g,"\\");
|
|
|
|
}
|
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",
|
|
|
|
priority: 1500
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
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);
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|