Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2013, 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 library curly_block_element; | 5 library curly_block_element; |
| 6 | 6 |
| 7 import 'package:polymer/polymer.dart'; | 7 import 'dart:async'; |
| 8 import 'observatory_element.dart'; | 8 import 'dart:html'; |
| 9 import 'helpers/tag.dart'; | |
|
Cutch
2016/07/07 19:50:57
fully qualify this import with "package:..."
cbernaschina
2016/07/07 22:08:13
Done.
| |
| 9 | 10 |
| 10 @CustomTag('curly-block') | 11 class CurlyBlockToggleEvent { |
| 11 class CurlyBlockElement extends ObservatoryElement { | 12 final CurlyBlockElement control; |
| 12 CurlyBlockElement.created() : super.created(); | |
| 13 | 13 |
| 14 @observable bool expanded = false; | 14 CurlyBlockToggleEvent(this.control); |
| 15 @observable bool busy = false; | 15 } |
| 16 @published var callback = null; | |
| 17 @published bool expand = false; | |
| 18 @published String expandKey; | |
| 19 | 16 |
| 20 void expandChanged(oldValue) { | 17 class CurlyBlockElement extends HtmlElement { |
| 21 expanded = expand; | 18 static final StyleElement _style = () { |
| 19 var style = new StyleElement(); | |
| 20 style.text = 'span.curly-block {' | |
| 21 ' color: #0489c3;' | |
| 22 ' cursor: pointer;' | |
| 23 '}' | |
| 24 'span.curly-block.disabled {' | |
| 25 ' color: white;' | |
| 26 ' cursor: wait;' | |
| 27 '}'; | |
| 28 return style; | |
| 29 }(); | |
| 30 | |
| 31 static const tag = const Tag<CurlyBlockElement>('curly-block-wrapped'); | |
| 32 | |
| 33 bool _expanded; | |
| 34 bool _disabled; | |
| 35 | |
| 36 bool get expanded => _expanded; | |
| 37 set expanded(bool expanded) { | |
| 38 if (_expanded != expanded) { | |
| 39 _expanded = expanded; | |
| 40 render(); | |
| 41 _onToggle.add(new CurlyBlockToggleEvent(this)); | |
| 42 } | |
| 22 } | 43 } |
| 23 | 44 bool get disabled => _disabled; |
| 24 void expandKeyChanged(oldValue) { | 45 set disabled(bool disabled) { |
| 25 if (expandKey != null) { | 46 if (_disabled != disabled) { |
| 26 var value = app.expansions[expandKey]; | 47 _disabled = disabled; |
| 27 if (value != null) { | 48 render(); |
| 28 if (expanded != value) { | |
| 29 toggleExpand(null, null, null); | |
| 30 } | |
| 31 } | |
| 32 } | 49 } |
| 33 } | 50 } |
| 34 | 51 |
| 35 void doneCallback() { | 52 final StreamController<CurlyBlockToggleEvent> _onToggle = |
| 36 expanded = !expanded; | 53 new StreamController<CurlyBlockToggleEvent>(); |
| 37 if (expandKey != null) { | 54 Stream<CurlyBlockToggleEvent> get onToggle => _onToggle.stream; |
| 38 app.expansions[expandKey] = expanded; | 55 |
| 39 } | 56 factory CurlyBlockElement({bool expanded: false, bool disabled:false}) { |
| 40 busy = false; | 57 assert(expanded is bool); |
| 58 assert(disabled is bool); | |
| 59 CurlyBlockElement e = document.createElement(tag.name); | |
| 60 e._expanded = expanded; | |
| 61 e._disabled = disabled; | |
| 62 return e; | |
| 41 } | 63 } |
| 42 | 64 |
| 43 void toggleExpand(var event, var b, var c) { | 65 CurlyBlockElement.created() : super.created() { |
| 44 assert(callback == null || expand == false); | 66 createShadowRoot(); |
| 45 if (busy) { | 67 } |
| 46 return; | 68 |
| 69 @override | |
| 70 void attached() { | |
| 71 super.attached(); | |
| 72 render(); | |
| 73 } | |
| 74 | |
| 75 void toggle() { | |
| 76 if (disabled) return; | |
| 77 expanded = !expanded; | |
| 78 } | |
| 79 | |
| 80 void render() { | |
| 81 List<Element> children = [ | |
| 82 _style.clone(true), | |
| 83 new SpanElement()..text = '{' | |
| 84 ]; | |
| 85 SpanElement label = new SpanElement() | |
| 86 ..classes = disabled ? ['curly-block', 'disabled'] : ['curly-block'] | |
| 87 ..innerHtml = expanded ? | |
| 88 ' ⊟ ' : ' ⊞ '; | |
| 89 if (disabled) { | |
| 90 children.add(label); | |
| 91 } else { | |
| 92 children.add(new AnchorElement() | |
| 93 ..onClick.listen((_) { toggle(); }) | |
| 94 ..children = [label]); | |
| 47 } | 95 } |
| 48 busy = true; | 96 if (expanded) { |
| 49 if (callback != null) { | 97 children.addAll([ |
| 50 callback(!expanded, doneCallback); | 98 new BRElement(), |
| 51 } else { | 99 new ContentElement() |
| 52 doneCallback(); | 100 ]); |
| 53 } | 101 } |
| 102 children.add(new SpanElement()..text = '}'); | |
| 103 shadowRoot.children = children; | |
| 54 } | 104 } |
| 55 } | 105 } |
| OLD | NEW |