Chromium Code Reviews| 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 import 'dart:async'; | |
| 7 import 'package:observatory/src/elements/helpers/tag.dart'; | |
| 8 import 'package:observatory/src/elements/helpers/rendering_scheduler.dart'; | |
| 9 | |
| 10 class NavMenuElement extends HtmlElement implements Renderable { | |
| 11 static final StyleElement _style = () { | |
| 12 var style = new StyleElement(); | |
| 13 style.text = 'li.nav-menu_label, li.nav-menu_spacer {' | |
|
Cutch
2016/07/19 14:19:05
use the ''' quotes with new lines.
cbernaschina
2016/07/19 19:18:20
Done.
| |
| 14 'float: left;' | |
| 15 '}' | |
| 16 'li.nav-menu_label > a, li.nav-menu_spacer {' | |
| 17 'display: block;' | |
| 18 'padding: 12px 8px;' | |
| 19 'color: White;' | |
| 20 'text-decoration: none;' | |
| 21 '}' | |
| 22 'li.nav-menu_label:hover {' | |
| 23 'background: #455;' | |
| 24 '}' | |
| 25 'li.nav-menu_label > ul {' | |
| 26 'display: none;' | |
| 27 'position: absolute;' | |
| 28 'top: 98%;' | |
| 29 'list-style: none;' | |
| 30 'margin: 0;' | |
| 31 'padding: 0;' | |
| 32 'width: auto;' | |
| 33 'z-index: 1000;' | |
| 34 'font: 400 16px \'Montserrat\', sans-serif;' | |
| 35 'color: white;' | |
| 36 'background: #567;' | |
| 37 '}' | |
| 38 'li.nav-menu_label > ul:after {' | |
| 39 'content: ""; clear: both; display: block;' | |
| 40 '}' | |
| 41 'li.nav-menu_label:hover > ul {' | |
| 42 'display: block;' | |
| 43 '}'; | |
| 44 return style; | |
| 45 }(); | |
| 46 | |
| 47 static const tag = const Tag<NavMenuElement>('nav-menu-wrapped'); | |
| 48 | |
| 49 RenderingScheduler _r; | |
| 50 | |
| 51 Stream<RenderedEvent<NavMenuElement>> get onRendered => _r.onRendered; | |
| 52 | |
| 53 String _label; | |
| 54 String _link; | |
| 55 bool _last; | |
| 56 String get label => _label; | |
| 57 String get link => _link; | |
| 58 bool get last => _last; | |
| 59 set label(String value) { | |
| 60 if (_label != value) { | |
| 61 _label = value; | |
| 62 _r.dirty(); | |
| 63 } else { | |
| 64 _r.scheduleNotification(); | |
| 65 } | |
| 66 } | |
| 67 set link(String value) { | |
| 68 if (_link != value) { | |
| 69 _link = value; | |
| 70 _r.dirty(); | |
| 71 } else { | |
| 72 _r.scheduleNotification(); | |
| 73 } | |
| 74 } | |
| 75 set last(bool value) { | |
| 76 if (_last != value) { | |
| 77 _last = value; | |
| 78 _r.dirty(); | |
| 79 } else { | |
| 80 _r.scheduleNotification(); | |
| 81 } | |
| 82 } | |
| 83 | |
| 84 | |
| 85 factory NavMenuElement(String label, {String link, bool last: false, | |
| 86 RenderingQueue queue}) { | |
| 87 assert(label != null); | |
| 88 assert(last != null); | |
| 89 NavMenuElement e = document.createElement(tag.name); | |
| 90 e._r = new RenderingScheduler(e, queue: queue); | |
| 91 e._label = label; | |
| 92 e._link = link; | |
| 93 e._last = last; | |
| 94 return e; | |
| 95 } | |
| 96 | |
| 97 NavMenuElement.created() : super.created() { createShadowRoot(); } | |
| 98 | |
| 99 @override | |
| 100 void attached() { super.attached(); _r.enable(); } | |
| 101 | |
| 102 @override | |
| 103 void detached() { | |
| 104 super.detached(); _r.disable(notify: true); | |
| 105 shadowRoot.children = []; | |
| 106 } | |
| 107 | |
| 108 void render() { | |
| 109 List<Element> children = [ | |
| 110 _style.clone(true), | |
| 111 new LIElement() | |
| 112 ..classes = ['nav-menu_label'] | |
| 113 ..children = [ | |
| 114 new AnchorElement(href: '#$link') | |
| 115 ..text = label, | |
| 116 new UListElement() | |
| 117 ..children = [ | |
| 118 new ContentElement() | |
| 119 ] | |
| 120 ] | |
| 121 ]; | |
| 122 if (!last) { | |
| 123 children.add( | |
| 124 new LIElement() | |
| 125 ..classes = ['nav-menu_spacer'] | |
| 126 ..innerHtml = '>' | |
| 127 ); | |
| 128 } | |
| 129 shadowRoot.children = children; | |
| 130 } | |
| 131 } | |
| OLD | NEW |