OLD | NEW |
---|---|
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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: 'history-list', | 6 is: 'history-list', |
7 | 7 |
8 properties: { | 8 properties: { |
9 // The search term for the current query. Set when the query returns. | 9 // The search term for the current query. Set when the query returns. |
10 searchedTerm: { | 10 searchedTerm: { |
11 type: String, | 11 type: String, |
12 value: '', | 12 value: '', |
13 }, | 13 }, |
14 | 14 |
15 lastSearchedTerm_: String, | 15 lastSearchedTerm_: String, |
16 | 16 |
17 querying: Boolean, | 17 querying: Boolean, |
18 | 18 |
19 // An array of history entries in reverse chronological order. | 19 // An array of history entries in reverse chronological order. |
20 historyData_: Array, | 20 historyData_: Array, |
21 | 21 |
22 resultLoadingDisabled_: { | 22 resultLoadingDisabled_: { |
23 type: Boolean, | 23 type: Boolean, |
24 value: false, | 24 value: false, |
25 }, | 25 }, |
26 }, | 26 }, |
27 | 27 |
28 listeners: { | 28 listeners: { |
29 'infinite-list.scroll': 'closeMenu_', | 29 'infinite-list.scroll': 'notifyListScroll_', |
tsergeant
2016/07/19 07:12:47
Rather than firing a new event, can you just close
calamity
2016/07/20 05:24:38
As discussed, the scroll event doesn't bubble.
| |
30 'tap': 'closeMenu_', | |
31 'toggle-menu': 'toggleMenu_', | |
32 'remove-bookmark-stars': 'removeBookmarkStars_', | 30 'remove-bookmark-stars': 'removeBookmarkStars_', |
33 }, | 31 }, |
34 | 32 |
35 /** @override */ | 33 /** @override */ |
36 attached: function() { | 34 attached: function() { |
37 // It is possible (eg, when middle clicking the reload button) for all other | 35 // It is possible (eg, when middle clicking the reload button) for all other |
38 // resize events to fire before the list is attached and can be measured. | 36 // resize events to fire before the list is attached and can be measured. |
39 // Adding another resize here ensures it will get sized correctly. | 37 // Adding another resize here ensures it will get sized correctly. |
40 /** @type {IronListElement} */(this.$['infinite-list']).notifyResize(); | 38 /** @type {IronListElement} */(this.$['infinite-list']).notifyResize(); |
41 }, | 39 }, |
42 | 40 |
43 /** | 41 /** |
44 * Closes the overflow menu. | |
45 * @private | |
46 */ | |
47 closeMenu_: function() { | |
48 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).closeMenu(); | |
49 }, | |
50 | |
51 /** | |
52 * Opens the overflow menu unless the menu is already open and the same button | |
53 * is pressed. | |
54 * @param {{detail: {item: !HistoryEntry, target: !HTMLElement}}} e | |
55 * @private | |
56 */ | |
57 toggleMenu_: function(e) { | |
58 var target = e.detail.target; | |
59 /** @type {CrSharedMenuElement} */(this.$.sharedMenu).toggleMenu( | |
60 target, e.detail.item); | |
61 }, | |
62 | |
63 /** | |
64 * Remove bookmark star for history items with matching URLs. | 42 * Remove bookmark star for history items with matching URLs. |
65 * @param {{detail: !string}} e | 43 * @param {{detail: !string}} e |
66 * @private | 44 * @private |
67 */ | 45 */ |
68 removeBookmarkStars_: function(e) { | 46 removeBookmarkStars_: function(e) { |
69 var url = e.detail; | 47 var url = e.detail; |
70 | 48 |
71 if (this.historyData_ === undefined) | 49 if (this.historyData_ === undefined) |
72 return; | 50 return; |
73 | 51 |
74 for (var i = 0; i < this.historyData_.length; i++) { | 52 for (var i = 0; i < this.historyData_.length; i++) { |
75 if (this.historyData_[i].url == url) | 53 if (this.historyData_[i].url == url) |
76 this.set('historyData_.' + i + '.starred', false); | 54 this.set('historyData_.' + i + '.starred', false); |
77 } | 55 } |
78 }, | 56 }, |
79 | 57 |
80 /** @private */ | |
81 onMoreFromSiteTap_: function() { | |
82 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | |
83 this.fire('search-domain', {domain: menu.itemData.domain}); | |
84 menu.closeMenu(); | |
85 }, | |
86 | |
87 /** @private */ | |
88 onRemoveFromHistoryTap_: function() { | |
89 var menu = /** @type {CrSharedMenuElement} */(this.$.sharedMenu); | |
90 md_history.BrowserService.getInstance() | |
91 .deleteItems([menu.itemData]) | |
92 .then(function(items) { | |
93 this.removeDeletedHistory_(items); | |
94 // This unselect-all is to reset the toolbar when deleting a selected | |
95 // item. TODO(tsergeant): Make this automatic based on observing list | |
96 // modifications. | |
97 this.fire('unselect-all'); | |
98 }.bind(this)); | |
99 menu.closeMenu(); | |
100 }, | |
101 | |
102 /** | 58 /** |
103 * Disables history result loading when there are no more history results. | 59 * Disables history result loading when there are no more history results. |
104 */ | 60 */ |
105 disableResultLoading: function() { | 61 disableResultLoading: function() { |
106 this.resultLoadingDisabled_ = true; | 62 this.resultLoadingDisabled_ = true; |
107 }, | 63 }, |
108 | 64 |
109 /** | 65 /** |
110 * Adds the newly updated history results into historyData_. Adds new fields | 66 * Adds the newly updated history results into historyData_. Adds new fields |
111 * for each result. | 67 * for each result. |
(...skipping 161 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
273 this.historyData_[i + 1].dateRelativeDay; | 229 this.historyData_[i + 1].dateRelativeDay; |
274 }, | 230 }, |
275 | 231 |
276 /** | 232 /** |
277 * @param {number} index | 233 * @param {number} index |
278 * @return {boolean} | 234 * @return {boolean} |
279 * @private | 235 * @private |
280 */ | 236 */ |
281 isFirstItem_: function(index) { | 237 isFirstItem_: function(index) { |
282 return index == 0; | 238 return index == 0; |
283 } | 239 }, |
240 | |
241 /** | |
242 * @private | |
243 */ | |
244 notifyListScroll_: function() { | |
245 this.fire('history-list-scrolled'); | |
246 }, | |
284 }); | 247 }); |
OLD | NEW |