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 | |
nweiz
2012/03/28 01:16:17
Why not "class $CLASSNAME$EXTENDS$IMPLEMENTS$NATIV
Jacob
2012/03/28 17:52:54
Because it extends _NodeImpl not _ElementImpl
Als
| |
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 if (const RegExp("^#\\w+\$").hasMatch(selectors)) { | |
17 return $dom_getElementById(selectors.substring(1)); | |
nweiz
2012/03/28 01:16:17
Is this really faster? That's kind of depressing.
Jacob
2012/03/28 17:52:54
Sad but true.... This is a LOT faster for getEleme
nweiz
2012/03/28 20:29:33
I'm not sure how much we want to care about false
Jacob
2012/03/28 21:01:30
I've added a comment that this has false negatives
| |
18 } | |
19 return $dom_querySelector(selectors); | |
20 } | |
21 | |
22 _ElementImpl $dom_querySelector(String selectors) native "return this.querySel ector(selectors);"; | |
nweiz
2012/03/28 01:16:17
Line length. Also, why isn't this autogenerated?
Jacob
2012/03/28 17:52:54
Obeying line length for these native lines does mo
| |
23 | |
24 ElementList queryAll(String selectors) { | |
25 if (const RegExp("""^\\[name=["'][^'"]+['"]\\]\$""").hasMatch(selectors)) { | |
26 final mutableMatches = $dom_getElementsByName( | |
27 selectors.substring(7,selectors.length - 2)); | |
28 int len = mutableMatches.length; | |
29 final copyOfMatches = new List<Element>(len); | |
30 for (int i = 0; i < len; ++i) { | |
31 copyOfMatches[i] = mutableMatches[i]; | |
32 } | |
33 return new _FrozenElementList._wrap(copyOfMatches); | |
34 } else if (const RegExp("^[*a-zA-Z0-9]+\$").hasMatch(selectors)) { | |
35 final mutableMatches = $dom_getElementsByTagName(selectors); | |
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 { | |
43 return new _FrozenElementList._wrap($dom_querySelectorAll(selectors)); | |
44 } | |
45 } | |
46 } | |
OLD | NEW |