prototype: Fix Selector.matchElements to allow for coma-separated selectors in Element#up/next/previous and Event#findElement.

This commit is contained in:
Tobie Langel 2008-01-06 21:49:16 +00:00
parent e9be4660e1
commit a246e777f5
6 changed files with 13 additions and 8 deletions

View File

@ -1,4 +1,5 @@
*SVN*
* Fix Selector.matchElements to allow for coma-separated selectors in Element#up/next/previous and Event#findElement. [Samuel Lebeau, Tobie Langel]
* Test.Unit refactoring. Allow running multiple instances of Test.Unit.Runner on the same page. Allow rake to run specific testcases (e.g.: rake test BROWSERS=firefox TESTS=array TESTCASES=testUniq,test$w). Closes #10704, #10705, #10706. [nicwilliams, Tobie Langel]

View File

@ -618,7 +618,7 @@ Object.extend(Selector, {
},
matchElements: function(elements, expression) {
var matches = new Selector(expression).findElements(), h = Selector.handlers;
var matches = $$(expression), h = Selector.handlers;
h.mark(matches);
for (var i = 0, results = [], element; element = elements[i]; i++)
if (element._counted) results.push(element);

View File

@ -445,8 +445,8 @@ Test.Unit.Assertions = {
Test.Unit.Testcase = Class.create(Test.Unit.Assertions, {
initialize: function(name, test, setup, teardown) {
this.name = name;
this.test = test || Prototype.emptyFunction;
this.setup = setup || Prototype.emptyFunction;
this.test = test || Prototype.emptyFunction;
this.setup = setup || Prototype.emptyFunction;
this.teardown = teardown || Prototype.emptyFunction;
this.messages = [];
this.actions = {};

View File

@ -942,6 +942,7 @@
assertElementMatches(element.up('ul', 1), 'ul#navigation_test');
assertEqual(undefined, element.up('garbage'));
assertEqual(undefined, element.up(6));
assertElementMatches(element.up('.non-existant, ul'), 'ul');
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '<div></div>'.times(3);
@ -955,6 +956,7 @@
assertElementMatches(element.down(1), 'em');
assertElementMatches(element.down('li', 5), 'li.last');
assertElementMatches(element.down('ul').down('li', 1), 'li#navigation_test_f');
assertElementMatches(element.down('.non-existant, .first'), 'li.first');
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '<div></div>'.times(3);
@ -968,6 +970,7 @@
assertElementMatches(element.previous('.first'), 'li.first');
assertEqual(undefined, element.previous(3));
assertEqual(undefined, $('navigation_test').down().previous());
assertElementMatches(element.previous('.non-existant, .first'), 'li.first');
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '<div></div>'.times(3);
@ -982,6 +985,7 @@
assertElementMatches(element.next('.last'), 'li.last');
assertEqual(undefined, element.next(3));
assertEqual(undefined, element.next(2).next());
assertElementMatches(element.next('.non-existant, .last'), 'li.last');
var dummy = $(document.createElement('DIV'));
dummy.innerHTML = '<div></div>'.times(3);

View File

@ -235,13 +235,12 @@
testEventFindElement: function() { with(this) {
var span = $("span"), event;
event = span.fire("test:somethingHappened");
assertEqual(span, event.findElement());
assertEqual(span, event.findElement('span'));
assertEqual($("inner"), event.findElement('p'));
assertElementMatches(event.findElement(), 'span#span');
assertElementMatches(event.findElement('span'), 'span#span');
assertElementMatches(event.findElement('p'), 'p#inner');
assertEqual(null, event.findElement('div.does_not_exist'));
assertElementMatches(event.findElement('.does_not_exist, span'), 'span#span');
}}
});
document.observe("dom:loaded", function(event) {

View File

@ -215,6 +215,7 @@
assertElementsMatch(Selector.matchElements($('list').descendants(), 'li'), '#item_1', '#item_2', '#item_3');
assertElementsMatch(Selector.matchElements($('fixtures').descendants(), 'a.internal'), '#link_1', '#link_2');
assertEnumEqual([], Selector.matchElements($('fixtures').descendants(), 'p.last'));
assertElementsMatch(Selector.matchElements($('fixtures').descendants(), '.inexistant, a.internal'), '#link_1', '#link_2');
}},
testSelectorFindElement: function() {with(this) {