| 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-toolbar', | 6 is: 'bookmarks-toolbar', |
| 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: 'onSearchTermChanged_', | 16 observer: 'onSearchTermChanged_', |
| 17 }, | 17 }, |
| 18 | 18 |
| 19 sidebarWidth: { | 19 sidebarWidth: { |
| 20 type: String, | 20 type: String, |
| 21 observer: 'onSidebarWidthChanged_', | 21 observer: 'onSidebarWidthChanged_', |
| 22 }, | 22 }, |
| 23 |
| 24 showSelectionOverlay: { |
| 25 type: Boolean, |
| 26 computed: 'shouldShowSelectionOverlay_(selectedCount_)', |
| 27 readOnly: true, |
| 28 reflectToAttribute: true, |
| 29 }, |
| 30 |
| 31 /** @private */ |
| 32 narrow_: { |
| 33 type: Boolean, |
| 34 reflectToAttribute: true, |
| 35 }, |
| 36 |
| 37 /** @private */ |
| 38 selectedCount_: Number, |
| 23 }, | 39 }, |
| 24 | 40 |
| 25 attached: function() { | 41 attached: function() { |
| 26 this.watch('searchTerm_', function(state) { | 42 this.watch('searchTerm_', function(state) { |
| 27 return state.search.term; | 43 return state.search.term; |
| 28 }); | 44 }); |
| 45 this.watch('selectedCount_', function(state) { |
| 46 return state.selection.items.size; |
| 47 }); |
| 48 this.updateFromStore(); |
| 29 }, | 49 }, |
| 30 | 50 |
| 31 /** @return {CrToolbarSearchFieldElement} */ | 51 /** @return {CrToolbarSearchFieldElement} */ |
| 32 get searchField() { | 52 get searchField() { |
| 33 return /** @type {CrToolbarElement} */ (this.$$('cr-toolbar')) | 53 return /** @type {CrToolbarElement} */ (this.$$('cr-toolbar')) |
| 34 .getSearchField(); | 54 .getSearchField(); |
| 35 }, | 55 }, |
| 36 | 56 |
| 37 /** | 57 /** |
| 38 * @param {Event} e | 58 * @param {Event} e |
| (...skipping 12 matching lines...) Expand all Loading... |
| 51 }, | 71 }, |
| 52 | 72 |
| 53 /** @private */ | 73 /** @private */ |
| 54 onAddBookmarkTap_: function() { | 74 onAddBookmarkTap_: function() { |
| 55 var dialog = | 75 var dialog = |
| 56 /** @type {BookmarksEditDialogElement} */ (this.$.addDialog.get()); | 76 /** @type {BookmarksEditDialogElement} */ (this.$.addDialog.get()); |
| 57 dialog.showAddDialog(false, assert(this.getState().selectedFolder)); | 77 dialog.showAddDialog(false, assert(this.getState().selectedFolder)); |
| 58 this.closeDropdownMenu_(); | 78 this.closeDropdownMenu_(); |
| 59 }, | 79 }, |
| 60 | 80 |
| 81 /** @private */ |
| 61 onAddFolderTap_: function() { | 82 onAddFolderTap_: function() { |
| 62 var dialog = | 83 var dialog = |
| 63 /** @type {BookmarksEditDialogElement} */ (this.$.addDialog.get()); | 84 /** @type {BookmarksEditDialogElement} */ (this.$.addDialog.get()); |
| 64 dialog.showAddDialog(true, assert(this.getState().selectedFolder)); | 85 dialog.showAddDialog(true, assert(this.getState().selectedFolder)); |
| 65 this.closeDropdownMenu_(); | 86 this.closeDropdownMenu_(); |
| 66 }, | 87 }, |
| 67 | 88 |
| 68 /** @private */ | 89 /** @private */ |
| 69 onImportTap_: function() { | 90 onImportTap_: function() { |
| 70 chrome.bookmarks.import(); | 91 chrome.bookmarks.import(); |
| 71 this.closeDropdownMenu_(); | 92 this.closeDropdownMenu_(); |
| 72 }, | 93 }, |
| 73 | 94 |
| 74 /** @private */ | 95 /** @private */ |
| 75 onExportTap_: function() { | 96 onExportTap_: function() { |
| 76 chrome.bookmarks.export(); | 97 chrome.bookmarks.export(); |
| 77 this.closeDropdownMenu_(); | 98 this.closeDropdownMenu_(); |
| 78 }, | 99 }, |
| 79 | 100 |
| 80 /** @private */ | 101 /** @private */ |
| 102 onClearSelectionTap_: function() { |
| 103 this.dispatch(bookmarks.actions.deselectItems()); |
| 104 }, |
| 105 |
| 106 /** @private */ |
| 81 closeDropdownMenu_: function() { | 107 closeDropdownMenu_: function() { |
| 82 var menu = /** @type {!CrActionMenuElement} */ (this.$.dropdown); | 108 var menu = /** @type {!CrActionMenuElement} */ (this.$.dropdown); |
| 83 menu.close(); | 109 menu.close(); |
| 84 }, | 110 }, |
| 85 | 111 |
| 86 /** | 112 /** |
| 87 * @param {Event} e | 113 * @param {Event} e |
| 88 * @private | 114 * @private |
| 89 */ | 115 */ |
| 90 onSearchChanged_: function(e) { | 116 onSearchChanged_: function(e) { |
| 91 var searchTerm = /** @type {string} */ (e.detail); | 117 var searchTerm = /** @type {string} */ (e.detail); |
| 92 if (searchTerm != this.searchTerm_) | 118 if (searchTerm != this.searchTerm_) |
| 93 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm)); | 119 this.dispatch(bookmarks.actions.setSearchTerm(searchTerm)); |
| 94 }, | 120 }, |
| 95 | 121 |
| 122 /** @private */ |
| 96 onSidebarWidthChanged_: function() { | 123 onSidebarWidthChanged_: function() { |
| 97 this.style.setProperty('--sidebar-width', this.sidebarWidth); | 124 this.style.setProperty('--sidebar-width', this.sidebarWidth); |
| 98 }, | 125 }, |
| 99 | 126 |
| 100 /** @private */ | 127 /** @private */ |
| 101 onSearchTermChanged_: function() { | 128 onSearchTermChanged_: function() { |
| 102 this.searchField.setValue(this.searchTerm_ || ''); | 129 this.searchField.setValue(this.searchTerm_ || ''); |
| 103 }, | 130 }, |
| 104 | 131 |
| 105 /** | 132 /** |
| 106 * @return {boolean} | 133 * @return {boolean} |
| 107 * @private | 134 * @private |
| 108 */ | 135 */ |
| 109 hasSearchTerm_: function() { | 136 hasSearchTerm_: function() { |
| 110 return !!this.searchTerm_; | 137 return !!this.searchTerm_; |
| 111 }, | 138 }, |
| 139 |
| 140 /** |
| 141 * @return {boolean} |
| 142 * @private |
| 143 */ |
| 144 shouldShowSelectionOverlay_: function() { |
| 145 return this.selectedCount_ > 1; |
| 146 }, |
| 147 |
| 148 /** |
| 149 * @return {string} |
| 150 * @private |
| 151 */ |
| 152 getItemsSelectedString_: function() { |
| 153 return loadTimeData.getStringF('itemsSelected', this.selectedCount_); |
| 154 }, |
| 112 }); | 155 }); |
| OLD | NEW |