jQuery Tabs "changes to save"

jQuery Tabs "changes to save"

With the Jquery tabs is there a way to save the changes made on a per user basis. I would also like to use the lists inside the tabs with the lists holding data retrieved from MySQL. What would the best way to go about this be. Unfortunately I am just a nooblet cutting and pasting code to get things to somewhat work.  

Thank you in advance
Steve

Here's a copy of the code I have used so far
  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Tabs - Simple manipulation</title>
  6. <link rel="stylesheet" href="../../themes/base/jquery.ui.all.css">
  7. <script src="../../jquery-1.8.3.js"></script>
  8. <script src="../../ui/jquery.ui.position.js"></script>
  9. <script src="../../ui/jquery.ui.core.js"></script>
  10. <script src="../../ui/jquery.ui.widget.js"></script>
  11. <script src="../../ui/jquery.ui.mouse.js"></script>
  12. <script src="../../ui/jquery.ui.sortable.js"></script>
  13. <script src="../../ui/jquery.ui.button.js"></script>
  14. <script src="../../ui/jquery.ui.tabs.js"></script>
  15. <script src="../../ui/jquery.ui.dialog.js"></script>
  16. <script src="../../ui/jquery.ui.droppable.js"></script>
  17. <link rel="stylesheet" href="../demos.css">
  18. <style>
  19. #dialog label, #dialog input { display:block; }
  20. #dialog label { margin-top: 0.5em; }
  21. #dialog input, #dialog textarea { width: 95%; }
  22. #tabs { margin-top: 1em; }
  23. #tabs li .ui-icon-close { float: left; margin: 0.4em 0.2em 0 0; cursor: pointer; }
  24. #add_tab { cursor: pointer; }
  25. #sortable1 li, #sortable2 li { margin: 0 5px 5px 5px; padding: 5px; font-size: 1.2em; width: 120px; }
  26. </style>
  27. <script>
  28. $(function() {
  29. $( "#sortable1, #sortable2" ).sortable().disableSelection();

  30. var $tabs = $( "#tabs" ).tabs();

  31. var $tab_items = $( "ul:first li", $tabs ).droppable({
  32. accept: ".connectedSortable li",
  33. hoverClass: "ui-state-hover",
  34. drop: function( event, ui ) {
  35. var $item = $( this );
  36. var $list = $( $item.find( "a" ).attr( "href" ) )
  37. .find( ".connectedSortable" );

  38. ui.draggable.hide( "slow", function() {
  39. $tabs.tabs( "select", $tab_items.index( $item ) );
  40. $( this ).appendTo( $list ).show( "slow" );
  41. });
  42. }
  43. });
  44. });
  45. </script>
  46. <script>
  47. $(function() {
  48. var tabTitle = $( "#tab_title" ),
  49. tabContent = $( "#tab_content" ),
  50. tabTemplate = "<li><a href='#{href}'>#{label}</a> <span class='ui-icon ui-icon-close'>Remove Tab</span></li>",
  51. tabCounter = 2;

  52. var tabs = $( "#tabs" ).tabs();

  53. // modal dialog init: custom buttons and a "close" callback reseting the form inside
  54. var dialog = $( "#dialog" ).dialog({
  55. autoOpen: false,
  56. modal: true,
  57. buttons: {
  58. Add: function() {
  59. addTab();
  60. $( this ).dialog( "close" );
  61. },
  62. Cancel: function() {
  63. $( this ).dialog( "close" );
  64. }
  65. },
  66. close: function() {
  67. form[ 0 ].reset();
  68. }
  69. });

  70. // addTab form: calls addTab function on submit and closes the dialog
  71. var form = dialog.find( "form" ).submit(function( event ) {
  72. addTab();
  73. dialog.dialog( "close" );
  74. event.preventDefault();
  75. });

  76. // actual addTab function: adds new tab using the input from the form above
  77. function addTab() {
  78. var label = tabTitle.val() || "Tab " + tabCounter,
  79. id = "tabs-" + tabCounter,
  80. li = $( tabTemplate.replace( /#\{href\}/g, "#" + id ).replace( /#\{label\}/g, label ) ),
  81. tabContentHtml = tabContent.val() || "Tab " + tabCounter;

  82. tabs.find( ".ui-tabs-nav" ).append( li );
  83. tabs.append( "<div id='" + id + "'></div>" );
  84. tabs.tabs( "refresh" );
  85. tabCounter++;
  86. }

  87. // addTab button: just opens the dialog
  88. $( "#add_tab" )
  89. .button()
  90. .click(function() {
  91. dialog.dialog( "open" );
  92. });

  93. // close icon: removing the tab on click
  94. $( "#tabs span.ui-icon-close" ).live( "click", function() {
  95. var panelId = $( this ).closest( "li" ).remove().attr( "aria-controls" );
  96. $( "#" + panelId ).remove();
  97. tabs.tabs( "refresh" );
  98. });
  99. });
  100. </script>
  101. <script>
  102. $(function() {
  103. var tabs = $( "#tabs" ).tabs();
  104. tabs.find( ".ui-tabs-nav" ).sortable({
  105. axis: "x",
  106. stop: function() {
  107. tabs.tabs( "refresh" );
  108. }
  109. });
  110. });
  111. </script>
  112. </head>
  113. <body>
  114. <div id="main_container">
  115. <div id="dialog" title="Tab data">
  116. <form>
  117. <fieldset class="ui-helper-reset">
  118. <label for="tab_title">Title</label>
  119. <input type="text" name="tab_title" id="tab_title" value="" class="ui-widget-content ui-corner-all" />
  120. </fieldset>
  121. </form>
  122. </div>

  123. <button id="add_tab">Add Tab</button>

  124. <div id="tabs">
  125. <ul>
  126. <li><a href="#tabs-1">Main</a></li>
  127. <li><a href="#tabs-2">Tab 2</a></li>
  128. <!--<li><a href="#tabs-3">Tab 3</a></li>  // Additional tabs added to the main-->
  129. </ul>
  130. <div id="tabs-1">
  131. <p>Test information.</p>
  132. </div>
  133. <div id="tabs-2">
  134. <ul id="sortable2" class="connectedSortable ui-helper-reset">
  135. <li class="ui-state-highlight">Item 1</li>
  136. <li class="ui-state-highlight">Item 2</li>
  137. <li class="ui-state-highlight">Item 3</li>
  138. <li class="ui-state-highlight">Item 4</li>
  139. <li class="ui-state-highlight">Item 5</li>
  140. </ul>
  141. </div>
  142. </div>
  143. </div>
  144. </body>
  145. </html>