| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 import 'dart:html'; | |
| 6 | |
| 7 import 'package:observatory/app.dart'; | |
| 8 import 'package:observatory/src/elements/helpers/tag.dart'; | |
| 9 import 'package:observatory/src/elements/shims/binding.dart'; | |
| 10 import 'package:observatory/src/elements/nav/menu.dart'; | |
| 11 | |
| 12 @bindable | |
| 13 class NavMenuElementWrapper extends HtmlElement { | |
| 14 static const binder = const Binder<NavMenuElementWrapper>(const { | |
| 15 'anchor': #anchor, 'link': #link, 'last': #last | |
| 16 }); | |
| 17 | |
| 18 static const tag = | |
| 19 const Tag<NavMenuElementWrapper>('nav-menu'); | |
| 20 | |
| 21 String _anchor = '---'; | |
| 22 String _link; | |
| 23 bool _last = false; | |
| 24 | |
| 25 String get anchor => _anchor; | |
| 26 String get link => _link; | |
| 27 bool get last => _last; | |
| 28 | |
| 29 set anchor(String value) { | |
| 30 _anchor = value; | |
| 31 render(); | |
| 32 } | |
| 33 set link(String value) { | |
| 34 _link = value; | |
| 35 render(); | |
| 36 } | |
| 37 set last(bool value) { | |
| 38 _last = value; | |
| 39 render(); | |
| 40 } | |
| 41 | |
| 42 NavMenuElementWrapper.created() : super.created() { | |
| 43 binder.registerCallback(this); | |
| 44 _anchor = getAttribute('anchor'); | |
| 45 _link = getAttribute('link'); | |
| 46 _last = _getBoolAttribute('last'); | |
| 47 createShadowRoot(); | |
| 48 render(); | |
| 49 } | |
| 50 | |
| 51 @override | |
| 52 void attached() { | |
| 53 super.attached(); | |
| 54 render(); | |
| 55 } | |
| 56 | |
| 57 void render() { | |
| 58 shadowRoot.children = []; | |
| 59 if (_anchor == null || _last == null) { | |
| 60 return; | |
| 61 } | |
| 62 | |
| 63 shadowRoot.children = [ | |
| 64 new NavMenuElement(_anchor, link: '#$_link', last: last, | |
| 65 queue: ObservatoryApplication.app.queue) | |
| 66 ..children = [new ContentElement()] | |
| 67 ]; | |
| 68 } | |
| 69 | |
| 70 bool _getBoolAttribute(String name) { | |
| 71 final String value = getAttribute(name); | |
| 72 return !(value == null || value == 'false'); | |
| 73 } | |
| 74 } | |
| OLD | NEW |