From 743794f4833967f7fc7105a5a99bcbf5d5e9eceb Mon Sep 17 00:00:00 2001 From: kristoffer Date: Thu, 28 Jan 2016 14:18:07 +0100 Subject: [PATCH] Debounce onResize by 1s Fixes terrible performance issues on IOS 8 Safari --- src/dat/gui/GUI.js | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) 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