| 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 | 6 |
| 7 import 'package:observatory/app.dart'; | 7 import 'package:observatory/app.dart'; |
| 8 import 'package:observatory/service.dart'; |
| 8 import 'package:observatory/src/elements/helpers/tag.dart'; | 9 import 'package:observatory/src/elements/helpers/tag.dart'; |
| 9 import 'package:observatory/src/elements/shims/binding.dart'; | 10 import 'package:observatory/src/elements/shims/binding.dart'; |
| 10 import 'package:observatory/src/elements/nav/menu.dart'; | 11 import 'package:observatory/src/elements/nav/class_menu.dart'; |
| 11 | 12 |
| 12 class NavMenuElementWrapper extends HtmlElement { | 13 class NavClassMenuElementWrapper extends HtmlElement { |
| 13 static final binder = new Binder<NavMenuElementWrapper>( | 14 static final binder = new Binder<NavClassMenuElementWrapper>( |
| 14 const [const Binding('anchor'), const Binding('link'), | 15 const [const Binding('last'), const Binding('cls')]); |
| 15 const Binding('last')]); | |
| 16 | 16 |
| 17 static const tag = | 17 static const tag = |
| 18 const Tag<NavMenuElementWrapper>('nav-menu'); | 18 const Tag<NavClassMenuElementWrapper>('class-nav-menu'); |
| 19 | 19 |
| 20 String _anchor = '---'; | |
| 21 String _link; | |
| 22 bool _last = false; | 20 bool _last = false; |
| 23 String get anchor => _anchor; | 21 Class _cls; |
| 24 String get link => _link; | |
| 25 bool get last => _last; | 22 bool get last => _last; |
| 26 set anchor(String value) { | 23 Class get cls => _cls; |
| 27 _anchor = value; render(); | |
| 28 } | |
| 29 set link(String value) { | |
| 30 _link = value; render(); | |
| 31 } | |
| 32 set last(bool value) { | 24 set last(bool value) { |
| 33 _last = value; render(); | 25 _last = value; render(); |
| 34 } | 26 } |
| 27 set cls(Class value) { |
| 28 _cls = value; render(); |
| 29 } |
| 35 | 30 |
| 36 NavMenuElementWrapper.created() : super.created() { | 31 NavClassMenuElementWrapper.created() : super.created() { |
| 37 binder.registerCallback(this); | 32 binder.registerCallback(this); |
| 38 _anchor = getAttribute('anchor'); | 33 _last = !isNullOrFalse(getAttribute('last')); |
| 39 _link = getAttribute('link'); | |
| 40 _last = getAttribute('') != null; | |
| 41 createShadowRoot(); | 34 createShadowRoot(); |
| 42 render(); | 35 render(); |
| 43 } | 36 } |
| 44 | 37 |
| 45 @override | 38 @override |
| 46 void attached() { | 39 void attached() { |
| 47 super.attached(); | 40 super.attached(); |
| 48 render(); | 41 render(); |
| 49 } | 42 } |
| 50 | 43 |
| 51 void render() { | 44 void render() { |
| 52 shadowRoot.children = []; | 45 shadowRoot.children = []; |
| 53 if (_anchor == null || _last == null) return; | 46 if (_cls == null || _last == null) return; |
| 54 | 47 |
| 55 shadowRoot.children = [ | 48 shadowRoot.children = [ |
| 56 new NavMenuElement(_anchor, link: _link, last: last, | 49 new NavClassMenuElement(cls.isolate, cls, last: last, |
| 57 queue: ObservatoryApplication.app.queue) | 50 queue: ObservatoryApplication.app.queue) |
| 58 ..children = [new ContentElement()] | 51 ..children = [new ContentElement()] |
| 59 ]; | 52 ]; |
| 60 } | 53 } |
| 54 |
| 55 static bool isNullOrFalse(String value) { |
| 56 return value == null || value == 'false'; |
| 57 } |
| 61 } | 58 } |
| OLD | NEW |