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

Side by Side Diff: samples/third_party/todomvc/web/editable_label.html

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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 <!DOCTYPE html> 1 <!DOCTYPE html>
2 <!-- 2 <!--
3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file 3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file
4 for details. All rights reserved. Use of this source code is governed by a 4 for details. All rights reserved. Use of this source code is governed by a
5 BSD-style license that can be found in the LICENSE file. 5 BSD-style license that can be found in the LICENSE file.
6 --> 6 -->
7 <html> 7 <html>
8 <head> 8 <head>
9 <meta charset="utf-8"> 9 <meta charset="utf-8">
10 </head> 10 </head>
11 <body> 11 <body>
12 <element name="editable-label" extends="div" apply-author-styles> 12 <polymer-element name="editable-label" attributes="value">
13 <template> 13 <template>
14 <template if="!editing"> 14 <template bind if="{{!editing}}">
15 <label class='edit-label' on-double-click="edit()">{{value}}</label> 15 <label class='edit-label' on-double-click="edit">{{value}}</label>
16 </template> 16 </template>
17 <template if="editing"> 17 <template bind if="{{editing}}">
18 <form on-submit="update($event)"> 18 <form on-submit="update">
19 <input id="edit" class="edit {{editing ? 'editing' : ''}}" 19 <input id="edit" class="edit editing"
20 on-blur="update($event)" 20 on-blur="update" on-key-up="maybeCancel">
21 on-key-up="maybeCancel($event)">
22 </form> 21 </form>
23 </template> 22 </template>
24 </template> 23 </template>
25 <script type="application/dart"> 24 <script type="application/dart" src="editable_label.dart"></script>
26 import 'dart:html'; 25 </polymer-element>
27 import 'package:web_ui/web_ui.dart';
28
29 /**
30 * Label whose [value] can be edited by double clicking. When editing, it
31 * displays a form and input element, otherwise it displays the label. You
32 * can enable two-way binding like this:
33 *
34 * <editable-label bind-value="dartAsignableValue">
35 * </editable-label>
36 */
37 @observable
38 class EditableLabel extends WebComponent {
39 bool editing;
40 String value;
41
42 InputElement get _editBox => getShadowRoot("editable-label").query('#edit');
43
44 void created() {
45 super.created();
46 editing = false;
47 value = '';
48 }
49
50 void edit() {
51 editing = true;
52
53 // This causes _editBox to be inserted.
54 deliverChangesSync();
55
56 // For IE and Firefox: use .focus(), then reset the value to move the
57 // cursor to the end.
58 _editBox.focus();
59 _editBox.value = '';
60 _editBox.value = value;
61 }
62
63 void update(Event e) {
64 e.preventDefault(); // don't submit the form
65 if (!editing) return; // bail if user canceled
66 value = _editBox.value;
67 editing = false;
68 }
69
70 void maybeCancel(KeyEvent e) {
71 if (e.keyCode == KeyCode.ESC) {
72 editing = false;
73 }
74 }
75 }
76 </script>
77 </element>
78 </body> 26 </body>
79 </html> 27 </html>
OLDNEW
« no previous file with comments | « samples/third_party/todomvc/web/editable_label.dart ('k') | samples/third_party/todomvc/web/index.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698