title: Save Dragable sitemap with jquery to database
body: <p>I have a question, I found a great script that I want to use for my website but I don't know how to save it to my database, the link <a href="http://boagworld.com/technology/creating-a-draggable-sitemap-with-jquery/" rel="nofollow">here</a>, could someone point me to the right direction?
  Thanks</p>
  
  <p>Take a look at the <a href="http://boagworld.com/demos/sitemap/" rel="nofollow">demo</a>. I want to be able to sort the list and then save it to my database.</p>
  
  <p>There is a function history but I just can't figure it out</p>
  
  <pre><code>`var sitemapHistory = {
     stack: new Array(),
     temp: null,
     //takes an element and saves it's position in the sitemap.
     //note: doesn't commit the save until commit() is called!
     //this is because we might decide to cancel the move
     saveState: function(item) {
        sitemapHistory.temp = { item: $(item), itemParent: $(item).parent(), itemAfter:  
        $(item).prev() };
     },
     commit: function() {
     if (sitemapHistory.temp != null) sitemapHistory.stack.push(sitemapHistory.temp);
     },
     //restores the state of the last moved item.
     restoreState: function() {
     var h = sitemapHistory.stack.pop();
     if (h == null) return;
     if (h.itemAfter.length &gt; 0) {
        h.itemAfter.after(h.item);
     }
     else {
        h.itemParent.prepend(h.item);
     }
     //checks the classes on the lists
     $('#sitemap li.sm2_liOpen').not(':has(li)').removeClass('sm2_liOpen');
     $('#sitemap li:has(ul li):not(.sm2_liClosed)').addClass('sm2_liOpen');
     }
  }
  `
  </code></pre>