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 Thumbnail = ntp.Thumbnail; | 8 var Thumbnail = ntp.Thumbnail; |
9 var ThumbnailPage = ntp.ThumbnailPage; | 9 var ThumbnailPage = ntp.ThumbnailPage; |
10 | 10 |
11 /** | 11 /** |
12 * Creates a new Most Visited object for tiling. | 12 * Creates a new Most Visited object for tiling. |
13 * @constructor | 13 * @constructor |
14 * @extends {Thumbnail} | 14 * @extends {Thumbnail} |
15 * @extends {HTMLAnchorElement} | 15 * @extends {HTMLAnchorElement} |
16 * @param {Object} config Tile page configuration object. | |
17 */ | 16 */ |
18 function MostVisited(config) { | 17 function MostVisited() { |
19 var el = cr.doc.createElement('a'); | 18 var el = cr.doc.createElement('a'); |
20 el.__proto__ = MostVisited.prototype; | 19 el.__proto__ = MostVisited.prototype; |
21 el.initialize(config); | 20 el.initialize(); |
22 | 21 |
23 return el; | 22 return el; |
24 } | 23 } |
25 | 24 |
26 MostVisited.prototype = { | 25 MostVisited.prototype = { |
27 __proto__: Thumbnail.prototype, | 26 __proto__: Thumbnail.prototype, |
28 | 27 |
29 /** | 28 /** |
30 * Initializes a MostVisited Thumbnail. | 29 * Initializes a MostVisited Thumbnail. |
31 * @param {Object} config TilePage configuration object. | |
32 */ | 30 */ |
33 initialize: function(config) { | 31 initialize: function() { |
34 Thumbnail.prototype.initialize.apply(this, arguments); | 32 Thumbnail.prototype.initialize.apply(this, arguments); |
35 | 33 |
36 this.addEventListener('click', this.handleClick_); | 34 this.addEventListener('click', this.handleClick_); |
37 this.addEventListener('keydown', this.handleKeyDown_); | 35 this.addEventListener('keydown', this.handleKeyDown_); |
38 this.addEventListener('carddeselected', this.handleCardDeselected_); | 36 this.addEventListener('carddeselected', this.handleCardDeselected_); |
39 this.addEventListener('cardselected', this.handleCardSelected_); | 37 this.addEventListener('cardselected', this.handleCardSelected_); |
40 }, | 38 }, |
41 | 39 |
42 /** | 40 /** |
43 * Clears the DOM hierarchy for this node, setting it back to the default | 41 * Clears the DOM hierarchy for this node, setting it back to the default |
44 * for a blank thumbnail. | 42 * for a blank thumbnail. |
45 */ | 43 */ |
46 reset: function() { | 44 reset: function() { |
47 Thumbnail.prototype.reset.apply(this, arguments); | 45 Thumbnail.prototype.reset.apply(this, arguments); |
48 | 46 |
49 var closeButton = cr.doc.createElement('div'); | 47 var closeButton = cr.doc.createElement('div'); |
50 closeButton.className = 'close-button'; | 48 closeButton.className = 'close-button'; |
51 closeButton.title = loadTimeData.getString('removethumbnailtooltip'); | 49 closeButton.title = loadTimeData.getString('removethumbnailtooltip'); |
52 this.appendChild(closeButton); | 50 this.appendChild(closeButton); |
53 }, | 51 }, |
54 | 52 |
55 /** | 53 /** |
56 * Update the appearance of this tile according to |data|. | 54 * Update the appearance of this tile according to |data|. |
57 * @param {Object} data A dictionary of relevant data for the page. | 55 * @param {Object} data A dictionary of relevant data for the page. |
58 */ | 56 */ |
59 setData: function(data) { | 57 set data(data) { |
| 58 Object.getOwnPropertyDescriptor(Thumbnail.prototype, 'data').set.apply( |
| 59 this, arguments); |
| 60 |
60 if (this.classList.contains('blacklisted') && data) { | 61 if (this.classList.contains('blacklisted') && data) { |
61 // Animate appearance of new tile. | 62 // Animate appearance of new tile. |
62 this.classList.add('new-tile-contents'); | 63 this.classList.add('new-tile-contents'); |
63 } | 64 } |
64 this.classList.remove('blacklisted'); | 65 this.classList.remove('blacklisted'); |
65 | 66 }, |
66 Thumbnail.prototype.setData.apply(this, arguments); | 67 get data() { |
| 68 return this.data_; |
67 }, | 69 }, |
68 | 70 |
69 /** | 71 /** |
70 * Handles a click on the tile. | 72 * Handles a click on the tile. |
71 * @param {Event} e The click event. | 73 * @param {Event} e The click event. |
72 * @private | 74 * @private |
73 */ | 75 */ |
74 handleClick_: function(e) { | 76 handleClick_: function(e) { |
75 if (e.target.classList.contains('close-button')) { | 77 if (e.target.classList.contains('close-button')) { |
76 this.blacklist_(); | 78 this.blacklist_(); |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
226 chrome.send('mostVisitedSelected'); | 228 chrome.send('mostVisitedSelected'); |
227 } | 229 } |
228 }; | 230 }; |
229 | 231 |
230 return { | 232 return { |
231 MostVisitedPage: MostVisitedPage, | 233 MostVisitedPage: MostVisitedPage, |
232 }; | 234 }; |
233 }); | 235 }); |
234 | 236 |
235 document.addEventListener('ntpLoaded', ntp.MostVisitedPage.onLoaded); | 237 document.addEventListener('ntpLoaded', ntp.MostVisitedPage.onLoaded); |
OLD | NEW |