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

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

Issue 2745593004: [MD Bookmarks] Add draggable sidebar. (Closed)
Patch Set: address comments, add window resize handler 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: {
13 /** @private */
14 sidebarWidth_: String,
15 },
16
17 /** @private{?function(!Event)} */
18 boundUpdateSidebarWidth_: null,
19
12 /** @override */ 20 /** @override */
13 attached: function() { 21 attached: function() {
14 chrome.bookmarks.getTree(function(results) { 22 chrome.bookmarks.getTree(function(results) {
15 var nodeList = bookmarks.util.normalizeNodes(results[0]); 23 var nodeList = bookmarks.util.normalizeNodes(results[0]);
16 var initialState = bookmarks.util.createEmptyState(); 24 var initialState = bookmarks.util.createEmptyState();
17 initialState.nodes = nodeList; 25 initialState.nodes = nodeList;
18 initialState.selectedFolder = nodeList['0'].children[0]; 26 initialState.selectedFolder = nodeList['0'].children[0];
19 27
20 bookmarks.Store.getInstance().init(initialState); 28 bookmarks.Store.getInstance().init(initialState);
21 bookmarks.ApiListener.init(); 29 bookmarks.ApiListener.init();
30
22 }.bind(this)); 31 }.bind(this));
32
33 this.boundUpdateSidebarWidth_ = this.updateSidebarWidth_.bind(this);
34
35 this.initializeSplitter_();
36 },
37
38 detached: function() {
39 window.removeEventListener('resize', this.boundUpdateSidebarWidth_);
40 },
41
42 /**
43 * Set up the splitter and set the initial width from localStorage.
44 * @private
45 */
46 initializeSplitter_: function() {
47 var splitter = this.$.splitter;
48 cr.ui.Splitter.decorate(splitter);
49 var splitterTarget = this.$.sidebar;
50
51 // The splitter persists the size of the left component in the local store.
52 if ('treeWidth' in window.localStorage) {
53 splitterTarget.style.width = window.localStorage['treeWidth'];
54 this.sidebarWidth_ = splitterTarget.getComputedStyleValue('width');
55 }
56
57 splitter.addEventListener('resize', function(e) {
58 window.localStorage['treeWidth'] = splitterTarget.style.width;
59 // TODO(calamity): This only fires when the resize is complete. This
60 // should be updated on every width change.
61 this.updateSidebarWidth_();
62 }.bind(this));
63
64 window.addEventListener('resize', this.boundUpdateSidebarWidth_);
65 },
66
67 /** @private */
68 updateSidebarWidth_: function() {
69 this.sidebarWidth_ = this.$.sidebar.getComputedStyleValue('width');
23 }, 70 },
24 }); 71 });
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698