In the example you provided, the jQuery plugin used is Nestable from dbushell. Do you have any control over the plugin you'll end up using ? The project is completely dead and has not been updated for 2 years.
It could be wise to maybe check for a solution still maintained and proposing your feature which is pretty much a 'protectRoot' feature that many libraries have nowadays.
If you have no control over the plugin, this feature at the moment is not implemented and will probably never be.
If you have control over the plugin but still want to use this one, a solution could be to use a fork (there are many since the project is dead) still maintained and having this feature.
Another solution would be to cherry pick yourself code you're interested in from the many pull requests submitted to the project but that will never be merged.
For example, this pull request add new callbacks instead of the only one available at the moment: beforeDragStart
, dragStart
, dragMove
, beforeDragEnd
, dragEnd
, etc. These new callbacks provides many arguments like the item you're currently moving, where it was before you started dragging it, and the destination. Based on these new informations and especially the destination, you could cancel the drag if the destination a root node.
$('.dd').nestable({})
.on('dragMove', function(event, item, source, destination) {
// item: item we're moving.
// source: original source of the item.
// destination: new position of the item.
});
Another pull request that could suits your needs is this one. It provides callback to reject specific drag event, you could for example reject a drag event if the item being dragged becomes a root element.
$('.dd').nestable({
reject: [
{
rule: function() {
// $(this) refers to the dragged element.
// Return TRUE to cancel the drag action.
return $(this).parent().hasClass("rootList");
}
}
]
});