Skip to main content

Search and Top Navigation

Ticket #4957: patch-4957.patch


File patch-4957.patch, 5.5 KB (added by jzaefferer, January 21, 2010 09:09PM UTC)
Index: ui/jquery.ui.core.js
===================================================================
--- ui/jquery.ui.core.js	(revision 3717)
+++ ui/jquery.ui.core.js	(working copy)
@@ -109,10 +109,10 @@
 			ret = $(context).parent();
 		} else if (value == 'clone') {
 			ret = $(context).clone().removeAttr('id');
-		} else if (value == 'window') {
-			ret = $(context).window(); // requires .window() plugin
+		} else if (value == 'window' || value === window) {
+			ret = $(window);
 		} else if (value.nodeType || typeof value == 'string' || $.isArray(value)) {
-			ret = $(value, context);
+			ret = $(value);
 		} else if ($.isFunction(value)) {
 			ret = value(context);
 		}
@@ -214,12 +214,6 @@
 		}
 
 		return 0;
-	},
-	
-	window: function() {
-		return this.pushStack($.unique($.map(this, function() {
-			return this.ownerDocument.defaultView;
-		})));
 	}
 });
 
Index: ui/jquery.ui.position.js
===================================================================
--- ui/jquery.ui.position.js	(revision 3712)
+++ ui/jquery.ui.position.js	(working copy)
@@ -6,6 +6,9 @@
  * and GPL (GPL-LICENSE.txt) licenses.
  *
  * http://docs.jquery.com/UI/Position
+ * 
+ * Depends:
+ *	jquery.ui.core.js
  */
 (function($) {
 
@@ -25,31 +28,8 @@
 	// make a copy, we don't want to modify arguments
 	options = $.extend({}, options);
 
-	var target = $(options.of),
-		collision = (options.collision || 'flip').split(' '),
-		offset = options.offset ? options.offset.split(' ') : [0, 0],
-		targetWidth,
-		targetHeight,
-		basePosition;
-
-	if (options.of.nodeType === 9) {
-		targetWidth = target.width();
-		targetHeight = target.height();
-		basePosition = { top: 0, left: 0 };
-	} else if (options.of.scrollTo && options.of.document) {
-		targetWidth = target.width();
-		targetHeight = target.height();
-		basePosition = { top: target.scrollTop(), left: target.scrollLeft() };
-	} else if (options.of.preventDefault) {
-		// force left top to allow flipping
-		options.at = 'left top';
-		targetWidth = targetHeight = 0;
-		basePosition = { top: options.of.pageY, left: options.of.pageX };
-	} else {
-		targetWidth = target.outerWidth();
-		targetHeight = target.outerHeight();
-		basePosition = target.offset();
-	}
+	var collision = (options.collision || 'flip').split(' '),
+		offset = options.offset ? options.offset.split(' ') : [0, 0];
 
 	// force my and at to have valid horizontal and veritcal positions
 	// if a value is missing or invalid, it will be converted to center 
@@ -79,36 +59,57 @@
 	}
 	offset[1] = parseInt(offset[1], 10) || 0;
 
-	switch (options.at[0]) {
-		case 'right':
-			basePosition.left += targetWidth;
-			break;
-		case horizontalDefault:
-			basePosition.left += targetWidth / 2;
-			break;
-	}
-
-	switch (options.at[1]) {
-		case 'bottom':
-			basePosition.top += targetHeight;
-			break;
-		case verticalDefault:
-			basePosition.top += targetHeight / 2;
-			break;
-	}
-
-	basePosition.left += offset[0];
-	basePosition.top += offset[1];
-
 	return this.each(function() {
 		var elem = $(this),
 			elemWidth = elem.outerWidth(),
 			elemHeight = elem.outerHeight(),
-			position = $.extend({}, basePosition),
-			over,
 			myOffset,
-			atOffset;
+			atOffset,
+			target = $.ui.element(options.of, this),
+			targetWidth,
+			targetHeight,
+			position;
 
+		if (target[0] && target[0].nodeType === 9) {
+			targetWidth = target.width();
+			targetHeight = target.height();
+			position = { top: 0, left: 0 };
+		} else if (target[0] && target[0].scrollTo && target[0].document) {
+			targetWidth = target.width();
+			targetHeight = target.height();
+			position = { top: target.scrollTop(), left: target.scrollLeft() };
+		} else if (options.of.preventDefault) {
+			// force left top to allow flipping
+			options.at = 'left top';
+			targetWidth = targetHeight = 0;
+			position = { top: options.of.pageY, left: options.of.pageX };
+		} else {
+			targetWidth = target.outerWidth();
+			targetHeight = target.outerHeight();
+			position = target.offset();
+		}
+		
+		position.left += offset[0];
+		position.top += offset[1];
+		
+		switch (options.at[0]) {
+			case 'right':
+				position.left += targetWidth;
+				break;
+			case horizontalDefault:
+				position.left += targetWidth / 2;
+				break;
+		}
+	
+		switch (options.at[1]) {
+			case 'bottom':
+				position.top += targetHeight;
+				break;
+			case verticalDefault:
+				position.top += targetHeight / 2;
+				break;
+		}
+		
 		switch (options.my[0]) {
 			case 'right':
 				position.left -= elemWidth;
Index: tests/unit/position/position.html
===================================================================
--- tests/unit/position/position.html	(revision 3712)
+++ tests/unit/position/position.html	(working copy)
@@ -4,6 +4,7 @@
 	jQuery UI Position Test Suite
 
 	
+	
 	
 
 	
Index: tests/unit/position/position_core.js
===================================================================
--- tests/unit/position/position_core.js	(revision 3712)
+++ tests/unit/position/position_core.js	(working copy)
@@ -129,7 +129,7 @@
 	$('#elx').position({
 		my: 'right bottom',
 		at: 'right bottom',
-		of: window,
+		of: 'window',
 		collision: 'none'
 	});
 	same($('#elx').offset(), {

Download in other formats:

Original Format