OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 Polymer({ | |
6 is: 'history-router', | |
7 | |
8 properties: { | |
9 selectedPage: { | |
10 type: String, | |
11 observer: 'serializePath_', | |
12 notify: true, | |
13 }, | |
14 | |
15 queryState: { | |
16 type: Object, | |
17 notify: true | |
18 }, | |
19 | |
20 path_: { | |
21 type: String, | |
22 observer: 'pathChanged_' | |
23 }, | |
24 | |
25 queryParams_: Object, | |
26 }, | |
27 | |
28 observers: [ | |
29 'queryParamsChanged_(queryParams_.*)', | |
30 'queryStateChanged_(queryState.searchTerm)', | |
31 ], | |
32 | |
33 /** @override */ | |
34 attached: function() { | |
35 // Redirect legacy search URLs to URLs compatible with material history. | |
36 if (window.location.hash) { | |
37 window.location.href = window.location.href.split('#')[0] + '?' + | |
38 window.location.hash.substr(1); | |
39 } | |
40 }, | |
41 | |
42 /** @private */ | |
43 serializePath_: function() { | |
44 var page = this.selectedPage == 'history' ? '' : this.selectedPage; | |
45 this.path_ = '/' + page; | |
46 }, | |
47 | |
48 /** @private */ | |
49 pathChanged_: function() { | |
50 var sections = this.path_.substr(1).split('/'); | |
51 this.selectedPage = sections[0] || 'history'; | |
52 }, | |
53 | |
54 /** @private */ | |
55 queryParamsChanged_: function() { | |
56 this.set('queryState.searchTerm', this.queryParams_.q || ''); | |
57 }, | |
58 | |
59 /** @private */ | |
60 queryStateChanged_: function() { | |
calamity
2016/09/22 05:12:26
searchTermChanged_, perhaps?
tsergeant
2016/09/22 23:57:42
Done.
| |
61 this.set('queryParams_.q', this.queryState.searchTerm || null); | |
62 }, | |
63 }); | |
OLD | NEW |