From 1afd0cea2def164b010aa48b6faa7273a4a91a61 Mon Sep 17 00:00:00 2001 From: Ian Gulliver Date: Sat, 26 Dec 2015 18:15:21 -0800 Subject: [PATCH] Fix window resizing. --- static/babystats.js | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/static/babystats.js b/static/babystats.js index 040ea1d..43db752 100644 --- a/static/babystats.js +++ b/static/babystats.js @@ -18,6 +18,9 @@ var BabyStats = function(container) { this.buildCells_(); this.buildStylesheet_(); + + window.addEventListener('resize', this.rebuildIfNeeded_.bind(this)); + var grid = this.calculateGrid_(); this.gridWidthCells_ = grid.gridWidthCells; this.gridHeightCells_ = grid.gridHeightCells; @@ -38,7 +41,18 @@ BabyStats.prototype.addCSSClass_ = function(node, className) { } classes.push(className); 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.