2013-12-11 20:45:35 +00:00
|
|
|
/*\
|
|
|
|
title: $:/core/modules/savers/fsosaver.js
|
|
|
|
type: application/javascript
|
|
|
|
module-type: saver
|
|
|
|
|
|
|
|
Handles saving changes via MS FileSystemObject ActiveXObject
|
|
|
|
|
|
|
|
Note: Since TiddlyWiki's markup contains the MOTW, the FileSystemObject normally won't be available.
|
|
|
|
However, if the wiki is loaded as an .HTA file (Windows HTML Applications) then the FSO can be used.
|
|
|
|
|
|
|
|
\*/
|
|
|
|
(function(){
|
|
|
|
|
|
|
|
/*jslint node: true, browser: true */
|
|
|
|
/*global $tw: false */
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
/*
|
|
|
|
Select the appropriate saver module and set it up
|
|
|
|
*/
|
|
|
|
var FSOSaver = function(wiki) {
|
|
|
|
};
|
|
|
|
|
|
|
|
FSOSaver.prototype.save = function(text,method,callback) {
|
|
|
|
// Get the pathname of this document
|
|
|
|
var pathname = unescape(document.location.pathname);
|
|
|
|
// Test for a Windows path of the form /x:\blah...
|
|
|
|
if(/^\/[A-Z]\:\\[^\\]+/i.test(pathname)) { // ie: ^/[a-z]:/[^/]+
|
|
|
|
// Remove the leading slash
|
|
|
|
pathname = pathname.substr(1);
|
2014-01-03 10:50:00 +00:00
|
|
|
} else if(document.location.hostname !== "" && /^\/\\[^\\]+\\[^\\]+/i.test(pathname)) { // test for \\server\share\blah... - ^/[^/]+/[^/]+
|
2013-12-11 20:45:35 +00:00
|
|
|
// Remove the leading slash
|
|
|
|
pathname = pathname.substr(1);
|
|
|
|
// reconstruct UNC path
|
|
|
|
pathname = "\\\\" + document.location.hostname + pathname;
|
2014-08-27 08:59:01 +00:00
|
|
|
} else {
|
|
|
|
return false;
|
|
|
|
}
|
2013-12-11 20:45:35 +00:00
|
|
|
// Save the file (as UTF-16)
|
|
|
|
var fso = new ActiveXObject("Scripting.FileSystemObject");
|
|
|
|
var file = fso.OpenTextFile(pathname,2,-1,-1);
|
|
|
|
file.Write(text);
|
|
|
|
file.Close();
|
2014-08-27 08:59:01 +00:00
|
|
|
// Callback that we succeeded
|
|
|
|
callback(null);
|
2013-12-11 20:45:35 +00:00
|
|
|
return true;
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Information about this saver
|
|
|
|
*/
|
|
|
|
FSOSaver.prototype.info = {
|
|
|
|
name: "FSOSaver",
|
2014-02-04 21:21:01 +00:00
|
|
|
priority: 120,
|
|
|
|
capabilities: ["save", "autosave"]
|
2013-12-11 20:45:35 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Static method that returns true if this saver is capable of working
|
|
|
|
*/
|
|
|
|
exports.canSave = function(wiki) {
|
|
|
|
try {
|
|
|
|
return (window.location.protocol === "file:") && !!(new ActiveXObject("Scripting.FileSystemObject"));
|
|
|
|
} catch(e) { return false; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/*
|
|
|
|
Create an instance of this saver
|
|
|
|
*/
|
|
|
|
exports.create = function(wiki) {
|
|
|
|
return new FSOSaver(wiki);
|
|
|
|
};
|
|
|
|
|
|
|
|
})();
|