Sortable - Enable portlets (styled divs) as sortables and use the connectWith option to allow sorting between columns.


SUBMITTED BY: jlolk3r

DATE: Jan. 19, 2016, 6:31 a.m.

FORMAT: HTML

SIZE: 2.8 kB

HITS: 1175

  1. <!doctype html>
  2. <html lang="en">
  3. <head>
  4. <meta charset="utf-8">
  5. <title>jQuery UI Sortable - Portlets</title>
  6. <link rel="stylesheet" href="//code.jquery.com/ui/1.11.4/themes/smoothness/jquery-ui.css">
  7. <script src="//code.jquery.com/jquery-1.10.2.js"></script>
  8. <script src="//code.jquery.com/ui/1.11.4/jquery-ui.js"></script>
  9. <link rel="stylesheet" href="/resources/demos/style.css">
  10. <style>
  11. body {
  12. min-width: 520px;
  13. }
  14. .column {
  15. width: 170px;
  16. float: left;
  17. padding-bottom: 100px;
  18. }
  19. .portlet {
  20. margin: 0 1em 1em 0;
  21. padding: 0.3em;
  22. }
  23. .portlet-header {
  24. padding: 0.2em 0.3em;
  25. margin-bottom: 0.5em;
  26. position: relative;
  27. }
  28. .portlet-toggle {
  29. position: absolute;
  30. top: 50%;
  31. right: 0;
  32. margin-top: -8px;
  33. }
  34. .portlet-content {
  35. padding: 0.4em;
  36. }
  37. .portlet-placeholder {
  38. border: 1px dotted black;
  39. margin: 0 1em 1em 0;
  40. height: 50px;
  41. }
  42. </style>
  43. <script>
  44. $(function() {
  45. $( ".column" ).sortable({
  46. connectWith: ".column",
  47. handle: ".portlet-header",
  48. cancel: ".portlet-toggle",
  49. placeholder: "portlet-placeholder ui-corner-all"
  50. });
  51. $( ".portlet" )
  52. .addClass( "ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" )
  53. .find( ".portlet-header" )
  54. .addClass( "ui-widget-header ui-corner-all" )
  55. .prepend( "<span class='ui-icon ui-icon-minusthick portlet-toggle'></span>");
  56. $( ".portlet-toggle" ).click(function() {
  57. var icon = $( this );
  58. icon.toggleClass( "ui-icon-minusthick ui-icon-plusthick" );
  59. icon.closest( ".portlet" ).find( ".portlet-content" ).toggle();
  60. });
  61. });
  62. </script>
  63. </head>
  64. <body>
  65. <div class="column">
  66. <div class="portlet">
  67. <div class="portlet-header">Feeds</div>
  68. <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
  69. </div>
  70. <div class="portlet">
  71. <div class="portlet-header">News</div>
  72. <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
  73. </div>
  74. </div>
  75. <div class="column">
  76. <div class="portlet">
  77. <div class="portlet-header">Shopping</div>
  78. <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
  79. </div>
  80. </div>
  81. <div class="column">
  82. <div class="portlet">
  83. <div class="portlet-header">Links</div>
  84. <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
  85. </div>
  86. <div class="portlet">
  87. <div class="portlet-header">Images</div>
  88. <div class="portlet-content">Lorem ipsum dolor sit amet, consectetuer adipiscing elit</div>
  89. </div>
  90. </div>
  91. </body>
  92. </html>

comments powered by Disqus