<html>
<head>
<meta charset="utf-8">
<title>Sortable: `put: []` demo</title>
<!-- Sortable.js -->
<script src="https://raw.githack.com/SortableJS/Sortable/master/Sortable.js"></script>
</head>
<body>
<div class="list-group nested-sortable">
<button type="button" class=filtered id=add>+</button>
<button type="button" class=filtered id=subtract>-</button>
<div class="list-group-item nested-1">foo 1</div>
<div class="list-group-item nested-1">foo 2</div>
<div class="list-group-item nested-1">foo 3</div>
<div class="list-group nested-sortable">
<div class="list-group-item nested-2">bar 1</div>
<div class="list-group-item nested-2">bar 2</div>
<div class="list-group-item nested-2">bar 3</div>
<div class="list-group nested-sortable">
<div class="list-group-item nested-3">bar 1</div>
<div class="list-group-item nested-3">bar 2</div>
<div class="list-group-item nested-3">bar 3</div>
</div>
</div>
</div>
</body>
</html>
function populate(){
// Nested demo
var nestedSortables = [].slice.call(document.querySelectorAll('.nested-sortable'));
// Loop through each nested sortable element
for (var i = 0; i < nestedSortables.length; i++) {
new Sortable(nestedSortables[i], {
group: 'nested',
animation: 150,
fallbackOnBody: true,
swapThreshold: 0.65,
filter: ".filtered"
});
}
return nestedSortables;
}
let sortables = populate();
additions = document.querySelectorAll(".add")
.forEach(function(add){
add.onclick = function (e) {
let par = e.currentTarget.parentNode;
let div = document.createElement("div");
div.className = "list-group nested-sortable";
let add_button = document.createElement("button");
add_button.className = "filtered add";
add_button.textContent = "+"
div.appendChild(add_button);
let subtract_button = document.createElement("button");
subtract_button.className = "filtered subtract";
subtract_button.textContent = "-"
div.appendChild(subtract_button);
let indiv = document.createElement("div");
indiv.className = "list-group-item nested-2"
indiv.textContent += "This just got added";
div.appendChild(indiv);
par.appendChild(div);
sortables = populate();
};
});
additions = document.querySelectorAll(".subtract")
.forEach(function(subtract){
subtract.onclick = function (e) {
let par = e.currentTarget.parentNode;
let children = par.childNodes
if(children[children.length - 1] == e.currentTarget)
return;
children[children.length - 1].remove();
sortables = populate();
}
});
Output
300px
You can jump to the latest bin by adding /latest
to your URL
Keyboard Shortcuts
Shortcut | Action |
---|---|
ctrl + [num] | Toggle nth panel |
ctrl + 0 | Close focused panel |
ctrl + enter | Re-render output. If console visible: run JS in console |
Ctrl + l | Clear the console |
ctrl + / | Toggle comment on selected lines |
ctrl + ] | Indents selected lines |
ctrl + [ | Unindents selected lines |
tab | Code complete & Emmet expand |
ctrl + shift + L | Beautify code in active panel |
ctrl + s | Save & lock current Bin from further changes |
ctrl + shift + s | Open the share options |
ctrl + y | Archive Bin |
Complete list of JS Bin shortcuts |
JS Bin URLs
URL | Action |
---|---|
/ | Show the full rendered output. This content will update in real time as it's updated from the /edit url. |
/edit | Edit the current bin |
/watch | Follow a Code Casting session |
/embed | Create an embeddable version of the bin |
/latest | Load the very latest bin (/latest goes in place of the revision) |
/[username]/last | View the last edited bin for this user |
/[username]/last/edit | Edit the last edited bin for this user |
/[username]/last/watch | Follow the Code Casting session for the latest bin for this user |
/quiet | Remove analytics and edit button from rendered output |
.js | Load only the JavaScript for a bin |
.css | Load only the CSS for a bin |
Except for username prefixed urls, the url may start with http://jsbin.com/abc and the url fragments can be added to the url to view it differently. |