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,
13 option: [ 1, "<select multiple='multiple'>", "</select>" ],
14 legend: [ 1, "<fieldset>", "</fieldset>" ],
15 thead: [ 1, "<table>", "</table>" ],
16 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
17 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
18 col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
19 area: [ 1, "<map>", "</map>" ],
20 _default: [ 0, "", "" ]
23 wrapMap.optgroup = wrapMap.option;
24 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
25 wrapMap.th = wrapMap.td;
27 // IE can't serialize <link> and <script> tags normally
28 if ( !jQuery.support.htmlSerialize ) {
29 wrapMap._default = [ 1, "div<div>", "</div>" ];
33 text: function( text ) {
34 if ( jQuery.isFunction(text) ) {
35 return this.each(function(i) {
36 var self = jQuery( this );
38 self.text( text.call(this, i, self.text()) );
42 if ( typeof text !== "object" && text !== undefined ) {
43 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
46 return jQuery.text( this );
49 wrapAll: function( html ) {
50 if ( jQuery.isFunction( html ) ) {
51 return this.each(function(i) {
52 jQuery(this).wrapAll( html.call(this, i) );
57 // The elements to wrap the target around
58 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
60 if ( this[0].parentNode ) {
61 wrap.insertBefore( this[0] );
67 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
68 elem = elem.firstChild;
78 wrapInner: function( html ) {
79 if ( jQuery.isFunction( html ) ) {
80 return this.each(function(i) {
81 jQuery(this).wrapInner( html.call(this, i) );
85 return this.each(function() {
86 var self = jQuery( this ),
87 contents = self.contents();
89 if ( contents.length ) {
90 contents.wrapAll( html );
98 wrap: function( html ) {
99 return this.each(function() {
100 jQuery( this ).wrapAll( html );
105 return this.parent().each(function() {
106 if ( !jQuery.nodeName( this, "body" ) ) {
107 jQuery( this ).replaceWith( this.childNodes );
113 return this.domManip(arguments, true, function( elem ) {
114 if ( this.nodeType === 1 ) {
115 this.appendChild( elem );
120 prepend: function() {
121 return this.domManip(arguments, true, function( elem ) {
122 if ( this.nodeType === 1 ) {
123 this.insertBefore( elem, this.firstChild );
129 if ( this[0] && this[0].parentNode ) {
130 return this.domManip(arguments, false, function( elem ) {
131 this.parentNode.insertBefore( elem, this );
133 } else if ( arguments.length ) {
134 var set = jQuery(arguments[0]);
135 set.push.apply( set, this.toArray() );
136 return this.pushStack( set, "before", arguments );
141 if ( this[0] && this[0].parentNode ) {
142 return this.domManip(arguments, false, function( elem ) {
143 this.parentNode.insertBefore( elem, this.nextSibling );
145 } else if ( arguments.length ) {
146 var set = this.pushStack( this, "after", arguments );
147 set.push.apply( set, jQuery(arguments[0]).toArray() );
152 // keepData is for internal use only--do not document
153 remove: function( selector, keepData ) {
154 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
155 if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
156 if ( !keepData && elem.nodeType === 1 ) {
157 jQuery.cleanData( elem.getElementsByTagName("*") );
158 jQuery.cleanData( [ elem ] );
161 if ( elem.parentNode ) {
162 elem.parentNode.removeChild( elem );
171 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
172 // Remove element nodes and prevent memory leaks
173 if ( elem.nodeType === 1 ) {
174 jQuery.cleanData( elem.getElementsByTagName("*") );
177 // Remove any remaining nodes
178 while ( elem.firstChild ) {
179 elem.removeChild( elem.firstChild );
186 clone: function( dataAndEvents, deepDataAndEvents ) {
187 dataAndEvents = dataAndEvents == null ? true : dataAndEvents;
188 deepDataAndEvents = deepDataAndEvents == null ? dataAndEvents : deepDataAndEvents;
190 return this.map( function () {
191 return jQuery.clone( this, dataAndEvents, deepDataAndEvents );
195 html: function( value ) {
196 if ( value === undefined ) {
197 return this[0] && this[0].nodeType === 1 ?
198 this[0].innerHTML.replace(rinlinejQuery, "") :
201 // See if we can take a shortcut and just use innerHTML
202 } else if ( typeof value === "string" && !rnocache.test( value ) &&
203 (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
204 !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
206 value = value.replace(rxhtmlTag, "<$1></$2>");
209 for ( var i = 0, l = this.length; i < l; i++ ) {
210 // Remove element nodes and prevent memory leaks
211 if ( this[i].nodeType === 1 ) {
212 jQuery.cleanData( this[i].getElementsByTagName("*") );
213 this[i].innerHTML = value;
217 // If using innerHTML throws an exception, use the fallback method
219 this.empty().append( value );
222 } else if ( jQuery.isFunction( value ) ) {
223 this.each(function(i){
224 var self = jQuery( this );
226 self.html( value.call(this, i, self.html()) );
230 this.empty().append( value );
236 replaceWith: function( value ) {
237 if ( this[0] && this[0].parentNode ) {
238 // Make sure that the elements are removed from the DOM before they are inserted
239 // this can help fix replacing a parent with child elements
240 if ( jQuery.isFunction( value ) ) {
241 return this.each(function(i) {
242 var self = jQuery(this), old = self.html();
243 self.replaceWith( value.call( this, i, old ) );
247 if ( typeof value !== "string" ) {
248 value = jQuery( value ).detach();
251 return this.each(function() {
252 var next = this.nextSibling,
253 parent = this.parentNode;
255 jQuery( this ).remove();
258 jQuery(next).before( value );
260 jQuery(parent).append( value );
264 return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
268 detach: function( selector ) {
269 return this.remove( selector, true );
272 domManip: function( args, table, callback ) {
273 var results, first, fragment, parent,
277 // We can't cloneNode fragments that contain checked, in WebKit
278 if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
279 return this.each(function() {
280 jQuery(this).domManip( args, table, callback, true );
284 if ( jQuery.isFunction(value) ) {
285 return this.each(function(i) {
286 var self = jQuery(this);
287 args[0] = value.call(this, i, table ? self.html() : undefined);
288 self.domManip( args, table, callback );
293 parent = value && value.parentNode;
295 // If we're in a fragment, just use that instead of building a new one
296 if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
297 results = { fragment: parent };
300 results = jQuery.buildFragment( args, this, scripts );
303 fragment = results.fragment;
305 if ( fragment.childNodes.length === 1 ) {
306 first = fragment = fragment.firstChild;
308 first = fragment.firstChild;
312 table = table && jQuery.nodeName( first, "tr" );
314 for ( var i = 0, l = this.length; i < l; i++ ) {
317 root(this[i], first) :
319 i > 0 || results.cacheable || (this.length > 1 && i > 0) ?
320 jQuery.clone( fragment, true, true ) :
326 if ( scripts.length ) {
327 jQuery.each( scripts, evalScript );
335 function root( elem, cur ) {
336 return jQuery.nodeName(elem, "table") ?
337 (elem.getElementsByTagName("tbody")[0] ||
338 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
342 function cloneCopyEvent( src, dest ) {
344 if ( dest.nodeType !== 1 || !jQuery.hasData( src ) ) {
348 var internalKey = jQuery.expando,
349 oldData = jQuery.data( src ),
350 curData = jQuery.data( dest, oldData );
352 // Switch to use the internal data object, if it exists, for the next
353 // stage of data copying
354 if ( (oldData = oldData[ internalKey ]) ) {
355 var events = oldData.events;
356 curData = curData[ internalKey ] = jQuery.extend({}, oldData);
359 delete curData.handle;
362 for ( var type in events ) {
363 for ( var i = 0, l = events[ type ].length; i < l; i++ ) {
364 jQuery.event.add( dest, type, events[ type ][ i ], events[ type ][ i ].data );
371 function cloneFixAttributes(src, dest) {
372 // We do not need to do anything for non-Elements
373 if ( dest.nodeType !== 1 ) {
377 var nodeName = dest.nodeName.toLowerCase();
379 // clearAttributes removes the attributes, which we don't want,
380 // but also removes the attachEvent events, which we *do* want
381 dest.clearAttributes();
383 // mergeAttributes, in contrast, only merges back on the
384 // original attributes, not the events
385 dest.mergeAttributes(src);
387 // IE6-8 fail to clone children inside object elements that use
388 // the proprietary classid attribute value (rather than the type
389 // attribute) to identify the type of content to display
390 if ( nodeName === "object" ) {
391 dest.outerHTML = src.outerHTML;
393 } else if ( nodeName === "input" && (src.type === "checkbox" || src.type === "radio") ) {
394 // IE6-8 fails to persist the checked state of a cloned checkbox
395 // or radio button. Worse, IE6-7 fail to give the cloned element
396 // a checked appearance if the defaultChecked value isn't also set
398 dest.defaultChecked = dest.checked = src.checked;
401 // IE6-7 get confused and end up setting the value of a cloned
402 // checkbox/radio button to an empty string instead of "on"
403 if ( dest.value !== src.value ) {
404 dest.value = src.value;
407 // IE6-8 fails to return the selected option to the default selected
408 // state when cloning options
409 } else if ( nodeName === "option" ) {
410 dest.selected = src.defaultSelected;
412 // IE6-8 fails to set the defaultValue to the correct value when
413 // cloning other types of input fields
414 } else if ( nodeName === "input" || nodeName === "textarea" ) {
415 dest.defaultValue = src.defaultValue;
418 // Event data gets referenced instead of copied if the expando
420 dest.removeAttribute( jQuery.expando );
423 jQuery.buildFragment = function( args, nodes, scripts ) {
424 var fragment, cacheable, cacheresults,
425 doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
427 // Only cache "small" (1/2 KB) HTML strings that are associated with the main document
428 // Cloning options loses the selected state, so don't cache them
429 // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
430 // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
431 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
432 args[0].charAt(0) === "<" && !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
435 cacheresults = jQuery.fragments[ args[0] ];
436 if ( cacheresults ) {
437 if ( cacheresults !== 1 ) {
438 fragment = cacheresults;
444 fragment = doc.createDocumentFragment();
445 jQuery.clean( args, doc, fragment, scripts );
449 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
452 return { fragment: fragment, cacheable: cacheable };
455 jQuery.fragments = {};
459 prependTo: "prepend",
460 insertBefore: "before",
461 insertAfter: "after",
462 replaceAll: "replaceWith"
463 }, function( name, original ) {
464 jQuery.fn[ name ] = function( selector ) {
466 insert = jQuery( selector ),
467 parent = this.length === 1 && this[0].parentNode;
469 if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
470 insert[ original ]( this[0] );
474 for ( var i = 0, l = insert.length; i < l; i++ ) {
475 var elems = (i > 0 ? this.clone(true) : this).get();
476 jQuery( insert[i] )[ original ]( elems );
477 ret = ret.concat( elems );
480 return this.pushStack( ret, name, insert.selector );
486 clone: function( elem, dataAndEvents, deepDataAndEvents ) {
487 var clone = elem.cloneNode(true),
491 if ( !jQuery.support.noCloneEvent && (elem.nodeType === 1 || elem.nodeType === 11) && !jQuery.isXMLDoc(elem) ) {
492 // IE copies events bound via attachEvent when using cloneNode.
493 // Calling detachEvent on the clone will also remove the events
494 // from the original. In order to get around this, we use some
495 // proprietary methods to clear the events. Thanks to MooTools
496 // guys for this hotness.
498 // Using Sizzle here is crazy slow, so we use getElementsByTagName
500 srcElements = elem.getElementsByTagName("*");
501 destElements = clone.getElementsByTagName("*");
503 // Weird iteration because IE will replace the length property
504 // with an element if you are cloning the body and one of the
505 // elements on the page has a name or id of "length"
506 for ( var i = 0; srcElements[i]; ++i ) {
507 cloneFixAttributes( srcElements[i], destElements[i] );
510 cloneFixAttributes( elem, clone );
513 // Copy the events from the original to the clone
514 if ( dataAndEvents ) {
516 cloneCopyEvent( elem, clone );
518 if ( deepDataAndEvents && "getElementsByTagName" in elem ) {
520 srcElements = elem.getElementsByTagName("*");
521 destElements = clone.getElementsByTagName("*");
523 if ( srcElements.length ) {
524 for ( var i = 0; srcElements[i]; ++i ) {
525 cloneCopyEvent( srcElements[i], destElements[i] );
530 // Return the cloned set
533 clean: function( elems, context, fragment, scripts ) {
534 context = context || document;
536 // !context.createElement fails in IE with an error but returns typeof 'object'
537 if ( typeof context.createElement === "undefined" ) {
538 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
543 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
544 if ( typeof elem === "number" ) {
552 // Convert html string into DOM nodes
553 if ( typeof elem === "string" && !rhtml.test( elem ) ) {
554 elem = context.createTextNode( elem );
556 } else if ( typeof elem === "string" ) {
557 // Fix "XHTML"-style tags in all browsers
558 elem = elem.replace(rxhtmlTag, "<$1></$2>");
560 // Trim whitespace, otherwise indexOf won't work as expected
561 var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
562 wrap = wrapMap[ tag ] || wrapMap._default,
564 div = context.createElement("div");
566 // Go to html and back, then peel off extra wrappers
567 div.innerHTML = wrap[1] + elem + wrap[2];
569 // Move to the right depth
574 // Remove IE's autoinserted <tbody> from table fragments
575 if ( !jQuery.support.tbody ) {
577 // String was a <table>, *may* have spurious <tbody>
578 var hasBody = rtbody.test(elem),
579 tbody = tag === "table" && !hasBody ?
580 div.firstChild && div.firstChild.childNodes :
582 // String was a bare <thead> or <tfoot>
583 wrap[1] === "<table>" && !hasBody ?
587 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
588 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
589 tbody[ j ].parentNode.removeChild( tbody[ j ] );
595 // IE completely kills leading whitespace when innerHTML is used
596 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
597 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
600 elem = div.childNodes;
603 if ( elem.nodeType ) {
606 ret = jQuery.merge( ret, elem );
611 for ( i = 0; ret[i]; i++ ) {
612 if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
613 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
616 if ( ret[i].nodeType === 1 ) {
617 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
619 fragment.appendChild( ret[i] );
627 cleanData: function( elems ) {
628 var data, id, cache = jQuery.cache, internalKey = jQuery.expando, special = jQuery.event.special,
629 deleteExpando = jQuery.support.deleteExpando;
631 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
632 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
636 id = elem[ jQuery.expando ];
639 data = cache[ id ] && cache[ id ][ internalKey ];
641 if ( data && data.events ) {
642 for ( var type in data.events ) {
643 if ( special[ type ] ) {
644 jQuery.event.remove( elem, type );
646 // This is a shortcut to avoid jQuery.event.remove's overhead
648 jQuery.removeEvent( elem, type, data.handle );
652 // Null the DOM reference to avoid IE6/7/8 leak (#7054)
654 data.handle.elem = null;
658 if ( deleteExpando ) {
659 delete elem[ jQuery.expando ];
661 } else if ( elem.removeAttribute ) {
662 elem.removeAttribute( jQuery.expando );
671 function evalScript( i, elem ) {
679 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
682 if ( elem.parentNode ) {
683 elem.parentNode.removeChild( elem );