From 89416b0ac6f35a7cf2e55384c527fe8f91a37e5c Mon Sep 17 00:00:00 2001 From: Dale Harvey Date: Wed, 9 Jan 2013 23:14:35 +0000 Subject: [PATCH] Add a default autosave canvas to localstorage git-svn-id: http://svg-edit.googlecode.com/svn/trunk@2273 eee81c28-f429-11dd-99c0-75d572ba1ddd --- editor/svg-editor.js | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/editor/svg-editor.js b/editor/svg-editor.js index a96d7ca1..cbe1e3fd 100644 --- a/editor/svg-editor.js +++ b/editor/svg-editor.js @@ -40,6 +40,7 @@ // changed in the UI and are stored in the browser, config can not curConfig = { + canvasName: 'default', canvas_expansion: 3, dimensions: [640,480], initFill: { @@ -254,6 +255,12 @@ } else if(urldata.url) { svgEditor.loadFromURL(urldata.url); } + } else { + var name = 'svgedit-' + Editor.curConfig.canvasName; + var cached = window.localStorage.getItem(name); + if (cached) { + Editor.loadFromString(cached); + } } })(); @@ -4364,6 +4371,13 @@ canv_menu.enableContextMenuItems('#delete,#cut,#copy'); window.onbeforeunload = function() { + + if ('localStorage' in window) { + var name = 'svgedit-' + Editor.curConfig.canvasName; + window.localStorage.setItem(name, svgCanvas.getSvgString()); + Editor.show_save_warning = false; + } + // Suppress warning if page is empty if(undoMgr.getUndoStackSize() === 0) { Editor.show_save_warning = false;