| 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-store', | 6 is: 'bookmarks-store', |
| 7 | 7 |
| 8 properties: { | 8 properties: { |
| 9 /** @type {BookmarkTreeNode} */ | 9 /** @type {BookmarkTreeNode} */ |
| 10 rootNode: { | 10 rootNode: { |
| 11 type: Object, | 11 type: Object, |
| 12 notify: true, | 12 notify: true, |
| 13 }, | 13 }, |
| 14 | 14 |
| 15 selectedId: { | 15 selectedId: { |
| 16 type: String, | 16 type: String, |
| 17 observer: 'updateSelectedNode_', | 17 observer: 'updateSelectedNode_', |
| 18 notify: true, | 18 notify: true, |
| 19 }, | 19 }, |
| 20 | 20 |
| 21 /** @type {BookmarkTreeNode} */ | 21 /** @type {BookmarkTreeNode} */ |
| 22 selectedNode: { | 22 selectedNode: { |
| 23 type: Object, | 23 type: Object, |
| 24 notify: true, | 24 notify: true, |
| 25 readOnly: true, | 25 readOnly: true, |
| 26 }, | 26 }, |
| 27 | 27 |
| 28 idToNodeMap_: Object, | 28 idToNodeMap_: Object, |
| 29 |
| 30 searchTerm: { |
| 31 type: String, |
| 32 observer: 'updateSearchResult_', |
| 33 notify: true, |
| 34 }, |
| 35 |
| 36 searchResult: { |
| 37 type: Array, |
| 38 value: [], |
| 39 notify: true, |
| 40 }, |
| 29 }, | 41 }, |
| 30 | 42 |
| 31 /** @private {Object} */ | 43 /** @private {Object} */ |
| 32 documentListeners_: null, | 44 documentListeners_: null, |
| 33 | 45 |
| 34 /** @override */ | 46 /** @override */ |
| 35 attached: function() { | 47 attached: function() { |
| 36 this.documentListeners_ = { | 48 this.documentListeners_ = { |
| 37 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this), | 49 'selected-folder-changed': this.onSelectedFolderChanged_.bind(this), |
| 38 'folder-open-changed': this.onFolderOpenChanged_.bind(this), | 50 'folder-open-changed': this.onFolderOpenChanged_.bind(this), |
| 51 'search-term-changed': this.onSearchTermChanged_.bind(this), |
| 39 }; | 52 }; |
| 40 for (var event in this.documentListeners_) | 53 for (var event in this.documentListeners_) |
| 41 document.addEventListener(event, this.documentListeners_[event]); | 54 document.addEventListener(event, this.documentListeners_[event]); |
| 42 }, | 55 }, |
| 43 | 56 |
| 44 /** @override */ | 57 /** @override */ |
| 45 detached: function() { | 58 detached: function() { |
| 46 for (var event in this.documentListeners_) | 59 for (var event in this.documentListeners_) |
| 47 document.removeEventListener(event, this.documentListeners_[event]); | 60 document.removeEventListener(event, this.documentListeners_[event]); |
| 48 }, | 61 }, |
| (...skipping 20 matching lines...) Expand all Loading... |
| 69 this.fire('selected-folder-changed', this.rootNode.children[0].id); | 82 this.fire('selected-folder-changed', this.rootNode.children[0].id); |
| 70 }, | 83 }, |
| 71 | 84 |
| 72 /** | 85 /** |
| 73 * Selects the folder specified by the event and deselects the previously | 86 * Selects the folder specified by the event and deselects the previously |
| 74 * selected folder. | 87 * selected folder. |
| 75 * @param {CustomEvent} e | 88 * @param {CustomEvent} e |
| 76 * @private | 89 * @private |
| 77 */ | 90 */ |
| 78 onSelectedFolderChanged_: function(e) { | 91 onSelectedFolderChanged_: function(e) { |
| 92 // Clear search and thus set the sidebar to active. |
| 93 this.set('searchTerm', ''); |
| 94 |
| 79 // Deselect the old folder if defined. | 95 // Deselect the old folder if defined. |
| 80 if (this.selectedId) | 96 if (this.selectedId) |
| 81 this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false); | 97 this.set(this.idToNodeMap_[this.selectedId].path + '.isSelected', false); |
| 82 | 98 |
| 83 var selectedId = /** @type {string} */ (e.detail); | 99 var selectedId = /** @type {string} */ (e.detail); |
| 84 var newFolder = this.idToNodeMap_[selectedId]; | 100 var newFolder = this.idToNodeMap_[selectedId]; |
| 85 this.set(newFolder.path + '.isSelected', true); | 101 this.set(newFolder.path + '.isSelected', true); |
| 86 this.selectedId = selectedId; | 102 this.selectedId = selectedId; |
| 87 }, | 103 }, |
| 88 | 104 |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 if (bookmarkNode.url) | 144 if (bookmarkNode.url) |
| 129 return; | 145 return; |
| 130 | 146 |
| 131 bookmarkNode.isSelected = false; | 147 bookmarkNode.isSelected = false; |
| 132 bookmarkNode.isOpen = true; | 148 bookmarkNode.isOpen = true; |
| 133 for (var i = 0; i < bookmarkNode.children.length; i++) { | 149 for (var i = 0; i < bookmarkNode.children.length; i++) { |
| 134 bookmarkNode.children[i].path = bookmarkNode.path + '.children.' + i; | 150 bookmarkNode.children[i].path = bookmarkNode.path + '.children.' + i; |
| 135 this.initNodes_(bookmarkNode.children[i]); | 151 this.initNodes_(bookmarkNode.children[i]); |
| 136 } | 152 } |
| 137 }, | 153 }, |
| 154 |
| 155 /** |
| 156 * @param {Event} e |
| 157 * @private |
| 158 */ |
| 159 onSearchTermChanged_: function(e) { |
| 160 this.searchTerm = /** @type {string} */ (e.detail); |
| 161 }, |
| 162 |
| 163 /** @private */ |
| 164 updateSearchResult_: function() { |
| 165 chrome.bookmarks.search(this.searchTerm, function(results) { |
| 166 this.searchResult = results; |
| 167 }.bind(this)); |
| 168 }, |
| 138 }); | 169 }); |
| OLD | NEW |