| 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 // For illustration purposes this type uses Polymer.register instead of | 14 // For illustration purposes this type uses Polymer.register instead of |
| 15 // CustomTag. We must mark it @reflectable to ensure its members | 15 // CustomTag. We must mark it @reflectable to ensure its members |
| 16 // (the event handlers) are preserved and can be referenced from HTML. | 16 // (the event handlers) are preserved and can be referenced from HTML. |
| 17 @reflectable | 17 @reflectable |
| 18 class EditableLabel extends PolymerElement { | 18 class EditableLabel extends PolymerElement { |
| 19 @observable bool editing = false; | 19 @observable bool editing = false; |
| 20 @published String value = ''; | 20 @published String value = ''; |
| 21 | 21 |
| 22 factory EditableLabel() => new Element.tag('editable-label'); | 22 factory EditableLabel() => new Element.tag('editable-label'); |
| 23 | 23 |
| 24 EditableLabel.created() : super.created(); | 24 EditableLabel.created() : super.created(); |
| 25 | 25 |
| 26 bool get applyAuthorStyles => true; | 26 bool get applyAuthorStyles => true; |
| 27 | 27 |
| 28 ShadowRoot get _shadowRoot => getShadowRoot('editable-label'); | 28 ShadowRoot get _shadowRoot => getShadowRoot('editable-label'); |
| 29 | 29 |
| 30 InputElement get _editBox => _shadowRoot.query('#edit'); | 30 InputElement get _editBox => _shadowRoot.querySelector('#edit'); |
| 31 | 31 |
| 32 void edit() { | 32 void edit() { |
| 33 editing = true; | 33 editing = true; |
| 34 | 34 |
| 35 // Wait for _editBox to be inserted. | 35 // Wait for _editBox to be inserted. |
| 36 onMutation(_shadowRoot).then((_) { | 36 onMutation(_shadowRoot).then((_) { |
| 37 // For IE and Firefox: use .focus(), then reset the value to move the | 37 // For IE and Firefox: use .focus(), then reset the value to move the |
| 38 // cursor to the end. | 38 // cursor to the end. |
| 39 _editBox.focus(); | 39 _editBox.focus(); |
| 40 _editBox.value = ''; | 40 _editBox.value = ''; |
| (...skipping 12 matching lines...) Expand all Loading... |
| 53 if (e.keyCode == KeyCode.ESC) { | 53 if (e.keyCode == KeyCode.ESC) { |
| 54 editing = false; | 54 editing = false; |
| 55 } | 55 } |
| 56 } | 56 } |
| 57 } | 57 } |
| 58 | 58 |
| 59 @initMethod | 59 @initMethod |
| 60 void _init() { | 60 void _init() { |
| 61 Polymer.register('editable-label', EditableLabel); | 61 Polymer.register('editable-label', EditableLabel); |
| 62 } | 62 } |
| OLD | NEW |