X-Git-Url: http://git.asbjorn.it/?a=blobdiff_plain;ds=inline;f=src%2Fmanipulation.js;h=e1657a8cf58b65ea9f4e02b7f6e16e41f56be355;hb=93fdbeb963a9c350f807818c7cc99982942a92f3;hp=105a0a949bbfc4da1ada191d2ccf89324923478b;hpb=391f83b2a251abd5ab27aeb52a647a853906ce66;p=jquery.git
diff --git a/src/manipulation.js b/src/manipulation.js
index 105a0a9..e1657a8 100644
--- a/src/manipulation.js
+++ b/src/manipulation.js
@@ -17,6 +17,7 @@ var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
tr: [ 2, "
" ],
td: [ 3, "" ],
col: [ 2, "" ],
+ area: [ 1, "" ],
_default: [ 0, "", "" ]
};
@@ -35,20 +36,7 @@ jQuery.fn.extend({
return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
}
- var ret = "";
-
- jQuery.each( this, function() {
- // Get the text from text nodes and CDATA nodes
- if ( this.nodeType === 3 || this.nodeType === 4 ) {
- ret += this.nodeValue;
-
- // Traverse everything else, except comment nodes
- } else if ( this.nodeType !== 8 ) {
- ret += jQuery.fn.text.call( this.childNodes );
- }
- });
-
- return ret;
+ return jQuery.getText( this );
},
wrapAll: function( html ) {
@@ -168,21 +156,8 @@ jQuery.fn.extend({
// Copy the events from the original to the clone
if ( events === true ) {
- var orig = this.find("*").andSelf(), i = 0;
-
- ret.find("*").andSelf().each(function(){
- if ( this.nodeName !== orig[i].nodeName ) { return; }
-
- var events = jQuery.data( orig[i], "events" );
-
- for ( var type in events ) {
- for ( var handler in events[ type ] ) {
- jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
- }
- }
-
- i++;
- });
+ cloneCopyEvent( this, ret );
+ cloneCopyEvent( this.find("*"), ret.find("*") );
}
// Return the cloned set
@@ -223,7 +198,17 @@ jQuery.fn.extend({
replaceWith: function( value ) {
if ( this[0] && this[0].parentNode ) {
- return this.after( value ).remove();
+ return this.each(function(){
+ var next = this.nextSibling, parent = this.parentNode;
+
+ jQuery(this).remove();
+
+ if ( next ) {
+ jQuery(next).before( value );
+ } else {
+ jQuery(parent).append( value );
+ }
+ });
} else {
return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
}
@@ -284,6 +269,24 @@ jQuery.fn.extend({
}
});
+function cloneCopyEvent(orig, ret) {
+ var i = 0;
+
+ ret.each(function(){
+ if ( this.nodeName !== orig[i].nodeName ) {
+ return;
+ }
+
+ var events = jQuery.data( orig[i], "events" );
+
+ for ( var type in events ) {
+ for ( var handler in events[ type ] ) {
+ jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
+ }
+ }
+ });
+}
+
function buildFragment(args, nodes, scripts){
var fragment, cacheable, cached, cacheresults, doc;
@@ -373,7 +376,7 @@ jQuery.extend({
context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
}
- var ret = [], div = context.createElement("div");
+ var ret = [];
jQuery.each(elems, function(i, elem){
if ( typeof elem === "number" ) {
@@ -393,7 +396,8 @@ jQuery.extend({
// Trim whitespace, otherwise indexOf won't work as expected
var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
wrap = wrapMap[ tag ] || wrapMap._default,
- depth = wrap[0];
+ depth = wrap[0],
+ div = context.createElement("div");
// Go to html and back, then peel off extra wrappers
div.innerHTML = wrap[1] + elem + wrap[2];
@@ -459,7 +463,7 @@ jQuery.extend({
function cleanData( elems ) {
for ( var i = 0, elem, id; (elem = elems[i]) != null; i++ ) {
- if ( (id = elem[expando]) ) {
+ if ( !jQuery.noData[elem.nodeNode.toLowerCase()] && (id = elem[expando]) ) {
delete jQuery.cache[ id ];
}
}