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-75d572ba1dddmaster
parent
8683c1f14a
commit
6fda1f7d99
|
@ -136,14 +136,54 @@
|
|||
var canvas=null;
|
||||
|
||||
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() {
|
||||
canvas = svg_edit_setup();
|
||||
if (wave && wave.isInWaveContainer()) {
|
||||
wave.setStateCallback(stateUpdated);
|
||||
}
|
||||
|
||||
canvas.bind("changed",sendDelta);
|
||||
}
|
||||
gadgets.util.registerOnLoadHandler(main);
|
||||
|
||||
|
|
Loading…
Reference in New Issue