Fix window resizing.
This commit is contained in:
@@ -18,6 +18,9 @@ var BabyStats = function(container) {
|
|||||||
|
|
||||||
this.buildCells_();
|
this.buildCells_();
|
||||||
this.buildStylesheet_();
|
this.buildStylesheet_();
|
||||||
|
|
||||||
|
window.addEventListener('resize', this.rebuildIfNeeded_.bind(this));
|
||||||
|
|
||||||
var grid = this.calculateGrid_();
|
var grid = this.calculateGrid_();
|
||||||
this.gridWidthCells_ = grid.gridWidthCells;
|
this.gridWidthCells_ = grid.gridWidthCells;
|
||||||
this.gridHeightCells_ = grid.gridHeightCells;
|
this.gridHeightCells_ = grid.gridHeightCells;
|
||||||
@@ -38,7 +41,18 @@ BabyStats.prototype.addCSSClass_ = function(node, className) {
|
|||||||
}
|
}
|
||||||
classes.push(className);
|
classes.push(className);
|
||||||
node.className = classes.join(' ');
|
node.className = classes.join(' ');
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
|
BabyStats.prototype.rebuildIfNeeded_ = function(e) {
|
||||||
|
var grid = this.calculateGrid_();
|
||||||
|
if (this.gridWidthCells_ != grid.gridWidthCells ||
|
||||||
|
this.gridHeightCells_ != grid.gridHeightCells) {
|
||||||
|
this.gridWidthCells_ = grid.gridWidthCells;
|
||||||
|
this.gridHeightCells_ = grid.gridHeightCells;
|
||||||
|
this.buildGrid_();
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Construct our stylesheet and insert it into the DOM.
|
* Construct our stylesheet and insert it into the DOM.
|
||||||
|
|||||||
Reference in New Issue
Block a user