diff --git a/CHANGELOG b/CHANGELOG index b5eb35c..4221452 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,9 @@ *SVN* +* Rename Element#getElementsBySelector to Element#select and add alias for Element#getElementsBySelector. [Thomas Fuchs] + +* Add Element#adjacent as a shortcut to selecting all adjacent nodes (and their children) that match a CSS selector. [Thomas Fuchs] + * Enhance the Enumerable and Array APIs to more closely match those of JavaScript 1.6 as implemented in Firefox 1.5. Closes #6650, #8409. [Mislav Marohnić, Sylvain Zimmer] - Add Array#lastIndexOf, and change Array#indexOf not to overwrite the native method. - Make Enumerable use Array.prototype.forEach instead of _each when possible (slight speed increase). diff --git a/src/dom.js b/src/dom.js index ed96502..0a8b455 100644 --- a/src/dom.js +++ b/src/dom.js @@ -223,11 +223,16 @@ Element.Methods = { nextSiblings[index || 0]; }, - getElementsBySelector: function() { + select: function() { var args = $A(arguments), element = $(args.shift()); return Selector.findChildElements(element, args); }, + adjacent: function() { + var args = $A(arguments), element = $(args.shift()); + return Selector.findChildElements(element.parentNode, args).without(element); + }, + readAttribute: function(element, name) { element = $(element); if (Prototype.Browser.IE) { @@ -595,6 +600,8 @@ Element.Methods = { } }; +Element.Methods.getElementsBySelector = Element.Methods.select; + if (!document.getElementsByClassName) document.getElementsByClassName = function(instanceMethods){ function isArray(className) { return ; diff --git a/test/unit/dom.html b/test/unit/dom.html index 24db2df..1f72677 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -659,11 +659,21 @@ }); }}, - testElementSelectorMethod: function() {with(this) { - var testSelector = $('container').getElementsBySelector('p.test'); - assertEqual(testSelector.length, 4); - assertEqual(testSelector[0], $('intended')); - assertEqual(testSelector[0], $$('#container p.test')[0]); + testElementSelectorMethod: function() {with(this) { + ['getElementsBySelector','select'].each(function(method){ + var testSelector = $('container')[method]('p.test'); + assertEqual(testSelector.length, 4); + assertEqual(testSelector[0], $('intended')); + assertEqual(testSelector[0], $$('#container p.test')[0]); + }); + }}, + + testElementAdjacent: function() {with(this) { + var elements = $('intended').adjacent('p'); + assertEqual(elements.length, 3); + elements.each(function(element){ + assert(element != $('intended')); + }); }}, testElementClassNameMethod: function() {with(this) {