@@ -81,13 +81,15 @@ const Main = (function() {
8181
8282 // window event listeners
8383 // resize function
84- window . onresize = function ( ) {
84+ function resizeWindow ( ) {
8585 body = document . body . getBoundingClientRect ( ) ;
8686 links . forEach ( l => l . hide ( ) ) ;
8787 svg . width ( body . width ) ;
8888 rm . width ( body . width ) ;
89- links . forEach ( l => l . show ( ) ) ;
89+ setSyntaxVisibility ( ) ;
9090 }
91+ window . onresize = debounce ( resizeWindow , 200 ) ;
92+
9193 document . getElementById ( 'dataset' ) . onchange = function ( e ) {
9294 if ( this . selectedIndex > 0 ) {
9395 changeDataset ( this . selectedIndex ) ;
@@ -229,6 +231,29 @@ const Main = (function() {
229231 // private functions
230232 //--------------------------------
231233
234+ // from https://davidwalsh.name/javascript-debounce-function,
235+ // as taken from underscore
236+
237+ // Returns a function, that, as long as it continues to be invoked, will not
238+ // be triggered. The function will be called after it stops being called for
239+ // N milliseconds. If `immediate` is passed, trigger the function on the
240+ // leading edge, instead of the trailing.
241+ function debounce ( func , wait , immediate ) {
242+ var timeout ;
243+ return function ( ) {
244+ var context = this , args = arguments ;
245+ var later = function ( ) {
246+ timeout = null ;
247+ if ( ! immediate ) func . apply ( context , args ) ;
248+ } ;
249+ var callNow = immediate && ! timeout ;
250+ clearTimeout ( timeout ) ;
251+ timeout = setTimeout ( later , wait ) ;
252+ if ( callNow ) func . apply ( context , args ) ;
253+ } ;
254+ } ;
255+
256+
232257 /** options to set visibility of syntax tree
233258 */
234259 function setSyntaxVisibility ( bool ) {
0 commit comments