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)/,
8 fcloseTag = function(all, front, tag){
9 return rselfClosing.test(tag) ?
11 front + "></" + tag + ">";
15 text: function( text ) {
16 if ( typeof text !== "object" && text !== undefined )
17 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
21 jQuery.each( text || this, function(){
22 jQuery.each( this.childNodes, function(){
23 if ( this.nodeType !== 8 ) {
24 ret += this.nodeType !== 1 ?
26 jQuery.fn.text( [ this ] );
34 wrapAll: function( html ) {
35 if ( jQuery.isFunction( html ) ) {
36 return this.each(function() {
37 jQuery(this).wrapAll( html.apply(this, arguments) );
42 // The elements to wrap the target around
43 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone();
45 if ( this[0].parentNode ) {
46 wrap.insertBefore( this[0] );
52 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
53 elem = elem.firstChild;
63 wrapInner: function( html ) {
64 return this.each(function(){
65 jQuery( this ).contents().wrapAll( html );
69 wrap: function( html ) {
70 return this.each(function(){
71 jQuery( this ).wrapAll( html );
76 return this.domManip(arguments, true, function(elem){
77 if ( this.nodeType === 1 ) {
78 this.appendChild( elem );
84 return this.domManip(arguments, true, function(elem){
85 if ( this.nodeType === 1 ) {
86 this.insertBefore( elem, this.firstChild );
92 return this.domManip(arguments, false, function(elem){
93 this.parentNode.insertBefore( elem, this );
98 return this.domManip(arguments, false, function(elem){
99 this.parentNode.insertBefore( elem, this.nextSibling );
103 clone: function( events ) {
105 var ret = this.map(function(){
106 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
107 // IE copies events bound via attachEvent when
108 // using cloneNode. Calling detachEvent on the
109 // clone will also remove the events from the orignal
110 // In order to get around this, we use innerHTML.
111 // Unfortunately, this means some modifications to
112 // attributes in IE that are actually only stored
113 // as properties will not be copied (such as the
114 // the name attribute on an input).
115 var html = this.outerHTML, ownerDocument = this.ownerDocument;
117 var div = ownerDocument.createElement("div");
118 div.appendChild( this.cloneNode(true) );
119 html = div.innerHTML;
122 return jQuery.clean([html.replace(rinlinejQuery, "")
123 .replace(rleadingWhitespace, "")], ownerDocument)[0];
125 return this.cloneNode(true);
129 // Copy the events from the original to the clone
130 if ( events === true ) {
131 var orig = this.find("*").andSelf(), i = 0;
133 ret.find("*").andSelf().each(function(){
134 if ( this.nodeName !== orig[i].nodeName ) { return; }
136 var events = jQuery.data( orig[i], "events" );
138 for ( var type in events ) {
139 for ( var handler in events[ type ] ) {
140 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
148 // Return the cloned set
152 html: function( value ) {
153 return value === undefined ?
155 this[0].innerHTML.replace(rinlinejQuery, "") :
157 this.empty().append( value );
160 replaceWith: function( value ) {
161 return this.after( value ).remove();
164 detach: function( selector ) {
165 return this.remove( selector, true );
168 domManip: function( args, table, callback ) {
169 var fragment, scripts, cacheable, cached, cacheresults, first,
172 if ( jQuery.isFunction(value) ) {
173 return this.each(function() {
174 args[0] = value.call(this);
175 return jQuery(this).domManip( args, table, callback );
180 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("<option") < 0 ) {
182 cacheresults = jQuery.fragments[ args[0] ];
183 if ( cacheresults ) {
184 if ( cacheresults !== 1 ) {
185 fragment = cacheresults;
192 fragment = (this[0].ownerDocument || this[0]).createDocumentFragment();
193 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment );
196 first = fragment.firstChild;
199 table = table && jQuery.nodeName( first, "tr" );
201 for ( var i = 0, l = this.length; i < l; i++ ) {
204 root(this[i], first) :
206 cacheable || this.length > 1 || i > 0 ?
207 fragment.cloneNode(true) :
214 jQuery.each( scripts, evalScript );
218 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
224 function root( elem, cur ) {
225 return jQuery.nodeName(elem, "table") ?
226 (elem.getElementsByTagName("tbody")[0] ||
227 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
233 jQuery.fragments = {};
237 prependTo: "prepend",
238 insertBefore: "before",
239 insertAfter: "after",
240 replaceAll: "replaceWith"
241 }, function(name, original){
242 jQuery.fn[ name ] = function( selector ) {
243 var ret = [], insert = jQuery( selector );
245 for ( var i = 0, l = insert.length; i < l; i++ ) {
246 var elems = (i > 0 ? this.clone(true) : this).get();
247 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
248 ret = ret.concat( elems );
251 return this.pushStack( ret, name, selector );
256 // keepData is for internal use only--do not document
257 remove: function( selector, keepData ) {
258 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
259 if ( !keepData && this.nodeType === 1 ) {
260 cleanData( jQuery("*", this).add(this) );
263 if ( this.parentNode ) {
264 this.parentNode.removeChild( this );
270 // Remove element nodes and prevent memory leaks
271 if ( this.nodeType === 1 ) {
272 cleanData( jQuery("*", this) );
275 // Remove any remaining nodes
276 while ( this.firstChild ) {
277 this.removeChild( this.firstChild );
280 }, function(name, fn){
281 jQuery.fn[ name ] = function(){
282 return this.each( fn, arguments );
287 clean: function( elems, context, fragment ) {
288 context = context || document;
290 // !context.createElement fails in IE with an error but returns typeof 'object'
291 if ( typeof context.createElement === "undefined" ) {
292 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
295 // If a single string is passed in and it's a single tag
296 // just do a createElement and skip the rest
297 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
298 var match = rsingleTag.exec(elems[0]);
300 return [ context.createElement( match[1] ) ];
304 var ret = [], scripts = [], div = context.createElement("div");
306 jQuery.each(elems, function(i, elem){
307 if ( typeof elem === "number" ) {
311 if ( !elem ) { return; }
313 // Convert html string into DOM nodes
314 if ( typeof elem === "string" ) {
315 // Fix "XHTML"-style tags in all browsers
316 elem = elem.replace(rxhtmlTag, fcloseTag);
318 // Trim whitespace, otherwise indexOf won't work as expected
319 var tags = elem.replace(rleadingWhitespace, "")
320 .substring(0, 10).toLowerCase();
323 // option or optgroup
324 !tags.indexOf("<opt") &&
325 [ 1, "<select multiple='multiple'>", "</select>" ] ||
327 !tags.indexOf("<leg") &&
328 [ 1, "<fieldset>", "</fieldset>" ] ||
330 rinsideTable.test(tags) &&
331 [ 1, "<table>", "</table>" ] ||
333 !tags.indexOf("<tr") &&
334 [ 2, "<table><tbody>", "</tbody></table>" ] ||
336 // <thead> matched above
337 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
338 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
340 !tags.indexOf("<col") &&
341 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
343 // IE can't serialize <link> and <script> tags normally
344 !jQuery.support.htmlSerialize &&
345 [ 1, "div<div>", "</div>" ] ||
349 // Go to html and back, then peel off extra wrappers
350 div.innerHTML = wrap[1] + elem + wrap[2];
352 // Move to the right depth
353 while ( wrap[0]-- ) {
357 // Remove IE's autoinserted <tbody> from table fragments
358 if ( !jQuery.support.tbody ) {
360 // String was a <table>, *may* have spurious <tbody>
361 var hasBody = rtbody.test(elem),
362 tbody = !tags.indexOf("<table") && !hasBody ?
363 div.firstChild && div.firstChild.childNodes :
365 // String was a bare <thead> or <tfoot>
366 wrap[1] == "<table>" && !hasBody ?
370 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
371 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
372 tbody[ j ].parentNode.removeChild( tbody[ j ] );
378 // IE completely kills leading whitespace when innerHTML is used
379 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
380 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
383 elem = jQuery.makeArray( div.childNodes );
386 if ( elem.nodeType ) {
389 ret = jQuery.merge( ret, elem );
395 for ( var i = 0; ret[i]; i++ ) {
396 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
397 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
399 if ( ret[i].nodeType === 1 ) {
400 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
402 fragment.appendChild( ret[i] );
413 function cleanData( elems ) {
414 for ( var i = 0, l = elems.length; i < l; i++ ) {
415 var id = elems[i][expando];
417 delete jQuery.cache[ id ];