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: { | 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 | 18 |
| 19 closedFoldersState_: { |
| 20 type: Object, |
| 21 observer: 'closedFoldersStateChanged_', |
| 22 }, |
| 23 |
19 /** @private */ | 24 /** @private */ |
20 sidebarWidth_: String, | 25 sidebarWidth_: String, |
21 }, | 26 }, |
22 | 27 |
23 /** @private{?function(!Event)} */ | 28 /** @private{?function(!Event)} */ |
24 boundUpdateSidebarWidth_: null, | 29 boundUpdateSidebarWidth_: null, |
25 | 30 |
26 /** @private {bookmarks.DNDManager} */ | 31 /** @private {bookmarks.DNDManager} */ |
27 dndManager_: null, | 32 dndManager_: null, |
28 | 33 |
29 /** @override */ | 34 /** @override */ |
30 attached: function() { | 35 attached: function() { |
31 this.watch('searchTerm_', function(store) { | 36 this.watch('searchTerm_', function(store) { |
32 return store.search.term; | 37 return store.search.term; |
33 }); | 38 }); |
34 | 39 |
| 40 this.watch('closedFoldersState_', function(store) { |
| 41 return store.closedFolders; |
| 42 }); |
| 43 |
35 chrome.bookmarks.getTree(function(results) { | 44 chrome.bookmarks.getTree(function(results) { |
36 var nodeList = bookmarks.util.normalizeNodes(results[0]); | 45 var nodeList = bookmarks.util.normalizeNodes(results[0]); |
37 var initialState = bookmarks.util.createEmptyState(); | 46 var initialState = bookmarks.util.createEmptyState(); |
38 initialState.nodes = nodeList; | 47 initialState.nodes = nodeList; |
39 initialState.selectedFolder = | 48 initialState.selectedFolder = nodeList[ROOT_NODE_ID].children[0]; |
40 nodeList[bookmarks.util.ROOT_NODE_ID].children[0]; | 49 var closedFoldersString = |
| 50 window.localStorage[LOCAL_STORAGE_CLOSED_FOLDERS_KEY]; |
| 51 initialState.closedFolders = closedFoldersString ? |
| 52 /** @type {!Object<string,boolean>} */ ( |
| 53 JSON.parse(closedFoldersString)) : |
| 54 {}; |
41 | 55 |
42 bookmarks.Store.getInstance().init(initialState); | 56 bookmarks.Store.getInstance().init(initialState); |
43 bookmarks.ApiListener.init(); | 57 bookmarks.ApiListener.init(); |
44 | 58 |
45 }.bind(this)); | 59 }.bind(this)); |
46 | 60 |
47 this.boundUpdateSidebarWidth_ = this.updateSidebarWidth_.bind(this); | 61 this.boundUpdateSidebarWidth_ = this.updateSidebarWidth_.bind(this); |
48 | 62 |
49 this.initializeSplitter_(); | 63 this.initializeSplitter_(); |
50 | 64 |
(...skipping 29 matching lines...) Expand all Loading... |
80 }.bind(this)); | 94 }.bind(this)); |
81 | 95 |
82 window.addEventListener('resize', this.boundUpdateSidebarWidth_); | 96 window.addEventListener('resize', this.boundUpdateSidebarWidth_); |
83 }, | 97 }, |
84 | 98 |
85 /** @private */ | 99 /** @private */ |
86 updateSidebarWidth_: function() { | 100 updateSidebarWidth_: function() { |
87 this.sidebarWidth_ = this.$.sidebar.getComputedStyleValue('width'); | 101 this.sidebarWidth_ = this.$.sidebar.getComputedStyleValue('width'); |
88 }, | 102 }, |
89 | 103 |
| 104 /** @private */ |
90 searchTermChanged_: function() { | 105 searchTermChanged_: function() { |
91 if (!this.searchTerm_) | 106 if (!this.searchTerm_) |
92 return; | 107 return; |
93 | 108 |
94 chrome.bookmarks.search(this.searchTerm_, function(results) { | 109 chrome.bookmarks.search(this.searchTerm_, function(results) { |
95 var ids = results.map(function(node) { | 110 var ids = results.map(function(node) { |
96 return node.id; | 111 return node.id; |
97 }); | 112 }); |
98 this.dispatch(bookmarks.actions.setSearchResults(ids)); | 113 this.dispatch(bookmarks.actions.setSearchResults(ids)); |
99 }.bind(this)); | 114 }.bind(this)); |
100 }, | 115 }, |
| 116 |
| 117 /** @private */ |
| 118 closedFoldersStateChanged_: function() { |
| 119 window.localStorage[LOCAL_STORAGE_CLOSED_FOLDERS_KEY] = |
| 120 JSON.stringify(this.closedFoldersState_); |
| 121 }, |
101 }); | 122 }); |
OLD | NEW |