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 cr.define('downloads', function() { | 5 cr.define('downloads', function() { |
6 var Manager = Polymer({ | 6 var Manager = Polymer({ |
7 is: 'downloads-manager', | 7 is: 'downloads-manager', |
8 | 8 |
9 properties: { | 9 properties: { |
10 hasDownloads_: { | 10 hasDownloads_: { |
11 observer: 'hasDownloadsChanged_', | 11 observer: 'hasDownloadsChanged_', |
12 type: Boolean, | 12 type: Boolean, |
13 }, | 13 }, |
14 | 14 |
15 items_: { | 15 items_: { |
16 type: Array, | 16 type: Array, |
17 value: function() { return []; }, | 17 value: function() { return []; }, |
18 }, | 18 }, |
19 }, | 19 }, |
20 | 20 |
21 hostAttributes: { | 21 hostAttributes: { |
22 loading: true, | 22 loading: true, |
23 }, | 23 }, |
24 | 24 |
| 25 listeners: { |
| 26 'downloads-list.scroll': 'onListScroll_', |
| 27 }, |
| 28 |
25 observers: [ | 29 observers: [ |
26 'itemsChanged_(items_.*)', | 30 'itemsChanged_(items_.*)', |
27 ], | 31 ], |
28 | 32 |
29 /** @private */ | 33 /** @private */ |
30 clearAll_: function() { | 34 clearAll_: function() { |
31 this.set('items_', []); | 35 this.set('items_', []); |
32 }, | 36 }, |
33 | 37 |
34 /** @private */ | 38 /** @private */ |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
82 * @param {Event} e | 86 * @param {Event} e |
83 * @private | 87 * @private |
84 */ | 88 */ |
85 onCommand_: function(e) { | 89 onCommand_: function(e) { |
86 if (e.command.id == 'clear-all-command') | 90 if (e.command.id == 'clear-all-command') |
87 downloads.ActionService.getInstance().clearAll(); | 91 downloads.ActionService.getInstance().clearAll(); |
88 else if (e.command.id == 'undo-command') | 92 else if (e.command.id == 'undo-command') |
89 downloads.ActionService.getInstance().undo(); | 93 downloads.ActionService.getInstance().undo(); |
90 }, | 94 }, |
91 | 95 |
| 96 /** |
| 97 * @param {Event} e |
| 98 * @private |
| 99 */ |
| 100 onListScroll_: function(e) { |
| 101 var list = this.$['downloads-list']; |
| 102 if (list.scrollHeight - list.scrollTop - list.offsetHeight <= 100) { |
| 103 // Approaching the end of the scrollback. Attempt to load more items. |
| 104 downloads.ActionService.getInstance().loadMore(); |
| 105 } |
| 106 }, |
| 107 |
92 /** @private */ | 108 /** @private */ |
93 onLoad_: function() { | 109 onLoad_: function() { |
94 cr.ui.decorate('command', cr.ui.Command); | 110 cr.ui.decorate('command', cr.ui.Command); |
95 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 111 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
96 document.addEventListener('command', this.onCommand_.bind(this)); | 112 document.addEventListener('command', this.onCommand_.bind(this)); |
97 | 113 |
98 // Shows all downloads. | 114 downloads.ActionService.getInstance().loadMore(); |
99 downloads.ActionService.getInstance().search(''); | |
100 }, | 115 }, |
101 | 116 |
102 /** | 117 /** |
103 * @param {number} index | 118 * @param {number} index |
104 * @private | 119 * @private |
105 */ | 120 */ |
106 removeItem_: function(index) { | 121 removeItem_: function(index) { |
107 this.splice('items_', index, 1); | 122 this.splice('items_', index, 1); |
108 this.updateHideDates_(index, index); | 123 this.updateHideDates_(index, index); |
| 124 this.onListScroll_(); |
109 }, | 125 }, |
110 | 126 |
111 /** | 127 /** |
112 * @param {number} start | 128 * @param {number} start |
113 * @param {number} end | 129 * @param {number} end |
114 * @private | 130 * @private |
115 */ | 131 */ |
116 updateHideDates_: function(start, end) { | 132 updateHideDates_: function(start, end) { |
117 for (var i = start; i <= end; ++i) { | 133 for (var i = start; i <= end; ++i) { |
118 var current = this.items_[i]; | 134 var current = this.items_[i]; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
156 Manager.removeItem = function(index) { | 172 Manager.removeItem = function(index) { |
157 Manager.get().removeItem_(index); | 173 Manager.get().removeItem_(index); |
158 }; | 174 }; |
159 | 175 |
160 Manager.updateItem = function(index, data) { | 176 Manager.updateItem = function(index, data) { |
161 Manager.get().updateItem_(index, data); | 177 Manager.get().updateItem_(index, data); |
162 }; | 178 }; |
163 | 179 |
164 return {Manager: Manager}; | 180 return {Manager: Manager}; |
165 }); | 181 }); |
OLD | NEW |