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

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

Issue 20863002: Introduce boot.js: this finally makes it possible to load and run Todomvc (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: review comments, fixed build.dart 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 'package:observe/observe.dart'; 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 @CustomTag('editable-label')
15 class EditableLabel extends PolymerElement with ObservableMixin { 16 class EditableLabel extends PolymerElement with ObservableMixin {
16 @observable bool editing = false; 17 @observable bool editing = false;
17 @observable String value = ''; 18 @observable String value = '';
18 bool get applyAuthorStyles => true; 19 bool get applyAuthorStyles => true;
19 20
20 // TODO(jmesserly): replace this with allowing not-operator in templates. 21 // TODO(jmesserly): replace this with allowing not-operator in templates.
21 bool get notEditing => !editing; 22 bool get notEditing => !editing;
22 23
23 InputElement get _editBox => getShadowRoot("editable-label").query('#edit'); 24 InputElement get _editBox => getShadowRoot("editable-label").query('#edit');
24 25
25 void created() { 26 void created() {
26 super.created(); 27 super.created();
27 28
28 bindProperty(this, const Symbol('editing'), 29 bindProperty(this, const Symbol('editing'),
29 () => notifyProperty(this, const Symbol('notEditing'))); 30 () => notifyProperty(this, const Symbol('notEditing')));
30 } 31 }
31 32
32 void edit() { 33 void edit() {
33 editing = true; 34 editing = true;
34 35
35 // This causes _editBox to be inserted. 36 // This causes _editBox to be inserted.
36 deliverChangeRecords(); 37 Observable.dirtyCheck();
37 38
38 // For IE and Firefox: use .focus(), then reset the value to move the 39 // TODO(sigmund): remove the 2 runAsync calls. To do so, we might want to
39 // cursor to the end. 40 // make dirtyCheck return a future or something to indicate that all
40 _editBox.focus(); 41 // change propagations are done.
41 _editBox.value = ''; 42 runAsync(() => runAsync(() {
42 _editBox.value = value; 43 // For IE and Firefox: use .focus(), then reset the value to move the
44 // cursor to the end.
45 _editBox.focus();
46 _editBox.value = '';
47 _editBox.value = value;
48 }));
43 } 49 }
44 50
45 void update(Event e) { 51 void update(Event e) {
46 e.preventDefault(); // don't submit the form 52 e.preventDefault(); // don't submit the form
47 if (!editing) return; // bail if user canceled 53 if (!editing) return; // bail if user canceled
48 value = _editBox.value; 54 value = _editBox.value;
49 editing = false; 55 editing = false;
50 } 56 }
51 57
52 void maybeCancel(KeyboardEvent e) { 58 void maybeCancel(KeyboardEvent e) {
53 if (e.keyCode == KeyCode.ESC) { 59 if (e.keyCode == KeyCode.ESC) {
54 editing = false; 60 editing = false;
55 } 61 }
56 } 62 }
57 } 63 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698