]> source.dussan.org Git - jquery-ui.git/commitdiff
Position: Extract getWithinInfo method, use that for tests that call getScrollInfo...
authorJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 13 Apr 2012 13:05:43 +0000 (15:05 +0200)
committerJörn Zaefferer <joern.zaefferer@gmail.com>
Fri, 13 Apr 2012 13:05:43 +0000 (15:05 +0200)
tests/unit/position/position_core_within.js
ui/jquery.ui.position.js

index 9dc91238f93ce361357da54eb514dc1b1e1021bb..c9670f8ff72e089b196781320428ee7cd5a210bc 100644 (file)
@@ -277,7 +277,7 @@ test( "collision: fit, no offset", function() {
 
        collisionTest({
                collision: "fit"
-       }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( within ).width }, "right bottom" );
+       }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
 
        collisionTest2({
                collision: "fit"
@@ -292,7 +292,7 @@ test( "collision: fit, with offset", function() {
        collisionTest({
                collision: "fit",
                at: "right+2 bottom+3"
-       }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( within ).width }, "right bottom");
+       }, { top: addTop + of.position().top + of.height() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom");
 
        collisionTest2({
                collision: "fit",
@@ -397,7 +397,7 @@ test( "collision: fit, with margin", function() {
 
        collisionTest({
                collision: "fit"
-       }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
+       }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
 
        collisionTest2({
                collision: "fit"
@@ -410,7 +410,7 @@ test( "collision: fit, with margin", function() {
 
        collisionTest({
                collision: "fit"
-       }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( within ).width }, "right bottom" );
+       }, { top: addTop + of.position().top + of.height() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - 10 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
 
        collisionTest2({
                collision: "fit"
@@ -423,7 +423,7 @@ test( "collision: fit, with margin", function() {
 
        collisionTest({
                collision: "fit"
-       }, { top: addTop + of.position().top + of.height() - 15 - $.position.getScrollInfo( within ).height, left: addLeft + of.position().left + of.width() - 15 - $.position.getScrollInfo( within ).width }, "right bottom" );
+       }, { top: addTop + of.position().top + of.height() - 15 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).height, left: addLeft + of.position().left + of.width() - 15 - $.position.getScrollInfo( $.position.getWithinInfo( within ) ).width }, "right bottom" );
 
        collisionTest2({
                collision: "fit"
index e83c23e449f5f44ba6b9f343d053fcb5ce710c38..9e7407d7b7ca1281a9414157a877012498fdb91d 100644 (file)
@@ -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 = {},