OLD | NEW |
1 // Copyright (c) 2016, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2016, 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 import 'dart:html'; | 5 import 'dart:html'; |
6 import 'dart:async'; | 6 import 'dart:async'; |
7 import 'package:observatory/src/elements/helpers/tag.dart'; | 7 import 'package:observatory/src/elements/helpers/tag.dart'; |
8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | 8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; |
9 | 9 |
10 class NavMenuItemElement extends HtmlElement implements Renderable { | 10 class NavMenuItemElement extends HtmlElement implements Renderable { |
(...skipping 11 matching lines...) Expand all Loading... |
22 String get link => _link; | 22 String get link => _link; |
23 Iterable<Element> get content => _content; | 23 Iterable<Element> get content => _content; |
24 | 24 |
25 set label(String value) => _label = _r.checkAndReact(_label, value); | 25 set label(String value) => _label = _r.checkAndReact(_label, value); |
26 set link(String value) => _link = _r.checkAndReact(_link, value); | 26 set link(String value) => _link = _r.checkAndReact(_link, value); |
27 set content(Iterable<Element> value) { | 27 set content(Iterable<Element> value) { |
28 _content = value.toList(); | 28 _content = value.toList(); |
29 _r.dirty(); | 29 _r.dirty(); |
30 } | 30 } |
31 | 31 |
32 | 32 factory NavMenuItemElement(String label, |
33 factory NavMenuItemElement(String label, {String link, | 33 {String link, RenderingQueue queue}) { |
34 RenderingQueue queue}) { | |
35 assert(label != null); | 34 assert(label != null); |
36 NavMenuItemElement e = document.createElement(tag.name); | 35 NavMenuItemElement e = document.createElement(tag.name); |
37 e._r = new RenderingScheduler(e, queue: queue); | 36 e._r = new RenderingScheduler(e, queue: queue); |
38 e._label = label; | 37 e._label = label; |
39 e._link = link; | 38 e._link = link; |
40 return e; | 39 return e; |
41 } | 40 } |
42 | 41 |
43 NavMenuItemElement.created() : super.created(); | 42 NavMenuItemElement.created() : super.created(); |
44 | 43 |
45 @override | 44 @override |
46 void attached() { | 45 void attached() { |
47 super.attached(); | 46 super.attached(); |
48 _r.enable(); | 47 _r.enable(); |
49 } | 48 } |
50 | 49 |
51 @override | 50 @override |
52 void detached() { | 51 void detached() { |
53 super.detached(); | 52 super.detached(); |
54 _r.disable(notify: true); | 53 _r.disable(notify: true); |
55 children = []; | 54 children = []; |
56 } | 55 } |
57 | 56 |
58 void render() { | 57 void render() { |
59 children = [ | 58 children = [ |
60 new LIElement() | 59 new LIElement() |
61 ..classes = ['nav-menu-item'] | 60 ..classes = ['nav-menu-item'] |
62 ..children = [ | 61 ..children = [ |
63 new AnchorElement(href: link) | 62 new AnchorElement(href: link)..text = label, |
64 ..text = label, | 63 new UListElement()..children = _content |
65 new UListElement() | |
66 ..children = _content | |
67 ] | 64 ] |
68 ]; | 65 ]; |
69 } | 66 } |
70 } | 67 } |
OLD | NEW |