George February 2016

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:

  • List item
    • List item
    • List item
    • List item

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

  • List item
    • List item
      • List item
        • List item

Answers


Lupa February 2016

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.

Post Status

Asked in February 2016
Viewed 1,050 times
Voted 5
Answered 1 times

Search




Leave an answer