JQuery 1.4's New 'Until' Methods Caught My Eye ... Introducing Element.GetUntil
By Ryan Florence, published 2010-01-15
Part of the issue Migrated Articles From Original Site Structure..
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);
}
});
})();