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

Unified Diff: chrome/browser/resources/md_history/router.js

Issue 2352293002: MD History: Replace app-route with a custom router (Closed)
Patch Set: Rebase Created 4 years, 3 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 side-by-side diff with in-line comments
Download patch
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);
+ },
+});

Powered by Google App Engine
This is Rietveld 408576698