Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(215)

Unified Diff: samples/third_party/todomvc/web/editable_label.dart

Issue 23224003: move polymer.dart into dart svn (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge/dart
Patch Set: add --deploy to todomvc sample Created 7 years, 4 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « samples/third_party/todomvc/web/app.html ('k') | samples/third_party/todomvc/web/editable_label.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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());
+}
« no previous file with comments | « samples/third_party/todomvc/web/app.html ('k') | samples/third_party/todomvc/web/editable_label.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698