1
0
mirror of https://github.com/Jermolene/TiddlyWiki5 synced 2024-06-16 10:29:54 +00:00

Add preliminary Dat file saver

See https://datproject.org/ and https://beakerbrowser.com/
This commit is contained in:
Jermolene 2016-12-21 12:09:04 +00:00
parent daad0ec142
commit a20da9f530

View File

@ -0,0 +1,55 @@
/*\
title: $:/core/modules/savers/dat.js
type: application/javascript
module-type: saver
Saves wiki using the Dat protocol (https://datproject.org/)
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Select the appropriate saver module and set it up
*/
var DatSaver = function(wiki) {
this.wiki = wiki;
};
DatSaver.prototype.save = function(text,method,callback) {
console.log("Saving Dat")
dat.writeFile(document.location.protocol + "//" + document.location.hostname + ":" + document.location.port + document.location.pathname,text,"utf8").then(function(value) {
callback(null);
},function(reason) {
callback("Dat Saver Error: " + reason);
});
return true;
};
/*
Information about this saver
*/
DatSaver.prototype.info = {
name: "dat",
priority: 3000,
capabilities: ["save", "autosave"]
};
/*
Static method that returns true if this saver is capable of working
*/
exports.canSave = function(wiki) {
return !!window.dat;
};
/*
Create an instance of this saver
*/
exports.create = function(wiki) {
return new DatSaver(wiki);
};
})();