JSFiddle - React, Tailwind, and code Playground
by bluey
HTML
<script src="http://dbushell.github.io/Nestable/jquery.nestable.js"></script>
<h1>Nestable</h1>
<p class="small">Copyright © <a href="http://dbushell.com/">David Bushell</a> | Made for <a href="http://www.browserlondon.com/">Browser</a></p>
<hr/>
<menu id="nestable-menu">
<button type="button" data-action="expand-all">Expand All</button>
<button type="button" data-action="collapse-all">Collapse All</button> ||||
<button type="button" id="add-item">Add Item</button>
</menu>
<div class="cf nestable-lists" style="width:350px; float:left;">
<div class="dd" id="nestable2">
<ol class="dd-list">
<li class="dd-item" data-id="13">
<div class="dd-handle">Item 13</div>
</li>
<li class="dd-item" data-id="14">
<div class="dd-handle">Item 14</div>
</li>
<li class="dd-item" data-id="15">
<div class="dd-handle">Item 15</div>
<ol class="dd-list">
<li class="dd-item" data-id="16"><div class="dd-handle">Item 16</div></li>
<li class="dd-item" data-id="17"><div class="dd-handle">Item 17</div></li>
<li class="dd-item" data-id="18"><div class="dd-handle">Item 18</div></li>
</ol>
</li>
</ol>
</div>
</div>
<p><strong>Serialised Output</strong></p>
<textarea id="nestable2-output"></textarea>
CSS
.cf:after { visibility: hidden; display: block; font-size: 0; content: " "; clear: both; height: 0; }
* html .cf { zoom: 1; }
*:first-child+html .cf { zoom: 1; }
html { margin: 0; padding: 0; }
body { font-size: 100%; margin: 0; padding: 1.75em; font-family: 'Helvetica Neue', Arial, sans-serif; }
h1 { font-size: 1.75em; margin: 0 0 0.6em 0; }
a { color: #2996cc; }
a:hover { text-decoration: none; }
p { line-height: 1.5em; }
.small { color: #666; font-size: 0.875em; }
.large { font-size: 1.25em; }
/**
* Nestable
*/
.dd { position: relative; display: block; margin: 0; padding: 0; max-width: 600px; list-style: none; font-size: 13px; line-height: 20px; }
.dd-list { display: block; position: relative; margin: 0; padding: 0; list-style: none; }
.dd-list .dd-list { padding-left: 30px; }
.dd-collapsed .dd-list { display: none; }
.dd-item,
.dd-empty,
.dd-placeholder { display: block; position: relative; margin: 0; padding: 0; min-height: 20px; font-size: 13px; line-height: 20px; }
.dd-handle { display: block; height: 30px; margin: 5px 0; padding: 5px 10px; color: #333; text-decoration: none; font-weight: bold; border: 1px solid #ccc;
background: #fafafa;
background: -webkit-linear-gradient(top, #fafafa 0%, #eee 100%);
background: -moz-linear-gradient(top, #fafafa 0%, #eee 100%);
background: linear-gradient(top, #fafafa 0%, #eee 100%);
-webkit-border-radius: 3px;
border-radius: 3px;
box-sizing: border-box; -moz-box-sizing: border-box;
}
.dd-handle:hover { color: #2ea8e5; background: #fff; }
.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; }
.dd-item > button:before { content: '+'; display: block; position: absolute; width: 100%; text-align: center; text-indent:...
JavaScript
var totalCount = 18;
var updateOutput = function(e)
{
var list = e.length ? e : $(e.target),
output = list.data('output');
if (window.JSON) {
output.val(window.JSON.stringify(list.nestable('serialize')));//, null, 2));
} else {
output.val('JSON browser support required for this demo.');
}
};
//Creates a new nestable item
$("#add-item").click(function() {
totalCount++;
var html = '<li class="dd-item" data-id="'+totalCount+'"><div class="dd-handle">Item '+totalCount+'</div></li>';
$(html).hide().appendTo("#nestable2 .dd-list:first").fadeIn();
});
// activate Nestable for list 2
$('#nestable2').nestable({
maxDepth : 5
})
.on('change', updateOutput);
// output initial serialised data
updateOutput($('#nestable2').data('output', $('#nestable2-output')));
$('#nestable-menu').on('click', function(e)
{
var target = $(e.target),
action = target.data('action');
if (action === 'expand-all') {
$('.dd').nestable('expandAll');
}
if (action === 'collapse-all') {
$('.dd').nestable('collapseAll');
}
});