Created
August 25, 2011 02:30
-
-
Save cgack/1169831 to your computer and use it in GitHub Desktop.
store history and local storage ex
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// store the canvas image and push to local storage | |
var storeHistory = function () { | |
img = canvas.toDataURL("image/png"); | |
history.pushState({ imageData: img }, "", window.location.href); | |
if (window.localStorage) { localStorage.curImg = img; } | |
}; | |
//retrieve local storage | |
if (window.localStorage) { | |
var img = new Image(); | |
$(img).load(function () { | |
canvas.getContext("2d").drawImage(img, 0, 0); | |
}); | |
if (localStorage.curImg) { | |
img.src = localStorage.curImg; | |
} | |
} | |
//do history moves | |
var undo = function () { | |
window.history.back(); | |
}; | |
var redo = function () { | |
window.history.forward(); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment