X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=e09dd7eb4c91b95430fadb5034a193dad4c1b050;hb=b2ea79c401588f9108b99c748699426063649143;hp=cb898cc3ca109b16b60d48f63424cf1cff610d53;hpb=8effe3a7dee91c833cc1774646da9d743600c64c;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index cb898cc..e09dd7e 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,17 +1,17 @@ +(function( jQuery ) { + var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g, rleadingWhitespace = /^\s+/, - rxhtmlTag = /(<([\w:]+)[^>]*?)\/>/g, - rselfClosing = /^(?:area|br|col|embed|hr|img|input|link|meta|param)$/i, + rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig, rtagName = /<([\w:]+)/, rtbody = /"; - }, + rnocache = /<(?:script|object|embed|option|style)/i, + // checked="checked" or checked (html5) + rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, + raction = /\=([^="'>\s]+\/)>/g, + rbodystart = /^\s*\s*$/i, wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], @@ -36,7 +36,8 @@ jQuery.fn.extend({ text: function( text ) { if ( jQuery.isFunction(text) ) { return this.each(function(i) { - var self = jQuery(this); + var self = jQuery( this ); + self.text( text.call(this, i, self.text()) ); }); } @@ -85,7 +86,8 @@ jQuery.fn.extend({ } return this.each(function() { - var self = jQuery( this ), contents = self.contents(); + var self = jQuery( this ), + contents = self.contents(); if ( contents.length ) { contents.wrapAll( html ); @@ -196,16 +198,19 @@ jQuery.fn.extend({ // attributes in IE that are actually only stored // as properties will not be copied (such as the // the name attribute on an input). - var html = this.outerHTML, ownerDocument = this.ownerDocument; + var html = this.outerHTML, + ownerDocument = this.ownerDocument; if ( !html ) { var div = ownerDocument.createElement("div"); div.appendChild( this.cloneNode(true) ); html = div.innerHTML; + } else if ( rbodystart.test(html) && rbodyend.test(html) ) { + html = html.replace( rbodystart, "
" ).replace( rbodyend, "
" ); } return jQuery.clean([html.replace(rinlinejQuery, "") // Handle the case in IE 8 where action=/test/> self-closes a tag - .replace(/\=([^="'>\s]+\/)>/g, '="$1">') + .replace(raction, '="$1">') .replace(rleadingWhitespace, "")], ownerDocument)[0]; } else { return this.cloneNode(true); @@ -233,7 +238,7 @@ jQuery.fn.extend({ (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) && !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) { - value = value.replace(rxhtmlTag, fcloseTag); + value = value.replace(rxhtmlTag, "<$1>"); try { for ( var i = 0, l = this.length; i < l; i++ ) { @@ -251,10 +256,9 @@ jQuery.fn.extend({ } else if ( jQuery.isFunction( value ) ) { this.each(function(i){ - var self = jQuery(this), old = self.html(); - self.empty().append(function(){ - return value.call( this, i, old ); - }); + var self = jQuery( this ); + + self.html( value.call(this, i, self.html()) ); }); } else { @@ -276,13 +280,14 @@ jQuery.fn.extend({ } if ( typeof value !== "string" ) { - value = jQuery(value).detach(); + value = jQuery( value ).detach(); } return this.each(function() { - var next = this.nextSibling, parent = this.parentNode; + var next = this.nextSibling, + parent = this.parentNode; - jQuery(this).remove(); + jQuery( this ).remove(); if ( next ) { jQuery(next).before( value ); @@ -300,7 +305,9 @@ jQuery.fn.extend({ }, domManip: function( args, table, callback ) { - var results, first, value = args[0], scripts = [], fragment, parent; + var results, first, fragment, parent, + value = args[0], + scripts = []; // We can't cloneNode fragments that contain checked, in WebKit if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) { @@ -325,7 +332,7 @@ jQuery.fn.extend({ results = { fragment: parent }; } else { - results = buildFragment( args, this, scripts ); + results = jQuery.buildFragment( args, this, scripts ); } fragment = results.fragment; @@ -375,7 +382,9 @@ function cloneCopyEvent(orig, ret) { return; } - var oldData = jQuery.data( orig[i++] ), curData = jQuery.data( this, oldData ), events = oldData && oldData.events; + var oldData = jQuery.data( orig[i++] ), + curData = jQuery.data( this, oldData ), + events = oldData && oldData.events; if ( events ) { delete curData.handle; @@ -390,7 +399,7 @@ function cloneCopyEvent(orig, ret) { }); } -function buildFragment( args, nodes, scripts ) { +jQuery.buildFragment = function( args, nodes, scripts ) { var fragment, cacheable, cacheresults, doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document); @@ -420,7 +429,7 @@ function buildFragment( args, nodes, scripts ) { } return { fragment: fragment, cacheable: cacheable }; -} +}; jQuery.fragments = {}; @@ -432,7 +441,8 @@ jQuery.each({ replaceAll: "replaceWith" }, function( name, original ) { jQuery.fn[ name ] = function( selector ) { - var ret = [], insert = jQuery( selector ), + var ret = [], + insert = jQuery( selector ), parent = this.length === 1 && this[0].parentNode; if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) { @@ -477,7 +487,7 @@ jQuery.extend({ } else if ( typeof elem === "string" ) { // Fix "XHTML"-style tags in all browsers - elem = elem.replace(rxhtmlTag, fcloseTag); + elem = elem.replace(rxhtmlTag, "<$1>"); // Trim whitespace, otherwise indexOf won't work as expected var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(), @@ -567,7 +577,7 @@ jQuery.extend({ jQuery.event.remove( elem, type ); } else { - removeEvent( elem, type, data.handle ); + jQuery.removeEvent( elem, type, data.handle ); } } } @@ -599,4 +609,6 @@ function evalScript( i, elem ) { if ( elem.parentNode ) { elem.parentNode.removeChild( elem ); } -} \ No newline at end of file +} + +})( jQuery );