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

Unified Diff: chrome/browser/resources/md_bookmarks/store.js

Issue 2637023002: [MD Bookmarks] Add routing. (Closed)
Patch Set: Id is now in the queryParam not path. Store has correct field for back/forwards navigation. Created 3 years, 11 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_bookmarks/store.js
diff --git a/chrome/browser/resources/md_bookmarks/store.js b/chrome/browser/resources/md_bookmarks/store.js
index baddea20b2e1979feb20095a57cae3ba320e3edd..f6d21de4226a0ceed7a9659a3ae9ce1b3a0255f6 100644
--- a/chrome/browser/resources/md_bookmarks/store.js
+++ b/chrome/browser/resources/md_bookmarks/store.js
@@ -48,6 +48,7 @@ var BookmarksStore = Polymer({
'selected-folder-changed': this.onSelectedFolderChanged_.bind(this),
'folder-open-changed': this.onFolderOpenChanged_.bind(this),
'search-term-changed': this.onSearchTermChanged_.bind(this),
+ 'url-changed': this.onUrlChanged_.bind(this),
};
for (var event in this.documentListeners_)
document.addEventListener(event, this.documentListeners_[event]);
@@ -72,8 +73,8 @@ var BookmarksStore = Polymer({
chrome.bookmarks.onChanged.addListener(this.onBookmarkChanged_.bind(this));
},
-////////////////////////////////////////////////////////////////////////////////
-// bookmarks-store, private:
+ //////////////////////////////////////////////////////////////////////////////
+ // bookmarks-store, private:
/**
* @param {BookmarkTreeNode} rootNode
@@ -85,7 +86,9 @@ var BookmarksStore = Polymer({
this.rootNode.path = 'rootNode';
BookmarksStore.generatePaths(rootNode, 0);
BookmarksStore.initNodes(this.rootNode, this.idToNodeMap_);
- this.fire('selected-folder-changed', this.rootNode.children[0].id);
+
+ // Initialize the store's fields from the router.
+ this.onUrlChanged_();
},
/** @private */
@@ -110,7 +113,7 @@ var BookmarksStore = Polymer({
/** @private */
updateSearchDisplay_: function() {
- if (this.searchTerm == '') {
+ if (!this.searchTerm) {
this.fire('selected-folder-changed', this.rootNode.children[0].id);
} else {
chrome.bookmarks.search(this.searchTerm, function(results) {
@@ -150,8 +153,8 @@ var BookmarksStore = Polymer({
delete this.idToNodeMap_[id];
},
-////////////////////////////////////////////////////////////////////////////////
-// bookmarks-store, bookmarks API event listeners:
+ //////////////////////////////////////////////////////////////////////////////
+ // bookmarks-store, bookmarks API event listeners:
/**
* Callback for when a bookmark node is removed.
@@ -191,8 +194,8 @@ var BookmarksStore = Polymer({
this.updateSearchDisplay_();
},
-////////////////////////////////////////////////////////////////////////////////
-// bookmarks-store, bookmarks app event listeners:
+ //////////////////////////////////////////////////////////////////////////////
+ // bookmarks-store, bookmarks app event listeners:
/**
* @param {Event} e
@@ -233,6 +236,21 @@ var BookmarksStore = Polymer({
if (!folder.isOpen && this.isAncestorOfSelected_(folder))
this.fire('selected-folder-changed', folder.id);
},
+
+ /**
+ * Handles events from the router where the url changes.
+ * @private
+ */
+ onUrlChanged_: function() {
+ var id = this.$.router.selectedId;
+ if (this.$.router.searchTerm) {
+ this.searchTerm = this.$.router.searchTerm;
+ } else if (id && id in this.idToNodeMap_ && !this.idToNodeMap_[id].url) {
+ this.fire('selected-folder-changed', id);
+ } else {
+ this.fire('selected-folder-changed', this.rootNode.children[0].id);
+ }
+ },
});
////////////////////////////////////////////////////////////////////////////////

Powered by Google App Engine
This is Rietveld 408576698