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