| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <!-- | 2 <!-- |
| 3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file | 3 Copyright (c) 2013, the Dart project authors. Please see the AUTHORS file |
| 4 for details. All rights reserved. Use of this source code is governed by a | 4 for details. All rights reserved. Use of this source code is governed by a |
| 5 BSD-style license that can be found in the LICENSE file. | 5 BSD-style license that can be found in the LICENSE file. |
| 6 --> | 6 --> |
| 7 <html> | 7 <html> |
| 8 <head> | 8 <head> |
| 9 <meta charset="utf-8"> | 9 <meta charset="utf-8"> |
| 10 </head> | 10 </head> |
| 11 <body> | 11 <body> |
| 12 <element name="router-options" extends="ul" apply-author-styles> | 12 <polymer-element name="router-options" extends="ul"> |
| 13 <template><content></content></template> | 13 <template><content></content></template> |
| 14 <script type="application/dart"> | 14 <script type="application/dart" src="router_options.dart"></script> |
| 15 import 'dart:html'; | 15 </polymer-element> |
| 16 import 'package:web_ui/web_ui.dart'; | |
| 17 import 'package:web_ui/observe/html.dart'; | |
| 18 | |
| 19 /** | |
| 20 * Given a set of child links to this page, this will add the "selected" CSS | |
| 21 * class to the link that matches window.location.hash. | |
| 22 * | |
| 23 * For example, if the current window.location.hash is "#/completed" and we | |
| 24 * have a tag like `<a href="#/completed">` it will get the class | |
| 25 * `class="selected"`, and other links will have that CSS class removed. | |
| 26 */ | |
| 27 class RouterOptions extends WebComponent { | |
| 28 | |
| 29 var _stopWatcher; | |
| 30 | |
| 31 void inserted() { | |
| 32 super.inserted(); | |
| 33 | |
| 34 var anchors = this.queryAll('a'); | |
| 35 | |
| 36 _stopWatcher = watchAndInvoke(() => locationHash, (e) { | |
| 37 var hash = e.newValue; | |
| 38 if (hash == '') hash = '#/'; | |
| 39 for (var a in anchors) { | |
| 40 updateCssClass(a, a.hash == hash, 'selected'); | |
| 41 } | |
| 42 }); | |
| 43 } | |
| 44 | |
| 45 void removed() { | |
| 46 _stopWatcher(); | |
| 47 super.removed(); | |
| 48 } | |
| 49 } | |
| 50 </script> | |
| 51 </element> | |
| 52 </body> | 16 </body> |
| 53 </html> | 17 </html> |
| OLD | NEW |