OLD | NEW |
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 // TODO(jmesserly): can we handle this more elegantly? | 5 // TODO(jmesserly): can we handle this more elegantly? |
6 // In general, it seems like we want a convenient way to take a Stream plus a | 6 // In general, it seems like we want a convenient way to take a Stream plus a |
7 // getter and convert this into an Observable. | 7 // getter and convert this into an Observable. |
8 | 8 |
9 /** Helpers for exposing dart:html as observable data. */ | 9 /** Helpers for exposing dart:html as observable data. */ |
10 library polymer.observe_html; | 10 library polymer.observe_html; |
(...skipping 14 matching lines...) Expand all Loading... |
25 window.onHashChange.listen(_notifyHashChange); | 25 window.onHashChange.listen(_notifyHashChange); |
26 window.onPopState.listen(_notifyHashChange); | 26 window.onPopState.listen(_notifyHashChange); |
27 } | 27 } |
28 | 28 |
29 String get hash => window.location.hash; | 29 String get hash => window.location.hash; |
30 | 30 |
31 /** | 31 /** |
32 * Pushes a new URL state, similar to the affect of clicking a link. | 32 * Pushes a new URL state, similar to the affect of clicking a link. |
33 * Has no effect if the [value] already equals [window.location.hash]. | 33 * Has no effect if the [value] already equals [window.location.hash]. |
34 */ | 34 */ |
35 set hash(String value) { | 35 void set hash(String value) { |
36 if (value == hash) return; | 36 if (value == hash) return; |
37 | 37 |
38 window.history.pushState(null, '', value); | 38 window.history.pushState(null, '', value); |
39 _notifyHashChange(null); | 39 _notifyHashChange(null); |
40 } | 40 } |
41 | 41 |
42 _notifyHashChange(_) { | 42 void _notifyHashChange(_) { |
43 notifyChange(new PropertyChangeRecord(const Symbol('hash'))); | 43 notifyChange(new PropertyChangeRecord(const Symbol('hash'))); |
44 } | 44 } |
45 } | 45 } |
46 | 46 |
47 /** Add or remove CSS class [className] based on the [value]. */ | 47 /** Add or remove CSS class [className] based on the [value]. */ |
48 void updateCssClass(Element element, String className, bool value) { | 48 void updateCssClass(Element element, String className, bool value) { |
49 if (value == true) { | 49 if (value == true) { |
50 element.classes.add(className); | 50 element.classes.add(className); |
51 } else { | 51 } else { |
52 element.classes.remove(className); | 52 element.classes.remove(className); |
53 } | 53 } |
54 } | 54 } |
55 | 55 |
56 /** Bind a CSS class to the observable [object] and property [path]. */ | 56 /** Bind a CSS class to the observable [object] and property [path]. */ |
57 PathObserver bindCssClass(Element element, String className, | 57 PathObserver bindCssClass(Element element, String className, |
58 Observable object, String path) { | 58 Observable object, String path) { |
59 | 59 |
60 return new PathObserver(object, path)..bindSync((value) { | 60 return new PathObserver(object, path)..bindSync((value) { |
61 updateCssClass(element, className, value); | 61 updateCssClass(element, className, value); |
62 }); | 62 }); |
63 } | 63 } |
OLD | NEW |