| 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    * See description for these values in suggestions_page_handler.h. |  | 
| 12    * @enum {number} |  | 
| 13    */ |  | 
| 14   var SuggestedSitesAction = { |  | 
| 15     CLICKED_SUGGESTED_TILE: 11, |  | 
| 16     CLICKED_OTHER_NTP_PANE: 12, |  | 
| 17     OTHER: 13 |  | 
| 18   }; |  | 
| 19 |  | 
| 20   /** |  | 
| 21    * A counter for generating unique tile IDs. | 11    * A counter for generating unique tile IDs. | 
| 22    */ | 12    */ | 
| 23   var tileID = 0; | 13   var tileID = 0; | 
| 24 | 14 | 
| 25   /** | 15   /** | 
| 26    * Creates a new Suggestions page object for tiling. | 16    * Creates a new Suggestions page object for tiling. | 
| 27    * @constructor | 17    * @constructor | 
| 28    * @extends {HTMLAnchorElement} | 18    * @extends {HTMLAnchorElement} | 
| 29    */ | 19    */ | 
| 30   function Suggestion() { | 20   function Suggestion() { | 
| (...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 138      */ | 128      */ | 
| 139     handleClick_: function(e) { | 129     handleClick_: function(e) { | 
| 140       if (e.target.classList.contains('close-button')) { | 130       if (e.target.classList.contains('close-button')) { | 
| 141         this.blacklist_(); | 131         this.blacklist_(); | 
| 142         e.preventDefault(); | 132         e.preventDefault(); | 
| 143       } else { | 133       } else { | 
| 144         // Records the index of this tile. | 134         // Records the index of this tile. | 
| 145         chrome.send('metricsHandler:recordInHistogram', | 135         chrome.send('metricsHandler:recordInHistogram', | 
| 146                     ['NewTabPage.SuggestedSite', this.index, 8]); | 136                     ['NewTabPage.SuggestedSite', this.index, 8]); | 
| 147         chrome.send('suggestedSitesAction', | 137         chrome.send('suggestedSitesAction', | 
| 148                     [SuggestedSitesAction.CLICKED_SUGGESTED_TILE]); | 138                     [ntp.NtpFollowAction.CLICKED_TILE]); | 
| 149       } | 139       } | 
| 150     }, | 140     }, | 
| 151 | 141 | 
| 152     /** | 142     /** | 
| 153      * Allow blacklisting suggestions site using the keyboard. | 143      * Allow blacklisting suggestions site using the keyboard. | 
| 154      * @param {Event} e The keydown event. | 144      * @param {Event} e The keydown event. | 
| 155      */ | 145      */ | 
| 156     handleKeyDown_: function(e) { | 146     handleKeyDown_: function(e) { | 
| 157       if (!cr.isMac && e.keyCode == 46 || // Del | 147       if (!cr.isMac && e.keyCode == 46 || // Del | 
| 158           cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 148           cr.isMac && e.metaKey && e.keyCode == 8) { // Cmd + Backspace | 
| (...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 327           tile.updateForData(page); | 317           tile.updateForData(page); | 
| 328       } | 318       } | 
| 329     }, | 319     }, | 
| 330 | 320 | 
| 331     /** | 321     /** | 
| 332      * Handles the 'card deselected' event (i.e. the user clicked to another | 322      * Handles the 'card deselected' event (i.e. the user clicked to another | 
| 333      * pane). | 323      * pane). | 
| 334      * @param {Event} e The CardChanged event. | 324      * @param {Event} e The CardChanged event. | 
| 335      */ | 325      */ | 
| 336     handleCardDeselected_: function(e) { | 326     handleCardDeselected_: function(e) { | 
| 337       chrome.send('suggestedSitesAction', | 327       if (!document.documentElement.classList.contains('starting-up')) { | 
| 338                   [SuggestedSitesAction.CLICKED_OTHER_NTP_PANE]); | 328         chrome.send('suggestedSitesAction', | 
|  | 329                     [ntp.NtpFollowAction.CLICKED_OTHER_NTP_PANE]); | 
|  | 330       } | 
| 339     }, | 331     }, | 
| 340 | 332 | 
| 341     /** | 333     /** | 
| 342      * Handles the 'card selected' event (i.e. the user clicked to select the | 334      * Handles the 'card selected' event (i.e. the user clicked to select the | 
| 343      * Suggested pane). | 335      * Suggested pane). | 
| 344      * @param {Event} e The CardChanged event. | 336      * @param {Event} e The CardChanged event. | 
| 345      */ | 337      */ | 
| 346     handleCardSelected_: function(e) { | 338     handleCardSelected_: function(e) { | 
| 347       chrome.send('suggestedSitesSelected'); | 339       if (!document.documentElement.classList.contains('starting-up')) | 
|  | 340         chrome.send('suggestedSitesSelected'); | 
| 348     }, | 341     }, | 
| 349 | 342 | 
| 350     /** | 343     /** | 
| 351      * Array of suggestions data objects. | 344      * Array of suggestions data objects. | 
| 352      * @type {Array} | 345      * @type {Array} | 
| 353      */ | 346      */ | 
| 354     get data() { | 347     get data() { | 
| 355       return this.data_; | 348       return this.data_; | 
| 356     }, | 349     }, | 
| 357     set data(data) { | 350     set data(data) { | 
| (...skipping 14 matching lines...) Expand all  Loading... | 
| 372     /** @inheritDoc */ | 365     /** @inheritDoc */ | 
| 373     shouldAcceptDrag: function(e) { | 366     shouldAcceptDrag: function(e) { | 
| 374       return false; | 367       return false; | 
| 375     }, | 368     }, | 
| 376 | 369 | 
| 377     /** @inheritDoc */ | 370     /** @inheritDoc */ | 
| 378     heightForWidth: heightForWidth, | 371     heightForWidth: heightForWidth, | 
| 379   }; | 372   }; | 
| 380 | 373 | 
| 381   /** | 374   /** | 
|  | 375    * Executed once the NTP has loaded. Checks if the Suggested pane is | 
|  | 376    * shown or not. If it is shown, the 'suggestedSitesSelected' message is sent | 
|  | 377    * to the C++ code, to record the fact that the user has seen this pane. | 
|  | 378    */ | 
|  | 379   SuggestionsPage.onLoaded = function() { | 
|  | 380     if (ntp.getCardSlider() && | 
|  | 381         ntp.getCardSlider().currentCardValue && | 
|  | 382         ntp.getCardSlider().currentCardValue.classList | 
|  | 383         .contains('suggestions-page')) { | 
|  | 384       chrome.send('suggestedSitesSelected'); | 
|  | 385     } | 
|  | 386   } | 
|  | 387 | 
|  | 388   /** | 
| 382    * We've gotten additional data for Suggestions page. Update our old data with | 389    * We've gotten additional data for Suggestions page. Update our old data with | 
| 383    * the new data. The ordering of the new data is not important, except when a | 390    * the new data. The ordering of the new data is not important, except when a | 
| 384    * page is pinned. Thus we try to minimize re-ordering. | 391    * page is pinned. Thus we try to minimize re-ordering. | 
| 385    * @param {Array} oldData The current Suggestions page list. | 392    * @param {Array} oldData The current Suggestions page list. | 
| 386    * @param {Array} newData The new Suggestions page list. | 393    * @param {Array} newData The new Suggestions page list. | 
| 387    * @return {Array} The merged page list that should replace the current page | 394    * @return {Array} The merged page list that should replace the current page | 
| 388    * list. | 395    * list. | 
| 389    */ | 396    */ | 
| 390   function refreshData(oldData, newData) { | 397   function refreshData(oldData, newData) { | 
| 391     oldData = oldData.slice(0, THUMBNAIL_COUNT); | 398     oldData = oldData.slice(0, THUMBNAIL_COUNT); | 
| (...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after  Loading... | 
| 448     } | 455     } | 
| 449 | 456 | 
| 450     return oldData; | 457     return oldData; | 
| 451   } | 458   } | 
| 452 | 459 | 
| 453   return { | 460   return { | 
| 454     SuggestionsPage: SuggestionsPage, | 461     SuggestionsPage: SuggestionsPage, | 
| 455     refreshData: refreshData, | 462     refreshData: refreshData, | 
| 456   }; | 463   }; | 
| 457 }); | 464 }); | 
|  | 465 | 
|  | 466 document.addEventListener('ntpLoaded', ntp.SuggestionsPage.onLoaded); | 
| OLD | NEW | 
|---|