sans-serif   serif

«

JQuery 1.4’s new ‘until’ methods caught my eye … introducing Element.GetUntil

January 15, 2010

So I did what every good mootools developer would … extended MooTools to do the same. The names in jQuery are nextUntil, prevUntil, and parentsUntil. I decided to stick to mootools tradition and make my code more clear: getAllNextUntil, getAllPreviousUntil, and getParentsUntil.

Download it from the forge, fork it on github.

Luckily, this doesn’t ship with every copy of MooTools core, I can’t imagine very many practical uses–but like I said, it caught my eye, here’s a demo.

Here’s the source if you’re interested:

(function(){

    var walkUntil = function(element, walk, match, nocash){
        var el = element[walk];
        var elements = [];
        while (el){
            if (el.nodeType == 1){
                if (!match || Element.match(el, match)) {
                    break;
                } else {
                    elements.push(el);
                }
            }
            el = el[walk];
        }
        return new Elements(elements, {ddup: false, cash: !nocash});
    }

    Element.implement({

        getAllPreviousUntil: function(match, nocash){
            return walkUntil(this, 'previousSibling', match, nocash);
        },

        getAllNextUntil: function(match, nocash){
            return walkUntil(this, 'nextSibling', match, nocash);
        },

        getParentsUntil: function(match, nocash){
            return walkUntil(this, 'parentNode', match, nocash);
        }

    });

})();

MooTools in this article

Related Posts:

Comments

5 Responses to “JQuery 1.4’s new ‘until’ methods caught my eye … introducing Element.GetUntil”

  1. Very nice Ryan! I love your blog and contributions!

  2. [...] 18, 2010 Ryan Florence made a blog post two days ago about implementing jQuery’s getUntil in MooTools. He did a fantastic job, but hwe concluded the post saying that saying that is not many real uses [...]

  3. Henrik Hansen says:

    Hey Ryan, I’ve actually used your code to something (semi) serious. I’ve used it to create a range selection: http://pjhh.wordpress.com/2010/01/18/making-use-of-element-getuntil/

  4. Eneko Alonso says:

    Nice… very nice :)

  5. [...] these new until methods were interesting so I extended MooTools with similar functionality. See my post about [...]

Leave a Reply

 

Comments RSS