diff --git a/src/dat/gui/GUI.js b/src/dat/gui/GUI.js index b0f61d3..d06d8e9 100644 --- a/src/dat/gui/GUI.js +++ b/src/dat/gui/GUI.js @@ -469,6 +469,24 @@ define([ }); }; + GUI.debounce = function (func, threshold) { + var timeout; + + return function debounced () { + var obj = this, args = arguments; + function delayed () { + func.apply(obj, args); + timeout = null; + } + + if (timeout) { + clearTimeout(timeout); + } + + timeout = setTimeout(delayed, threshold); + }; + }; + GUI.CLASS_AUTO_PLACE = 'a'; GUI.CLASS_AUTO_PLACE_CONTAINER = 'ac'; GUI.CLASS_MAIN = 'main'; @@ -614,7 +632,7 @@ define([ this.closed = true; }, - onResize: function() { + onResize: GUI.debounce(function() { var root = this.getRoot(); @@ -648,7 +666,7 @@ define([ root.__closeButton.style.width = root.width + 'px'; } - }, + }, 1000), /** * Mark objects for saving. The order of these objects cannot change as