]> source.dussan.org Git - jquery-ui.git/commitdiff
Position: Handle $(document) and $(window) for the of option. Fixes #5963 - Position...
authorScott González <scott.gonzalez@gmail.com>
Fri, 27 Aug 2010 17:34:14 +0000 (13:34 -0400)
committerScott González <scott.gonzalez@gmail.com>
Fri, 27 Aug 2010 17:34:14 +0000 (13:34 -0400)
tests/unit/position/position_core.js
ui/jquery.ui.position.js

index 3976e43ab21aae5adf7df5ed22792a0c343e3830..426231ee3c515857bcaf33bf72875ada1f47be35 100644 (file)
@@ -128,6 +128,17 @@ test('of', function() {
                left: $(document).width() - 10
        }, 'document');
        
+       $('#elx').position({
+               my: 'right bottom',
+               at: 'right bottom',
+               of: $(document),
+               collision: 'none'
+       });
+       same($('#elx').offset(), {
+               top: $(document).height() - 10,
+               left: $(document).width() - 10
+       }, 'document');
+       
        $('#elx').position({
                my: 'right bottom',
                at: 'right bottom',
@@ -139,6 +150,17 @@ test('of', function() {
                left: $(window).width() - 10
        }, 'window');
        
+       $('#elx').position({
+               my: 'right bottom',
+               at: 'right bottom',
+               of: $(window),
+               collision: 'none'
+       });
+       same($('#elx').offset(), {
+               top: $(window).height() - 10,
+               left: $(window).width() - 10
+       }, 'window');
+       
        $(window).scrollTop(500).scrollLeft(200);
        $('#elx').position({
                my: 'right bottom',
index dbe28ffa59ab4b3b41fb2670bd141986e347d441..a14c5c6127dfe9ca4285406e57d6178433769da8 100644 (file)
@@ -26,21 +26,22 @@ $.fn.position = function( options ) {
        options = $.extend( {}, options );
 
        var target = $( options.of ),
+               targetElem = target[0],
                collision = ( options.collision || "flip" ).split( " " ),
                offset = options.offset ? options.offset.split( " " ) : [ 0, 0 ],
                targetWidth,
                targetHeight,
                basePosition;
 
-       if ( options.of.nodeType === 9 ) {
+       if ( targetElem.nodeType === 9 ) {
                targetWidth = target.width();
                targetHeight = target.height();
                basePosition = { top: 0, left: 0 };
-       } else if ( options.of.scrollTo && options.of.document ) {
+       } else if ( targetElem.scrollTo && targetElem.document ) {
                targetWidth = target.width();
                targetHeight = target.height();
                basePosition = { top: target.scrollTop(), left: target.scrollLeft() };
-       } else if ( options.of.preventDefault ) {
+       } else if ( targetElem.preventDefault ) {
                // force left top to allow flipping
                options.at = "left top";
                targetWidth = targetHeight = 0;