Is there a way to have not only position of object remembered, but if it has been rotated?

Is there a way to have not only position of object remembered, but if it has been rotated?

Is there a way to make it remember rotation as well as location? 



  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title></title>
  6. <style>
  7. #draggable, #draggable2 {cursor:move; }

  8. #containment-wrapper {
  9.     width: 1500px;
  10.     height: 2000px;
  11. border: 2px solid #ccc;}
  12. .zoomTarget {
  13.  width: 1000px;
  14.       height: 500px;
  15.       border: 2px solid #ccc;
  16. }

  17.  .object {
  18. float: right;
  19.     -webkit-transition-duration: .3s;
  20.     -moz-transition-duration: .3s;
  21.     -o-transition-duration: .3s;
  22.     transition-duration: .3s;
  23.     -webkit-transition-property: -webkit-transform;
  24.     -moz-transition-property: -moz-transform;
  25.     -o-transition-property: -o-transform;
  26.     transition-property: transform;

  27. }
  28.   .team01 {background-color:orange; }
  29.   .team02 {background-color:red; } 
  30.   .team03 {background-color:blue;} 
  31.  
  32. body {font-family: sans-serif;}
  33. p {background-color:rgba(255,255,255,0.6); color:black;font-size:small;}
  34.  .instructions p {font-size:medium;}
  35. .instructions {width:700px;} 
  36. </style>


  37. </head>

  38. <script src="https://code.jquery.com/jquery-2.2.4.min.js"></script>
  39. <script src="https://cdnjs.cloudflare.com/ajax/libs/jqueryui/1.11.4/jquery-ui.min.js"></script>
  40. <script src="https://rawgit.com/godswearhats/jquery-ui-rotatable/master/jquery.ui.rotatable.min.js"></script>



  41. <script>
  42. var positions = JSON.parse(localStorage.positions || "{}");
  43. $(function () {
  44.     var d = $("[id=draggable]").attr("id", function (i) {
  45.         return "draggable_" + i
  46.     })
  47.     $.each(positions, function (id, pos) {
  48.         $("#" + id).css(pos)
  49.     })
  50.     d.draggable({
  51.         containment: "#containment-wrapper",
  52.         scroll: false,
  53.         stop: function (event, ui) {
  54.             positions[this.id] = ui.position
  55.             localStorage.positions = JSON.stringify(positions)
  56.         }
  57.     });
  58. });
  59. </script>


  60. <body>


  61. <div class="instructions">
  62. <p><strong>ZOOM Controls: </strong>Click on a Suite area to Zoom in, click again (other than on a "movable item") to zoom out. 
  63. Mouse out of area and view will pan (auto-scroll).</p>
  64. <p><strong>Movable Item: </strong>Click/Drag on an item to move it. Click on it to rotate 90. </p>
  65. <p><strong>Rememberted Positions: </strong>It will remember the location of the items. 
  66. It stores this info with cookies, and will not be transfered with links to the page to another computer or to another browser. 
  67. It currently does not remember if an item has been rotated or not.</p>
  68. </div>

  69. <div id="containment-wrapper">

  70. <div class="page-body">
  71. <div style="width: 1000px; height: 500px; background-color: lightgray;">Suite 01</div>
  72. <div style="width: 1000px; height: 500px;  background-color: lightblue;">Suite 02</div>
  73. <div style="width: 1000px; height: 500px; background-color: lightgray;">Suite 03</div>
  74. </div>


  75. <div id="draggable" class="object team01" style="width: 200px; height: 300px;"><p>box 01</p></div>
  76. <div id="draggable" class="object team02" style="width: 400px; height: 200px;"><p>box 02</p></div>
  77. <div id="draggable" class="object team03" style="width: 250px; height: 200px;"><p>box 03</p></div>
  78. <div id="draggable" class="object team03" style="width: 350px; height: 150px;"><p>box 04</p></div>


  79. </div>





  80. <script>
  81. $(".object").draggable();
  82. $(".object").click(function() {
  83.     //alert($( this ).css( "transform" ));
  84.     if (  $( this ).css( "transform" ) == 'none' ){
  85.         $(this).css("transform","rotate(90deg)");
  86.     } else {
  87.         $(this).css("transform","" );
  88.     }
  89. });
  90. </script>

  91. <script src="js/zoom.js"></script>
  92. <script>
  93. document.querySelector( '.page-body' ).addEventListener( 'click', function( event ) {
  94. event.preventDefault();
  95. zoom.to({ element: event.target });
  96. } );
  97. </script>


  98. </body>
  99. </html>

I have tried various ways, but I can't seem to get it.

  1. <script>
  2. var positions = JSON.parse(localStorage.positions || "[{"position"}, {"transform"}]");

  3. $(function () {
  4.     var d = $("[id=draggable]").attr("id", function (i) {
  5.         return "draggable_" + i
  6.     })
  7.     $.each(positions, function (id, pos) {
  8.         $("#" + id).css(pos)
  9.     })
  10.     d.draggable({
  11.         containment: "#containment-wrapper",
  12.         scroll: false,
  13.         stop: function (event, ui) {
  14.             positions[this.id] = ui.position, ui.transform
  15.             localStorage.positions = JSON.stringify(positions)
  16.         }
  17.     });
  18. });
  19. </script>
I've been working on this for days, please help if you can. 

Thank you in advance.


I've gotten this far by using information here  https://forum.jquery.com/topic/save-position-of-draggable-item
Save position of draggable item. @ jakecigar helped for that post