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_ui/web_ui.dart'; | 9 import 'package:web_ui/web_ui.dart'; |
10 | 10 |
11 main() { | 11 main() {} |
12 // listen on changes to #hash in the URL | |
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. | |
15 // See http://dartbug.com/5483 | |
16 updateFilters(e) { | |
17 viewModel.showIncomplete = window.location.hash != '#/completed'; | |
18 viewModel.showDone = window.location.hash != '#/active'; | |
19 dispatch(); | |
20 } | |
21 window.onHashChange.listen(updateFilters); | |
22 window.onPopState.listen(updateFilters); | |
23 } | |
24 | 12 |
25 void addTodo(Event e) { | 13 void addTodo(Event e) { |
26 e.preventDefault(); // don't submit the form | 14 e.preventDefault(); // don't submit the form |
27 var input = query('#new-todo'); | 15 var input = query('#new-todo'); |
28 if (input.value == '') return; | 16 if (input.value == '') return; |
29 app.todos.add(new Todo(input.value)); | 17 app.todos.add(new Todo(input.value)); |
30 input.value = ''; | 18 input.value = ''; |
31 } | 19 } |
OLD | NEW |