/
saver.js
57 lines (48 loc) · 1.08 KB
/
saver.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
/*\
title: $:/plugins/tiddlywiki/tahoelafs/saver.js
type: application/javascript
module-type: saver
A bare bones saver for Tahoe-LAFS. It just PUTs the new HTML file back to the server at the same URL.
\*/
(function(){
/*jslint node: true, browser: true */
/*global $tw: false */
"use strict";
/*
Select the appropriate saver module and set it up
*/
var TahoeSaver = function(wiki) {
this.wiki = wiki;
};
TahoeSaver.prototype.save = function(text) {
// Do the HTTP post
var http = new XMLHttpRequest();
http.open("PUT",document.location.toString(),true);
http.onreadystatechange = function() {
if(http.readyState == 4 && http.status == 200) {
window.alert("Saved to Tahoe-LAFS: " + http.responseText);
}
};
http.send(text);
return true;
};
/*
Information about this saver
*/
TahoeSaver.prototype.info = {
name: "tahoelafs",
priority: 1000
};
/*
Static method that returns true if this saver is capable of working
*/
exports.canSave = function(wiki) {
return true;
};
/*
Create an instance of this saver
*/
exports.create = function(wiki) {
return new TahoeSaver(wiki);
};
})();