I'm not so much looking for specific code but rather overall approaches for dealing with the following situation: A user can, by way of click and drag, create a new div wrapped text (lets call it a text node). I want to somehow save the state of the user modified DOM.
Check my JSBin sample to see exactly what I mean.
The code's been extracted from my Ember project but this is what it does:
- The Click to edit area is just an Ember view
- When you drag it to the workspace, Click to edit is cloned and all Ember bindings are lost (which is totally fine)
So after a user adds one or many text nodes to the workspace I end up with something like this:
<div class="workspace">
<div class="text" style="top: 86px; left: 141px;">Text Node 1</div>
<div class="text" style="top: 99px; left: 100px;">Text Node 2</div>
<div class="text" style="top: 10px; left: 44px;">Text Node 3</div>
</div>
tl;dr (get to the **cking question already)
How would I save this information so I can faithfully recreate the users changes on another page?
Some ideas
- On route change, loop through every DOM element with the
.textclass and create an object which store the DOM text and style attributes? I'd then have to create a 'build' type function that loops through the objects and recreates those DOM elements on a given page. - On route change, loop through every DOM element and save each one into an array as a jQuery object. 'Rebuilding' would just be a question of looping each item in the array and appending to the DOM.
In closing, what do you think? Ideas, criticisms & past experiences are very much welcome.