| 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 todomvc.web.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 { | 14 class EditableLabel extends PolymerElement { |
| 15 @observable bool editing = false; | 15 @observable bool editing = false; |
| 16 @published String value = ''; | 16 @published String value = ''; |
| 17 | 17 |
| 18 factory EditableLabel() => new Element.tag('editable-label'); |
| 19 |
| 20 EditableLabel.created() : super.created(); |
| 21 |
| 18 bool get applyAuthorStyles => true; | 22 bool get applyAuthorStyles => true; |
| 19 | 23 |
| 20 InputElement get _editBox => getShadowRoot("editable-label").query('#edit'); | 24 InputElement get _editBox => getShadowRoot("editable-label").query('#edit'); |
| 21 | 25 |
| 22 void edit() { | 26 void edit() { |
| 23 editing = true; | 27 editing = true; |
| 24 | 28 |
| 25 // This causes _editBox to be inserted. | 29 // This causes _editBox to be inserted. |
| 26 performMicrotaskCheckpoint(); | 30 performMicrotaskCheckpoint(); |
| 27 | 31 |
| (...skipping 13 matching lines...) Expand all Loading... |
| 41 | 45 |
| 42 void maybeCancel(KeyboardEvent e) { | 46 void maybeCancel(KeyboardEvent e) { |
| 43 if (e.keyCode == KeyCode.ESC) { | 47 if (e.keyCode == KeyCode.ESC) { |
| 44 editing = false; | 48 editing = false; |
| 45 } | 49 } |
| 46 } | 50 } |
| 47 } | 51 } |
| 48 | 52 |
| 49 @initMethod | 53 @initMethod |
| 50 void _init() { | 54 void _init() { |
| 51 Polymer.register('editable-label', EditableLabel); | 55 Polymer.register('editable-label', type: EditableLabel); |
| 52 } | 56 } |
| OLD | NEW |