1 // exclude the following css properties to add px
2 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
4 defaultView = document.defaultView || {};
7 text: function( text ) {
8 if ( typeof text !== "object" && text != null )
9 return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );
13 jQuery.each( text || this, function(){
14 jQuery.each( this.childNodes, function(){
15 if ( this.nodeType != 8 )
16 ret += this.nodeType != 1 ?
18 jQuery.fn.text( [ this ] );
25 wrapAll: function( html ) {
27 // The elements to wrap the target around
28 var wrap = jQuery( html, this[0].ownerDocument ).clone();
30 if ( this[0].parentNode )
31 wrap.insertBefore( this[0] );
36 while ( elem.firstChild )
37 elem = elem.firstChild;
46 wrapInner: function( html ) {
47 return this.each(function(){
48 jQuery( this ).contents().wrapAll( html );
52 wrap: function( html ) {
53 return this.each(function(){
54 jQuery( this ).wrapAll( html );
59 return this.domManip(arguments, true, function(elem){
60 if (this.nodeType == 1)
61 this.appendChild( elem );
66 return this.domManip(arguments, true, function(elem){
67 if (this.nodeType == 1)
68 this.insertBefore( elem, this.firstChild );
73 return this.domManip(arguments, false, function(elem){
74 this.parentNode.insertBefore( elem, this );
79 return this.domManip(arguments, false, function(elem){
80 this.parentNode.insertBefore( elem, this.nextSibling );
84 clone: function( events ) {
86 var ret = this.map(function(){
87 if ( !jQuery.support.noCloneEvent && !jQuery.isXMLDoc(this) ) {
88 // IE copies events bound via attachEvent when
89 // using cloneNode. Calling detachEvent on the
90 // clone will also remove the events from the orignal
91 // In order to get around this, we use innerHTML.
92 // Unfortunately, this means some modifications to
93 // attributes in IE that are actually only stored
94 // as properties will not be copied (such as the
95 // the name attribute on an input).
96 var html = this.outerHTML, ownerDocument = this.ownerDocument;
98 var div = ownerDocument.createElement("div");
99 div.appendChild( this.cloneNode(true) );
100 html = div.innerHTML;
103 return jQuery.clean([html.replace(/ jQuery\d+="(?:\d+|null)"/g, "").replace(/^\s*/, "")], ownerDocument)[0];
105 return this.cloneNode(true);
108 // Copy the events from the original to the clone
109 if ( events === true ) {
110 var orig = this.find("*").andSelf(), i = 0;
112 ret.find("*").andSelf().each(function(){
113 if ( this.nodeName !== orig[i].nodeName )
116 var events = jQuery.data( orig[i], "events" );
118 for ( var type in events ) {
119 for ( var handler in events[ type ] ) {
120 jQuery.event.add( this, type, events[ type ][ handler ], events[ type ][ handler ].data );
128 // Return the cloned set
132 html: function( value ) {
133 return value === undefined ?
135 this[0].innerHTML.replace(/ jQuery\d+="(?:\d+|null)"/g, "") :
137 this.empty().append( value );
140 replaceWith: function( value ) {
141 return this.after( value ).remove();
144 domManip: function( args, table, callback ) {
146 var fragment = (this[0].ownerDocument || this[0]).createDocumentFragment(),
147 scripts = jQuery.clean( args, (this[0].ownerDocument || this[0]), fragment ),
148 first = fragment.firstChild;
151 for ( var i = 0, l = this.length; i < l; i++ )
152 callback.call( root(this[i], first), this.length > 1 || i > 0 ?
153 fragment.cloneNode(true) : fragment );
156 jQuery.each( scripts, evalScript );
161 function root( elem, cur ) {
162 return table && jQuery.nodeName(elem, "table") && jQuery.nodeName(cur, "tr") ?
163 (elem.getElementsByTagName("tbody")[0] ||
164 elem.appendChild(elem.ownerDocument.createElement("tbody"))) :
172 prependTo: "prepend",
173 insertBefore: "before",
174 insertAfter: "after",
175 replaceAll: "replaceWith"
176 }, function(name, original){
177 jQuery.fn[ name ] = function( selector ) {
178 var ret = [], insert = jQuery( selector );
180 for ( var i = 0, l = insert.length; i < l; i++ ) {
181 var elems = (i > 0 ? this.clone(true) : this).get();
182 jQuery.fn[ original ].apply( jQuery(insert[i]), elems );
183 ret = ret.concat( elems );
186 return this.pushStack( ret, name, selector );
191 remove: function( selector ) {
192 if ( !selector || jQuery.multiFilter( selector, [ this ] ).length ) {
193 if ( this.nodeType === 1 ) {
194 cleanData( this.getElementsByTagName("*") );
198 if ( this.parentNode ) {
199 this.parentNode.removeChild( this );
205 // Remove element nodes and prevent memory leaks
206 if ( this.nodeType === 1 ) {
207 cleanData( this.getElementsByTagName("*") );
210 // Remove any remaining nodes
211 while ( this.firstChild ) {
212 this.removeChild( this.firstChild );
215 }, function(name, fn){
216 jQuery.fn[ name ] = function(){
217 return this.each( fn, arguments );
222 clean: function( elems, context, fragment ) {
223 context = context || document;
225 // !context.createElement fails in IE with an error but returns typeof 'object'
226 if ( typeof context.createElement === "undefined" )
227 context = context.ownerDocument || context[0] && context[0].ownerDocument || document;
229 // If a single string is passed in and it's a single tag
230 // just do a createElement and skip the rest
231 if ( !fragment && elems.length === 1 && typeof elems[0] === "string" ) {
232 var match = /^<(\w+)\s*\/?>$/.exec(elems[0]);
234 return [ context.createElement( match[1] ) ];
237 var ret = [], scripts = [], div = context.createElement("div");
239 jQuery.each(elems, function(i, elem){
240 if ( typeof elem === "number" )
246 // Convert html string into DOM nodes
247 if ( typeof elem === "string" ) {
248 // Fix "XHTML"-style tags in all browsers
249 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){
250 return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?
252 front + "></" + tag + ">";
255 // Trim whitespace, otherwise indexOf won't work as expected
256 var tags = elem.replace(/^\s+/, "").substring(0, 10).toLowerCase();
259 // option or optgroup
260 !tags.indexOf("<opt") &&
261 [ 1, "<select multiple='multiple'>", "</select>" ] ||
263 !tags.indexOf("<leg") &&
264 [ 1, "<fieldset>", "</fieldset>" ] ||
266 tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&
267 [ 1, "<table>", "</table>" ] ||
269 !tags.indexOf("<tr") &&
270 [ 2, "<table><tbody>", "</tbody></table>" ] ||
272 // <thead> matched above
273 (!tags.indexOf("<td") || !tags.indexOf("<th")) &&
274 [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||
276 !tags.indexOf("<col") &&
277 [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||
279 // IE can't serialize <link> and <script> tags normally
280 !jQuery.support.htmlSerialize &&
281 [ 1, "div<div>", "</div>" ] ||
285 // Go to html and back, then peel off extra wrappers
286 div.innerHTML = wrap[1] + elem + wrap[2];
288 // Move to the right depth
292 // Remove IE's autoinserted <tbody> from table fragments
293 if ( !jQuery.support.tbody ) {
295 // String was a <table>, *may* have spurious <tbody>
296 var hasBody = /<tbody/i.test(elem),
297 tbody = !tags.indexOf("<table") && !hasBody ?
298 div.firstChild && div.firstChild.childNodes :
300 // String was a bare <thead> or <tfoot>
301 wrap[1] == "<table>" && !hasBody ?
305 for ( var j = tbody.length - 1; j >= 0 ; --j )
306 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )
307 tbody[ j ].parentNode.removeChild( tbody[ j ] );
311 // IE completely kills leading whitespace when innerHTML is used
312 if ( !jQuery.support.leadingWhitespace && /^\s/.test( elem ) )
313 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );
315 elem = jQuery.makeArray( div.childNodes );
321 ret = jQuery.merge( ret, elem );
326 for ( var i = 0; ret[i]; i++ ) {
327 if ( jQuery.nodeName( ret[i], "script" ) && (!ret[i].type || ret[i].type.toLowerCase() === "text/javascript") ) {
328 scripts.push( ret[i].parentNode ? ret[i].parentNode.removeChild( ret[i] ) : ret[i] );
330 if ( ret[i].nodeType === 1 )
331 ret.splice.apply( ret, [i + 1, 0].concat(jQuery.makeArray(ret[i].getElementsByTagName("script"))) );
332 fragment.appendChild( ret[i] );
343 function cleanData( elems ) {
344 for ( var i = 0, l = elems.length; i < l; i++ ) {
345 var id = elems[i][expando];
347 delete jQuery.cache[ id ];