Switch to Array.forEach() where possible
This commit is contained in:
@@ -201,10 +201,10 @@ CameraGrid.prototype.setSelected_ = function(index) {
|
|||||||
*/
|
*/
|
||||||
CameraGrid.prototype.buildCells_ = function() {
|
CameraGrid.prototype.buildCells_ = function() {
|
||||||
this.cells_ = [];
|
this.cells_ = [];
|
||||||
for (var i = 0; i < this.sourceUrls_.length; i++) {
|
this.sourceUrls_.forEach(function(sourceUrl) {
|
||||||
var cell = document.createElement('cameraGridCell');
|
var cell = document.createElement('cameraGridCell');
|
||||||
this.cells_.push(cell);
|
this.cells_.push(cell);
|
||||||
}
|
}, this);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -307,12 +307,11 @@ CameraGrid.prototype.calculateGrid_ = function() {
|
|||||||
var minCells = Number.MAX_VALUE;
|
var minCells = Number.MAX_VALUE;
|
||||||
var maxScale = 0.0;
|
var maxScale = 0.0;
|
||||||
var chosenHeight, chosenWidth, chosenConstraint = CameraGrid.Dimension.HEIGHT;
|
var chosenHeight, chosenWidth, chosenConstraint = CameraGrid.Dimension.HEIGHT;
|
||||||
for (var i = 0; i < gridOptions.length; i++) {
|
gridOptions.forEach(function(gridOption) {
|
||||||
var gridOption = gridOptions[i];
|
|
||||||
var numCells = gridOption[0] * gridOption[1];
|
var numCells = gridOption[0] * gridOption[1];
|
||||||
if (numCells < numTiles) {
|
if (numCells < numTiles) {
|
||||||
// Can't fit all the tiles in (we've rounded down too far).
|
// Can't fit all the tiles in (we've rounded down too far).
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
var widthScale = (containerWidth / gridOption[0]) / this.tileScaleWidth_;
|
var widthScale = (containerWidth / gridOption[0]) / this.tileScaleWidth_;
|
||||||
var heightScale = (containerHeight / gridOption[1]) / this.tileScaleHeight_;
|
var heightScale = (containerHeight / gridOption[1]) / this.tileScaleHeight_;
|
||||||
@@ -326,18 +325,18 @@ CameraGrid.prototype.calculateGrid_ = function() {
|
|||||||
}
|
}
|
||||||
if (scale < maxScale) {
|
if (scale < maxScale) {
|
||||||
// This would make cells smaller than another viable solution.
|
// This would make cells smaller than another viable solution.
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
if (scale == maxScale && numCells > minCells) {
|
if (scale == maxScale && numCells > minCells) {
|
||||||
// Same cell size as another viable solution, but ours has more cells.
|
// Same cell size as another viable solution, but ours has more cells.
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
chosenWidth = gridOption[0];
|
chosenWidth = gridOption[0];
|
||||||
chosenHeight = gridOption[1];
|
chosenHeight = gridOption[1];
|
||||||
chosenConstraint = constraint;
|
chosenConstraint = constraint;
|
||||||
minCells = numCells;
|
minCells = numCells;
|
||||||
maxScale = scale;
|
maxScale = scale;
|
||||||
}
|
}, this);
|
||||||
|
|
||||||
return /** @struct */ {
|
return /** @struct */ {
|
||||||
gridWidthCells: chosenWidth,
|
gridWidthCells: chosenWidth,
|
||||||
@@ -357,16 +356,15 @@ CameraGrid.prototype.calculateGrid_ = function() {
|
|||||||
* @private
|
* @private
|
||||||
*/
|
*/
|
||||||
CameraGrid.prototype.findMinimumResolution_ = function(tileWidth, tileHeight) {
|
CameraGrid.prototype.findMinimumResolution_ = function(tileWidth, tileHeight) {
|
||||||
for (var i = 0; i < this.resolutions_.length; i++) {
|
this.resolutions_.forEach(function(resolution) {
|
||||||
var resolution = this.resolutions_[i];
|
|
||||||
if (resolution[0] < tileWidth && resolution[1] < tileHeight) {
|
if (resolution[0] < tileWidth && resolution[1] < tileHeight) {
|
||||||
continue;
|
return;
|
||||||
}
|
}
|
||||||
return /** @struct */ {
|
return /** @struct */ {
|
||||||
imgWidthPx: resolution[0],
|
imgWidthPx: resolution[0],
|
||||||
imgHeightPx: resolution[1],
|
imgHeightPx: resolution[1],
|
||||||
};
|
};
|
||||||
}
|
}, this);
|
||||||
console.log('Your screen is larger than the largest feed resolution. Images will be scaled up');
|
console.log('Your screen is larger than the largest feed resolution. Images will be scaled up');
|
||||||
var lastResolution = this.resolutions_[this.resolutions_.length - 1];
|
var lastResolution = this.resolutions_[this.resolutions_.length - 1];
|
||||||
return {
|
return {
|
||||||
|
|||||||
Reference in New Issue
Block a user