TiddlyWiki5/js/HttpSync.js
Jeremy Ruston 0ac55688c4 Browser now syncs changes with server which syncs with the file system
A bit rough and ready, but this gives us basic support for editting
tiddlers in the browser and updating the original file on the server
2012-04-05 12:21:49 +01:00

35 lines
770 B
JavaScript

/*\
title: js/HttpSync.js
\*/
(function(){
/*jslint node: true */
"use strict";
function HttpSync(store) {
this.store = store;
this.changeCounts = {};
store.addEventListener("",function(changes) {
for(var title in changes) {
var tiddler = store.getTiddler(title);
if(tiddler) {
var fieldStrings = tiddler.getFieldStrings(),
fields = {},
t;
for(t=0; t<fieldStrings.length; t++) {
fields[fieldStrings[t].name] = fieldStrings[t].value;
}
fields.text = tiddler.text;
var x = new XMLHttpRequest();
x.open("PUT",window.location.toString() + encodeURIComponent(title),true);
x.setRequestHeader("Content-type", "application/json");
x.send(JSON.stringify(fields));
}
}
});
}
exports.HttpSync = HttpSync;
})();