diff --git a/CHANGELOG b/CHANGELOG index 3880358..c4a65aa 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,7 @@ *SVN* +* Add Element#childElements as an alias for Element#immediateDescendants. [Tobie Langel] + * Optimize DOM navigation methods (Element#up, Element#down, Element#previous, Element#next) for no-argument calls. Closes #7848. [haraldmartin, sam] * Add Element#firstDescendant to retrieve the first non-text child node of an element. [sam] diff --git a/src/dom.js b/src/dom.js index 7a47873..5f07e88 100644 --- a/src/dom.js +++ b/src/dom.js @@ -426,7 +426,10 @@ Element.Methods = { } }; -Object.extend(Element.Methods, {childOf: Element.Methods.descendantOf}); +Object.extend(Element.Methods, { + childOf: Element.Methods.descendantOf, + childElements: Element.Methods.immediateDescendants +}); if (Prototype.Browser.Opera) { Element.Methods._getStyle = Element.Methods.getStyle; diff --git a/test/unit/dom.html b/test/unit/dom.html index 89a36f5..da3dbf8 100644 --- a/test/unit/dom.html +++ b/test/unit/dom.html @@ -484,16 +484,20 @@ assertNull($('navigation_test_next_sibling').firstDescendant()); }}, - testElementImmediateDescendants: function() {with(this) { - assertElementsMatch($('navigation_test').immediateDescendants(), + testElementChildElements: function() {with(this) { + assertElementsMatch($('navigation_test').childElements(), 'li.first', 'li', 'li#navigation_test_c', 'li.last'); assertNotEqual(0, $('navigation_test_next_sibling').childNodes.length); - assertEnumEqual([], $('navigation_test_next_sibling').immediateDescendants()); + assertEnumEqual([], $('navigation_test_next_sibling').childElements()); var dummy = $(document.createElement('DIV')); dummy.innerHTML = '
'.times(3); - assert(typeof dummy.immediateDescendants()[0].setStyle == 'function'); + assert(typeof dummy.childElements()[0].setStyle == 'function'); }}, + + testElementImmediateDescendants: function() {with(this) { + assertIdentical(Element.Methods.childElements, Element.Methods.immediateDescendants); + }}, testElementPreviousSiblings: function() {with(this) { assertElementsMatch($('navigation_test').previousSiblings(),