From f6e0bb4c3863981a22e61ed8b5d8bce31e4f7298 Mon Sep 17 00:00:00 2001 From: bordun Date: Mon, 6 Jun 2016 18:12:51 +0200 Subject: [PATCH] improve widget's size watcher and trigger it directly when window resizes --- browser/js/browser-headless.bundle.js | 50 ++++++++++++++------------- browser/js/jquery/jquery.resize.js | 50 ++++++++++++++------------- 2 files changed, 52 insertions(+), 48 deletions(-) diff --git a/browser/js/browser-headless.bundle.js b/browser/js/browser-headless.bundle.js index e48b70cf..b5d2309c 100644 --- a/browser/js/browser-headless.bundle.js +++ b/browser/js/browser-headless.bundle.js @@ -4545,40 +4545,42 @@ void 0===c?d&&"get"in d&&null!==(e=d.get(a,b))?e:(e=n.find.attr(a,b),null==e?voi } } - function resizePollingLoop() { + function checkResizes(){ + // Iterate over all elements to which the 'resize' event is bound. + for (var i = elems.length - 1; i >= 0; i--) { + var elem = elems[i], + width = elem.offsetWidth, + height = elem.offsetHeight - // yep, setTimeout, 'cuz requestAnimation doesn't seem to perform that well - resizeTimeout = window.setTimeout(function(){ - // Iterate over all elements to which the 'resize' event is bound. - for (var i = elems.length - 1; i >= 0; i--) { - var elem = elems[i], - width = elem.offsetWidth, - height = elem.offsetHeight + if (!width) continue - if (!width) continue - - var data = { - w:elem.resizedataw, - h:elem.resizedatah - } - - // If element size has changed since the last time, update the element - // data store and trigger the 'resize' event. - if ( width != data.w || height != data.h ) { - elem.resizedataw = width - elem.resizedatah = height - $(elem).trigger('resize',[width,height]) + var data = { + w:elem.resizedataw, + h:elem.resizedatah } + // If element size has changed since the last time, update the element + // data store and trigger the 'resize' event. + if ( width != data.w || height != data.h ) { + elem.resizedataw = width + elem.resizedatah = height + $(elem).triggerHandler('resize',[width,height]) } - // Loop. - resizePollingLoop() + } - }, pollInterval ) + // Loop. + resizePollingLoop() + } + + function resizePollingLoop() { + // yep, setTimeout, 'cuz requestAnimation doesn't seem to perform that well + resizeTimeout = window.setTimeout(checkResizes, pollInterval) } + $(window).resize(checkResizes) + })(jQuery) },{}],38:[function(require,module,exports){ diff --git a/browser/js/jquery/jquery.resize.js b/browser/js/jquery/jquery.resize.js index 7c4b47f9..d7f7afc5 100644 --- a/browser/js/jquery/jquery.resize.js +++ b/browser/js/jquery/jquery.resize.js @@ -56,38 +56,40 @@ } } - function resizePollingLoop() { + function checkResizes(){ + // Iterate over all elements to which the 'resize' event is bound. + for (var i = elems.length - 1; i >= 0; i--) { + var elem = elems[i], + width = elem.offsetWidth, + height = elem.offsetHeight - // yep, setTimeout, 'cuz requestAnimation doesn't seem to perform that well - resizeTimeout = window.setTimeout(function(){ - // Iterate over all elements to which the 'resize' event is bound. - for (var i = elems.length - 1; i >= 0; i--) { - var elem = elems[i], - width = elem.offsetWidth, - height = elem.offsetHeight + if (!width) continue - if (!width) continue - - var data = { - w:elem.resizedataw, - h:elem.resizedatah - } - - // If element size has changed since the last time, update the element - // data store and trigger the 'resize' event. - if ( width != data.w || height != data.h ) { - elem.resizedataw = width - elem.resizedatah = height - $(elem).trigger('resize',[width,height]) + var data = { + w:elem.resizedataw, + h:elem.resizedatah } + // If element size has changed since the last time, update the element + // data store and trigger the 'resize' event. + if ( width != data.w || height != data.h ) { + elem.resizedataw = width + elem.resizedatah = height + $(elem).triggerHandler('resize',[width,height]) } - // Loop. - resizePollingLoop() + } - }, pollInterval ) + // Loop. + resizePollingLoop() + } + + function resizePollingLoop() { + // yep, setTimeout, 'cuz requestAnimation doesn't seem to perform that well + resizeTimeout = window.setTimeout(checkResizes, pollInterval) } + $(window).resize(checkResizes) + })(jQuery)