Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(95)

Side by Side Diff: example/todomvc/web/router_options.dart

Issue 19497002: Reducing the amount of code we generate in the compiler: We still continue (Closed) Base URL: git@github.com:dart-lang/web-ui.git@master
Patch Set: Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 library router_options; 5 library router_options;
6 6
7 import 'dart:html'; 7 import 'dart:html';
8 import 'package:polymer/polymer.dart'; 8 import 'package:polymer/polymer.dart';
9 9
10 /** 10 /**
11 * Given a set of child links to this page, this will add the "selected" CSS 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. 12 * class to the link that matches window.location.hash.
13 * 13 *
14 * For example, if the current window.location.hash is "#/completed" and we 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 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. 16 * `class="selected"`, and other links will have that CSS class removed.
17 */ 17 */
18 class RouterOptions extends CustomElement { 18 class RouterOptions extends PolymerElement {
19 19
20 bool get applyAuthorStyles => true;
20 var _sub; 21 var _sub;
21 22
22 void inserted() { 23 void inserted() {
23 super.inserted(); 24 super.inserted();
24 25
25 var anchors = this.queryAll('a'); 26 var anchors = this.queryAll('a');
26 27
27 _updateHash(records) { 28 _updateHash(records) {
28 var hash = window.location.hash; 29 var hash = window.location.hash;
29 if (hash == '') hash = '#/'; 30 if (hash == '') hash = '#/';
30 for (var a in anchors) { 31 for (var a in anchors) {
31 if (a.hash == hash) { 32 if (a.hash == hash) {
32 a.classes.add('selected'); 33 a.classes.add('selected');
33 } else { 34 } else {
34 a.classes.remove('selected'); 35 a.classes.remove('selected');
35 } 36 }
36 } 37 }
37 } 38 }
38 39
39 _updateHash(null); 40 _updateHash(null);
40 _sub = windowLocation.changes.listen(_updateHash); 41 _sub = windowLocation.changes.listen(_updateHash);
41 } 42 }
42 43
43 void removed() { 44 void removed() {
44 _sub.cancel(); 45 _sub.cancel();
45 super.removed(); 46 super.removed();
46 } 47 }
47 } 48 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698