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

Side by Side Diff: chrome/browser/resources/md_bookmarks/app.js

Issue 2745593004: [MD Bookmarks] Add draggable sidebar. (Closed)
Patch Set: rebase Created 3 years, 9 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 unified diff | Download patch
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 Polymer({ 5 Polymer({
6 is: 'bookmarks-app', 6 is: 'bookmarks-app',
7 7
8 behaviors: [ 8 behaviors: [
9 bookmarks.StoreClient, 9 bookmarks.StoreClient,
10 ], 10 ],
11 11
12 properties: { 12 properties: {
13 /** @private */ 13 /** @private */
14 searchTerm_: { 14 searchTerm_: {
15 type: String, 15 type: String,
16 observer: 'searchTermChanged_', 16 observer: 'searchTermChanged_',
17 }, 17 },
18
19 /** @private */
20 sidebarWidth_: String,
18 }, 21 },
19 22
23 /** @private{?function(!Event)} */
24 boundUpdateSidebarWidth_: null,
25
20 /** @override */ 26 /** @override */
21 attached: function() { 27 attached: function() {
22 this.watch('searchTerm_', function(store) { 28 this.watch('searchTerm_', function(store) {
23 return store.search.term; 29 return store.search.term;
24 }); 30 });
25 31
26 chrome.bookmarks.getTree(function(results) { 32 chrome.bookmarks.getTree(function(results) {
27 var nodeList = bookmarks.util.normalizeNodes(results[0]); 33 var nodeList = bookmarks.util.normalizeNodes(results[0]);
28 var initialState = bookmarks.util.createEmptyState(); 34 var initialState = bookmarks.util.createEmptyState();
29 initialState.nodes = nodeList; 35 initialState.nodes = nodeList;
30 initialState.selectedFolder = nodeList['0'].children[0]; 36 initialState.selectedFolder = nodeList['0'].children[0];
31 37
32 bookmarks.Store.getInstance().init(initialState); 38 bookmarks.Store.getInstance().init(initialState);
33 bookmarks.ApiListener.init(); 39 bookmarks.ApiListener.init();
40
34 }.bind(this)); 41 }.bind(this));
42
43 this.boundUpdateSidebarWidth_ = this.updateSidebarWidth_.bind(this);
44
45 this.initializeSplitter_();
46 },
47
48 detached: function() {
49 window.removeEventListener('resize', this.boundUpdateSidebarWidth_);
50 },
51
52 /**
53 * Set up the splitter and set the initial width from localStorage.
54 * @private
55 */
56 initializeSplitter_: function() {
57 var splitter = this.$.splitter;
58 cr.ui.Splitter.decorate(splitter);
59 var splitterTarget = this.$.sidebar;
60
61 // The splitter persists the size of the left component in the local store.
62 if ('treeWidth' in window.localStorage) {
63 splitterTarget.style.width = window.localStorage['treeWidth'];
64 this.sidebarWidth_ = splitterTarget.getComputedStyleValue('width');
65 }
66
67 splitter.addEventListener('resize', function(e) {
68 window.localStorage['treeWidth'] = splitterTarget.style.width;
69 // TODO(calamity): This only fires when the resize is complete. This
70 // should be updated on every width change.
71 this.updateSidebarWidth_();
72 }.bind(this));
73
74 window.addEventListener('resize', this.boundUpdateSidebarWidth_);
75 },
76
77 /** @private */
78 updateSidebarWidth_: function() {
79 this.sidebarWidth_ = this.$.sidebar.getComputedStyleValue('width');
35 }, 80 },
36 81
37 searchTermChanged_: function() { 82 searchTermChanged_: function() {
38 if (!this.searchTerm_) 83 if (!this.searchTerm_)
39 return; 84 return;
40 85
41 chrome.bookmarks.search(this.searchTerm_, function(results) { 86 chrome.bookmarks.search(this.searchTerm_, function(results) {
42 var ids = results.map(function(node) { 87 var ids = results.map(function(node) {
43 return node.id; 88 return node.id;
44 }); 89 });
45 this.dispatch(bookmarks.actions.setSearchResults(ids)); 90 this.dispatch(bookmarks.actions.setSearchResults(ids));
46 }.bind(this)); 91 }.bind(this));
47 }, 92 },
48 }); 93 });
OLDNEW
« no previous file with comments | « chrome/browser/resources/md_bookmarks/app.html ('k') | chrome/browser/resources/md_bookmarks/compiled_resources2.gyp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698