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.offsetHeight && | |
asanka
2015/12/07 20:31:50
Imma n00b. Shouldn't this be list.scrollHeight > l
Dan Beam
2015/12/09 06:55:21
https://drafts.csswg.org/cssom-view/#dom-htmleleme
| |
103 list.scrollTop + list.offsetHeight == list.scrollHeight) { | |
104 // Reached the end of the scrollback. Attempt to load more items. | |
105 downloads.ActionService.getInstance().loadMore(); | |
106 } | |
107 }, | |
108 | |
92 /** @private */ | 109 /** @private */ |
93 onLoad_: function() { | 110 onLoad_: function() { |
94 cr.ui.decorate('command', cr.ui.Command); | 111 cr.ui.decorate('command', cr.ui.Command); |
95 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); | 112 document.addEventListener('canExecute', this.onCanExecute_.bind(this)); |
96 document.addEventListener('command', this.onCommand_.bind(this)); | 113 document.addEventListener('command', this.onCommand_.bind(this)); |
97 | 114 |
98 // Shows all downloads. | 115 downloads.ActionService.getInstance().loadMore(); |
99 downloads.ActionService.getInstance().search(''); | |
100 }, | 116 }, |
101 | 117 |
102 /** | 118 /** |
103 * @param {number} index | 119 * @param {number} index |
104 * @private | 120 * @private |
105 */ | 121 */ |
106 removeItem_: function(index) { | 122 removeItem_: function(index) { |
107 this.splice('items_', index, 1); | 123 this.splice('items_', index, 1); |
108 this.updateHideDates_(index, index); | 124 this.updateHideDates_(index, index); |
109 }, | 125 }, |
(...skipping 46 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 |