diff options
author | Noah Loomans <noahloomans@gmail.com> | 2017-03-23 10:10:44 +0100 |
---|---|---|
committer | Noah Loomans <noahloomans@gmail.com> | 2017-03-23 10:10:44 +0100 |
commit | 36ea1abe1f922a4a97c535348c7f1b94fcf6721c (patch) | |
tree | a2d424e3ee657bb93e64ee7dd9136749ad026fea /public/javascripts/zoom.js | |
parent | aacb48afce4ee021535f938b2b418a2e0796d105 (diff) |
Zoom table out when it doesn't fit the screen
Diffstat (limited to 'public/javascripts/zoom.js')
-rw-r--r-- | public/javascripts/zoom.js | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/public/javascripts/zoom.js b/public/javascripts/zoom.js new file mode 100644 index 0000000..59b80db --- /dev/null +++ b/public/javascripts/zoom.js @@ -0,0 +1,30 @@ +const schedule = require('./schedule') + +const self = {} + +self._nodes = { + body: document.body +} + +self._handleResize = function () { + // the table node may not exist before this function is called + const tableNode = document.querySelector('center > table') + + // infact, it may not even exist when this function is called. + if (!tableNode) return + + const tableWidth = tableNode.getBoundingClientRect().width + const tableGoalWidth = self._nodes.body.getBoundingClientRect().width * 0.9 + const zoomFactor = tableGoalWidth / tableWidth + + if (zoomFactor < 1) { + tableNode.style.zoom = `${zoomFactor}` + } else { + tableNode.style.zoom = `1` + } +} + +schedule.on('load', self._handleResize) +window.addEventListener('resize', self._handleResize) + +module.exports = self |