diff options
author | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-04-13 15:05:43 +0200 |
---|---|---|
committer | Jörn Zaefferer <joern.zaefferer@gmail.com> | 2012-04-13 15:05:43 +0200 |
commit | 7dcfae7da2242f807e053cd4bac8d0799c38c86f (patch) | |
tree | c4d2209744c249f6844393a0a25b33196b655045 /ui | |
parent | c0a5e52f875d3c4179f485e7209bd9e26d691110 (diff) | |
download | jquery-ui-7dcfae7da2242f807e053cd4bac8d0799c38c86f.tar.gz jquery-ui-7dcfae7da2242f807e053cd4bac8d0799c38c86f.zip |
Position: Extract getWithinInfo method, use that for tests that call getScrollInfo directly, pass within info to that, gets rid of a few more DOM accesses
Diffstat (limited to 'ui')
-rw-r--r-- | ui/jquery.ui.position.js | 38 |
1 files changed, 20 insertions, 18 deletions
diff --git a/ui/jquery.ui.position.js b/ui/jquery.ui.position.js index e83c23e44..9e7407d7b 100644 --- a/ui/jquery.ui.position.js +++ b/ui/jquery.ui.position.js @@ -38,16 +38,28 @@ $.position = { return w1 - w2; }, - getScrollInfo: function(within) { - var notWindow = within[0] !== window, - overflowX = notWindow ? within.css( "overflow-x" ) : "", - overflowY = notWindow ? within.css( "overflow-y" ) : "", + getScrollInfo: function( within ) { + var overflowX = within.isWindow ? "" : within.element.css( "overflow-x" ), + overflowY = within.isWindow ? "" : within.element.css( "overflow-y" ), scrollbarWidth = overflowX === "auto" || overflowX === "scroll" ? $.position.scrollbarWidth() : 0, scrollbarHeight = overflowY === "auto" || overflowY === "scroll" ? $.position.scrollbarWidth() : 0; return { - height: within.height() < within[0].scrollHeight ? scrollbarHeight : 0, - width: within.width() < within[0].scrollWidth ? scrollbarWidth : 0 + height: within.height < within.element[0].scrollHeight ? scrollbarHeight : 0, + width: within.width < within.element[0].scrollWidth ? scrollbarWidth : 0 + }; + }, + getWithinInfo: function( element ) { + var withinElement = $( element || window ), + isWindow = $.isWindow( withinElement[0] ); + return { + element: withinElement, + isWindow: isWindow, + offset: withinElement.offset(), + scrollLeft: withinElement.scrollLeft(), + scrollTop: withinElement.scrollTop(), + width: isWindow ? withinElement.width() : withinElement.outerWidth(), + height: isWindow ? withinElement.height() : withinElement.outerHeight() }; }, getOffsets: function( offsets, width, height ) { @@ -70,18 +82,8 @@ $.fn.position = function( options ) { options = $.extend( {}, options ); var target = $( options.of ), - withinElement = $( options.within || window ), - isWindow = $.isWindow( withinElement[0] ), - within = { - element: withinElement, - isWindow: isWindow, - offset: withinElement.offset(), - scrollLeft: withinElement.scrollLeft(), - scrollTop: withinElement.scrollTop(), - width: isWindow ? withinElement.width() : withinElement.outerWidth(), - height: isWindow ? withinElement.height() : withinElement.outerHeight() - }, - scrollInfo = $.position.getScrollInfo( withinElement ), + within = $.position.getWithinInfo( options.within ), + scrollInfo = $.position.getScrollInfo( within ), targetElem = target[0], collision = ( options.collision || "flip" ).split( " " ), offsets = {}, |