| Index: samples/third_party/todomvc/web/editable_label.dart
|
| diff --git a/samples/third_party/todomvc/web/editable_label.dart b/samples/third_party/todomvc/web/editable_label.dart
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8b6e279c34475ee5664f91dc8fcb1e3febe0a41b
|
| --- /dev/null
|
| +++ b/samples/third_party/todomvc/web/editable_label.dart
|
| @@ -0,0 +1,51 @@
|
| +// Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
|
| +// for details. All rights reserved. Use of this source code is governed by a
|
| +// BSD-style license that can be found in the LICENSE file.
|
| +
|
| +library editable_label;
|
| +
|
| +import 'dart:html';
|
| +import 'package:polymer/polymer.dart';
|
| +
|
| +/**
|
| + * Label whose [value] can be edited by double clicking. When editing, it
|
| + * displays a form and input element, otherwise it displays the label.
|
| + */
|
| +class EditableLabel extends PolymerElement with ObservableMixin {
|
| + @observable bool editing = false;
|
| + @observable String value = '';
|
| + bool get applyAuthorStyles => true;
|
| +
|
| + InputElement get _editBox => getShadowRoot("editable-label").query('#edit');
|
| +
|
| + void edit() {
|
| + editing = true;
|
| +
|
| + // This causes _editBox to be inserted.
|
| + performMicrotaskCheckpoint();
|
| +
|
| + // For IE and Firefox: use .focus(), then reset the value to move the
|
| + // cursor to the end.
|
| + _editBox.focus();
|
| + _editBox.value = '';
|
| + _editBox.value = value;
|
| + }
|
| +
|
| + void update(Event e) {
|
| + e.preventDefault(); // don't submit the form
|
| + if (!editing) return; // bail if user canceled
|
| + value = _editBox.value;
|
| + editing = false;
|
| + }
|
| +
|
| + void maybeCancel(KeyboardEvent e) {
|
| + if (e.keyCode == KeyCode.ESC) {
|
| + editing = false;
|
| + }
|
| + }
|
| +}
|
| +
|
| +@polymerInitMethod
|
| +void _init() {
|
| + registerPolymerElement('editable-label', () => new EditableLabel());
|
| +}
|
|
|