OLD | NEW |
| (Empty) |
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 | |
3 // BSD-style license that can be found in the LICENSE file. | |
4 | |
5 library collapsible_content_element; | |
6 | |
7 import 'dart:html'; | |
8 import 'package:polymer/polymer.dart'; | |
9 import 'observatory_element.dart'; | |
10 | |
11 /// An element which conditionally displays its children elements. | |
12 @CustomTag('collapsible-content') | |
13 class CollapsibleContentElement extends ObservatoryElement { | |
14 static const String _openIconClass = 'glyphicon glyphicon-chevron-down'; | |
15 static const String _closeIconClass = 'glyphicon glyphicon-chevron-up'; | |
16 | |
17 @observable String iconClass = _openIconClass; | |
18 @observable String displayValue = 'none'; | |
19 | |
20 bool _collapsed = true; | |
21 bool get collapsed => _collapsed; | |
22 set collapsed(bool r) { | |
23 _collapsed = r; | |
24 _refresh(); | |
25 } | |
26 | |
27 CollapsibleContentElement.created() : super.created(); | |
28 | |
29 void enteredView() { | |
30 super.enteredView(); | |
31 _refresh(); | |
32 } | |
33 | |
34 void toggleDisplay(Event e, var detail, Node target) { | |
35 collapsed = !collapsed; | |
36 _refresh(); | |
37 } | |
38 | |
39 | |
40 | |
41 void _refresh() { | |
42 if (_collapsed) { | |
43 iconClass = _openIconClass; | |
44 displayValue = 'none'; | |
45 } else { | |
46 iconClass = _closeIconClass; | |
47 displayValue = 'block'; | |
48 } | |
49 } | |
50 } | |
OLD | NEW |