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 editable_label; | 5 library todomvc.web.editable_label; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'package:polymer/polymer.dart'; | 8 import 'package:polymer/polymer.dart'; |
9 | 9 |
10 /** | 10 /** |
11 * Label whose [value] can be edited by double clicking. When editing, it | 11 * Label whose [value] can be edited by double clicking. When editing, it |
12 * displays a form and input element, otherwise it displays the label. | 12 * displays a form and input element, otherwise it displays the label. |
13 */ | 13 */ |
14 class EditableLabel extends PolymerElement with ObservableMixin { | 14 class EditableLabel extends PolymerElement { |
15 @observable bool editing = false; | 15 @observable bool editing = false; |
16 @observable String value = ''; | 16 @published String value = ''; |
17 | |
17 bool get applyAuthorStyles => true; | 18 bool get applyAuthorStyles => true; |
18 | 19 |
19 InputElement get _editBox => getShadowRoot("editable-label").query('#edit'); | 20 InputElement get _editBox => getShadowRoot("editable-label").query('#edit'); |
20 | 21 |
21 void edit() { | 22 void edit() { |
22 editing = true; | 23 editing = true; |
23 | 24 |
24 // This causes _editBox to be inserted. | 25 // This causes _editBox to be inserted. |
25 performMicrotaskCheckpoint(); | 26 performMicrotaskCheckpoint(); |
26 | 27 |
(...skipping 12 matching lines...) Expand all Loading... | |
39 } | 40 } |
40 | 41 |
41 void maybeCancel(KeyboardEvent e) { | 42 void maybeCancel(KeyboardEvent e) { |
42 if (e.keyCode == KeyCode.ESC) { | 43 if (e.keyCode == KeyCode.ESC) { |
43 editing = false; | 44 editing = false; |
44 } | 45 } |
45 } | 46 } |
46 } | 47 } |
47 | 48 |
48 void main() { | 49 void main() { |
49 registerPolymerElement('editable-label', () => new EditableLabel()); | 50 Polymer.register('editable-label', EditableLabel); |
blois
2013/09/27 21:40:52
Any idea why this uses the explicit register rathe
Jennifer Messerly
2013/09/30 17:44:37
to show off (and test) the alternate form.
| |
50 } | 51 } |
OLD | NEW |