index.html 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305
  1. <!DOCTYPE html>
  2. <!--[if lt IE 7]> <html lang="en" class="lt-ie9 lt-ie8 lt-ie7"> <![endif]-->
  3. <!--[if IE 7]> <html lang="en" class="lt-ie9 lt-ie8"> <![endif]-->
  4. <!--[if IE 8]> <html lang="en" class="lt-ie9"> <![endif]-->
  5. <!--[if IE 9]> <html lang="en" class="ie9"> <![endif]-->
  6. <!--[if gt IE 9]><!--> <html lang="en"> <!--<![endif]-->
  7. <head>
  8. <meta charset="utf-8">
  9. <meta name="viewport" content="width=device-width, initial-scale=1, minimum-scale=1">
  10. <title>Nestable</title>
  11. <style type="text/css">
  12. .cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
  13. * html .cf { zoom: 1; }
  14. *:first-child+html .cf { zoom: 1; }
  15. html { margin: 0; padding: 0; }
  16. body { font-size: 100%; margin: 0; padding: 1.75em; font-family: 'Helvetica Neue', Arial, sans-serif; }
  17. h1 { font-size: 1.75em; margin: 0 0 0.6em 0; }
  18. a { color: #2996cc; }
  19. a:hover { text-decoration: none; }
  20. p { line-height: 1.5em; }
  21. .small { color: #666; font-size: 0.875em; }
  22. .large { font-size: 1.25em; }
  23. /**
  24. * Nestable
  25. */
  26. .dd { position: relative; display: block; margin: 0; padding: 0; max-width: 600px; list-style: none; font-size: 13px; line-height: 20px; }
  27. .dd-list { display: block; position: relative; margin: 0; padding: 0; list-style: none; }
  28. .dd-list .dd-list { padding-left: 30px; }
  29. .dd-collapsed .dd-list { display: none; }
  30. .dd-item,
  31. .dd-empty,
  32. .dd-placeholder { display: block; position: relative; margin: 0; padding: 0; min-height: 20px; font-size: 13px; line-height: 20px; }
  33. .dd-handle { display: block; height: 30px; margin: 5px 0; padding: 5px 10px; color: #333; text-decoration: none; font-weight: bold; border: 1px solid #ccc;
  34. background: #fafafa;
  35. background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  36. background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  37. background: linear-gradient(top, #fafafa 0%, #eee 100%);
  38. -webkit-border-radius: 3px;
  39. border-radius: 3px;
  40. box-sizing: border-box; -moz-box-sizing: border-box;
  41. }
  42. .dd-handle:hover { color: #2ea8e5; background: #fff; }
  43. .dd-item > button { display: block; position: relative; cursor: pointer; float: left; width: 25px; height: 20px; margin: 5px 0; padding: 0; text-indent: 100%; white-space: nowrap; overflow: hidden; border: 0; background: transparent; font-size: 12px; line-height: 1; text-align: center; font-weight: bold; }
  44. .dd-item > button:before { content: '+'; display: block; position: absolute; width: 100%; text-align: center; text-indent: 0; }
  45. .dd-item > button[data-action="collapse"]:before { content: '-'; }
  46. .dd-placeholder,
  47. .dd-empty { margin: 5px 0; padding: 0; min-height: 30px; background: #f2fbff; border: 1px dashed #b6bcbf; box-sizing: border-box; -moz-box-sizing: border-box; }
  48. .dd-empty { border: 1px dashed #bbb; min-height: 100px; background-color: #e5e5e5;
  49. background-image: -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  50. -webkit-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  51. background-image: -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  52. -moz-linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  53. background-image: linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff),
  54. linear-gradient(45deg, #fff 25%, transparent 25%, transparent 75%, #fff 75%, #fff);
  55. background-size: 60px 60px;
  56. background-position: 0 0, 30px 30px;
  57. }
  58. .dd-dragel { position: absolute; pointer-events: none; z-index: 9999; }
  59. .dd-dragel > .dd-item .dd-handle { margin-top: 0; }
  60. .dd-dragel .dd-handle {
  61. -webkit-box-shadow: 2px 4px 6px 0 rgba(0,0,0,.1);
  62. box-shadow: 2px 4px 6px 0 rgba(0,0,0,.1);
  63. }
  64. /**
  65. * Nestable Extras
  66. */
  67. .nestable-lists { display: block; clear: both; padding: 30px 0; width: 100%; border: 0; border-top: 2px solid #ddd; border-bottom: 2px solid #ddd; }
  68. #nestable-menu { padding: 0; margin: 20px 0; }
  69. #nestable-output,
  70. #nestable2-output { width: 100%; height: 7em; font-size: 0.75em; line-height: 1.333333em; font-family: Consolas, monospace; padding: 5px; box-sizing: border-box; -moz-box-sizing: border-box; }
  71. #nestable2 .dd-handle {
  72. color: #fff;
  73. border: 1px solid #999;
  74. background: #bbb;
  75. background: -webkit-linear-gradient(top, #bbb 0%, #999 100%);
  76. background: -moz-linear-gradient(top, #bbb 0%, #999 100%);
  77. background: linear-gradient(top, #bbb 0%, #999 100%);
  78. }
  79. #nestable2 .dd-handle:hover { background: #bbb; }
  80. #nestable2 .dd-item > button:before { color: #fff; }
  81. @media only screen and (min-width: 700px) {
  82. .dd { float: left; width: 48%; }
  83. .dd + .dd { margin-left: 2%; }
  84. }
  85. .dd-hover > .dd-handle { background: #2ea8e5 !important; }
  86. /**
  87. * Nestable Draggable Handles
  88. */
  89. .dd3-content { display: block; height: 30px; margin: 5px 0; padding: 5px 10px 5px 40px; color: #333; text-decoration: none; font-weight: bold; border: 1px solid #ccc;
  90. background: #fafafa;
  91. background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
  92. background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
  93. background: linear-gradient(top, #fafafa 0%, #eee 100%);
  94. -webkit-border-radius: 3px;
  95. border-radius: 3px;
  96. box-sizing: border-box; -moz-box-sizing: border-box;
  97. }
  98. .dd3-content:hover { color: #2ea8e5; background: #fff; }
  99. .dd-dragel > .dd3-item > .dd3-content { margin: 0; }
  100. .dd3-item > button { margin-left: 30px; }
  101. .dd3-handle { position: absolute; margin: 0; left: 0; top: 0; cursor: pointer; width: 30px; text-indent: 100%; white-space: nowrap; overflow: hidden;
  102. border: 1px solid #aaa;
  103. background: #ddd;
  104. background: -webkit-linear-gradient(top, #ddd 0%, #bbb 100%);
  105. background: -moz-linear-gradient(top, #ddd 0%, #bbb 100%);
  106. background: linear-gradient(top, #ddd 0%, #bbb 100%);
  107. border-top-right-radius: 0;
  108. border-bottom-right-radius: 0;
  109. }
  110. .dd3-handle:before { content: '≡'; display: block; position: absolute; left: 0; top: 3px; width: 100%; text-align: center; text-indent: 0; color: #fff; font-size: 20px; font-weight: normal; }
  111. .dd3-handle:hover { background: #ddd; }
  112. </style>
  113. </head>
  114. <body>
  115. <h1>Nestable</h1>
  116. <p>Drag &amp; drop hierarchical list with mouse and touch compatibility (jQuery plugin)</p>
  117. <p><strong><a href="https://github.com/dbushell/Nestable">Code on GitHub</a></strong></p>
  118. <p><strong>PLEASE NOTE: I cannot provide any support or guidance beyond this README. If this code helps you that's great but I have no plans to develop Nestable beyond this demo (it's not a final product and has limited functionality). I cannot reply to any requests for help.</strong></p>
  119. <menu id="nestable-menu">
  120. <button type="button" data-action="expand-all">Expand All</button>
  121. <button type="button" data-action="collapse-all">Collapse All</button>
  122. </menu>
  123. <div class="cf nestable-lists">
  124. <div class="dd" id="nestable">
  125. <ol class="dd-list">
  126. <li class="dd-item" data-id="1">
  127. <div class="dd-handle">Item 1</div>
  128. </li>
  129. <li class="dd-item" data-id="2">
  130. <div class="dd-handle">Item 2</div>
  131. <ol class="dd-list">
  132. <li class="dd-item" data-id="3"><div class="dd-handle">Item 3</div></li>
  133. <li class="dd-item" data-id="4"><div class="dd-handle">Item 4</div></li>
  134. <li class="dd-item" data-id="5">
  135. <div class="dd-handle">Item 5</div>
  136. <ol class="dd-list">
  137. <li class="dd-item" data-id="6"><div class="dd-handle">Item 6</div></li>
  138. <li class="dd-item" data-id="7"><div class="dd-handle">Item 7</div></li>
  139. <li class="dd-item" data-id="8"><div class="dd-handle">Item 8</div></li>
  140. </ol>
  141. </li>
  142. <li class="dd-item" data-id="9"><div class="dd-handle">Item 9</div></li>
  143. <li class="dd-item" data-id="10"><div class="dd-handle">Item 10</div></li>
  144. </ol>
  145. </li>
  146. <li class="dd-item" data-id="11">
  147. <div class="dd-handle">Item 11</div>
  148. </li>
  149. <li class="dd-item" data-id="12">
  150. <div class="dd-handle">Item 12</div>
  151. </li>
  152. </ol>
  153. </div>
  154. <div class="dd" id="nestable2">
  155. <ol class="dd-list">
  156. <li class="dd-item" data-id="13">
  157. <div class="dd-handle">Item 13</div>
  158. </li>
  159. <li class="dd-item" data-id="14">
  160. <div class="dd-handle">Item 14</div>
  161. </li>
  162. <li class="dd-item" data-id="15">
  163. <div class="dd-handle">Item 15</div>
  164. <ol class="dd-list">
  165. <li class="dd-item" data-id="16"><div class="dd-handle">Item 16</div></li>
  166. <li class="dd-item" data-id="17"><div class="dd-handle">Item 17</div></li>
  167. <li class="dd-item" data-id="18"><div class="dd-handle">Item 18</div></li>
  168. </ol>
  169. </li>
  170. </ol>
  171. </div>
  172. </div>
  173. <p><strong>Serialised Output (per list)</strong></p>
  174. <textarea id="nestable-output"></textarea>
  175. <textarea id="nestable2-output"></textarea>
  176. <p>&nbsp;</p>
  177. <div class="cf nestable-lists">
  178. <p><strong>Draggable Handles</strong></p>
  179. <p>If you're clever with your CSS and markup this can be achieved without any JavaScript changes.</p>
  180. <div class="dd" id="nestable3">
  181. <ol class="dd-list">
  182. <li class="dd-item dd3-item" data-id="13">
  183. <div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">Item 13</div>
  184. </li>
  185. <li class="dd-item dd3-item" data-id="14">
  186. <div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">Item 14</div>
  187. </li>
  188. <li class="dd-item dd3-item" data-id="15">
  189. <div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">Item 15</div>
  190. <ol class="dd-list">
  191. <li class="dd-item dd3-item" data-id="16">
  192. <div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">Item 16</div>
  193. </li>
  194. <li class="dd-item dd3-item" data-id="17">
  195. <div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">Item 17</div>
  196. </li>
  197. <li class="dd-item dd3-item" data-id="18">
  198. <div class="dd-handle dd3-handle">Drag</div><div class="dd3-content">Item 18</div>
  199. </li>
  200. </ol>
  201. </li>
  202. </ol>
  203. </div>
  204. </div>
  205. <p class="small">Copyright &copy; <a href="http://dbushell.com/">David Bushell</a> | Made for <a href="http://www.browserlondon.com/">Browser</a></p>
  206. <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
  207. <script src="jquery.nestable.js"></script>
  208. <script>
  209. $(document).ready(function()
  210. {
  211. var updateOutput = function(e)
  212. {
  213. var list = e.length ? e : $(e.target),
  214. output = list.data('output');
  215. if (window.JSON) {
  216. output.val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
  217. } else {
  218. output.val('JSON browser support required for this demo.');
  219. }
  220. };
  221. // activate Nestable for list 1
  222. $('#nestable').nestable({
  223. group: 1
  224. })
  225. .on('change', updateOutput);
  226. // activate Nestable for list 2
  227. $('#nestable2').nestable({
  228. group: 1
  229. })
  230. .on('change', updateOutput);
  231. // output initial serialised data
  232. updateOutput($('#nestable').data('output', $('#nestable-output')));
  233. updateOutput($('#nestable2').data('output', $('#nestable2-output')));
  234. $('#nestable-menu').on('click', function(e)
  235. {
  236. var target = $(e.target),
  237. action = target.data('action');
  238. if (action === 'expand-all') {
  239. $('.dd').nestable('expandAll');
  240. }
  241. if (action === 'collapse-all') {
  242. $('.dd').nestable('collapseAll');
  243. }
  244. });
  245. $('#nestable3').nestable();
  246. });
  247. </script>
  248. </body>
  249. </html>