* Looks for a child or parent node which has specified classname. * Equivalent to jQuery's $(container).find(".className") * @param {Element} target Target element. * @param {String} search Class name or node name to look for. * @param {Boolean} reverse If set to true, will go up the node tree i
(target, search, reverse /* optional */)
| 485 | * @return {Element} Returns found child or parent element on null. |
| 486 | */ |
| 487 | function findElement(target, search, reverse /* optional */) |
| 488 | { |
| 489 | if (target == null) |
| 490 | return null; |
| 491 | |
| 492 | var nodes = reverse != true ? target.childNodes : [ target.parentNode ], |
| 493 | propertyToFind = { '#' : 'id', '.' : 'className' }[search.substr(0, 1)] || 'nodeName', |
| 494 | expectedValue, |
| 495 | found |
| 496 | ; |
| 497 | |
| 498 | expectedValue = propertyToFind != 'nodeName' |
| 499 | ? search.substr(1) |
| 500 | : search.toUpperCase() |
| 501 | ; |
| 502 | |
| 503 | // main return of the found node |
| 504 | if ((target[propertyToFind] || '').indexOf(expectedValue) != -1) |
| 505 | return target; |
| 506 | |
| 507 | for (var i = 0; nodes && i < nodes.length && found == null; i++) |
| 508 | found = findElement(nodes[i], search, reverse); |
| 509 | |
| 510 | return found; |
| 511 | }; |
| 512 | |
| 513 | /** |
| 514 | * Looks for a parent node which has specified classname. |
no outgoing calls
no test coverage detected