Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Position: Handle $(document) and $(window) for the of option. Fixes #…

…5963 - Position: option 'of' accepts jQuery object unless it wraps document. Fixes #5655 - (Possible) Typo in jquery.ui.position 1.8.1.
  • Loading branch information...
commit 52a052be79d21aa519ccb513dc00a7c54868ef03 1 parent 2acfde9
@scottgonzalez scottgonzalez authored
Showing with 26 additions and 3 deletions.
  1. +22 −0 tests/unit/position/position_core.js
  2. +4 −3 ui/jquery.ui.position.js
View
22 tests/unit/position/position_core.js
@@ -131,6 +131,17 @@ test('of', function() {
$('#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',
of: window,
collision: 'none'
});
@@ -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',
View
7 ui/jquery.ui.position.js
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.