1 var rinlinejQuery = / jQuery\d+="(?:\d+|null)"/g,
2 rleadingWhitespace = /^\s+/,
3 rxhtmlTag = /(<(\w+)[^>]*?)\/>/g,
4 rselfClosing = /^(?:abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i,
5 rinsideTable = /^<(thead|tbody|tfoot|colg|cap)/,
7 fcloseTag = function(all, front, tag){
8 return rselfClosing.test(tag) ?
10 front + "></" + tag + ">";
14 text: function( text ) {
15 if ( typeof text !== "object" && text !== undefined )
16 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
20 jQuery.each( text || this, function(){
21 jQuery.each( this.childNodes, function(){
22 if ( this.nodeType !== 8 ) {
23 ret += this.nodeType !== 1 ?
25 jQuery.fn.text( [ this ] );
33 wrapAll: function( html ) {
34 if ( jQuery.isFunction( html ) ) {
35 return this.each(function() {
36 jQuery(this).wrapAll( html.apply(this, arguments) );
41 // The elements to wrap the target around
42 var wrap = jQuery( html, this[0].ownerDocument ).eq(0).clone();
44 if ( this[0].parentNode ) {
45 wrap.insertBefore( this[0] );
51 while ( elem.firstChild && elem.firstChild.nodeType === 1 ) {
52 elem = elem.firstChild;
62 wrapInner: function( html ) {
63 return this.each(function(){
64 jQuery( this ).contents().wrapAll( html );
68 wrap: function( html ) {
69 return this.each(function(){
70 jQuery( this ).wrapAll( html );
75 return this.domManip(arguments, true, function(elem){
76 if ( this.nodeType === 1 ) {
77 this.appendChild( elem );
83 return this.domManip(arguments, true, function(elem){
84 if ( this.nodeType === 1 ) {
85 this.insertBefore( elem, this.firstChild );
91 return this.domManip(arguments, false, function(elem){
92 this.parentNode.insertBefore( elem, this );
97 return this.domManip(arguments, false, function(elem){
98 this.parentNode.insertBefore( elem, this.nextSibling );
102 clone: function( events ) {
104 var ret = this.map(function(){
105 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
106 // IE copies events bound via attachEvent when
107 // using cloneNode. Calling detachEvent on the
108 // clone will also remove the events from the orignal
109 // In order to get around this, we use innerHTML.
110 // Unfortunately, this means some modifications to
111 // attributes in IE that are actually only stored
112 // as properties will not be copied (such as the
113 // the name attribute on an input).
114 var html = this.outerHTML, ownerDocument = this.ownerDocument;
116 var div = ownerDocument.createElement("div");
117 div.appendChild( this.cloneNode(true) );
118 html = div.innerHTML;
121 return jQuery.clean([html.replace(rinlinejQuery, "")
122 .replace(rleadingWhitespace, "")], ownerDocument)[0];
124 return this.cloneNode(true);
128 // Copy the events from the original to the clone
129 if ( events === true ) {
130 var orig = this.find("*").andSelf(), i = 0;
132 ret.find("*").andSelf().each(function(){
133 if ( this.nodeName !== orig[i].nodeName ) { return; }
135 var events = jQuery.data( orig[i], "events" );
137 for ( var type in events ) {
138 for ( var handler in events[ type ] ) {
139 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
147 // Return the cloned set
151 html: function( value ) {
152 return value === undefined ?
154 this[0].innerHTML.replace(rinlinejQuery, "") :
156 this.empty().append( value );
159 replaceWith: function( value ) {
160 return this.after( value ).remove();
163 detach: function( selector ) {
164 return this.remove( selector, true );
167 domManip: function( args, table, callback ) {
168 var results, first, value = args[0], scripts = [];
170 if ( jQuery.isFunction(value) ) {
171 return this.each(function() {
172 args[0] = value.call(this);
173 return jQuery(this).domManip( args, table, callback );
178 // If we're in a fragment, just use that instead of building a new one
179 if ( args[0] && args[0].parentNode && args[0].parentNode.nodeType === 11 ) {
180 results = { fragment: args[0].parentNode };
182 results = buildFragment( args, this[0], scripts );
185 first = results.fragment.firstChild;
188 table = table && jQuery.nodeName( first, "tr" );
190 for ( var i = 0, l = this.length; i < l; i++ ) {
193 root(this[i], first) :
195 results.cacheable || this.length > 1 || i > 0 ?
196 results.fragment.cloneNode(true) :
203 jQuery.each( scripts, evalScript );
209 function root( elem, cur ) {
210 return jQuery.nodeName(elem, "table") ?
211 (elem.getElementsByTagName("tbody")[0] ||
212 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
218 function buildFragment(args, nodes, scripts){
219 var fragment, cacheable, cached, cacheresults, doc;
221 if ( args.length === 1 && typeof args[0] === "string" && args[0].length < 512 && args[0].indexOf("<option") < 0 ) {
223 cacheresults = jQuery.fragments[ args[0] ];
224 if ( cacheresults ) {
225 if ( cacheresults !== 1 ) {
226 fragment = cacheresults;
233 doc = (nodes && nodes[0] ? nodes[0].ownerDocument || nodes[0] : document);
234 fragment = doc.createDocumentFragment();
235 jQuery.clean( args, doc, fragment, scripts );
239 jQuery.fragments[ args[0] ] = cacheresults ? fragment : 1;
242 return { fragment: fragment, cacheable: cacheable };
245 jQuery.fragments = {};
249 prependTo: "prepend",
250 insertBefore: "before",
251 insertAfter: "after",
252 replaceAll: "replaceWith"
253 }, function(name, original){
254 jQuery.fn[ name ] = function( selector ) {
255 var ret = [], insert = jQuery( selector );
257 for ( var i = 0, l = insert.length; i < l; i++ ) {
258 var elems = (i > 0 ? this.clone(true) : this).get();
259 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
260 ret = ret.concat( elems );
263 return this.pushStack( ret, name, selector );
268 // keepData is for internal use only--do not document
269 remove: function( selector, keepData ) {
270 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
271 if ( !keepData && this.nodeType === 1 ) {
272 cleanData( jQuery("*", this).add(this) );
275 if ( this.parentNode ) {
276 this.parentNode.removeChild( this );
282 // Remove element nodes and prevent memory leaks
283 if ( this.nodeType === 1 ) {
284 cleanData( jQuery("*", this) );
287 // Remove any remaining nodes
288 while ( this.firstChild ) {
289 this.removeChild( this.firstChild );
292 }, function(name, fn){
293 jQuery.fn[ name ] = function(){
294 return this.each( fn, arguments );
299 clean: function( elems, context, fragment, scripts ) {
300 context = context || document;
302 // !context.createElement fails in IE with an error but returns typeof 'object'
303 if ( typeof context.createElement === "undefined" ) {
304 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
307 var ret = [], div = context.createElement("div");
309 jQuery.each(elems, function(i, elem){
310 if ( typeof elem === "number" ) {
314 if ( !elem ) { return; }
316 // Convert html string into DOM nodes
317 if ( typeof elem === "string" ) {
318 // Fix "XHTML"-style tags in all browsers
319 elem = elem.replace(rxhtmlTag, fcloseTag);
321 // Trim whitespace, otherwise indexOf won't work as expected
322 var tags = elem.replace(rleadingWhitespace, "")
323 .substring(0, 10).toLowerCase();
326 // option or optgroup
327 !tags.indexOf("<opt") &&
328 [ 1, "<select multiple='multiple'>", "</select>" ] ||
330 !tags.indexOf("<leg") &&
331 [ 1, "<fieldset>", "</fieldset>" ] ||
333 rinsideTable.test(tags) &&
334 [ 1, "<table>", "</table>" ] ||
336 !tags.indexOf("<tr") &&
337 [ 2, "<table><tbody>", "</tbody></table>" ] ||
339 // <thead> matched above
340 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
341 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
343 !tags.indexOf("<col") &&
344 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
346 // IE can't serialize <link> and <script> tags normally
347 !jQuery.support.htmlSerialize &&
348 [ 1, "div<div>", "</div>" ] ||
352 // Go to html and back, then peel off extra wrappers
353 div.innerHTML = wrap[1] + elem + wrap[2];
355 // Move to the right depth
356 while ( wrap[0]-- ) {
360 // Remove IE's autoinserted <tbody> from table fragments
361 if ( !jQuery.support.tbody ) {
363 // String was a <table>, *may* have spurious <tbody>
364 var hasBody = rtbody.test(elem),
365 tbody = !tags.indexOf("<table") && !hasBody ?
366 div.firstChild && div.firstChild.childNodes :
368 // String was a bare <thead> or <tfoot>
369 wrap[1] == "<table>" && !hasBody ?
373 for ( var j = tbody.length - 1; j >= 0 ; --j ) {
374 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length ) {
375 tbody[ j ].parentNode.removeChild( tbody[ j ] );
381 // IE completely kills leading whitespace when innerHTML is used
382 if ( !jQuery.support.leadingWhitespace && rleadingWhitespace.test( elem ) ) {
383 div.insertBefore( context.createTextNode( rleadingWhitespace.exec(elem)[0] ), div.firstChild );
386 elem = jQuery.makeArray( div.childNodes );
389 if ( elem.nodeType ) {
392 ret = jQuery.merge( ret, elem );
398 for ( var i = 0; ret[i]; i++ ) {
399 if ( scripts && jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
400 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
402 if ( ret[i].nodeType === 1 ) {
403 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
405 fragment.appendChild( ret[i] );
414 function cleanData( elems ) {
415 for ( var i = 0, l = elems.length; i < l; i++ ) {
416 var id = elems[i][expando];
418 delete jQuery.cache[ id ];