| Index: chrome/browser/resources/md_history/router.js
|
| diff --git a/chrome/browser/resources/md_history/router.js b/chrome/browser/resources/md_history/router.js
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8d7b196bdc36221a753a6f878e9ab0caf0abf384
|
| --- /dev/null
|
| +++ b/chrome/browser/resources/md_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_.*)',
|
| + 'searchTermChanged_(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 */
|
| + searchTermChanged_: function() {
|
| + this.set('queryParams_.q', this.queryState.searchTerm || null);
|
| + },
|
| +});
|
|
|