javascriptnestedmootoolssubmenunested-sortable

How to limit NestedSortables sublevels?


I use http://mootools.net/forge/p/nestedsortables to sort a list of li elements, now it can sort them to unlimited sublevels. I need to limit it to only one sublevel.

https://jsfiddle.net/dq3xqvu9/

new NestedSortables('menu', {
  onStart: function(el) {  },
  onComplete: function(el) {  }
});

Good - I want to be able to move them to only one sublevel:

NOT Good - by default NestedSortables allows you to move the items to unlimited sublevels like:


Solution

  • I added these three restrictions to NestedSortables Class:

      abort += (this.getDepth(dest, (move == 'inside')) > 1);
      abort += ((move == 'inside') && (el.getFirst('ul') != null));
      abort += ((move != 'inside') && (el.getFirst('ul') != null) && (this.getDepth(dest, (move == 'inside')) > 0));
    

    Complete code on updated JSFiddle.

    This modification limits the number of sub-levels to 1.