X-Git-Url: http://git.asbjorn.biz/?a=blobdiff_plain;f=src%2Fmanipulation.js;h=99d51a80cacb0ca20cde0d8cdca49c534b086a41;hb=b5b3c73db3e4e615e504cd0af08ff6842b104542;hp=9ef41e07554b883391f1fd792bfdf3f77e24daaa;hpb=1b28bba4d2ba692047813cf5185a7d55e2362472;p=jquery.git diff --git a/src/manipulation.js b/src/manipulation.js index 9ef41e0..99d51a8 100644 --- a/src/manipulation.js +++ b/src/manipulation.js @@ -1,16 +1,15 @@ +(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 = /"; - }, + rhtml = /<|&#?\w+;/, + rnocache = /<(?:script|object|embed|option|style)/i, + // checked="checked" or checked (html5) + rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, + raction = /\=([^="'>\s]+\/)>/g, wrapMap = { option: [ 1, "" ], legend: [ 1, "
", "
" ], @@ -44,7 +43,7 @@ jQuery.fn.extend({ return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) ); } - return jQuery.getText( this ); + return jQuery.text( this ); }, wrapAll: function( html ) { @@ -203,6 +202,8 @@ jQuery.fn.extend({ } return jQuery.clean([html.replace(rinlinejQuery, "") + // Handle the case in IE 8 where action=/test/> self-closes a tag + .replace(raction, '="$1">') .replace(rleadingWhitespace, "")], ownerDocument)[0]; } else { return this.cloneNode(true); @@ -226,11 +227,11 @@ jQuery.fn.extend({ null; // See if we can take a shortcut and just use innerHTML - } else if ( typeof value === "string" && !/"); try { for ( var i = 0, l = this.length; i < l; i++ ) { @@ -248,10 +249,8 @@ 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 { @@ -265,16 +264,17 @@ jQuery.fn.extend({ if ( this[0] && this[0].parentNode ) { // Make sure that the elements are removed from the DOM before they are inserted // this can help fix replacing a parent with child elements - if ( !jQuery.isFunction( value ) ) { - value = jQuery( value ).detach(); - - } else { + if ( jQuery.isFunction( value ) ) { return this.each(function(i) { var self = jQuery(this), old = self.html(); self.replaceWith( value.call( this, i, old ) ); }); } + if ( typeof value !== "string" ) { + value = jQuery(value).detach(); + } + return this.each(function() { var next = this.nextSibling, parent = this.parentNode; @@ -296,7 +296,7 @@ jQuery.fn.extend({ }, domManip: function( args, table, callback ) { - var results, first, value = args[0], scripts = [], fragment; + var results, first, value = args[0], scripts = [], fragment, parent; // We can't cloneNode fragments that contain checked, in WebKit if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) { @@ -314,11 +314,14 @@ jQuery.fn.extend({ } if ( this[0] ) { + parent = value && value.parentNode; + // If we're in a fragment, just use that instead of building a new one - if ( args[0] && args[0].parentNode && args[0].parentNode.nodeType === 11 ) { - results = { fragment: args[0].parentNode }; + if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) { + results = { fragment: parent }; + } else { - results = buildFragment( args, this, scripts ); + results = jQuery.buildFragment( args, this, scripts ); } fragment = results.fragment; @@ -350,16 +353,16 @@ jQuery.fn.extend({ } return this; - - function root( elem, cur ) { - return jQuery.nodeName(elem, "table") ? - (elem.getElementsByTagName("tbody")[0] || - elem.appendChild(elem.ownerDocument.createElement("tbody"))) : - elem; - } } }); +function root( elem, cur ) { + return jQuery.nodeName(elem, "table") ? + (elem.getElementsByTagName("tbody")[0] || + elem.appendChild(elem.ownerDocument.createElement("tbody"))) : + elem; +} + function cloneCopyEvent(orig, ret) { var i = 0; @@ -383,17 +386,16 @@ 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); // Only cache "small" (1/2 KB) strings that are associated with the main document // Cloning options loses the selected state, so don't cache them - // IE 6 doesn't like it when you put elements in a fragment + // IE 6 doesn't like it when you put or elements in a fragment // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document && - args[0].indexOf(" 0 ? this.clone(true) : this).get(); - jQuery.fn[ original ].apply( jQuery(insert[i]), elems ); + jQuery( insert[i] )[ original ]( elems ); ret = ret.concat( elems ); } @@ -470,7 +473,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(), @@ -523,7 +526,7 @@ jQuery.extend({ } if ( fragment ) { - for ( var i = 0; ret[i]; i++ ) { + for ( i = 0; ret[i]; i++ ) { if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) { scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] ); @@ -540,24 +543,58 @@ jQuery.extend({ }, cleanData: function( elems ) { - var data, id, cache = jQuery.cache; + var data, id, cache = jQuery.cache, + special = jQuery.event.special, + deleteExpando = jQuery.support.deleteExpando; for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) { + if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) { + continue; + } + id = elem[ jQuery.expando ]; if ( id ) { data = cache[ id ]; - if ( data.events ) { - for ( var event in data.events ) { - removeEvent( elem, event, data.handle ); + if ( data && data.events ) { + for ( var type in data.events ) { + if ( special[ type ] ) { + jQuery.event.remove( elem, type ); + + } else { + jQuery.removeEvent( elem, type, data.handle ); + } } } - removeExpando( elem ); + if ( deleteExpando ) { + delete elem[ jQuery.expando ]; + + } else if ( elem.removeAttribute ) { + elem.removeAttribute( jQuery.expando ); + } delete cache[ id ]; } } } }); + +function evalScript( i, elem ) { + if ( elem.src ) { + jQuery.ajax({ + url: elem.src, + async: false, + dataType: "script" + }); + } else { + jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" ); + } + + if ( elem.parentNode ) { + elem.parentNode.removeChild( elem ); + } +} + +})( jQuery );