From cb67eb535c0f695941235f402cc4b405f70bc022 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Jo=CC=88rn=20Zaefferer?= Date: Fri, 13 Apr 2012 15:12:37 +0200 Subject: [PATCH] Position: Cache the scrollbarWidth calculation result --- ui/jquery.ui.position.js | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index 9e7407d7b..31da2237b 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -16,10 +16,14 @@ var rhorizontal = /left|center|right/, roffset = /[\+\-]\d+%?/, rposition = /^\w+/, rpercent = /%$/, - _position = $.fn.position; + _position = $.fn.position, + cachedScrollbarWidth; $.position = { scrollbarWidth: function() { + if ( cachedScrollbarWidth !== undefined ) { + return cachedScrollbarWidth; + } var w1, w2, div = $( "
" ), innerDiv = div.children()[0]; @@ -36,7 +40,7 @@ $.position = { div.remove(); - return w1 - w2; + return (cachedScrollbarWidth = w1 - w2); }, getScrollInfo: function( within ) { var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ), -- 2.39.5