Chromium Code Reviews| 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 Tile = ntp.Tile2; | 8 var Tile = ntp.Tile2; |
| 9 var TilePage = ntp.TilePage2; | 9 var TilePage = ntp.TilePage2; |
| 10 | 10 |
| (...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 103 var favicon = thumbnailImage.querySelector('.thumbnail-favicon'); | 103 var favicon = thumbnailImage.querySelector('.thumbnail-favicon'); |
| 104 if (favicon) | 104 if (favicon) |
| 105 thumbnailImage.removeChild(favicon); | 105 thumbnailImage.removeChild(favicon); |
| 106 | 106 |
| 107 var self = this; | 107 var self = this; |
| 108 var image = new Image(); | 108 var image = new Image(); |
| 109 | 109 |
| 110 // If the thumbnail image fails to load, show the favicon and URL instead. | 110 // If the thumbnail image fails to load, show the favicon and URL instead. |
| 111 // TODO(jeremycho): Move to a separate function? | 111 // TODO(jeremycho): Move to a separate function? |
| 112 image.onerror = function() { | 112 image.onerror = function() { |
| 113 banner = self.ownerDocument.createElement('div'); | 113 banner = thumbnailImage.querySelector('.thumbnail-banner') || |
| 114 self.ownerDocument.createElement('div'); | |
| 114 banner.className = 'thumbnail-banner'; | 115 banner.className = 'thumbnail-banner'; |
| 115 | 116 |
| 116 // For now, just strip leading http://www and trailing backslash. | 117 // For now, just strip leading http://www and trailing backslash. |
| 117 // TODO(jeremycho): Consult with UX on URL truncation. | 118 // TODO(jeremycho): Consult with UX on URL truncation. |
| 118 banner.textContent = dataUrl.replace(/^(http:\/\/)?(www\.)?|\/$/gi, ''); | 119 banner.textContent = dataUrl.replace(/^(http:\/\/)?(www\.)?|\/$/gi, ''); |
| 119 thumbnailImage.appendChild(banner); | 120 thumbnailImage.appendChild(banner); |
| 120 | 121 |
| 121 favicon = self.ownerDocument.createElement('div'); | 122 favicon = thumbnailImage.querySelector('.thumbnail-favicon') || |
| 123 self.ownerDocument.createElement('div'); | |
| 122 favicon.className = 'thumbnail-favicon'; | 124 favicon.className = 'thumbnail-favicon'; |
| 123 favicon.style.backgroundImage = | 125 favicon.style.backgroundImage = |
| 124 url('chrome://favicon/size/16/' + dataUrl); | 126 url('chrome://favicon/size/16/' + dataUrl); |
| 125 thumbnailImage.appendChild(favicon); | 127 thumbnailImage.appendChild(favicon); |
| 126 } | 128 } |
| 127 | 129 |
| 128 var thumbnailUrl = ntp.getThumbnailUrl(dataUrl); | 130 var thumbnailUrl = ntp.getThumbnailUrl(dataUrl); |
| 129 thumbnailImage.style.backgroundImage = url(thumbnailUrl); | 131 thumbnailImage.style.backgroundImage = url(thumbnailUrl); |
| 130 image.src = thumbnailUrl; | 132 image.src = thumbnailUrl; |
| 131 }, | 133 }, |
| (...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 203 return; | 205 return; |
| 204 | 206 |
| 205 if (i >= data.length) | 207 if (i >= data.length) |
| 206 tile.reset(); | 208 tile.reset(); |
| 207 else | 209 else |
| 208 tile.updateForData(page); | 210 tile.updateForData(page); |
| 209 } | 211 } |
| 210 }, | 212 }, |
| 211 | 213 |
| 212 /** | 214 /** |
| 213 * Array of thumbnail data objects. | 215 * Returns an array of thumbnail data objects. |
| 214 * @type {Array} | 216 * @return {Array} An array of thumbnail data objects. |
| 215 */ | 217 */ |
| 216 get data() { | 218 getData: function() { |
| 217 return this.data_; | 219 return this.data_; |
| 218 }, | 220 }, |
| 219 set data(data) { | 221 |
| 220 console.error('ThumbnailPage: data_ setter is not implemented.'); | 222 /** |
| 223 * Sets the data that will be used to create Thumbnails. | |
| 224 * @param {Array} data The array of data. | |
| 225 */ | |
| 226 setData: function(data) { | |
| 227 var maxTileCount = this.config_.maxTileCount; | |
| 228 this.data_ = data.slice(0, maxTileCount); | |
| 229 | |
| 230 var dataLength = this.data_.length; | |
| 231 var tileCount = this.tileCount; | |
| 232 // Create or remove tiles if necessary. | |
| 233 if (tileCount < dataLength) | |
|
Evan Stade
2012/09/13 07:50:52
if one condition in an if/else block has curlies,
| |
| 234 this.createTiles_(dataLength - tileCount); | |
| 235 else if (tileCount > dataLength) { | |
| 236 // TODO(jeremycho): Consider rewriting removeTile to be compatible with | |
| 237 // pages other than Apps and calling it here. | |
| 238 for (var i = 0; i < tileCount - dataLength; i++) | |
| 239 this.tiles_.pop(); | |
| 240 } | |
| 241 | |
| 242 // TODO(pedrosimonetti): Fix this as part of a larger restructuring of | |
| 243 // the layout/render logic. | |
| 244 if (dataLength != tileCount && this.hasBeenRendered()) | |
| 245 this.renderGrid_(); | |
| 246 this.updateTiles_(); | |
| 221 }, | 247 }, |
| 222 | 248 |
| 223 /** @inheritDoc */ | 249 /** @inheritDoc */ |
| 224 shouldAcceptDrag: function(e) { | 250 shouldAcceptDrag: function(e) { |
| 225 return false; | 251 return false; |
| 226 }, | 252 }, |
| 227 }; | 253 }; |
| 228 | 254 |
| 229 return { | 255 return { |
| 230 Thumbnail: Thumbnail, | 256 Thumbnail: Thumbnail, |
| 231 ThumbnailPage: ThumbnailPage | 257 ThumbnailPage: ThumbnailPage |
| 232 }; | 258 }; |
| 233 }); | 259 }); |
| OLD | NEW |