Chromium Code Reviews| Index: chrome/browser/resources/md_history/history_router.js |
| diff --git a/chrome/browser/resources/md_history/history_router.js b/chrome/browser/resources/md_history/history_router.js |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4cb3e3b5f7574f07b6044ee074b0f482bd9f7f5a |
| --- /dev/null |
| +++ b/chrome/browser/resources/md_history/history_router.js |
| @@ -0,0 +1,63 @@ |
| +// Copyright 2016 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +Polymer({ |
| + is: 'history-router', |
| + |
| + properties: { |
| + selectedPage: { |
| + type: String, |
| + observer: 'serializePath_', |
| + notify: true, |
| + }, |
| + |
| + queryState: { |
| + type: Object, |
| + notify: true |
| + }, |
| + |
| + path_: { |
| + type: String, |
| + observer: 'pathChanged_' |
| + }, |
| + |
| + queryParams_: Object, |
| + }, |
| + |
| + observers: [ |
| + 'queryParamsChanged_(queryParams_.*)', |
| + 'queryStateChanged_(queryState.searchTerm)', |
| + ], |
| + |
| + /** @override */ |
| + attached: function() { |
| + // Redirect legacy search URLs to URLs compatible with material history. |
| + if (window.location.hash) { |
| + window.location.href = window.location.href.split('#')[0] + '?' + |
| + window.location.hash.substr(1); |
| + } |
| + }, |
| + |
| + /** @private */ |
| + serializePath_: function() { |
| + var page = this.selectedPage == 'history' ? '' : this.selectedPage; |
| + this.path_ = '/' + page; |
| + }, |
| + |
| + /** @private */ |
| + pathChanged_: function() { |
| + var sections = this.path_.substr(1).split('/'); |
| + this.selectedPage = sections[0] || 'history'; |
| + }, |
| + |
| + /** @private */ |
| + queryParamsChanged_: function() { |
| + this.set('queryState.searchTerm', this.queryParams_.q || ''); |
| + }, |
| + |
| + /** @private */ |
| + queryStateChanged_: function() { |
|
calamity
2016/09/22 05:12:26
searchTermChanged_, perhaps?
tsergeant
2016/09/22 23:57:42
Done.
|
| + this.set('queryParams_.q', this.queryState.searchTerm || null); |
| + }, |
| +}); |