2014-01-01 17:59:47 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/savers/nodewebkit.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: saver
|
|
|
|
|
2015-03-10 16:54:53 +00:00
|
|
|
Handles saving changes in the NW.js environment. Not required by TiddlyDesktop, which re-uses the TiddlyFox saver, but useful if you're embedding a single TiddlyWiki document into a NW.js app.
|
2014-01-01 17:59:47 +00:00
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false, netscape: false, Components: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
var NodeWebKitSaver = function(wiki) {
|
|
|
|
};
|
|
|
|
|
|
|
|
NodeWebKitSaver.prototype.save = function(text,method,callback) {
|
|
|
|
// Bail out unless this is a save (rather than a download)
|
|
|
|
if(method !== "save") {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
// Get the pathname of this document
|
|
|
|
var pathname = document.location.pathname;
|
|
|
|
// Test for a Windows path of the form /x:/blah/blah
|
|
|
|
if(/^\/[A-Z]\:\//i.test(pathname)) {
|
|
|
|
// Remove the leading slash
|
|
|
|
pathname = pathname.substr(1);
|
|
|
|
// Convert slashes to backslashes
|
|
|
|
pathname = pathname.replace(/\//g,"\\");
|
|
|
|
}
|
|
|
|
// Try to save
|
|
|
|
var fs = require("fs");
|
|
|
|
fs.writeFile(pathname,text,callback);
|
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Information about this saver
|
|
|
|
*/
|
|
|
|
NodeWebKitSaver.prototype.info = {
|
|
|
|
name: "nodewebkit",
|
|
|
|
priority: 1700
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static method that returns true if this saver is capable of working
|
|
|
|
*/
|
|
|
|
exports.canSave = function(wiki) {
|
|
|
|
// Check if we're running under node-webkit
|
2014-08-30 20:32:55 +00:00
|
|
|
return (typeof process == "object");
|
2014-01-01 17:59:47 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create an instance of this saver
|
|
|
|
*/
|
|
|
|
exports.create = function(wiki) {
|
|
|
|
return new NodeWebKitSaver(wiki);
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|