Coder Social home page Coder Social logo

Comments (4)

louisajaca avatar louisajaca commented on July 1, 2024

I think I have fixed the issue using the new _clearEmpty:

_clearEmpty: function (item) {
            function replaceClass(elem, search, replace, swap) {
                if (swap) {
                    search = [replace, replace = search][0];
                }

                $(elem).removeClass(search).addClass(replace);
            }

            var o = this.options,
                childrenList = $(item).children(o.listType),
                hasChildren = childrenList.is(':not(:empty)');

            var doNotClear =
                o.doNotClear ||
                hasChildren ||
                o.protectRoot && $(item)[0] === this.element[0];

            if (o.isTree) {
                replaceClass(item, o.branchClass, o.leafClass, doNotClear);

                if (doNotClear && hasChildren) {
                    if (childrenList.is(':visible'))
                        replaceClass(item, o.collapsedClass, o.expandedClass);
                    else
                        replaceClass(item, o.expandedClass, o.collapsedClass);
                }
            }

            if (!doNotClear) {
                childrenList.remove();
            }
        }

from nestedsortable.

MSvelander avatar MSvelander commented on July 1, 2024

Even with the new _clearEmpty there is an issue.

If I have all items de-collapsed.
skarmavbild 2015-11-21 kl 15 10 24

  • Then collapse 3 (not 3.1 and 3.3)
  • Move 4
  • De-collapse 3

3.1 and 3.3 is collapsed but with de-collapsed icon.

skarmavbild 2015-11-21 kl 15 10 55

De-collapse 3.1 and 3.3 and the icon change to collapse-icon.

skarmavbild 2015-11-21 kl 15 11 53

Any ideas on a solution?

from nestedsortable.

larikitty avatar larikitty commented on July 1, 2024

+1 (same issue)

from nestedsortable.

noraheuer avatar noraheuer commented on July 1, 2024

I edited the _clearEmpty (v. 2.1a)
This seems to work for me.

#816 because :empty includes text nodes as child elements
- hasChildren = childrenList.is(':not(:empty)');
+ hasChildren = childrenList.has('li').length;

#825-828 removed as that caused all branches of the tree to open
- if (doNotClear && hasChildren) {
-   replaceClass(item, o.collapsedClass, o.expandedClass);
- }

#832-833 remove expandedClass when childList is removed
- childrenList.remove();
+ childrenList.parent().removeClass(o.expandedClass);
+ childrenList.remove();

complete method

_clearEmpty: function (item) {
    function replaceClass(elem, search, replace, swap) {
        if (swap) {
            search = [replace, replace = search][0];
        }

        $(elem).removeClass(search).addClass(replace);
    }

    var o = this.options,
        childrenList = $(item).children(o.listType),
        hasChildren = childrenList.has('li').length;

    var doNotClear =
        o.doNotClear ||
        hasChildren ||
        o.protectRoot && $(item)[0] === this.element[0];

    if (o.isTree) {
        replaceClass(item, o.branchClass, o.leafClass, doNotClear);             
    }

    if (!doNotClear) {
        childrenList.parent().removeClass(o.expandedClass);
        childrenList.remove();
    }
}

from nestedsortable.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.