OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file |
| 2 // for details. All rights reserved. Use of this source code is governed by a |
| 3 // BSD-style license that can be found in the LICENSE file. |
| 4 |
| 5 class $CLASSNAME extends _NodeImpl |
| 6 implements Document |
| 7 $if FROG |
| 8 native "*HTMLDocument" |
| 9 $endif |
| 10 { |
| 11 |
| 12 $!MEMBERS |
| 13 // TODO(jacobr): implement all Element methods not on Document. |
| 14 |
| 15 _ElementImpl query(String selectors) { |
| 16 // It is fine for our RegExp to detect element id query selectors to have |
| 17 // false negatives but not false positives. |
| 18 if (const RegExp("^#[_a-zA-Z]\\w*\$").hasMatch(selectors)) { |
| 19 return $dom_getElementById(selectors.substring(1)); |
| 20 } |
| 21 return $dom_querySelector(selectors); |
| 22 } |
| 23 |
| 24 // TODO(jacobr): autogenerate this method. |
| 25 $if FROG |
| 26 _ElementImpl $dom_querySelector(String selectors) native "return this.querySel
ector(selectors);"; |
| 27 $else |
| 28 _ElementImpl $dom_querySelector(String selectors) => |
| 29 _wrap(_.querySelector(selectors)); |
| 30 $endif |
| 31 |
| 32 ElementList queryAll(String selectors) { |
| 33 if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) { |
| 34 final mutableMatches = $dom_getElementsByName( |
| 35 selectors.substring(7,selectors.length - 2)); |
| 36 int len = mutableMatches.length; |
| 37 final copyOfMatches = new List<Element>(len); |
| 38 for (int i = 0; i < len; ++i) { |
| 39 copyOfMatches[i] = mutableMatches[i]; |
| 40 } |
| 41 return new _FrozenElementList._wrap(copyOfMatches); |
| 42 } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) { |
| 43 final mutableMatches = $dom_getElementsByTagName(selectors); |
| 44 int len = mutableMatches.length; |
| 45 final copyOfMatches = new List<Element>(len); |
| 46 for (int i = 0; i < len; ++i) { |
| 47 copyOfMatches[i] = mutableMatches[i]; |
| 48 } |
| 49 return new _FrozenElementList._wrap(copyOfMatches); |
| 50 } else { |
| 51 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); |
| 52 } |
| 53 } |
| 54 } |
OLD | NEW |