| 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 /** |
| 11 * @enum {number} |
| 12 */ |
| 13 var SuggestedSitesAction = { |
| 14 OTHER: 0, |
| 15 CLICKED_SUGGESTED_TILE: 1, |
| 16 CLICKED_OTHER_NTP_PANE: 2, |
| 17 OMNIBOX_NAVIGATION: 3 |
| 18 }; |
| 19 |
| 20 /** |
| 11 * A counter for generating unique tile IDs. | 21 * A counter for generating unique tile IDs. |
| 12 */ | 22 */ |
| 13 var tileID = 0; | 23 var tileID = 0; |
| 14 | 24 |
| 15 /** | 25 /** |
| 16 * Creates a new Suggestions page object for tiling. | 26 * Creates a new Suggestions page object for tiling. |
| 17 * @constructor | 27 * @constructor |
| 18 * @extends {HTMLAnchorElement} | 28 * @extends {HTMLAnchorElement} |
| 19 */ | 29 */ |
| 20 function Suggestion() { | 30 function Suggestion() { |
| (...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 * @param {Event} e The click event. | 137 * @param {Event} e The click event. |
| 128 */ | 138 */ |
| 129 handleClick_: function(e) { | 139 handleClick_: function(e) { |
| 130 if (e.target.classList.contains('close-button')) { | 140 if (e.target.classList.contains('close-button')) { |
| 131 this.blacklist_(); | 141 this.blacklist_(); |
| 132 e.preventDefault(); | 142 e.preventDefault(); |
| 133 } else { | 143 } else { |
| 134 // Records the index of this tile. | 144 // Records the index of this tile. |
| 135 chrome.send('metricsHandler:recordInHistogram', | 145 chrome.send('metricsHandler:recordInHistogram', |
| 136 ['NewTabPage.SuggestedSite', this.index, 8]); | 146 ['NewTabPage.SuggestedSite', this.index, 8]); |
| 147 chrome.send('suggestedSitesAction', |
| 148 [SuggestedSitesAction.CLICKED_SUGGESTED_TILE]); |
| 137 } | 149 } |
| 138 }, | 150 }, |
| 139 | 151 |
| 140 /** | 152 /** |
| 141 * Allow blacklisting suggestions site using the keyboard. | 153 * Allow blacklisting suggestions site using the keyboard. |
| 142 * @param {Event} e The keydown event. | 154 * @param {Event} e The keydown event. |
| 143 */ | 155 */ |
| 144 handleKeyDown_: function(e) { | 156 handleKeyDown_: function(e) { |
| 145 if (!cr.isMac && e.keyCode == 46 || // Del | 157 if (!cr.isMac && e.keyCode == 46 || // Del |
| 146 cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 158 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; | 291 return el; |
| 280 } | 292 } |
| 281 | 293 |
| 282 SuggestionsPage.prototype = { | 294 SuggestionsPage.prototype = { |
| 283 __proto__: TilePage.prototype, | 295 __proto__: TilePage.prototype, |
| 284 | 296 |
| 285 initialize: function() { | 297 initialize: function() { |
| 286 this.classList.add('suggestions-page'); | 298 this.classList.add('suggestions-page'); |
| 287 this.data_ = null; | 299 this.data_ = null; |
| 288 this.suggestionsTiles_ = this.getElementsByClassName('suggestions real'); | 300 this.suggestionsTiles_ = this.getElementsByClassName('suggestions real'); |
| 301 |
| 302 this.addEventListener('carddeselected', this.handleCardDeselected_); |
| 303 this.addEventListener('cardselected', this.handleCardSelected_); |
| 289 }, | 304 }, |
| 290 | 305 |
| 291 /** | 306 /** |
| 292 * Create blank (filler) tiles. | 307 * Create blank (filler) tiles. |
| 293 * @private | 308 * @private |
| 294 */ | 309 */ |
| 295 createTiles_: function() { | 310 createTiles_: function() { |
| 296 for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 311 for (var i = 0; i < THUMBNAIL_COUNT; i++) { |
| 297 this.appendTile(new Suggestion()); | 312 this.appendTile(new Suggestion()); |
| 298 } | 313 } |
| 299 }, | 314 }, |
| 300 | 315 |
| 301 /** | 316 /** |
| 302 * Update the tiles after a change to |this.data_|. | 317 * Update the tiles after a change to |this.data_|. |
| 303 */ | 318 */ |
| 304 updateTiles_: function() { | 319 updateTiles_: function() { |
| 305 for (var i = 0; i < THUMBNAIL_COUNT; i++) { | 320 for (var i = 0; i < THUMBNAIL_COUNT; i++) { |
| 306 var page = this.data_[i]; | 321 var page = this.data_[i]; |
| 307 var tile = this.suggestionsTiles_[i]; | 322 var tile = this.suggestionsTiles_[i]; |
| 308 | 323 |
| 309 if (i >= this.data_.length) | 324 if (i >= this.data_.length) |
| 310 tile.reset(); | 325 tile.reset(); |
| 311 else | 326 else |
| 312 tile.updateForData(page); | 327 tile.updateForData(page); |
| 313 } | 328 } |
| 314 }, | 329 }, |
| 315 | 330 |
| 316 /** | 331 /** |
| 332 * Handles the 'card deselected' event (i.e. the user clicked to another |
| 333 * pane). |
| 334 * @param {Event} e The CardChanged event. |
| 335 */ |
| 336 handleCardDeselected_: function(e) { |
| 337 chrome.send('suggestedSitesAction', |
| 338 [SuggestedSitesAction.CLICKED_OTHER_NTP_PANE]); |
| 339 }, |
| 340 |
| 341 /** |
| 342 * Handles the 'card selected' event (i.e. the user clicked to select the |
| 343 * Suggested pane). |
| 344 * @param {Event} e The CardChanged event. |
| 345 */ |
| 346 handleCardSelected_: function(e) { |
| 347 chrome.send('suggestedSitesSelected'); |
| 348 }, |
| 349 |
| 350 /** |
| 317 * Array of suggestions data objects. | 351 * Array of suggestions data objects. |
| 318 * @type {Array} | 352 * @type {Array} |
| 319 */ | 353 */ |
| 320 get data() { | 354 get data() { |
| 321 return this.data_; | 355 return this.data_; |
| 322 }, | 356 }, |
| 323 set data(data) { | 357 set data(data) { |
| 324 var startTime = Date.now(); | 358 var startTime = Date.now(); |
| 325 | 359 |
| 326 // The first time data is set, create the tiles. | 360 // The first time data is set, create the tiles. |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 414 } | 448 } |
| 415 | 449 |
| 416 return oldData; | 450 return oldData; |
| 417 } | 451 } |
| 418 | 452 |
| 419 return { | 453 return { |
| 420 SuggestionsPage: SuggestionsPage, | 454 SuggestionsPage: SuggestionsPage, |
| 421 refreshData: refreshData, | 455 refreshData: refreshData, |
| 422 }; | 456 }; |
| 423 }); | 457 }); |
| OLD | NEW |