OLD | NEW |
---|---|
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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('ntp', function() { | 5 cr.define('ntp', function() { |
6 'use strict'; | 6 'use strict'; |
7 | 7 |
8 var TilePage = ntp.TilePage; | 8 var TilePage = ntp.TilePage; |
9 | 9 |
10 /** | 10 /** |
(...skipping 116 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
127 * @param {Event} e The click event. | 127 * @param {Event} e The click event. |
128 */ | 128 */ |
129 handleClick_: function(e) { | 129 handleClick_: function(e) { |
130 if (e.target.classList.contains('close-button')) { | 130 if (e.target.classList.contains('close-button')) { |
131 this.blacklist_(); | 131 this.blacklist_(); |
132 e.preventDefault(); | 132 e.preventDefault(); |
133 } else { | 133 } else { |
134 // Records the index of this tile. | 134 // Records the index of this tile. |
135 chrome.send('metricsHandler:recordInHistogram', | 135 chrome.send('metricsHandler:recordInHistogram', |
136 ['NewTabPage.SuggestedSite', this.index, 8]); | 136 ['NewTabPage.SuggestedSite', this.index, 8]); |
137 chrome.send('suggestedSitesAction', [1]); | |
Evan Stade
2012/04/03 22:52:33
you need an enum, don't just toss magic values aro
macourteau
2012/04/04 19:41:09
Done.
| |
137 } | 138 } |
138 }, | 139 }, |
139 | 140 |
140 /** | 141 /** |
141 * Allow blacklisting suggestions site using the keyboard. | 142 * Allow blacklisting suggestions site using the keyboard. |
142 * @param {Event} e The keydown event. | 143 * @param {Event} e The keydown event. |
143 */ | 144 */ |
144 handleKeyDown_: function(e) { | 145 handleKeyDown_: function(e) { |
145 if (!cr.isMac && e.keyCode == 46 || // Del | 146 if (!cr.isMac && e.keyCode == 46 || // Del |
146 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 147 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
279 return el; | 280 return el; |
280 } | 281 } |
281 | 282 |
282 SuggestionsPage.prototype = { | 283 SuggestionsPage.prototype = { |
283 __proto__: TilePage.prototype, | 284 __proto__: TilePage.prototype, |
284 | 285 |
285 initialize: function() { | 286 initialize: function() { |
286 this.classList.add('suggestions-page'); | 287 this.classList.add('suggestions-page'); |
287 this.data_ = null; | 288 this.data_ = null; |
288 this.suggestionsTiles_ = this.getElementsByClassName('suggestions real'); | 289 this.suggestionsTiles_ = this.getElementsByClassName('suggestions real'); |
290 | |
291 this.addEventListener('carddeselected', this.handleCardDeselected_); | |
292 this.addEventListener('cardselected', this.handleCardSelected_); | |
289 }, | 293 }, |
290 | 294 |
291 /** | 295 /** |
292 * Create blank (filler) tiles. | 296 * Create blank (filler) tiles. |
293 * @private | 297 * @private |
294 */ | 298 */ |
295 createTiles_: function() { | 299 createTiles_: function() { |
296 for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 300 for (var i = 0; i < THUMBNAIL_COUNT; i++) { |
297 this.appendTile(new Suggestion()); | 301 this.appendTile(new Suggestion()); |
298 } | 302 } |
299 }, | 303 }, |
300 | 304 |
301 /** | 305 /** |
302 * Update the tiles after a change to |this.data_|. | 306 * Update the tiles after a change to |this.data_|. |
303 */ | 307 */ |
304 updateTiles_: function() { | 308 updateTiles_: function() { |
305 for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 309 for (var i = 0; i < THUMBNAIL_COUNT; i++) { |
306 var page = this.data_[i]; | 310 var page = this.data_[i]; |
307 var tile = this.suggestionsTiles_[i]; | 311 var tile = this.suggestionsTiles_[i]; |
308 | 312 |
309 if (i >= this.data_.length) | 313 if (i >= this.data_.length) |
310 tile.reset(); | 314 tile.reset(); |
311 else | 315 else |
312 tile.updateForData(page); | 316 tile.updateForData(page); |
313 } | 317 } |
314 }, | 318 }, |
315 | 319 |
316 /** | 320 /** |
321 * Handles the 'card deselected' event (i.e. the user clicked to another | |
322 * pane). | |
323 * @param {Event} e The CardChanged event. | |
324 */ | |
325 handleCardDeselected_: function(e) { | |
326 chrome.send('suggestedSitesAction', [2]); | |
327 }, | |
328 | |
329 /** | |
330 * Handles the 'card selected' event (i.e. the user clicked to select the | |
331 * Suggested pane). | |
332 * @param {Event} e The CardChanged event. | |
333 */ | |
334 handleCardSelected_: function(e) { | |
335 chrome.send('suggestedSitesSelected'); | |
336 }, | |
337 | |
338 /** | |
317 * Array of suggestions data objects. | 339 * Array of suggestions data objects. |
318 * @type {Array} | 340 * @type {Array} |
319 */ | 341 */ |
320 get data() { | 342 get data() { |
321 return this.data_; | 343 return this.data_; |
322 }, | 344 }, |
323 set data(data) { | 345 set data(data) { |
324 var startTime = Date.now(); | 346 var startTime = Date.now(); |
325 | 347 |
326 // The first time data is set, create the tiles. | 348 // The first time data is set, create the tiles. |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
414 } | 436 } |
415 | 437 |
416 return oldData; | 438 return oldData; |
417 } | 439 } |
418 | 440 |
419 return { | 441 return { |
420 SuggestionsPage: SuggestionsPage, | 442 SuggestionsPage: SuggestionsPage, |
421 refreshData: refreshData, | 443 refreshData: refreshData, |
422 }; | 444 }; |
423 }); | 445 }); |
OLD | NEW |