Prototype: Rename Element#getElementsBySelector to Element#select and add alias for Element#getElementsBySelector. Add Element#adjacent as a shortcut to selecting all adjacent nodes (and their children) that match a CSS selector.
This commit is contained in:
parent
1c17b6381a
commit
cea24d6cc2
|
@ -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).
|
||||
|
|
|
@ -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 ;
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue