2
* Copyright 2004 ThoughtWorks, Inc
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
8
* http://www.apache.org/licenses/LICENSE-2.0
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
18
elementFindMatchingChildren = function(element, selector) {
21
var childCount = element.childNodes.length;
22
for (var i=0; i<childCount; i++) {
23
var child = element.childNodes[i];
24
if (selector(child)) {
27
childMatches = elementFindMatchingChildren(child, selector);
28
matches.push(childMatches);
32
return matches.flatten();
35
ELEMENT_NODE_TYPE = 1;
37
elementFindFirstMatchingChild = function(element, selector) {
39
var childCount = element.childNodes.length;
40
for (var i=0; i<childCount; i++) {
41
var child = element.childNodes[i];
42
if (child.nodeType == ELEMENT_NODE_TYPE) {
43
if (selector(child)) {
46
result = elementFindFirstMatchingChild(child, selector);
55
elementFindFirstMatchingParent = function(element, selector) {
56
var current = element.parentNode;
57
while (current != null) {
58
if (selector(current)) {
61
current = current.parentNode;
66
elementFindMatchingChildById = function(element, id) {
67
return elementFindFirstMatchingChild(element, function(element){return element.id==id} );