Skip to content

Instantly share code, notes, and snippets.

@Batistleman
Last active Aug 29, 2015
Embed
What would you like to do?
<script src="raphael.savage.js" ></script>
<script type="text/javascript">
$(function() {
// Connect the div to a Savage.Editor instance.
var savageEditor = new Savage.Editor("savage-editor");
// When the get json button is clicked:
$("#savage-editor-get-json").on("click", function(){
var jsonRepresentation = savageEditor.saveToJSON();
// jsonRepresentation will now contain the full svg data of the editor. You could store this in a database.
});
$("#savage-editor-load-json").on("click", function(){
// you can retreive the json description from your database, or write something manually:
var jsonRepresentation = '{"objects":[{"type":"arrow","start":{"x":129,"y":196},"stop":{"x":264,"y":195},"color":"#ee0000"}]}';
// clear the editor if you want
savageEditor.clearEditor();
// load the json into the editor.
savageEditor.loadFromJSON(jsonRepresentation);
});
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment