OLD | NEW |
1 // Copyright (c) 2012, the Dart project authors. Please see the AUTHORS file | 1 // Copyright (c) 2012, 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 main; | 5 library main; |
6 | 6 |
7 import 'dart:html'; | 7 import 'dart:html'; |
8 import 'model.dart'; | 8 import 'model.dart'; |
9 import 'package:web_components/web_components.dart'; | 9 import 'package:web_ui/web_ui.dart'; |
10 | 10 |
11 main() { | 11 main() { |
12 // listen on changes to #hash in the URL | 12 // listen on changes to #hash in the URL |
13 // Note: listen on both popState and hashChange, because IE9 doens't support | 13 // Note: listen on both popState and hashChange, because IE9 doens't support |
14 // history API, and it doesn't work properly on Opera 12. | 14 // history API, and it doesn't work properly on Opera 12. |
15 // See http://dartbug.com/5483 | 15 // See http://dartbug.com/5483 |
16 updateFilters(e) { | 16 updateFilters(e) { |
17 viewModel.showIncomplete = window.location.hash != '#/completed'; | 17 viewModel.showIncomplete = window.location.hash != '#/completed'; |
18 viewModel.showDone = window.location.hash != '#/active'; | 18 viewModel.showDone = window.location.hash != '#/active'; |
19 dispatch(); | 19 dispatch(); |
20 } | 20 } |
21 window.on.hashChange.add(updateFilters); | 21 window.on.hashChange.add(updateFilters); |
22 window.on.popState.add(updateFilters); | 22 window.on.popState.add(updateFilters); |
23 } | 23 } |
24 | 24 |
25 void addTodo(Event e) { | 25 void addTodo(Event e) { |
26 e.preventDefault(); // don't submit the form | 26 e.preventDefault(); // don't submit the form |
27 var input = query('#new-todo'); | 27 var input = query('#new-todo'); |
28 if (input.value == '') return; | 28 if (input.value == '') return; |
29 app.todos.add(new Todo(input.value)); | 29 app.todos.add(new Todo(input.value)); |
30 input.value = ''; | 30 input.value = ''; |
31 } | 31 } |
OLD | NEW |