toolness / p5.js-widget

A reusable widget for embedding editable p5 sketches in web pages.
https://toolness.github.io/p5.js-widget/
GNU Lesser General Public License v2.1
162 stars 44 forks source link

Implement autosave w/ sessionStorage. #41

Closed toolness closed 8 years ago

toolness commented 8 years ago

This fixes #40 by storing the current code (whenever it changes) in sessionStorage and bringing it back on re-instantiation. The new code is added to the CodeMirror widget's history stack to make undo/revert easy.

Also, this change requires each widget on a page to have a unique identifier, so that each widget can have its own unique sessionStorage key. This identifier is created by combining the document.referrer of the widget (i.e., the URL of the embedding page) with a number based on the position of the widget in the embedding page's DOM.