Skip to content

Instantly share code, notes, and snippets.

@Batistleman
Last active August 29, 2015 14:07
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Batistleman/3ebf2bcf6f4baf877ea3 to your computer and use it in GitHub Desktop.
Save Batistleman/3ebf2bcf6f4baf877ea3 to your computer and use it in GitHub Desktop.
<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