mirror of
https://github.com/Jermolene/TiddlyWiki5.git
synced 2026-01-08 10:12:37 -08:00
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
35 lines
770 B
JavaScript
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;
|
|
|
|
})();
|