Skip to main content

Bug Tracker

Side navigation

Ticket #1264: patch.txt


File patch.txt, 2.8 KB (added by flamefork, June 02, 2007 03:54PM UTC)
@@ -42,7 +42,7 @@
 		// HANDLE: $(html) -> $(array)
 		var m = /^[^<]*(<(.|\s)+>)[^>]*$/.exec(a);
 		if ( m )
-			a = jQuery.clean( [ m[1] ] );
+			a = jQuery.clean( [ m[1] ], c );
 		
 		// HANDLE: $(expr)
 		else
@@ -554,8 +554,8 @@
 	 * @cat DOM/Attributes
 	 */
 	text: function(e) {
-		if ( typeof e == "string" )
-			return this.empty().append( document.createTextNode( e ) );
+		if ( typeof e == "string" && this.length )
+			return this.empty().append( this.get(0).ownerDocument.createTextNode( e ) );
 
 		var t = "";
 		jQuery.each( e || this, function(){
@@ -616,7 +616,7 @@
 	 */
 	wrap: function() {
 		// The elements to wrap the target around
-		var a = jQuery.clean(arguments);
+		var a = jQuery.clean(arguments, this);
 
 		// Wrap each of the matched elements individually
 		return this.each(function(){
@@ -667,7 +667,7 @@
 	append: function() {
 		return this.domManip(arguments, true, 1, function(a){
 			this.appendChild( a );
-		});
+		}, this);
 	},
 
 	/**
@@ -1122,9 +1122,9 @@
 	 * @type jQuery
 	 * @cat Core
 	 */
-	domManip: function(args, table, dir, fn){
+	domManip: function(args, table, dir, fn, context){
 		var clone = this.length > 1; 
-		var a = jQuery.clean(args);
+		var a = jQuery.clean(args, context);
 		if ( dir < 0 )
 			a.reverse();
 
@@ -1132,7 +1132,7 @@
 			var obj = this;
 
 			if ( table && jQuery.nodeName(this, "table") && jQuery.nodeName(a[0], "tr") )
-				obj = this.getElementsByTagName("tbody")[0] || this.appendChild(document.createElement("tbody"));
+				obj = this.getElementsByTagName("tbody")[0] || this.appendChild(this.ownerDocument.createElement("tbody"));
 
 			jQuery.each( a, function(){
 				fn.apply( obj, [ clone ? this.cloneNode(true) : this ] );
@@ -1442,10 +1442,21 @@
 		return ret;
 	},
 	
-	clean: function(a) {
+	clean: function(a, context) {
 		var r = [];
+        var contextDoc = document;
+        if (context) {
+            if (context instanceof jQuery && context.length) {
+                context = context.get(0);
+            }
+            if (context.ownerDocument) {
+                contextDoc = context.ownerDocument;
+            } else if (context.body) {
+                contextDoc = context;
+            }
+        }
 
-		jQuery.each( a, function(i,arg){
+        jQuery.each( a, function(i,arg){
 			if ( !arg ) return;
 
 			if ( arg.constructor == Number )
@@ -1454,7 +1465,7 @@
 			 // Convert html string into DOM nodes
 			if ( typeof arg == "string" ) {
 				// Trim whitespace, otherwise indexOf won't work as expected
-				var s = jQuery.trim(arg), div = document.createElement("div"), tb = [];
+				var s = jQuery.trim(arg), div = contextDoc.createElement("div"), tb = [];
 
 				var wrap =
 					 // option or optgroup

Download in other formats:

Original Format