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 rchecked = /checked\s*(?:[^=]|=\s*.checked.)/i, // checked="checked" or checked (html5)
11 raction = /\=([^="'>\s]+\/)>/g,
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);
37 self.text( text.call(this, i, self.text()) );
41 if ( typeof text !== "object" && text !== undefined ) {
42 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
45 return jQuery.text( this );
48 wrapAll: function( html ) {
49 if ( jQuery.isFunction( html ) ) {
50 return this.each(function(i) {
51 jQuery(this).wrapAll( html.call(this, i) );
56 // The elements to wrap the target around
57 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone(true);
59 if ( this[0].parentNode ) {
60 wrap.insertBefore( this[0] );
66 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
67 elem = elem.firstChild;
77 wrapInner: function( html ) {
78 if ( jQuery.isFunction( html ) ) {
79 return this.each(function(i) {
80 jQuery(this).wrapInner( html.call(this, i) );
84 return this.each(function() {
85 var self = jQuery( this ), contents = self.contents();
87 if ( contents.length ) {
88 contents.wrapAll( html );
96 wrap: function( html ) {
97 return this.each(function() {
98 jQuery( this ).wrapAll( html );
103 return this.parent().each(function() {
104 if ( !jQuery.nodeName( this, "body" ) ) {
105 jQuery( this ).replaceWith( this.childNodes );
111 return this.domManip(arguments, true, function( elem ) {
112 if ( this.nodeType === 1 ) {
113 this.appendChild( elem );
118 prepend: function() {
119 return this.domManip(arguments, true, function( elem ) {
120 if ( this.nodeType === 1 ) {
121 this.insertBefore( elem, this.firstChild );
127 if ( this[0] && this[0].parentNode ) {
128 return this.domManip(arguments, false, function( elem ) {
129 this.parentNode.insertBefore( elem, this );
131 } else if ( arguments.length ) {
132 var set = jQuery(arguments[0]);
133 set.push.apply( set, this.toArray() );
134 return this.pushStack( set, "before", arguments );
139 if ( this[0] && this[0].parentNode ) {
140 return this.domManip(arguments, false, function( elem ) {
141 this.parentNode.insertBefore( elem, this.nextSibling );
143 } else if ( arguments.length ) {
144 var set = this.pushStack( this, "after", arguments );
145 set.push.apply( set, jQuery(arguments[0]).toArray() );
150 // keepData is for internal use only--do not document
151 remove: function( selector, keepData ) {
152 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
153 if ( !selector || jQuery.filter( selector, [ elem ] ).length ) {
154 if ( !keepData && elem.nodeType === 1 ) {
155 jQuery.cleanData( elem.getElementsByTagName("*") );
156 jQuery.cleanData( [ elem ] );
159 if ( elem.parentNode ) {
160 elem.parentNode.removeChild( elem );
169 for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
170 // Remove element nodes and prevent memory leaks
171 if ( elem.nodeType === 1 ) {
172 jQuery.cleanData( elem.getElementsByTagName("*") );
175 // Remove any remaining nodes
176 while ( elem.firstChild ) {
177 elem.removeChild( elem.firstChild );
184 clone: function( events ) {
186 var ret = this.map(function() {
187 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
188 // IE copies events bound via attachEvent when
189 // using cloneNode. Calling detachEvent on the
190 // clone will also remove the events from the orignal
191 // In order to get around this, we use innerHTML.
192 // Unfortunately, this means some modifications to
193 // attributes in IE that are actually only stored
194 // as properties will not be copied (such as the
195 // the name attribute on an input).
196 var html = this.outerHTML, ownerDocument = this.ownerDocument;
198 var div = ownerDocument.createElement("div");
199 div.appendChild( this.cloneNode(true) );
200 html = div.innerHTML;
203 return jQuery.clean([html.replace(rinlinejQuery, "")
204 // Handle the case in IE 8 where action=/test/> self-closes a tag
205 .replace(raction, '="$1">')
206 .replace(rleadingWhitespace, "")], ownerDocument)[0];
208 return this.cloneNode(true);
212 // Copy the events from the original to the clone
213 if ( events === true ) {
214 cloneCopyEvent( this, ret );
215 cloneCopyEvent( this.find("*"), ret.find("*") );
218 // Return the cloned set
222 html: function( value ) {
223 if ( value === undefined ) {
224 return this[0] && this[0].nodeType === 1 ?
225 this[0].innerHTML.replace(rinlinejQuery, "") :
228 // See if we can take a shortcut and just use innerHTML
229 } else if ( typeof value === "string" && !rnocache.test( value ) &&
230 (jQuery.support.leadingWhitespace || !rleadingWhitespace.test( value )) &&
231 !wrapMap[ (rtagName.exec( value ) || ["", ""])[1].toLowerCase() ] ) {
233 value = value.replace(rxhtmlTag, "<$1></$2>");
236 for ( var i = 0, l = this.length; i < l; i++ ) {
237 // Remove element nodes and prevent memory leaks
238 if ( this[i].nodeType === 1 ) {
239 jQuery.cleanData( this[i].getElementsByTagName("*") );
240 this[i].innerHTML = value;
244 // If using innerHTML throws an exception, use the fallback method
246 this.empty().append( value );
249 } else if ( jQuery.isFunction( value ) ) {
250 this.each(function(i){
251 var self = jQuery(this);
252 self.html( value.call(this, i, self.html()) );
256 this.empty().append( value );
262 replaceWith: function( value ) {
263 if ( this[0] && this[0].parentNode ) {
264 // Make sure that the elements are removed from the DOM before they are inserted
265 // this can help fix replacing a parent with child elements
266 if ( jQuery.isFunction( value ) ) {
267 return this.each(function(i) {
268 var self = jQuery(this), old = self.html();
269 self.replaceWith( value.call( this, i, old ) );
273 if ( typeof value !== "string" ) {
274 value = jQuery(value).detach();
277 return this.each(function() {
278 var next = this.nextSibling, parent = this.parentNode;
280 jQuery(this).remove();
283 jQuery(next).before( value );
285 jQuery(parent).append( value );
289 return this.pushStack( jQuery(jQuery.isFunction(value) ? value() : value), "replaceWith", value );
293 detach: function( selector ) {
294 return this.remove( selector, true );
297 domManip: function( args, table, callback ) {
298 var results, first, value = args[0], scripts = [], fragment, parent;
300 // We can't cloneNode fragments that contain checked, in WebKit
301 if ( !jQuery.support.checkClone && arguments.length === 3 && typeof value === "string" && rchecked.test( value ) ) {
302 return this.each(function() {
303 jQuery(this).domManip( args, table, callback, true );
307 if ( jQuery.isFunction(value) ) {
308 return this.each(function(i) {
309 var self = jQuery(this);
310 args[0] = value.call(this, i, table ? self.html() : undefined);
311 self.domManip( args, table, callback );
316 parent = value && value.parentNode;
318 // If we're in a fragment, just use that instead of building a new one
319 if ( jQuery.support.parentNode && parent && parent.nodeType === 11 && parent.childNodes.length === this.length ) {
320 results = { fragment: parent };
323 results = jQuery.buildFragment( args, this, scripts );
326 fragment = results.fragment;
328 if ( fragment.childNodes.length === 1 ) {
329 first = fragment = fragment.firstChild;
331 first = fragment.firstChild;
335 table = table && jQuery.nodeName( first, "tr" );
337 for ( var i = 0, l = this.length; i < l; i++ ) {
340 root(this[i], first) :
342 i > 0 || results.cacheable || this.length > 1 ?
343 fragment.cloneNode(true) :
349 if ( scripts.length ) {
350 jQuery.each( scripts, evalScript );
358 function root( elem, cur ) {
359 return jQuery.nodeName(elem, "table") ?
360 (elem.getElementsByTagName("tbody")[0] ||
361 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
365 function cloneCopyEvent(orig, ret) {
368 ret.each(function() {
369 if ( this.nodeName !== (orig[i] && orig[i].nodeName) ) {
373 var oldData = jQuery.data( orig[i++] ), curData = jQuery.data( this, oldData ), events = oldData && oldData.events;
376 delete curData.handle;
379 for ( var type in events ) {
380 for ( var handler in events[ type ] ) {
381 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
388 jQuery.buildFragment = function( args, nodes, scripts ) {
389 var fragment, cacheable, cacheresults,
390 doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
392 // Only cache "small" (1/2 KB) strings that are associated with the main document
393 // Cloning options loses the selected state, so don't cache them
394 // IE 6 doesn't like it when you put <object> or <embed> elements in a fragment
395 // Also, WebKit does not clone 'checked' attributes on cloneNode, so don't cache
396 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && doc === document &&
397 !rnocache.test( args[0] ) && (jQuery.support.checkClone || !rchecked.test( args[0] )) ) {
400 cacheresults = jQuery.fragments[ args[0] ];
401 if ( cacheresults ) {
402 if ( cacheresults !== 1 ) {
403 fragment = cacheresults;
409 fragment = doc.createDocumentFragment();
410 jQuery.clean( args, doc, fragment, scripts );
414 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
417 return { fragment: fragment, cacheable: cacheable };
420 jQuery.fragments = {};
424 prependTo: "prepend",
425 insertBefore: "before",
426 insertAfter: "after",
427 replaceAll: "replaceWith"
428 }, function( name, original ) {
429 jQuery.fn[ name ] = function( selector ) {
430 var ret = [], insert = jQuery( selector ),
431 parent = this.length === 1 && this[0].parentNode;
433 if ( parent && parent.nodeType === 11 && parent.childNodes.length === 1 && insert.length === 1 ) {
434 insert[ original ]( this[0] );
438 for ( var i = 0, l = insert.length; i < l; i++ ) {
439 var elems = (i > 0 ? this.clone(true) : this).get();
440 jQuery( insert[i] )[ original ]( elems );
441 ret = ret.concat( elems );
444 return this.pushStack( ret, name, insert.selector );
450 clean: function( elems, context, fragment, scripts ) {
451 context = context || document;
453 // !context.createElement fails in IE with an error but returns typeof 'object'
454 if ( typeof context.createElement === "undefined" ) {
455 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
460 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
461 if ( typeof elem === "number" ) {
469 // Convert html string into DOM nodes
470 if ( typeof elem === "string" && !rhtml.test( elem ) ) {
471 elem = context.createTextNode( elem );
473 } else if ( typeof elem === "string" ) {
474 // Fix "XHTML"-style tags in all browsers
475 elem = elem.replace(rxhtmlTag, "<$1></$2>");
477 // Trim whitespace, otherwise indexOf won't work as expected
478 var tag = (rtagName.exec( elem ) || ["", ""])[1].toLowerCase(),
479 wrap = wrapMap[ tag ] || wrapMap._default,
481 div = context.createElement("div");
483 // Go to html and back, then peel off extra wrappers
484 div.innerHTML = wrap[1] + elem + wrap[2];
486 // Move to the right depth
491 // Remove IE's autoinserted <tbody> from table fragments
492 if ( !jQuery.support.tbody ) {
494 // String was a <table>, *may* have spurious <tbody>
495 var hasBody = rtbody.test(elem),
496 tbody = tag === "table" && !hasBody ?
497 div.firstChild && div.firstChild.childNodes :
499 // String was a bare <thead> or <tfoot>
500 wrap[1] === "<table>" && !hasBody ?
504 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
505 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
506 tbody[ j ].parentNode.removeChild( tbody[ j ] );
512 // IE completely kills leading whitespace when innerHTML is used
513 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
514 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
517 elem = div.childNodes;
520 if ( elem.nodeType ) {
523 ret = jQuery.merge( ret, elem );
528 for ( i = 0; ret[i]; i++ ) {
529 if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
530 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
533 if ( ret[i].nodeType === 1 ) {
534 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
536 fragment.appendChild( ret[i] );
544 cleanData: function( elems ) {
545 var data, id, cache = jQuery.cache,
546 special = jQuery.event.special,
547 deleteExpando = jQuery.support.deleteExpando;
549 for ( var i = 0, elem; (elem = elems[i]) != null; i++ ) {
550 if ( elem.nodeName && jQuery.noData[elem.nodeName.toLowerCase()] ) {
554 id = elem[ jQuery.expando ];
559 if ( data && data.events ) {
560 for ( var type in data.events ) {
561 if ( special[ type ] ) {
562 jQuery.event.remove( elem, type );
565 jQuery.removeEvent( elem, type, data.handle );
570 if ( deleteExpando ) {
571 delete elem[ jQuery.expando ];
573 } else if ( elem.removeAttribute ) {
574 elem.removeAttribute( jQuery.expando );
583 function evalScript( i, elem ) {
591 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );
594 if ( elem.parentNode ) {
595 elem.parentNode.removeChild( elem );