From 5411a1f3a53bb15d05acf23e0e79adf393f8b0e6 Mon Sep 17 00:00:00 2001 From: Kushagra Gour Date: Sat, 26 Nov 2016 13:29:50 +0530 Subject: [PATCH] debounce collapse updation. --- src/script.js | 25 +++++++++++++++---------- 1 file changed, 15 insertions(+), 10 deletions(-) diff --git a/src/script.js b/src/script.js index 2300425..f46b160 100644 --- a/src/script.js +++ b/src/script.js @@ -81,15 +81,21 @@ function updateCodeWrapCollapseStates() { - ['#js-html-code', '#js-css-code', '#js-js-code'].forEach(function (selector) { - var el = document.querySelector(selector); - var bounds = el.getBoundingClientRect(); - if (bounds.width < 150) { - el.classList.add('is-minimized'); - } else { - el.classList.remove('is-minimized'); - } - }); + // if (updateCodeWrapCollapseStates.timeout) { + clearTimeout(updateCodeWrapCollapseStates.timeout); + // } + updateCodeWrapCollapseStates.timeout = setTimeout(function () { + console.log('refreshing'); + ['#js-html-code', '#js-css-code', '#js-js-code'].forEach(function (selector) { + var el = document.querySelector(selector); + var bounds = el.getBoundingClientRect(); + if (bounds.width < 150) { + el.classList.add('is-minimized'); + } else { + el.classList.remove('is-minimized'); + } + }); + }, 500); } function resetSplitting() { @@ -644,7 +650,6 @@ ['#js-html-code', '#js-css-code', '#js-js-code'].forEach(function (selector) { var el = document.querySelector(selector); el.addEventListener('transitionend', function() { - console.log('transitionend') updateCodeWrapCollapseStates(); }); });