From db5df84bcc72564c25d676668950214df78490da Mon Sep 17 00:00:00 2001 From: Kevin Kwok Date: Sun, 22 Nov 2009 20:13:06 +0000 Subject: [PATCH] Embed communication protocol updated, embed api file added git-svn-id: http://svg-edit.googlecode.com/svn/trunk@966 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/embedapi.js | 126 +++++++++++++++++++++++++++++++++++++++++++ editor/svg-editor.js | 33 +++++++++++- 2 files changed, 157 insertions(+), 2 deletions(-) create mode 100644 editor/embedapi.js diff --git a/editor/embedapi.js b/editor/embedapi.js new file mode 100644 index 00000000..457b5d97 --- /dev/null +++ b/editor/embedapi.js @@ -0,0 +1,126 @@ +/* +Embedded SVG-edit API + +General usage: +- Have an iframe somewhere pointing to a version of svg-edit > r1000 +- Initialize the magic with: +var svgCanvas = new embedded_svg_edit(window.frames['svgedit']); +- Pass functions in this format: +svgCanvas.setSvgString("string") +- Or if a callback is needed: +svgCanvas.setSvgString("string")(function(data, error){ + if(error){ + //there was an error + }else{ + //handle data + } +}) + +Everything is done with the same API as the real svg-edit, +and all documentation is unchanged. The only difference is +when handling returns, the callback notation is used instead. + +var blah = new embedded_svg_edit(window.frames['svgedit']); +blah.clearSelection("woot","blah",1337,[1,2,3,4,5,"moo"],-42,{a: "tree",b:6, c: 9})(function(){console.log("GET DATA",arguments)}) +*/ + +function embedded_svg_edit(frame){ + //initialize communication + this.frame = frame; + //this.stack = [] //callback stack + this.callbacks = {}; //successor to stack + this.encode = embedded_svg_edit.encode; + //List of functions extracted with this: + //Run in firebug on http://svg-edit.googlecode.com/svn/trunk/docs/files/svgcanvas-js.html + + //for(var i=0,q=[],f = document.querySelectorAll("div.CFunction h3.CTitle a");i