git.asbjorn.biz
/
jquery.git
/ commitdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
| commitdiff |
tree
raw
|
patch
|
inline
| side by side (parent:
0c97178
)
Only try to wrap the element if it's not disconnected, fixed #3828.
author
John Resig
<jeresig@gmail.com>
Mon, 12 Jan 2009 14:07:14 +0000
(14:07 +0000)
committer
John Resig
<jeresig@gmail.com>
Mon, 12 Jan 2009 14:07:14 +0000
(14:07 +0000)
src/core.js
patch
|
blob
|
history
test/unit/core.js
patch
|
blob
|
history
diff --git
a/src/core.js
b/src/core.js
index
6c439a5
..
a11ceb4
100644
(file)
--- a/
src/core.js
+++ b/
src/core.js
@@
-206,20
+206,22
@@
jQuery.fn = jQuery.prototype = {
},
wrapAll: function( html ) {
},
wrapAll: function( html ) {
- if ( this[0] )
+ if ( this[0] ) {
// The elements to wrap the target around
// The elements to wrap the target around
- jQuery( html, this[0].ownerDocument )
- .clone()
- .insertBefore( this[0] )
- .map(function(){
- var elem = this;
-
- while ( elem.firstChild )
- elem = elem.firstChild;
-
- return elem;
- })
- .append(this);
+ var wrap = jQuery( html, this[0].ownerDocument ).clone();
+
+ if ( this[0].parentNode )
+ wrap.insertBefore( this[0] );
+
+ wrap.map(function(){
+ var elem = this;
+
+ while ( elem.firstChild )
+ elem = elem.firstChild;
+
+ return elem;
+ }).append(this);
+ }
return this;
},
return this;
},
diff --git
a/test/unit/core.js
b/test/unit/core.js
index
8483361
..
80a9335
100644
(file)
--- a/
test/unit/core.js
+++ b/
test/unit/core.js
@@
-751,7
+751,7
@@
test("text()", function() {
});
test("wrap(String|Element)", function() {
});
test("wrap(String|Element)", function() {
- expect(8);
+ expect(10);
var defaultText = 'Try them out:'
var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
var defaultText = 'Try them out:'
var result = jQuery('#first').wrap('<div class="red"><span></span></div>').text();
equals( defaultText, result, 'Check for wrapping of on-the-fly html' );
@@
-776,6
+776,11
@@
test("wrap(String|Element)", function() {
j.wrap("<i></i>");
equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
j.wrap("<i></i>");
equals( jQuery("#nonnodes > i").length, 3, "Check node,textnode,comment wraps ok" );
equals( jQuery("#nonnodes > i").text(), j.text() + j[1].nodeValue, "Check node,textnode,comment wraps doesn't hurt text" );
+
+ // Try wrapping a disconnected node
+ j = jQuery("<label/>").wrap("<li/>");
+ equals( j[0].nodeName, "LABEL", "Element is a label" );
+ equals( j[0].parentNode.nodeName, "LI", "Element has been wrapped" );
});
test("wrapAll(String|Element)", function() {
});
test("wrapAll(String|Element)", function() {