Coder Social home page Coder Social logo

Comments (3)

chrisgraham avatar chrisgraham commented on September 25, 2024

It's not ideal as it will mess with column height balancing, but I think it is good enough.

from columnizer-jquery-plugin.

chrisgraham avatar chrisgraham commented on September 25, 2024

It's also not ideal because it only looks at elements, not text nodes. So if you have a text node, then a removeiffirst element, it will get removed incorrectly. I'm going to completely change how this is approached in my next post.

from columnizer-jquery-plugin.

chrisgraham avatar chrisgraham commented on September 25, 2024

Ergh, was planning to move code into the columnize function, but then I realised this is not going to be called for the last column, and I think cause other issues because there's no "total height" anymore. So to keep things 'simple' I just had to leave the height balancing problem alone, because it's not really solvable.

Here we go...

            for (var i = 0; i < numCols; i++) {
                var $col = $inBox.children().eq(i);
                var runOn;

                do  {
                    runOn=$col.children(":first-child.removeiffirst");
                    if (runOn.length!=0) {
                        // Protect if a relevant text node preceding
                        if (runOn[0].previousSibling && runOn[0].previousSibling.nodeType==3) {
                            if (runOn[0].previousSibling.nodeValue.replace(/\s/g,'')!='') {
                                break;
                            }
                        }
                        // Okay, strip then
                        $(runOn[0]).remove();
                    }
                }
                while (runOn.length!=0);

                do  {
                    runOn=$col.children(":last-child.removeiflast");
                    if (runOn.length!=0) {
                        // Protect if a relevant text node suceeding
                        if (runOn[0].nextSibling && runOn[0].nextSibling.nodeType==3) {
                            if (runOn[0].nextSibling.nodeValue.replace(/\s/g,'')!='') {
                                break;
                            }
                        }
                        // Okay, strip then
                        $(runOn[0]).remove();
                    }
                }
                while (runOn.length!=0);
            }

from columnizer-jquery-plugin.

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.