State send/update adapted from my earlier version - not completely working yet, but mostly there

git-svn-id: http://svg-edit.googlecode.com/svn/trunk@81 eee81c28-f429-11dd-99c0-75d572ba1ddd
master
Vidar Hokstad 2009-06-09 22:19:52 +00:00
parent 8683c1f14a
commit 6fda1f7d99
1 changed files with 41 additions and 1 deletions

View File

@ -136,14 +136,54 @@
var canvas=null; var canvas=null;
function stateUpdated() { function stateUpdated() {
canvas.updateState(wave.getState()); var state = wave.getState();
var keys = state.getKeys();
document.canvas.each(function(e) {
if (e) {
var ob;
var v = state.get(e.nodeId);
eval("ob="+v); // FIXME: Yes, I'm using eval... Dirty, dirty..
if (ob) canvas.updateElementFromJson(data)
else {
var node = svgdoc.getElementById(k);
if (node) node.parentNode.removeChild(node);
}
keys.remove(e.nodeId);
} else {
e.parent().remove(e);
}
});
// New nodes
for (var k in keys) {
var ob;
var v = state.get(e.nodeId);
eval("ob="+v); // FIXME: Yes, I'm using eval... Dirty, dirty..
if (ob) canvas.updateElementFromJson(data)
}
} }
function sendDelta(canvas, elem) {
if (wave) return;
var delta = {};
var attrs = {};
var a = elem.attributes;
for (var i = 0; i < a.length; i++) {
attrs[a.item(i).nodeName] = a.item(i).nodeValue;
};
var ob = { element: elem.nodeName,
attr: attrs };
delta[elem.id] = wave.util.printJson(ob,false);
wave.getState().submitDelta(delta);
}
function main() { function main() {
canvas = svg_edit_setup(); canvas = svg_edit_setup();
if (wave && wave.isInWaveContainer()) { if (wave && wave.isInWaveContainer()) {
wave.setStateCallback(stateUpdated); wave.setStateCallback(stateUpdated);
} }
canvas.bind("changed",sendDelta);
} }
gadgets.util.registerOnLoadHandler(main); gadgets.util.registerOnLoadHandler(main);