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

Side by Side Diff: example/todomvc/web/editable_label.dart

Issue 22254002: fixes for latest SDK (Closed) Base URL: https://github.com/dart-lang/web-ui.git@master
Patch Set: fix comments 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
OLDNEW
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 editable_label; 5 library editable_label;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 import 'dart:async'; 8 import 'dart:async';
9 import 'package:polymer/polymer.dart'; 9 import 'package:polymer/polymer.dart';
10 10
11 /** 11 /**
12 * Label whose [value] can be edited by double clicking. When editing, it 12 * Label whose [value] can be edited by double clicking. When editing, it
13 * displays a form and input element, otherwise it displays the label. 13 * displays a form and input element, otherwise it displays the label.
14 */ 14 */
15 class EditableLabel extends PolymerElement with ObservableMixin { 15 class EditableLabel extends PolymerElement with ObservableMixin {
16 @observable bool editing = false; 16 @observable bool editing = false;
17 @observable String value = ''; 17 @observable String value = '';
18 bool get applyAuthorStyles => true; 18 bool get applyAuthorStyles => true;
19 19
20 // TODO(jmesserly): replace this with allowing not-operator in templates.
21 bool get notEditing => !editing;
22
23 InputElement get _editBox => getShadowRoot("editable-label").query('#edit'); 20 InputElement get _editBox => getShadowRoot("editable-label").query('#edit');
24 21
25 void created() {
26 super.created();
27
28 bindProperty(this, const Symbol('editing'),
29 () => notifyProperty(this, const Symbol('notEditing')));
30 }
31
32 void edit() { 22 void edit() {
33 editing = true; 23 editing = true;
34 24
35 // This causes _editBox to be inserted. 25 // This causes _editBox to be inserted.
36 Observable.dirtyCheck(); 26 performMicrotaskCheckpoint();
37 27
38 // TODO(sigmund): remove the 2 runAsync calls. To do so, we might want to 28 // For IE and Firefox: use .focus(), then reset the value to move the
39 // make dirtyCheck return a future or something to indicate that all 29 // cursor to the end.
40 // change propagations are done. 30 _editBox.focus();
41 runAsync(() => runAsync(() { 31 _editBox.value = '';
42 // For IE and Firefox: use .focus(), then reset the value to move the 32 _editBox.value = value;
43 // cursor to the end.
44 _editBox.focus();
45 _editBox.value = '';
46 _editBox.value = value;
47 }));
48 } 33 }
49 34
50 void update(Event e) { 35 void update(Event e) {
51 e.preventDefault(); // don't submit the form 36 e.preventDefault(); // don't submit the form
52 if (!editing) return; // bail if user canceled 37 if (!editing) return; // bail if user canceled
53 value = _editBox.value; 38 value = _editBox.value;
54 editing = false; 39 editing = false;
55 } 40 }
56 41
57 void maybeCancel(KeyboardEvent e) { 42 void maybeCancel(KeyboardEvent e) {
58 if (e.keyCode == KeyCode.ESC) { 43 if (e.keyCode == KeyCode.ESC) {
59 editing = false; 44 editing = false;
60 } 45 }
61 } 46 }
62 } 47 }
63 48
64 @polymerInitMethod 49 @polymerInitMethod
65 void _init() { 50 void _init() {
66 registerPolymerElement('editable-label', () => new EditableLabel()); 51 registerPolymerElement('editable-label', () => new EditableLabel());
67 } 52 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698