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,
14 option: [ 1, "<select multiple='multiple'>", "</select>" ],
15 legend: [ 1, "<fieldset>", "</fieldset>" ],
16 thead: [ 1, "<table>", "</table>" ],
17 tr: [ 2, "<table><tbody>", "</tbody></table>" ],
18 td: [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ],
19 col: [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ],
20 area: [ 1, "<map>", "</map>" ],
21 _default: [ 0, "", "" ]
24 wrapMap.optgroup = wrapMap.option;
25 wrapMap.tbody = wrapMap.tfoot = wrapMap.colgroup = wrapMap.caption = wrapMap.thead;
26 wrapMap.th = wrapMap.td;
28 // IE can't serialize <link> and <script> tags normally
29 if ( !jQuery.support.htmlSerialize ) {
30 wrapMap._default = [ 1, "div<div>", "</div>" ];
34 text: function( text ) {
35 if ( jQuery.isFunction(text) ) {
36 return this.each(function(i) {
37 var self = jQuery( this );
39 self.text( text.call(this, i, self.text()) );
43 if ( typeof text !== "object" && text !== undefined ) {
44 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
47 return jQuery.text( this );
50 wrapAll: function( html ) {
51 if ( jQuery.isFunction( html ) ) {
52 return this.each(function(i) {
53 jQuery(this).wrapAll( html.call(this, i) );
58 // The elements to wrap the target around
59 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
61 if ( this[0].parentNode ) {
62 wrap.insertBefore( this[0] );
68 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
69 elem = elem.firstChild;
79 wrapInner: function( html ) {
80 if ( jQuery.isFunction( html ) ) {
81 return this.each(function(i) {
82 jQuery(this).wrapInner( html.call(this, i) );
86 return this.each(function() {
87 var self = jQuery( this ),
88 contents = self.contents();
90 if ( contents.length ) {
91 contents.wrapAll( html );
99 wrap: function( html ) {
100 return this.each(function() {
101 jQuery( this ).wrapAll( html );
106 return this.parent().each(function() {
107 if ( !jQuery.nodeName( this, "body" ) ) {
108 jQuery( this ).replaceWith( this.childNodes );
114 return this.domManip(arguments, true, function( elem ) {
115 if ( this.nodeType === 1 ) {
116 this.appendChild( elem );
121 prepend: function() {
122 return this.domManip(arguments, true, function( elem ) {
123 if ( this.nodeType === 1 ) {
124 this.insertBefore( elem, this.firstChild );
130 if ( this[0] && this[0].parentNode ) {
131 return this.domManip(arguments, false, function( elem ) {
132 this.parentNode.insertBefore( elem, this );
134 } else if ( arguments.length ) {
135 var set = jQuery(arguments[0]);
136 set.push.apply( set, this.toArray() );
137 return this.pushStack( set, "before", arguments );
142 if ( this[0] && this[0].parentNode ) {
143 return this.domManip(arguments, false, function( elem ) {
144 this.parentNode.insertBefore( elem, this.nextSibling );
146 } else if ( arguments.length ) {
147 var set = this.pushStack( this, "after", arguments );
148 set.push.apply( set, jQuery(arguments[0]).toArray() );
153 // keepData is for internal use only--do not document
154 remove: function( selector, keepData ) {
155 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
156 if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
157 if ( !keepData && elem.nodeType === 1 ) {
158 jQuery.cleanData( elem.getElementsByTagName("*") );
159 jQuery.cleanData( [ elem ] );
162 if ( elem.parentNode ) {
163 elem.parentNode.removeChild( elem );
172 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
173 // Remove element nodes and prevent memory leaks
174 if ( elem.nodeType === 1 ) {
175 jQuery.cleanData( elem.getElementsByTagName("*") );
178 // Remove any remaining nodes
179 while ( elem.firstChild ) {
180 elem.removeChild( elem.firstChild );
187 clone: function( events ) {
189 var ret = this.map(function() {
190 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
191 // IE copies events bound via attachEvent when
192 // using cloneNode. Calling detachEvent on the
193 // clone will also remove the events from the orignal
194 // In order to get around this, we use innerHTML.
195 // Unfortunately, this means some modifications to
196 // attributes in IE that are actually only stored
197 // as properties will not be copied (such as the
198 // the name attribute on an input).
199 var html = this.outerHTML,
200 ownerDocument = this.ownerDocument;
203 var div = ownerDocument.createElement("div");
204 div.appendChild( this.cloneNode(true) );
205 html = div.innerHTML;
208 return jQuery.clean([html.replace(rinlinejQuery, "")
209 // Handle the case in IE 8 where action=/test/> self-closes a tag
210 .replace(raction, '="$1">')
211 .replace(rleadingWhitespace, "")], ownerDocument)[0];
213 return this.cloneNode(true);
217 // Copy the events from the original to the clone
218 if ( events === true ) {
219 cloneCopyEvent( this, ret );
220 cloneCopyEvent( this.find("*"), ret.find("*") );
223 // Return the cloned set
227 html: function( value ) {
228 if ( value === undefined ) {
229 return this[0] && this[0].nodeType === 1 ?
230 this[0].innerHTML.replace(rinlinejQuery, "") :
233 // See if we can take a shortcut and just use innerHTML
234 } else if ( typeof value === "string" && !rnocache.test( value ) &&
235 (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
236 !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
238 value = value.replace(rxhtmlTag, "<$1></$2>");
241 for ( var i = 0, l = this.length; i < l; i++ ) {
242 // Remove element nodes and prevent memory leaks
243 if ( this[i].nodeType === 1 ) {
244 jQuery.cleanData( this[i].getElementsByTagName("*") );
245 this[i].innerHTML = value;
249 // If using innerHTML throws an exception, use the fallback method
251 this.empty().append( value );
254 } else if ( jQuery.isFunction( value ) ) {
255 this.each(function(i){
256 var self = jQuery( this );
258 self.html( value.call(this, i, self.html()) );
262 this.empty().append( value );
268 replaceWith: function( value ) {
269 if ( this[0] && this[0].parentNode ) {
270 // Make sure that the elements are removed from the DOM before they are inserted
271 // this can help fix replacing a parent with child elements
272 if ( jQuery.isFunction( value ) ) {
273 return this.each(function(i) {
274 var self = jQuery(this), old = self.html();
275 self.replaceWith( value.call( this, i, old ) );
279 if ( typeof value !== "string" ) {
280 value = jQuery( value ).detach();
283 return this.each(function() {
284 var next = this.nextSibling,
285 parent = this.parentNode;
287 jQuery( this ).remove();
290 jQuery(next).before( value );
292 jQuery(parent).append( value );
296 return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
300 detach: function( selector ) {
301 return this.remove( selector, true );
304 domManip: function( args, table, callback ) {
305 var results, first, fragment, parent,
309 // We can't cloneNode fragments that contain checked, in WebKit
310 if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
311 return this.each(function() {
312 jQuery(this).domManip( args, table, callback, true );
316 if ( jQuery.isFunction(value) ) {
317 return this.each(function(i) {
318 var self = jQuery(this);
319 args[0] = value.call(this, i, table ? self.html() : undefined);
320 self.domManip( args, table, callback );
325 parent = value && value.parentNode;
327 // If we're in a fragment, just use that instead of building a new one
328 if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
329 results = { fragment: parent };
332 results = jQuery.buildFragment( args, this, scripts );
335 fragment = results.fragment;
337 if ( fragment.childNodes.length === 1 ) {
338 first = fragment = fragment.firstChild;
340 first = fragment.firstChild;
344 table = table && jQuery.nodeName( first, "tr" );
346 for ( var i = 0, l = this.length; i < l; i++ ) {
349 root(this[i], first) :
351 i > 0 || results.cacheable || this.length > 1 ?
352 fragment.cloneNode(true) :
358 if ( scripts.length ) {
359 jQuery.each( scripts, evalScript );
367 function root( elem, cur ) {
368 return jQuery.nodeName(elem, "table") ?
369 (elem.getElementsByTagName("tbody")[0] ||
370 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
374 function cloneCopyEvent(orig, ret) {
377 ret.each(function() {
378 if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) {
382 var oldData = jQuery.data( orig[i++] ),
383 curData = jQuery.data( this, oldData ),
384 events = oldData && oldData.events;
387 delete curData.handle;
390 for ( var type in events ) {
391 for ( var handler in events[ type ] ) {
392 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
399 jQuery.buildFragment = function( args, nodes, scripts ) {
400 var fragment, cacheable, cacheresults,
401 doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
403 // Only cache "small" (1/2 KB) strings that are associated with the main document
404 // Cloning options loses the selected state, so don't cache them
405 // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
406 // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
407 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
408 !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
411 cacheresults = jQuery.fragments[ args[0] ];
412 if ( cacheresults ) {
413 if ( cacheresults !== 1 ) {
414 fragment = cacheresults;
420 fragment = doc.createDocumentFragment();
421 jQuery.clean( args, doc, fragment, scripts );
425 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
428 return { fragment: fragment, cacheable: cacheable };
431 jQuery.fragments = {};
435 prependTo: "prepend",
436 insertBefore: "before",
437 insertAfter: "after",
438 replaceAll: "replaceWith"
439 }, function( name, original ) {
440 jQuery.fn[ name ] = function( selector ) {
442 insert = jQuery( selector ),
443 parent = this.length === 1 && this[0].parentNode;
445 if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
446 insert[ original ]( this[0] );
450 for ( var i = 0, l = insert.length; i < l; i++ ) {
451 var elems = (i > 0 ? this.clone(true) : this).get();
452 jQuery( insert[i] )[ original ]( elems );
453 ret = ret.concat( elems );
456 return this.pushStack( ret, name, insert.selector );
462 clean: function( elems, context, fragment, scripts ) {
463 context = context || document;
465 // !context.createElement fails in IE with an error but returns typeof 'object'
466 if ( typeof context.createElement === "undefined" ) {
467 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
472 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
473 if ( typeof elem === "number" ) {
481 // Convert html string into DOM nodes
482 if ( typeof elem === "string" && !rhtml.test( elem ) ) {
483 elem = context.createTextNode( elem );
485 } else if ( typeof elem === "string" ) {
486 // Fix "XHTML"-style tags in all browsers
487 elem = elem.replace(rxhtmlTag, "<$1></$2>");
489 // Trim whitespace, otherwise indexOf won't work as expected
490 var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
491 wrap = wrapMap[ tag ] || wrapMap._default,
493 div = context.createElement("div");
495 // Go to html and back, then peel off extra wrappers
496 div.innerHTML = wrap[1] + elem + wrap[2];
498 // Move to the right depth
503 // Remove IE's autoinserted <tbody> from table fragments
504 if ( !jQuery.support.tbody ) {
506 // String was a <table>, *may* have spurious <tbody>
507 var hasBody = rtbody.test(elem),
508 tbody = tag === "table" && !hasBody ?
509 div.firstChild && div.firstChild.childNodes :
511 // String was a bare <thead> or <tfoot>
512 wrap[1] === "<table>" && !hasBody ?
516 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
517 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
518 tbody[ j ].parentNode.removeChild( tbody[ j ] );
524 // IE completely kills leading whitespace when innerHTML is used
525 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
526 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
529 elem = div.childNodes;
532 if ( elem.nodeType ) {
535 ret = jQuery.merge( ret, elem );
540 for ( i = 0; ret[i]; i++ ) {
541 if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
542 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
545 if ( ret[i].nodeType === 1 ) {
546 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
548 fragment.appendChild( ret[i] );
556 cleanData: function( elems ) {
557 var data, id, cache = jQuery.cache,
558 special = jQuery.event.special,
559 deleteExpando = jQuery.support.deleteExpando;
561 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
562 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
566 id = elem[ jQuery.expando ];
571 if ( data && data.events ) {
572 for ( var type in data.events ) {
573 if ( special[ type ] ) {
574 jQuery.event.remove( elem, type );
577 jQuery.removeEvent( elem, type, data.handle );
582 if ( deleteExpando ) {
583 delete elem[ jQuery.expando ];
585 } else if ( elem.removeAttribute ) {
586 elem.removeAttribute( jQuery.expando );
595 function evalScript( i, elem ) {
603 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
606 if ( elem.parentNode ) {
607 elem.parentNode.removeChild( elem );