3 var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
4 rleadingWhitespace = /^\s+/,
5 rxhtmlTag = /<(?!area|br|col|embed|hr|img|input|link|meta|param)(([\w:]+)[^>]*)\/>/ig,
6 rtagName = /<([\w:]+)/,
9 rnocache = /<(?:script|object|embed|option|style)/i,
10 // checked="checked" or checked (html5)
11 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i,
12 raction = /\=([^="'>\s]+\/)>/g,
13 rbodystart = /^\s*<body/i,
14 rbodyend = /<\/body>\s*$/i,
16 option: [ 1, "<select multiple='multiple'>", "</select>" ],
17 legend: [ 1, "<fieldset>", "</fieldset>" ],
18 thead: [ 1, "<table>", "</table>" ],
19 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
20 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
21 col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
22 area: [ 1, "<map>", "</map>" ],
23 _default: [ 0, "", "" ]
26 wrapMap.optgroup = wrapMap.option;
27 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
28 wrapMap.th = wrapMap.td;
30 // IE can't serialize <link> and <script> tags normally
31 if ( !jQuery.support.htmlSerialize ) {
32 wrapMap._default = [ 1, "div<div>", "</div>" ];
36 text: function( text ) {
37 if ( jQuery.isFunction(text) ) {
38 return this.each(function(i) {
39 var self = jQuery( this );
41 self.text( text.call(this, i, self.text()) );
45 if ( typeof text !== "object" && text !== undefined ) {
46 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
49 return jQuery.text( this );
52 wrapAll: function( html ) {
53 if ( jQuery.isFunction( html ) ) {
54 return this.each(function(i) {
55 jQuery(this).wrapAll( html.call(this, i) );
60 // The elements to wrap the target around
61 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
63 if ( this[0].parentNode ) {
64 wrap.insertBefore( this[0] );
70 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
71 elem = elem.firstChild;
81 wrapInner: function( html ) {
82 if ( jQuery.isFunction( html ) ) {
83 return this.each(function(i) {
84 jQuery(this).wrapInner( html.call(this, i) );
88 return this.each(function() {
89 var self = jQuery( this ),
90 contents = self.contents();
92 if ( contents.length ) {
93 contents.wrapAll( html );
101 wrap: function( html ) {
102 return this.each(function() {
103 jQuery( this ).wrapAll( html );
108 return this.parent().each(function() {
109 if ( !jQuery.nodeName( this, "body" ) ) {
110 jQuery( this ).replaceWith( this.childNodes );
116 return this.domManip(arguments, true, function( elem ) {
117 if ( this.nodeType === 1 ) {
118 this.appendChild( elem );
123 prepend: function() {
124 return this.domManip(arguments, true, function( elem ) {
125 if ( this.nodeType === 1 ) {
126 this.insertBefore( elem, this.firstChild );
132 if ( this[0] && this[0].parentNode ) {
133 return this.domManip(arguments, false, function( elem ) {
134 this.parentNode.insertBefore( elem, this );
136 } else if ( arguments.length ) {
137 var set = jQuery(arguments[0]);
138 set.push.apply( set, this.toArray() );
139 return this.pushStack( set, "before", arguments );
144 if ( this[0] && this[0].parentNode ) {
145 return this.domManip(arguments, false, function( elem ) {
146 this.parentNode.insertBefore( elem, this.nextSibling );
148 } else if ( arguments.length ) {
149 var set = this.pushStack( this, "after", arguments );
150 set.push.apply( set, jQuery(arguments[0]).toArray() );
155 // keepData is for internal use only--do not document
156 remove: function( selector, keepData ) {
157 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
158 if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
159 if ( !keepData && elem.nodeType === 1 ) {
160 jQuery.cleanData( elem.getElementsByTagName("*") );
161 jQuery.cleanData( [ elem ] );
164 if ( elem.parentNode ) {
165 elem.parentNode.removeChild( elem );
174 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
175 // Remove element nodes and prevent memory leaks
176 if ( elem.nodeType === 1 ) {
177 jQuery.cleanData( elem.getElementsByTagName("*") );
180 // Remove any remaining nodes
181 while ( elem.firstChild ) {
182 elem.removeChild( elem.firstChild );
189 clone: function( events ) {
191 var ret = this.map(function() {
192 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
193 // IE copies events bound via attachEvent when
194 // using cloneNode. Calling detachEvent on the
195 // clone will also remove the events from the orignal
196 // In order to get around this, we use innerHTML.
197 // Unfortunately, this means some modifications to
198 // attributes in IE that are actually only stored
199 // as properties will not be copied (such as the
200 // the name attribute on an input).
201 var html = this.outerHTML,
202 ownerDocument = this.ownerDocument;
204 var div = ownerDocument.createElement("div");
205 div.appendChild( this.cloneNode(true) );
206 html = div.innerHTML;
207 } else if ( rbodystart.test(html) && rbodyend.test(html) ) {
208 html = html.replace( rbodystart, "<div>" ).replace( rbodyend, "</div>" );
211 return jQuery.clean([html.replace(rinlinejQuery, "")
212 // Handle the case in IE 8 where action=/test/> self-closes a tag
213 .replace(raction, '="$1">')
214 .replace(rleadingWhitespace, "")], ownerDocument)[0];
216 return this.cloneNode(true);
220 // Copy the events from the original to the clone
221 if ( events === true ) {
222 cloneCopyEvent( this, ret );
223 cloneCopyEvent( this.find("*"), ret.find("*") );
226 // Return the cloned set
230 html: function( value ) {
231 if ( value === undefined ) {
232 return this[0] && this[0].nodeType === 1 ?
233 this[0].innerHTML.replace(rinlinejQuery, "") :
236 // See if we can take a shortcut and just use innerHTML
237 } else if ( typeof value === "string" && !rnocache.test( value ) &&
238 (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
239 !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
241 value = value.replace(rxhtmlTag, "<$1></$2>");
244 for ( var i = 0, l = this.length; i < l; i++ ) {
245 // Remove element nodes and prevent memory leaks
246 if ( this[i].nodeType === 1 ) {
247 jQuery.cleanData( this[i].getElementsByTagName("*") );
248 this[i].innerHTML = value;
252 // If using innerHTML throws an exception, use the fallback method
254 this.empty().append( value );
257 } else if ( jQuery.isFunction( value ) ) {
258 this.each(function(i){
259 var self = jQuery( this );
261 self.html( value.call(this, i, self.html()) );
265 this.empty().append( value );
271 replaceWith: function( value ) {
272 if ( this[0] && this[0].parentNode ) {
273 // Make sure that the elements are removed from the DOM before they are inserted
274 // this can help fix replacing a parent with child elements
275 if ( jQuery.isFunction( value ) ) {
276 return this.each(function(i) {
277 var self = jQuery(this), old = self.html();
278 self.replaceWith( value.call( this, i, old ) );
282 if ( typeof value !== "string" ) {
283 value = jQuery( value ).detach();
286 return this.each(function() {
287 var next = this.nextSibling,
288 parent = this.parentNode;
290 jQuery( this ).remove();
293 jQuery(next).before( value );
295 jQuery(parent).append( value );
299 return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
303 detach: function( selector ) {
304 return this.remove( selector, true );
307 domManip: function( args, table, callback ) {
308 var results, first, fragment, parent,
312 // We can't cloneNode fragments that contain checked, in WebKit
313 if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
314 return this.each(function() {
315 jQuery(this).domManip( args, table, callback, true );
319 if ( jQuery.isFunction(value) ) {
320 return this.each(function(i) {
321 var self = jQuery(this);
322 args[0] = value.call(this, i, table ? self.html() : undefined);
323 self.domManip( args, table, callback );
328 parent = value && value.parentNode;
330 // If we're in a fragment, just use that instead of building a new one
331 if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
332 results = { fragment: parent };
335 results = jQuery.buildFragment( args, this, scripts );
338 fragment = results.fragment;
340 if ( fragment.childNodes.length === 1 ) {
341 first = fragment = fragment.firstChild;
343 first = fragment.firstChild;
347 table = table && jQuery.nodeName( first, "tr" );
349 for ( var i = 0, l = this.length; i < l; i++ ) {
352 root(this[i], first) :
354 i > 0 || results.cacheable || this.length > 1 ?
355 fragment.cloneNode(true) :
361 if ( scripts.length ) {
362 jQuery.each( scripts, evalScript );
370 function root( elem, cur ) {
371 return jQuery.nodeName(elem, "table") ?
372 (elem.getElementsByTagName("tbody")[0] ||
373 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
377 function cloneCopyEvent(orig, ret) {
380 ret.each(function() {
381 if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) {
385 var oldData = jQuery.data( orig[i++] ),
386 curData = jQuery.data( this, oldData ),
387 events = oldData && oldData.events;
390 delete curData.handle;
393 for ( var type in events ) {
394 for ( var handler in events[ type ] ) {
395 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
402 jQuery.buildFragment = function( args, nodes, scripts ) {
403 var fragment, cacheable, cacheresults,
404 doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
406 // Only cache "small" (1/2 KB) strings that are associated with the main document
407 // Cloning options loses the selected state, so don't cache them
408 // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
409 // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
410 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
411 !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
414 cacheresults = jQuery.fragments[ args[0] ];
415 if ( cacheresults ) {
416 if ( cacheresults !== 1 ) {
417 fragment = cacheresults;
423 fragment = doc.createDocumentFragment();
424 jQuery.clean( args, doc, fragment, scripts );
428 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
431 return { fragment: fragment, cacheable: cacheable };
434 jQuery.fragments = {};
438 prependTo: "prepend",
439 insertBefore: "before",
440 insertAfter: "after",
441 replaceAll: "replaceWith"
442 }, function( name, original ) {
443 jQuery.fn[ name ] = function( selector ) {
445 insert = jQuery( selector ),
446 parent = this.length === 1 && this[0].parentNode;
448 if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
449 insert[ original ]( this[0] );
453 for ( var i = 0, l = insert.length; i < l; i++ ) {
454 var elems = (i > 0 ? this.clone(true) : this).get();
455 jQuery( insert[i] )[ original ]( elems );
456 ret = ret.concat( elems );
459 return this.pushStack( ret, name, insert.selector );
465 clean: function( elems, context, fragment, scripts ) {
466 context = context || document;
468 // !context.createElement fails in IE with an error but returns typeof 'object'
469 if ( typeof context.createElement === "undefined" ) {
470 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
475 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
476 if ( typeof elem === "number" ) {
484 // Convert html string into DOM nodes
485 if ( typeof elem === "string" && !rhtml.test( elem ) ) {
486 elem = context.createTextNode( elem );
488 } else if ( typeof elem === "string" ) {
489 // Fix "XHTML"-style tags in all browsers
490 elem = elem.replace(rxhtmlTag, "<$1></$2>");
492 // Trim whitespace, otherwise indexOf won't work as expected
493 var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
494 wrap = wrapMap[ tag ] || wrapMap._default,
496 div = context.createElement("div");
498 // Go to html and back, then peel off extra wrappers
499 div.innerHTML = wrap[1] + elem + wrap[2];
501 // Move to the right depth
506 // Remove IE's autoinserted <tbody> from table fragments
507 if ( !jQuery.support.tbody ) {
509 // String was a <table>, *may* have spurious <tbody>
510 var hasBody = rtbody.test(elem),
511 tbody = tag === "table" && !hasBody ?
512 div.firstChild && div.firstChild.childNodes :
514 // String was a bare <thead> or <tfoot>
515 wrap[1] === "<table>" && !hasBody ?
519 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
520 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
521 tbody[ j ].parentNode.removeChild( tbody[ j ] );
527 // IE completely kills leading whitespace when innerHTML is used
528 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
529 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
532 elem = div.childNodes;
535 if ( elem.nodeType ) {
538 ret = jQuery.merge( ret, elem );
543 for ( i = 0; ret[i]; i++ ) {
544 if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
545 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
548 if ( ret[i].nodeType === 1 ) {
549 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
551 fragment.appendChild( ret[i] );
559 cleanData: function( elems ) {
560 var data, id, cache = jQuery.cache,
561 special = jQuery.event.special,
562 deleteExpando = jQuery.support.deleteExpando;
564 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
565 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
569 id = elem[ jQuery.expando ];
574 if ( data && data.events ) {
575 for ( var type in data.events ) {
576 if ( special[ type ] ) {
577 jQuery.event.remove( elem, type );
580 jQuery.removeEvent( elem, type, data.handle );
585 if ( deleteExpando ) {
586 delete elem[ jQuery.expando ];
588 } else if ( elem.removeAttribute ) {
589 elem.removeAttribute( jQuery.expando );
598 function evalScript( i, elem ) {
606 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
609 if ( elem.parentNode ) {
610 elem.parentNode.removeChild( elem );