OLD | NEW |
1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
2 // for details. All rights reserved. Use of this source code is governed by a | 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. | 3 // BSD-style license that can be found in the LICENSE file. |
4 | 4 |
5 library web.link; | 5 library web.link; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'package:dartdoc_viewer/item.dart'; | 8 import 'package:dartdoc_viewer/item.dart'; |
9 import 'package:dartdoc_viewer/search.dart' show searchIndex; | 9 import 'package:dartdoc_viewer/search.dart' show searchIndex; |
10 import 'package:polymer/polymer.dart'; | 10 import 'package:polymer/polymer.dart'; |
| 11 import 'package:dartdoc_viewer/location.dart'; |
11 | 12 |
12 // TODO(jmesserly): just extend HtmlElement? | 13 // TODO(jmesserly): just extend HtmlElement? |
13 @CustomTag("dartdoc-link") | 14 @CustomTag("dartdoc-link") |
14 class LinkElement extends PolymerElement { | 15 class LinkElement extends PolymerElement { |
15 @published LinkableType type; | 16 @published LinkableType type; |
16 | 17 |
17 LinkElement.created() : super.created(); | 18 LinkElement.created() : super.created(); |
18 | 19 |
19 enteredView() { | 20 enteredView() { |
20 super.enteredView(); | 21 super.enteredView(); |
21 searchIndex.onLoad(typeChanged); | 22 searchIndex.onLoad(typeChanged); |
22 } | 23 } |
23 | 24 |
24 void typeChanged() { | 25 void typeChanged() { |
25 this.children.clear(); | 26 this.children.clear(); |
26 if (type == null) return; | 27 if (type == null) return; |
27 | 28 |
28 Element child; | 29 Element child; |
29 final location = type.loc.withoutAnchor; | 30 final location = type.loc.withoutAnchor; |
30 if (searchIndex.map.containsKey(location)) { | 31 if (searchIndex.map.containsKey(location)) { |
31 child = new AnchorElement()..href = '#${type.loc.withAnchor}'; | 32 child = new AnchorElement()..href = locationPrefixed(type.loc.withAnchor); |
32 } else { | 33 } else { |
33 child = new Element.tag('i'); | 34 child = new Element.tag('i'); |
34 } | 35 } |
35 this.append(child..text = type.simpleType); | 36 this.append(child..text = type.simpleType); |
36 } | 37 } |
37 } | 38 } |
OLD | NEW |