| 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-folder-node', | 6 is: 'bookmarks-folder-node', |
| 7 | 7 |
| 8 behaviors: [ | 8 behaviors: [ |
| 9 bookmarks.StoreClient, | 9 bookmarks.StoreClient, |
| 10 ], | 10 ], |
| 11 | 11 |
| 12 properties: { | 12 properties: { |
| 13 itemId: { | 13 itemId: { |
| 14 type: String, | 14 type: String, |
| 15 observer: 'updateFromStore', | 15 observer: 'updateFromStore', |
| 16 }, | 16 }, |
| 17 | 17 |
| 18 depth: { |
| 19 type: Number, |
| 20 observer: 'depthChanged_', |
| 21 }, |
| 22 |
| 18 /** @type {BookmarkNode} */ | 23 /** @type {BookmarkNode} */ |
| 19 item: Object, | 24 item: Object, |
| 20 | 25 |
| 21 isClosed: Boolean, | 26 isClosed: Boolean, |
| 22 | 27 |
| 23 selectedFolder: String, | 28 selectedFolder: String, |
| 24 | 29 |
| 25 isSelectedFolder: { | 30 isSelectedFolder: { |
| 26 type: Boolean, | 31 type: Boolean, |
| 27 value: false, | 32 value: false, |
| 28 reflectToAttribute: true, | 33 reflectToAttribute: true, |
| 29 computed: 'computeIsSelected_(itemId, selectedFolder)' | 34 computed: 'computeIsSelected_(itemId, selectedFolder)' |
| 30 }, | 35 }, |
| 31 }, | 36 }, |
| 32 | 37 |
| 33 attached: function() { | 38 attached: function() { |
| 34 this.observe('item', function(state) { | 39 this.observe('item', function(state) { |
| 35 return state.nodes[this.itemId]; | 40 return state.nodes[this.itemId]; |
| 36 }.bind(this)); | 41 }.bind(this)); |
| 37 this.observe('isClosed', function(state) { | |
| 38 return !!state.closedFolders[this.itemId]; | |
| 39 }.bind(this)); | |
| 40 this.observe('selectedFolder', function(state) { | 42 this.observe('selectedFolder', function(state) { |
| 41 return state.selectedFolder; | 43 return state.selectedFolder; |
| 42 }); | 44 }); |
| 43 | 45 |
| 44 this.updateFromStore(); | 46 this.updateFromStore(); |
| 45 }, | 47 }, |
| 46 | 48 |
| 47 /** | 49 /** |
| 48 * @private | 50 * @private |
| 49 * @return {string} | 51 * @return {string} |
| (...skipping 17 matching lines...) Expand all Loading... |
| 67 | 69 |
| 68 /** | 70 /** |
| 69 * Occurs when the drop down arrow is tapped. | 71 * Occurs when the drop down arrow is tapped. |
| 70 * @private | 72 * @private |
| 71 */ | 73 */ |
| 72 toggleFolder_: function() { | 74 toggleFolder_: function() { |
| 73 this.dispatch( | 75 this.dispatch( |
| 74 bookmarks.actions.changeFolderOpen(this.item.id, this.isClosed)); | 76 bookmarks.actions.changeFolderOpen(this.item.id, this.isClosed)); |
| 75 }, | 77 }, |
| 76 | 78 |
| 79 /** |
| 80 * @private |
| 81 * @param {string} itemId |
| 82 * @param {string} selectedFolder |
| 83 * @return {boolean} |
| 84 */ |
| 77 computeIsSelected_: function(itemId, selectedFolder) { | 85 computeIsSelected_: function(itemId, selectedFolder) { |
| 78 return itemId == selectedFolder; | 86 return itemId == selectedFolder; |
| 79 }, | 87 }, |
| 80 | 88 |
| 81 /** | 89 /** |
| 82 * @private | 90 * @private |
| 83 * @return {boolean} | 91 * @return {boolean} |
| 84 */ | 92 */ |
| 85 hasChildFolder_: function() { | 93 hasChildFolder_: function() { |
| 86 for (var i = 0; i < this.item.children.length; i++) { | 94 for (var i = 0; i < this.item.children.length; i++) { |
| 87 var child = this.getState().nodes[this.item.children[i]]; | 95 var child = this.getState().nodes[this.item.children[i]]; |
| 88 if (!child.url) | 96 if (!child.url) |
| 89 return true; | 97 return true; |
| 90 } | 98 } |
| 91 return false; | 99 return false; |
| 92 }, | 100 }, |
| 93 | 101 |
| 94 /** | 102 /** @private */ |
| 95 * @param {string} itemId | 103 depthChanged_: function() { |
| 96 * @private | 104 this.$['folder-label'].style.paddingLeft = |
| 97 * @return {boolean} | 105 `calc(${this.depth} * var(--padding-left-per-depth))`; |
| 98 */ | 106 }, |
| 99 isFolder_: function(itemId) { | |
| 100 return !this.getState().nodes[itemId].url; | |
| 101 } | |
| 102 }); | 107 }); |
| OLD | NEW |