| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // BSD-style license that can be found in the LICENSE file. | |
| 4 | |
| 5 library todomvc.web.router_options; | |
| 6 | |
| 7 import 'dart:html'; | |
| 8 import 'package:polymer/polymer.dart'; | |
| 9 | |
| 10 /** | |
| 11 * Given a set of child links to this page, this will add the "selected" CSS | |
| 12 * class to the link that matches window.location.hash. | |
| 13 * | |
| 14 * For example, if the current window.location.hash is "#/completed" and we | |
| 15 * have a tag like `<a href="#/completed">` it will get the class | |
| 16 * `class="selected"`, and other links will have that CSS class removed. | |
| 17 */ | |
| 18 @CustomTag('router-options') | |
| 19 class RouterOptions extends UListElement with Polymer, Observable { | |
| 20 factory RouterOptions() => new Element.tag('ul', 'router-options'); | |
| 21 | |
| 22 RouterOptions.created() : super.created() { | |
| 23 polymerCreated(); | |
| 24 } | |
| 25 | |
| 26 bool get applyAuthorStyles => true; | |
| 27 var _sub; | |
| 28 | |
| 29 void enteredView() { | |
| 30 super.enteredView(); | |
| 31 | |
| 32 var anchors = this.querySelectorAll('a'); | |
| 33 | |
| 34 _updateHash(records) { | |
| 35 var hash = window.location.hash; | |
| 36 if (hash == '') hash = '#/'; | |
| 37 for (var a in anchors) { | |
| 38 if (a.hash == hash) { | |
| 39 a.classes.add('selected'); | |
| 40 } else { | |
| 41 a.classes.remove('selected'); | |
| 42 } | |
| 43 } | |
| 44 } | |
| 45 | |
| 46 _updateHash(null); | |
| 47 _sub = windowLocation.changes.listen(_updateHash); | |
| 48 } | |
| 49 | |
| 50 void leftView() { | |
| 51 _sub.cancel(); | |
| 52 super.leftView(); | |
| 53 } | |
| 54 } | |
| OLD | NEW |