Chromium Code Reviews| OLD | NEW |
|---|---|
| 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 hideSplitter_: Boolean, | |
|
tsergeant
2017/03/13 02:46:33
Nit: \n, @private
calamity
2017/03/13 07:04:50
Done.
| |
| 14 sidebarWidth_: String, | |
| 15 }, | |
| 16 | |
| 12 /** @override */ | 17 /** @override */ |
| 13 attached: function() { | 18 attached: function() { |
| 14 chrome.bookmarks.getTree(function(results) { | 19 chrome.bookmarks.getTree(function(results) { |
| 15 var nodeList = bookmarks.util.normalizeNodes(results[0]); | 20 var nodeList = bookmarks.util.normalizeNodes(results[0]); |
| 16 var initialState = bookmarks.util.createEmptyState(); | 21 var initialState = bookmarks.util.createEmptyState(); |
| 17 initialState.nodes = nodeList; | 22 initialState.nodes = nodeList; |
| 18 initialState.selectedFolder = nodeList['0'].children[0]; | 23 initialState.selectedFolder = nodeList['0'].children[0]; |
| 19 | 24 |
| 20 bookmarks.Store.getInstance().init(initialState); | 25 bookmarks.Store.getInstance().init(initialState); |
| 21 bookmarks.ApiListener.init(); | 26 bookmarks.ApiListener.init(); |
| 27 | |
| 28 Polymer.RenderStatus.afterNextRender(this, this.updateSplitter_); | |
| 29 }.bind(this)); | |
| 30 | |
| 31 this.initializeSplitter_(); | |
| 32 bookmarks.Store.getInstance().addObserver(this); | |
|
tsergeant
2017/03/13 02:46:33
This line shouldn't be necessary? StoreClient alre
calamity
2017/03/13 07:04:50
Oops. Done.
| |
| 33 }, | |
| 34 | |
| 35 /** | |
| 36 * Set up the splitter and set the initial width from localStorage. | |
|
tsergeant
2017/03/13 02:46:33
@private
calamity
2017/03/13 07:04:50
Done.
| |
| 37 */ | |
| 38 initializeSplitter_: function() { | |
| 39 var splitter = this.$.splitter; | |
| 40 cr.ui.Splitter.decorate(splitter); | |
| 41 var splitterTarget = splitter.previousElementSibling; | |
| 42 | |
| 43 // The splitter persists the size of the left component in the local store. | |
| 44 if ('treeWidth' in window.localStorage) { | |
| 45 splitterTarget.style.width = window.localStorage['treeWidth']; | |
| 46 this.sidebarWidth_ = splitterTarget.getComputedStyleValue('width'); | |
| 47 } | |
| 48 | |
| 49 splitter.addEventListener('resize', function(e) { | |
| 50 window.localStorage['treeWidth'] = splitterTarget.style.width; | |
| 51 // TODO(calamity): This only fires when the resize is complete. This | |
| 52 // should be updated on every width change. | |
| 53 this.sidebarWidth_ = splitterTarget.getComputedStyleValue('width'); | |
| 22 }.bind(this)); | 54 }.bind(this)); |
| 23 }, | 55 }, |
| 56 | |
| 57 /** | |
| 58 * Shows/hides the splitter and sets the max and min width of the sidebar when | |
| 59 * resized by the splitter. | |
| 60 */ | |
| 61 updateSplitter_: function() { | |
|
tsergeant
2017/03/13 02:46:33
This only runs on startup, right?
So if the split
calamity
2017/03/13 07:04:50
Removed sneaky hiding behavior as discussed.
| |
| 62 // TODO(calamity): Make this work when folders are closed on startup. | |
| 63 var sidebar = this.$.sidebar; | |
| 64 this.hideSplitter_ = sidebar.offsetHeight == sidebar.scrollHeight && | |
| 65 `${sidebar.offsetWidth}px` == | |
| 66 sidebar.getComputedStyleValue('min-width'); | |
| 67 }, | |
| 24 }); | 68 }); |
| OLD | NEW |