1 var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
2 rleadingWhitespace = /^\s+/,
3 rsingleTag = /^<(\w+)\s*\/?>$/,
4 rxhtmlTag = /(<(\w+)[^>]*?)\/>/g,
5 rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i,
6 rinsideTable = /^<(thead|tbody|tfoot|colg|cap)/,
10 text: function( text ) {
11 if ( typeof text !== "object" && text !== undefined )
12 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
16 jQuery.each( text || this, function(){
17 jQuery.each( this.childNodes, function(){
18 if ( this.nodeType !== 8 ) {
19 ret += this.nodeType !== 1 ?
21 jQuery.fn.text( [ this ] );
29 wrapAll: function( html ) {
30 if ( jQuery.isFunction( html ) ) {
31 return this.each(function() {
32 jQuery(this).wrapAll( html.apply(this, arguments) );
37 // The elements to wrap the target around
38 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone();
40 if ( this[0].parentNode ) {
41 wrap.insertBefore( this[0] );
47 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
48 elem = elem.firstChild;
58 wrapInner: function( html ) {
59 return this.each(function(){
60 jQuery( this ).contents().wrapAll( html );
64 wrap: function( html ) {
65 return this.each(function(){
66 jQuery( this ).wrapAll( html );
71 return this.domManip(arguments, true, function(elem){
72 if ( this.nodeType === 1 ) {
73 this.appendChild( elem );
79 return this.domManip(arguments, true, function(elem){
80 if ( this.nodeType === 1 ) {
81 this.insertBefore( elem, this.firstChild );
87 return this.domManip(arguments, false, function(elem){
88 this.parentNode.insertBefore( elem, this );
93 return this.domManip(arguments, false, function(elem){
94 this.parentNode.insertBefore( elem, this.nextSibling );
98 clone: function( events ) {
100 var ret = this.map(function(){
101 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
102 // IE copies events bound via attachEvent when
103 // using cloneNode. Calling detachEvent on the
104 // clone will also remove the events from the orignal
105 // In order to get around this, we use innerHTML.
106 // Unfortunately, this means some modifications to
107 // attributes in IE that are actually only stored
108 // as properties will not be copied (such as the
109 // the name attribute on an input).
110 var html = this.outerHTML, ownerDocument = this.ownerDocument;
112 var div = ownerDocument.createElement("div");
113 div.appendChild( this.cloneNode(true) );
114 html = div.innerHTML;
117 return jQuery.clean([html.replace(rinlinejQuery, "")
118 .replace(rleadingWhitespace, "")], ownerDocument)[0];
120 return this.cloneNode(true);
124 // Copy the events from the original to the clone
125 if ( events === true ) {
126 var orig = this.find("*").andSelf(), i = 0;
128 ret.find("*").andSelf().each(function(){
129 if ( this.nodeName !== orig[i].nodeName ) { return; }
131 var events = jQuery.data( orig[i], "events" );
133 for ( var type in events ) {
134 for ( var handler in events[ type ] ) {
135 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
143 // Return the cloned set
147 html: function( value ) {
148 return value === undefined ?
150 this[0].innerHTML.replace(rinlinejQuery, "") :
152 this.empty().append( value );
155 replaceWith: function( value ) {
156 return this.after( value ).remove();
159 domManip: function( args, table, callback ) {
160 var fragment, scripts, cacheable, cached, cacheresults, first,
163 if ( jQuery.isFunction(value) ) {
164 return this.each(function() {
165 args[0] = value.call(this);
166 return jQuery(this).domManip( args, table, callback );
171 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("<option") < 0 ) {
173 cacheresults = jQuery.fragments[ args[0] ];
174 if ( cacheresults ) {
175 if ( cacheresults !== 1 ) {
176 fragment = cacheresults;
183 fragment = (this[0].ownerDocument || this[0]).createDocumentFragment();
184 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment );
187 first = fragment.firstChild;
190 table = table && jQuery.nodeName( first, "tr" );
192 for ( var i = 0, l = this.length; i < l; i++ ) {
195 root(this[i], first) :
197 cacheable || this.length > 1 || i > 0 ?
198 fragment.cloneNode(true) :
205 jQuery.each( scripts, evalScript );
209 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
215 function root( elem, cur ) {
216 return jQuery.nodeName(elem, "table") ?
217 (elem.getElementsByTagName("tbody")[0] ||
218 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
224 jQuery.fragments = {};
228 prependTo: "prepend",
229 insertBefore: "before",
230 insertAfter: "after",
231 replaceAll: "replaceWith"
232 }, function(name, original){
233 jQuery.fn[ name ] = function( selector ) {
234 var ret = [], insert = jQuery( selector );
236 for ( var i = 0, l = insert.length; i < l; i++ ) {
237 var elems = (i > 0 ? this.clone(true) : this).get();
238 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
239 ret = ret.concat( elems );
242 return this.pushStack( ret, name, selector );
247 remove: function( selector ) {
248 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
249 if ( this.nodeType === 1 ) {
250 cleanData( jQuery("*", this).add(this) );
253 if ( this.parentNode ) {
254 this.parentNode.removeChild( this );
260 // Remove element nodes and prevent memory leaks
261 if ( this.nodeType === 1 ) {
262 cleanData( jQuery("*", this) );
265 // Remove any remaining nodes
266 while ( this.firstChild ) {
267 this.removeChild( this.firstChild );
270 }, function(name, fn){
271 jQuery.fn[ name ] = function(){
272 return this.each( fn, arguments );
277 clean: function( elems, context, fragment ) {
278 context = context || document;
280 // !context.createElement fails in IE with an error but returns typeof 'object'
281 if ( typeof context.createElement === "undefined" ) {
282 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
285 // If a single string is passed in and it's a single tag
286 // just do a createElement and skip the rest
287 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
288 var match = rsingleTag.exec(elems[0]);
290 return [ context.createElement( match[1] ) ];
294 var ret = [], scripts = [], div = context.createElement("div");
296 jQuery.each(elems, function(i, elem){
297 if ( typeof elem === "number" ) {
301 if ( !elem ) { return; }
303 // Convert html string into DOM nodes
304 if ( typeof elem === "string" ) {
305 // Fix "XHTML"-style tags in all browsers
306 elem = elem.replace(rxhtmlTag, function(all, front, tag){
307 return rselfClosing.test(tag) ?
309 front + "></" + tag + ">";
312 // Trim whitespace, otherwise indexOf won't work as expected
313 var tags = elem.replace(rleadingWhitespace, "")
314 .substring(0, 10).toLowerCase();
317 // option or optgroup
318 !tags.indexOf("<opt") &&
319 [ 1, "<select multiple='multiple'>", "</select>" ] ||
321 !tags.indexOf("<leg") &&
322 [ 1, "<fieldset>", "</fieldset>" ] ||
324 rinsideTable.test(tags) &&
325 [ 1, "<table>", "</table>" ] ||
327 !tags.indexOf("<tr") &&
328 [ 2, "<table><tbody>", "</tbody></table>" ] ||
330 // <thead> matched above
331 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
332 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
334 !tags.indexOf("<col") &&
335 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
337 // IE can't serialize <link> and <script> tags normally
338 !jQuery.support.htmlSerialize &&
339 [ 1, "div<div>", "</div>" ] ||
343 // Go to html and back, then peel off extra wrappers
344 div.innerHTML = wrap[1] + elem + wrap[2];
346 // Move to the right depth
347 while ( wrap[0]-- ) {
351 // Remove IE's autoinserted <tbody> from table fragments
352 if ( !jQuery.support.tbody ) {
354 // String was a <table>, *may* have spurious <tbody>
355 var hasBody = rtbody.test(elem),
356 tbody = !tags.indexOf("<table") && !hasBody ?
357 div.firstChild && div.firstChild.childNodes :
359 // String was a bare <thead> or <tfoot>
360 wrap[1] == "<table>" && !hasBody ?
364 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
365 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
366 tbody[ j ].parentNode.removeChild( tbody[ j ] );
372 // IE completely kills leading whitespace when innerHTML is used
373 if ( !jQuery.support.leadingWhitespace && leadingWhitespace.test( elem ) ) {
374 div.insertBefore( context.createTextNode( leadingWhitespace.exec(elem)[0] ), div.firstChild );
377 elem = jQuery.makeArray( div.childNodes );
380 if ( elem.nodeType ) {
383 ret = jQuery.merge( ret, elem );
389 for ( var i = 0; ret[i]; i++ ) {
390 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
391 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
393 if ( ret[i].nodeType === 1 ) {
394 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
396 fragment.appendChild( ret[i] );
407 function cleanData( elems ) {
408 for ( var i = 0, l = elems.length; i < l; i++ ) {
409 var id = elems[i][expando];
411 delete jQuery.cache[ id ];