From 35c083122ef678d4db4b71ced4985c73ac072abe Mon Sep 17 00:00:00 2001 From: Philipp Oppermann Date: Thu, 28 Jul 2016 19:51:36 +0200 Subject: [PATCH] Add function to automatically add/rm the coarse class Based on viewport height. Automatically adjusted onresize. --- static/js/main.js | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) diff --git a/static/js/main.js b/static/js/main.js index 81bc7233..a1c32e85 100644 --- a/static/js/main.js +++ b/static/js/main.js @@ -15,5 +15,26 @@ window.onload = function() { container.appendChild(heading); container.appendChild(toc); + + resize_toc(container); } } + +function resize_toc(container) { + var containerHeight = container.clientHeight; + + var resize = function() { + if (containerHeight > document.documentElement.clientHeight - 100) { + container.classList.add('coarse'); + } else { + container.classList.remove('coarse'); + } + }; + resize(); + + var resizeId; + window.onresize = function() { + clearTimeout(resizeId); + resizeId = setTimeout(resize, 300); + }; +}