Added a check to make sure that .style exists before trying to access it (Bug #2105).
[jquery.git] / src / core.js
1 /*\r
2  * jQuery @VERSION - New Wave Javascript\r
3  *\r
4  * Copyright (c) 2007 John Resig (jquery.com)\r
5  * Dual licensed under the MIT (MIT-LICENSE.txt)\r
6  * and GPL (GPL-LICENSE.txt) licenses.\r
7  *\r
8  * $Date$\r
9  * $Rev$\r
10  */\r
11 \r
12 // Map over jQuery in case of overwrite\r
13 if ( window.jQuery )\r
14         var _jQuery = window.jQuery;\r
15 \r
16 var jQuery = window.jQuery = function( selector, context ) {\r
17         // The jQuery object is actually just the init constructor 'enhanced'\r
18         return new jQuery.prototype.init( selector, context );\r
19 };\r
20 \r
21 // Map over the $ in case of overwrite\r
22 if ( window.$ )\r
23         var _$ = window.$;\r
24         \r
25 // Map the jQuery namespace to the '$' one\r
26 window.$ = jQuery;\r
27 \r
28 // A simple way to check for HTML strings or ID strings\r
29 // (both of which we optimize for)\r
30 var quickExpr = /^[^<]*(<(.|\s)+>)[^>]*$|^#(\w+)$/;\r
31 \r
32 // Is it a simple selector\r
33 var isSimple = /^.[^:#\[\.]*$/;\r
34 \r
35 jQuery.fn = jQuery.prototype = {\r
36         init: function( selector, context ) {\r
37                 // Make sure that a selection was provided\r
38                 selector = selector || document;\r
39 \r
40                 // Handle $(DOMElement)\r
41                 if ( selector.nodeType ) {\r
42                         this[0] = selector;\r
43                         this.length = 1;\r
44                         return this;\r
45 \r
46                 // Handle HTML strings\r
47                 } else if ( typeof selector == "string" ) {\r
48                         // Are we dealing with HTML string or an ID?\r
49                         var match = quickExpr.exec( selector );\r
50 \r
51                         // Verify a match, and that no context was specified for #id\r
52                         if ( match && (match[1] || !context) ) {\r
53 \r
54                                 // HANDLE: $(html) -> $(array)\r
55                                 if ( match[1] )\r
56                                         selector = jQuery.clean( [ match[1] ], context );\r
57 \r
58                                 // HANDLE: $("#id")\r
59                                 else {\r
60                                         var elem = document.getElementById( match[3] );\r
61 \r
62                                         // Make sure an element was located\r
63                                         if ( elem )\r
64                                                 // Handle the case where IE and Opera return items\r
65                                                 // by name instead of ID\r
66                                                 if ( elem.id != match[3] )\r
67                                                         return jQuery().find( selector );\r
68 \r
69                                                 // Otherwise, we inject the element directly into the jQuery object\r
70                                                 else {\r
71                                                         this[0] = elem;\r
72                                                         this.length = 1;\r
73                                                         return this;\r
74                                                 }\r
75 \r
76                                         else\r
77                                                 selector = [];\r
78                                 }\r
79 \r
80                         // HANDLE: $(expr, [context])\r
81                         // (which is just equivalent to: $(content).find(expr)\r
82                         } else\r
83                                 return new jQuery( context ).find( selector );\r
84 \r
85                 // HANDLE: $(function)\r
86                 // Shortcut for document ready\r
87                 } else if ( jQuery.isFunction( selector ) )\r
88                         return new jQuery( document )[ jQuery.fn.ready ? "ready" : "load" ]( selector );\r
89 \r
90                 return this.setArray(\r
91                         // HANDLE: $(array)\r
92                         selector.constructor == Array && selector ||\r
93 \r
94                         // HANDLE: $(arraylike)\r
95                         // Watch for when an array-like object, contains DOM nodes, is passed in as the selector\r
96                         (selector.jquery || selector.length && selector != window && !selector.nodeType && selector[0] != undefined && selector[0].nodeType) && jQuery.makeArray( selector ) ||\r
97 \r
98                         // HANDLE: $(*)\r
99                         [ selector ] );\r
100         },\r
101         \r
102         // The current version of jQuery being used\r
103         jquery: "@VERSION",\r
104 \r
105         // The number of elements contained in the matched element set\r
106         size: function() {\r
107                 return this.length;\r
108         },\r
109         \r
110         // The number of elements contained in the matched element set\r
111         length: 0,\r
112 \r
113         // Get the Nth element in the matched element set OR\r
114         // Get the whole matched element set as a clean array\r
115         get: function( num ) {\r
116                 return num == undefined ?\r
117 \r
118                         // Return a 'clean' array\r
119                         jQuery.makeArray( this ) :\r
120 \r
121                         // Return just the object\r
122                         this[ num ];\r
123         },\r
124         \r
125         // Take an array of elements and push it onto the stack\r
126         // (returning the new matched element set)\r
127         pushStack: function( elems ) {\r
128                 // Build a new jQuery matched element set\r
129                 var ret = jQuery( elems );\r
130 \r
131                 // Add the old object onto the stack (as a reference)\r
132                 ret.prevObject = this;\r
133 \r
134                 // Return the newly-formed element set\r
135                 return ret;\r
136         },\r
137         \r
138         // Force the current matched set of elements to become\r
139         // the specified array of elements (destroying the stack in the process)\r
140         // You should use pushStack() in order to do this, but maintain the stack\r
141         setArray: function( elems ) {\r
142                 // Resetting the length to 0, then using the native Array push\r
143                 // is a super-fast way to populate an object with array-like properties\r
144                 this.length = 0;\r
145                 Array.prototype.push.apply( this, elems );\r
146                 \r
147                 return this;\r
148         },\r
149 \r
150         // Execute a callback for every element in the matched set.\r
151         // (You can seed the arguments with an array of args, but this is\r
152         // only used internally.)\r
153         each: function( callback, args ) {\r
154                 return jQuery.each( this, callback, args );\r
155         },\r
156 \r
157         // Determine the position of an element within \r
158         // the matched set of elements\r
159         index: function( elem ) {\r
160                 var ret = -1;\r
161 \r
162                 // Locate the position of the desired element\r
163                 this.each(function(i){\r
164                         if ( this == elem )\r
165                                 ret = i;\r
166                 });\r
167 \r
168                 return ret;\r
169         },\r
170 \r
171         attr: function( name, value, type ) {\r
172                 var options = name;\r
173                 \r
174                 // Look for the case where we're accessing a style value\r
175                 if ( name.constructor == String )\r
176                         if ( value == undefined )\r
177                                 return this.length && jQuery[ type || "attr" ]( this[0], name ) || undefined;\r
178 \r
179                         else {\r
180                                 options = {};\r
181                                 options[ name ] = value;\r
182                         }\r
183                 \r
184                 // Check to see if we're setting style values\r
185                 return this.each(function(i){\r
186                         // Set all the styles\r
187                         for ( name in options )\r
188                                 jQuery.attr(\r
189                                         type ?\r
190                                                 this.style :\r
191                                                 this,\r
192                                         name, jQuery.prop( this, options[ name ], type, i, name )\r
193                                 );\r
194                 });\r
195         },\r
196 \r
197         css: function( key, value ) {\r
198                 // ignore negative width and height values\r
199                 if ( (key == 'width' || key == 'height') && parseFloat(value) < 0 )\r
200                         value = undefined;\r
201                 return this.attr( key, value, "curCSS" );\r
202         },\r
203 \r
204         text: function( text ) {\r
205                 if ( typeof text != "object" && text != null )\r
206                         return this.empty().append( (this[0] && this[0].ownerDocument || document).createTextNode( text ) );\r
207 \r
208                 var ret = "";\r
209 \r
210                 jQuery.each( text || this, function(){\r
211                         jQuery.each( this.childNodes, function(){\r
212                                 if ( this.nodeType != 8 )\r
213                                         ret += this.nodeType != 1 ?\r
214                                                 this.nodeValue :\r
215                                                 jQuery.fn.text( [ this ] );\r
216                         });\r
217                 });\r
218 \r
219                 return ret;\r
220         },\r
221 \r
222         wrapAll: function( html ) {\r
223                 if ( this[0] )\r
224                         // The elements to wrap the target around\r
225                         jQuery( html, this[0].ownerDocument )\r
226                                 .clone()\r
227                                 .insertBefore( this[0] )\r
228                                 .map(function(){\r
229                                         var elem = this;\r
230 \r
231                                         while ( elem.firstChild )\r
232                                                 elem = elem.firstChild;\r
233 \r
234                                         return elem;\r
235                                 })\r
236                                 .append(this);\r
237 \r
238                 return this;\r
239         },\r
240 \r
241         wrapInner: function( html ) {\r
242                 return this.each(function(){\r
243                         jQuery( this ).contents().wrapAll( html );\r
244                 });\r
245         },\r
246 \r
247         wrap: function( html ) {\r
248                 return this.each(function(){\r
249                         jQuery( this ).wrapAll( html );\r
250                 });\r
251         },\r
252 \r
253         append: function() {\r
254                 return this.domManip(arguments, true, false, function(elem){\r
255                         if (this.nodeType == 1)\r
256                                 this.appendChild( elem );\r
257                 });\r
258         },\r
259 \r
260         prepend: function() {\r
261                 return this.domManip(arguments, true, true, function(elem){\r
262                         if (this.nodeType == 1)\r
263                                 this.insertBefore( elem, this.firstChild );\r
264                 });\r
265         },\r
266         \r
267         before: function() {\r
268                 return this.domManip(arguments, false, false, function(elem){\r
269                         this.parentNode.insertBefore( elem, this );\r
270                 });\r
271         },\r
272 \r
273         after: function() {\r
274                 return this.domManip(arguments, false, true, function(elem){\r
275                         this.parentNode.insertBefore( elem, this.nextSibling );\r
276                 });\r
277         },\r
278 \r
279         end: function() {\r
280                 return this.prevObject || jQuery( [] );\r
281         },\r
282 \r
283         find: function( selector ) {\r
284                 var elems = jQuery.map(this, function(elem){\r
285                         return jQuery.find( selector, elem );\r
286                 });\r
287 \r
288                 return this.pushStack( /[^+>] [^+>]/.test( selector ) || selector.indexOf("..") > -1 ?\r
289                         jQuery.unique( elems ) :\r
290                         elems );\r
291         },\r
292 \r
293         clone: function( events ) {\r
294                 // Do the clone\r
295                 var ret = this.map(function(){\r
296                         if ( jQuery.browser.msie && !jQuery.isXMLDoc(this) ) {\r
297                                 // IE copies events bound via attachEvent when\r
298                                 // using cloneNode. Calling detachEvent on the\r
299                                 // clone will also remove the events from the orignal\r
300                                 // In order to get around this, we use innerHTML.\r
301                                 // Unfortunately, this means some modifications to \r
302                                 // attributes in IE that are actually only stored \r
303                                 // as properties will not be copied (such as the\r
304                                 // the name attribute on an input).\r
305                                 var clone = this.cloneNode(true),\r
306                                         container = document.createElement("div"),\r
307                                         container2 = document.createElement("div");\r
308                                 container.appendChild(clone);\r
309                                 container2.innerHTML = container.innerHTML;\r
310                                 return container2.firstChild;\r
311                         } else\r
312                                 return this.cloneNode(true);\r
313                 });\r
314 \r
315                 // Need to set the expando to null on the cloned set if it exists\r
316                 // removeData doesn't work here, IE removes it from the original as well\r
317                 // this is primarily for IE but the data expando shouldn't be copied over in any browser\r
318                 var clone = ret.find("*").andSelf().each(function(){\r
319                         if ( this[ expando ] != undefined )\r
320                                 this[ expando ] = null;\r
321                 });\r
322                 \r
323                 // Copy the events from the original to the clone\r
324                 if ( events === true )\r
325                         this.find("*").andSelf().each(function(i){\r
326                                 if (this.nodeType == 3)\r
327                                         return;\r
328                                 var events = jQuery.data( this, "events" );\r
329 \r
330                                 for ( var type in events )\r
331                                         for ( var handler in events[ type ] )\r
332                                                 jQuery.event.add( clone[ i ], type, events[ type ][ handler ], events[ type ][ handler ].data );\r
333                         });\r
334 \r
335                 // Return the cloned set\r
336                 return ret;\r
337         },\r
338 \r
339         filter: function( selector ) {\r
340                 return this.pushStack(\r
341                         jQuery.isFunction( selector ) &&\r
342                         jQuery.grep(this, function(elem, i){\r
343                                 return selector.call( elem, i );\r
344                         }) ||\r
345 \r
346                         jQuery.multiFilter( selector, this ) );\r
347         },\r
348 \r
349         not: function( selector ) {\r
350                 if ( selector.constructor == String )\r
351                         // test special case where just one selector is passed in\r
352                         if ( isSimple.test( selector ) )\r
353                                 return this.pushStack( jQuery.multiFilter( selector, this, true ) );\r
354                         else\r
355                                 selector = jQuery.multiFilter( selector, this );\r
356 \r
357                 var isArrayLike = selector.length && selector[selector.length - 1] !== undefined && !selector.nodeType;\r
358                 return this.filter(function() {\r
359                         return isArrayLike ? jQuery.inArray( this, selector ) < 0 : this != selector;\r
360                 });\r
361         },\r
362 \r
363         add: function( selector ) {\r
364                 return !selector ? this : this.pushStack( jQuery.merge( \r
365                         this.get(),\r
366                         selector.constructor == String ? \r
367                                 jQuery( selector ).get() :\r
368                                 selector.length != undefined && (!selector.nodeName || jQuery.nodeName(selector, "form")) ?\r
369                                         selector : [selector] ) );\r
370         },\r
371 \r
372         is: function( selector ) {\r
373                 return selector ?\r
374                         jQuery.multiFilter( selector, this ).length > 0 :\r
375                         false;\r
376         },\r
377 \r
378         hasClass: function( selector ) {\r
379                 return this.is( "." + selector );\r
380         },\r
381         \r
382         val: function( value ) {\r
383                 if ( value == undefined ) {\r
384 \r
385                         if ( this.length ) {\r
386                                 var elem = this[0];\r
387 \r
388                                 // We need to handle select boxes special\r
389                                 if ( jQuery.nodeName( elem, "select" ) ) {\r
390                                         var index = elem.selectedIndex,\r
391                                                 values = [],\r
392                                                 options = elem.options,\r
393                                                 one = elem.type == "select-one";\r
394                                         \r
395                                         // Nothing was selected\r
396                                         if ( index < 0 )\r
397                                                 return null;\r
398 \r
399                                         // Loop through all the selected options\r
400                                         for ( var i = one ? index : 0, max = one ? index + 1 : options.length; i < max; i++ ) {\r
401                                                 var option = options[ i ];\r
402 \r
403                                                 if ( option.selected ) {\r
404                                                         // Get the specifc value for the option\r
405                                                         value = jQuery.browser.msie && !option.attributes.value.specified ? option.text : option.value;\r
406                                                         \r
407                                                         // We don't need an array for one selects\r
408                                                         if ( one )\r
409                                                                 return value;\r
410                                                         \r
411                                                         // Multi-Selects return an array\r
412                                                         values.push( value );\r
413                                                 }\r
414                                         }\r
415                                         \r
416                                         return values;\r
417                                         \r
418                                 // Everything else, we just grab the value\r
419                                 } else\r
420                                         return (this[0].value || "").replace(/\r/g, "");\r
421 \r
422                         }\r
423 \r
424                         return undefined;\r
425                 }\r
426 \r
427                 return this.each(function(){\r
428                         if ( this.nodeType != 1 )\r
429                                 return;\r
430 \r
431                         if ( value.constructor == Array && /radio|checkbox/.test( this.type ) )\r
432                                 this.checked = (jQuery.inArray(this.value, value) >= 0 ||\r
433                                         jQuery.inArray(this.name, value) >= 0);\r
434 \r
435                         else if ( jQuery.nodeName( this, "select" ) ) {\r
436                                 var values = value.constructor == Array ?\r
437                                         value :\r
438                                         [ value ];\r
439 \r
440                                 jQuery( "option", this ).each(function(){\r
441                                         this.selected = (jQuery.inArray( this.value, values ) >= 0 ||\r
442                                                 jQuery.inArray( this.text, values ) >= 0);\r
443                                 });\r
444 \r
445                                 if ( !values.length )\r
446                                         this.selectedIndex = -1;\r
447 \r
448                         } else\r
449                                 this.value = value;\r
450                 });\r
451         },\r
452         \r
453         html: function( value ) {\r
454                 return value == undefined ?\r
455                         (this.length ?\r
456                                 this[0].innerHTML :\r
457                                 null) :\r
458                         this.empty().append( value );\r
459         },\r
460 \r
461         replaceWith: function( value ) {\r
462                 return this.after( value ).remove();\r
463         },\r
464 \r
465         eq: function( i ) {\r
466                 return this.slice( i, i + 1 );\r
467         },\r
468 \r
469         slice: function() {\r
470                 return this.pushStack( Array.prototype.slice.apply( this, arguments ) );\r
471         },\r
472 \r
473         map: function( callback ) {\r
474                 return this.pushStack( jQuery.map(this, function(elem, i){\r
475                         return callback.call( elem, i, elem );\r
476                 }));\r
477         },\r
478 \r
479         andSelf: function() {\r
480                 return this.add( this.prevObject );\r
481         },\r
482         \r
483         domManip: function( args, table, reverse, callback ) {\r
484                 var clone = this.length > 1, elems; \r
485 \r
486                 return this.each(function(){\r
487                         if ( !elems ) {\r
488                                 elems = jQuery.clean( args, this.ownerDocument );\r
489 \r
490                                 if ( reverse )\r
491                                         elems.reverse();\r
492                         }\r
493 \r
494                         var obj = this;\r
495 \r
496                         if ( table && jQuery.nodeName( this, "table" ) && jQuery.nodeName( elems[0], "tr" ) )\r
497                                 obj = this.getElementsByTagName("tbody")[0] || this.appendChild( this.ownerDocument.createElement("tbody") );\r
498 \r
499                         var scripts = jQuery( [] );\r
500 \r
501                         jQuery.each(elems, function(){\r
502                                 var elem = clone ?\r
503                                         jQuery( this ).clone( true )[0] :\r
504                                         this;\r
505 \r
506                                 // execute all scripts after the elements have been injected\r
507                                 if ( jQuery.nodeName( elem, "script" ) ) {\r
508                                         scripts = scripts.add( elem );\r
509                                 } else {\r
510                                         // Remove any inner scripts for later evaluation\r
511                                         if ( elem.nodeType == 1 )\r
512                                                 scripts = scripts.add( jQuery( "script", elem ).remove() );\r
513 \r
514                                         // Inject the elements into the document\r
515                                         callback.call( obj, elem );\r
516                                 }\r
517                         });\r
518 \r
519                         scripts.each( evalScript );\r
520                 });\r
521         }\r
522 };\r
523 \r
524 // Give the init function the jQuery prototype for later instantiation\r
525 jQuery.prototype.init.prototype = jQuery.prototype;\r
526 \r
527 function evalScript( i, elem ) {\r
528         if ( elem.src )\r
529                 jQuery.ajax({\r
530                         url: elem.src,\r
531                         async: false,\r
532                         dataType: "script"\r
533                 });\r
534 \r
535         else\r
536                 jQuery.globalEval( elem.text || elem.textContent || elem.innerHTML || "" );\r
537 \r
538         if ( elem.parentNode )\r
539                 elem.parentNode.removeChild( elem );\r
540 }\r
541 \r
542 jQuery.extend = jQuery.fn.extend = function() {\r
543         // copy reference to target object\r
544         var target = arguments[0] || {}, i = 1, length = arguments.length, deep = false, options;\r
545 \r
546         // Handle a deep copy situation\r
547         if ( target.constructor == Boolean ) {\r
548                 deep = target;\r
549                 target = arguments[1] || {};\r
550                 // skip the boolean and the target\r
551                 i = 2;\r
552         }\r
553 \r
554         // Handle case when target is a string or something (possible in deep copy)\r
555         if ( typeof target != "object" && typeof target != "function" )\r
556                 target = {};\r
557 \r
558         // extend jQuery itself if only one argument is passed\r
559         if ( length == 1 ) {\r
560                 target = this;\r
561                 i = 0;\r
562         }\r
563 \r
564         for ( ; i < length; i++ )\r
565                 // Only deal with non-null/undefined values\r
566                 if ( (options = arguments[ i ]) != null )\r
567                         // Extend the base object\r
568                         for ( var name in options ) {\r
569                                 // Prevent never-ending loop\r
570                                 if ( target === options[ name ] )\r
571                                         continue;\r
572 \r
573                                 // Recurse if we're merging object values\r
574                                 if ( deep && options[ name ] && typeof options[ name ] == "object" && target[ name ] && !options[ name ].nodeType )\r
575                                         target[ name ] = jQuery.extend( target[ name ], options[ name ] );\r
576 \r
577                                 // Don't bring in undefined values\r
578                                 else if ( options[ name ] != undefined )\r
579                                         target[ name ] = options[ name ];\r
580 \r
581                         }\r
582 \r
583         // Return the modified object\r
584         return target;\r
585 };\r
586 \r
587 var expando = "jQuery" + (new Date()).getTime(), uuid = 0, windowData = {};\r
588 \r
589 // exclude the following css properties to add px\r
590 var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i;\r
591 \r
592 jQuery.extend({\r
593         noConflict: function( deep ) {\r
594                 window.$ = _$;\r
595 \r
596                 if ( deep )\r
597                         window.jQuery = _jQuery;\r
598 \r
599                 return jQuery;\r
600         },\r
601 \r
602         // See test/unit/core.js for details concerning this function.\r
603         isFunction: function( fn ) {\r
604                 return !!fn && typeof fn != "string" && !fn.nodeName && \r
605                         fn.constructor != Array && /function/i.test( fn + "" );\r
606         },\r
607         \r
608         // check if an element is in a (or is an) XML document\r
609         isXMLDoc: function( elem ) {\r
610                 return elem.documentElement && !elem.body ||\r
611                         elem.tagName && elem.ownerDocument && !elem.ownerDocument.body;\r
612         },\r
613 \r
614         // Evalulates a script in a global context\r
615         globalEval: function( data ) {\r
616                 data = jQuery.trim( data );\r
617 \r
618                 if ( data ) {\r
619                         // Inspired by code by Andrea Giammarchi\r
620                         // http://webreflection.blogspot.com/2007/08/global-scope-evaluation-and-dom.html\r
621                         var head = document.getElementsByTagName("head")[0] || document.documentElement,\r
622                                 script = document.createElement("script");\r
623 \r
624                         script.type = "text/javascript";\r
625                         if ( jQuery.browser.msie )\r
626                                 script.text = data;\r
627                         else\r
628                                 script.appendChild( document.createTextNode( data ) );\r
629 \r
630                         head.appendChild( script );\r
631                         head.removeChild( script );\r
632                 }\r
633         },\r
634 \r
635         nodeName: function( elem, name ) {\r
636                 return elem.nodeName && elem.nodeName.toUpperCase() == name.toUpperCase();\r
637         },\r
638         \r
639         cache: {},\r
640         \r
641         data: function( elem, name, data ) {\r
642                 elem = elem == window ?\r
643                         windowData :\r
644                         elem;\r
645 \r
646                 var id = elem[ expando ];\r
647 \r
648                 // Compute a unique ID for the element\r
649                 if ( !id ) \r
650                         id = elem[ expando ] = ++uuid;\r
651 \r
652                 // Only generate the data cache if we're\r
653                 // trying to access or manipulate it\r
654                 if ( name && !jQuery.cache[ id ] )\r
655                         jQuery.cache[ id ] = {};\r
656                 \r
657                 // Prevent overriding the named cache with undefined values\r
658                 if ( data != undefined )\r
659                         jQuery.cache[ id ][ name ] = data;\r
660                 \r
661                 // Return the named cache data, or the ID for the element       \r
662                 return name ?\r
663                         jQuery.cache[ id ][ name ] :\r
664                         id;\r
665         },\r
666         \r
667         removeData: function( elem, name ) {\r
668                 elem = elem == window ?\r
669                         windowData :\r
670                         elem;\r
671 \r
672                 var id = elem[ expando ];\r
673 \r
674                 // If we want to remove a specific section of the element's data\r
675                 if ( name ) {\r
676                         if ( jQuery.cache[ id ] ) {\r
677                                 // Remove the section of cache data\r
678                                 delete jQuery.cache[ id ][ name ];\r
679 \r
680                                 // If we've removed all the data, remove the element's cache\r
681                                 name = "";\r
682 \r
683                                 for ( name in jQuery.cache[ id ] )\r
684                                         break;\r
685 \r
686                                 if ( !name )\r
687                                         jQuery.removeData( elem );\r
688                         }\r
689 \r
690                 // Otherwise, we want to remove all of the element's data\r
691                 } else {\r
692                         // Clean up the element expando\r
693                         try {\r
694                                 delete elem[ expando ];\r
695                         } catch(e){\r
696                                 // IE has trouble directly removing the expando\r
697                                 // but it's ok with using removeAttribute\r
698                                 if ( elem.removeAttribute )\r
699                                         elem.removeAttribute( expando );\r
700                         }\r
701 \r
702                         // Completely remove the data cache\r
703                         delete jQuery.cache[ id ];\r
704                 }\r
705         },\r
706 \r
707         // args is for internal usage only\r
708         each: function( object, callback, args ) {\r
709                 if ( args ) {\r
710                         if ( object.length == undefined )\r
711                                 for ( var name in object )\r
712                                         callback.apply( object[ name ], args );\r
713                         else\r
714                                 for ( var i = 0, length = object.length; i < length; i++ )\r
715                                         if ( callback.apply( object[ i ], args ) === false )\r
716                                                 break;\r
717 \r
718                 // A special, fast, case for the most common use of each\r
719                 } else {\r
720                         if ( object.length == undefined )\r
721                                 for ( var name in object )\r
722                                         callback.call( object[ name ], name, object[ name ] );\r
723                         else\r
724                                 for ( var i = 0, length = object.length, value = object[0]; \r
725                                         i < length && callback.call( value, i, value ) !== false; value = object[++i] ){}\r
726                 }\r
727 \r
728                 return object;\r
729         },\r
730         \r
731         prop: function( elem, value, type, i, name ) {\r
732                         // Handle executable functions\r
733                         if ( jQuery.isFunction( value ) )\r
734                                 value = value.call( elem, i );\r
735                                 \r
736                         // Handle passing in a number to a CSS property\r
737                         return value && value.constructor == Number && type == "curCSS" && !exclude.test( name ) ?\r
738                                 value + "px" :\r
739                                 value;\r
740         },\r
741 \r
742         className: {\r
743                 // internal only, use addClass("class")\r
744                 add: function( elem, classNames ) {\r
745                         jQuery.each((classNames || "").split(/\s+/), function(i, className){\r
746                                 if ( elem.nodeType == 1 && !jQuery.className.has( elem.className, className ) )\r
747                                         elem.className += (elem.className ? " " : "") + className;\r
748                         });\r
749                 },\r
750 \r
751                 // internal only, use removeClass("class")\r
752                 remove: function( elem, classNames ) {\r
753                         if (elem.nodeType == 1)\r
754                                 elem.className = classNames != undefined ?\r
755                                         jQuery.grep(elem.className.split(/\s+/), function(className){\r
756                                                 return !jQuery.className.has( classNames, className );  \r
757                                         }).join(" ") :\r
758                                         "";\r
759                 },\r
760 \r
761                 // internal only, use is(".class")\r
762                 has: function( elem, className ) {\r
763                         return jQuery.inArray( className, (elem.className || elem).toString().split(/\s+/) ) > -1;\r
764                 }\r
765         },\r
766 \r
767         // A method for quickly swapping in/out CSS properties to get correct calculations\r
768         swap: function( elem, options, callback ) {\r
769                 var old = {};\r
770                 // Remember the old values, and insert the new ones\r
771                 for ( var name in options ) {\r
772                         old[ name ] = elem.style[ name ];\r
773                         elem.style[ name ] = options[ name ];\r
774                 }\r
775 \r
776                 callback.call( elem );\r
777 \r
778                 // Revert the old values\r
779                 for ( var name in options )\r
780                         elem.style[ name ] = old[ name ];\r
781         },\r
782 \r
783         css: function( elem, name, force ) {\r
784                 if ( name == "width" || name == "height" ) {\r
785                         var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];\r
786                 \r
787                         function getWH() {\r
788                                 val = name == "width" ? elem.offsetWidth : elem.offsetHeight;\r
789                                 var padding = 0, border = 0;\r
790                                 jQuery.each( which, function() {\r
791                                         padding += parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;\r
792                                         border += parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;\r
793                                 });\r
794                                 val -= Math.round(padding + border);\r
795                         }\r
796                 \r
797                         if ( jQuery(elem).is(":visible") )\r
798                                 getWH();\r
799                         else\r
800                                 jQuery.swap( elem, props, getWH );\r
801                         \r
802                         return Math.max(0, val);\r
803                 }\r
804                 \r
805                 return jQuery.curCSS( elem, name, force );\r
806         },\r
807 \r
808         curCSS: function( elem, name, force ) {\r
809                 var ret;\r
810 \r
811                 // A helper method for determining if an element's values are broken\r
812                 function color( elem ) {\r
813                         if ( !jQuery.browser.safari )\r
814                                 return false;\r
815 \r
816                         var ret = document.defaultView.getComputedStyle( elem, null );\r
817                         return !ret || ret.getPropertyValue("color") == "";\r
818                 }\r
819 \r
820                 // We need to handle opacity special in IE\r
821                 if ( name == "opacity" && jQuery.browser.msie ) {\r
822                         ret = jQuery.attr( elem.style, "opacity" );\r
823 \r
824                         return ret == "" ?\r
825                                 "1" :\r
826                                 ret;\r
827                 }\r
828                 // Opera sometimes will give the wrong display answer, this fixes it, see #2037\r
829                 if ( jQuery.browser.opera && name == "display" ) {\r
830                         var save = elem.style.display;\r
831                         elem.style.display = "block";\r
832                         elem.style.display = save;\r
833                 }\r
834                 \r
835                 // Make sure we're using the right name for getting the float value\r
836                 if ( name.match( /float/i ) )\r
837                         name = styleFloat;\r
838 \r
839                 if ( !force && elem.style && elem.style[ name ] )\r
840                         ret = elem.style[ name ];\r
841 \r
842                 else if ( document.defaultView && document.defaultView.getComputedStyle ) {\r
843 \r
844                         // Only "float" is needed here\r
845                         if ( name.match( /float/i ) )\r
846                                 name = "float";\r
847 \r
848                         name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();\r
849 \r
850                         var getComputedStyle = document.defaultView.getComputedStyle( elem, null );\r
851 \r
852                         if ( getComputedStyle && !color( elem ) )\r
853                                 ret = getComputedStyle.getPropertyValue( name );\r
854 \r
855                         // If the element isn't reporting its values properly in Safari\r
856                         // then some display: none elements are involved\r
857                         else {\r
858                                 var swap = [], stack = [];\r
859 \r
860                                 // Locate all of the parent display: none elements\r
861                                 for ( var a = elem; a && color(a); a = a.parentNode )\r
862                                         stack.unshift(a);\r
863 \r
864                                 // Go through and make them visible, but in reverse\r
865                                 // (It would be better if we knew the exact display type that they had)\r
866                                 for ( var i = 0; i < stack.length; i++ )\r
867                                         if ( color( stack[ i ] ) ) {\r
868                                                 swap[ i ] = stack[ i ].style.display;\r
869                                                 stack[ i ].style.display = "block";\r
870                                         }\r
871 \r
872                                 // Since we flip the display style, we have to handle that\r
873                                 // one special, otherwise get the value\r
874                                 ret = name == "display" && swap[ stack.length - 1 ] != null ?\r
875                                         "none" :\r
876                                         ( getComputedStyle && getComputedStyle.getPropertyValue( name ) ) || "";\r
877 \r
878                                 // Finally, revert the display styles back\r
879                                 for ( var i = 0; i < swap.length; i++ )\r
880                                         if ( swap[ i ] != null )\r
881                                                 stack[ i ].style.display = swap[ i ];\r
882                         }\r
883 \r
884                         // We should always get a number back from opacity\r
885                         if ( name == "opacity" && ret == "" )\r
886                                 ret = "1";\r
887 \r
888                 } else if ( elem.currentStyle ) {\r
889                         var camelCase = name.replace(/\-(\w)/g, function(all, letter){\r
890                                 return letter.toUpperCase();\r
891                         });\r
892 \r
893                         ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];\r
894 \r
895                         // From the awesome hack by Dean Edwards\r
896                         // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291\r
897 \r
898                         // If we're not dealing with a regular pixel number\r
899                         // but a number that has a weird ending, we need to convert it to pixels\r
900                         if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {\r
901                                 // Remember the original values\r
902                                 var style = elem.style.left, runtimeStyle = elem.runtimeStyle.left;\r
903 \r
904                                 // Put in the new values to get a computed value out\r
905                                 elem.runtimeStyle.left = elem.currentStyle.left;\r
906                                 elem.style.left = ret || 0;\r
907                                 ret = elem.style.pixelLeft + "px";\r
908 \r
909                                 // Revert the changed values\r
910                                 elem.style.left = style;\r
911                                 elem.runtimeStyle.left = runtimeStyle;\r
912                         }\r
913                 }\r
914 \r
915                 return ret;\r
916         },\r
917         \r
918         clean: function( elems, context ) {\r
919                 var ret = [];\r
920                 context = context || document;\r
921                 // !context.createElement fails in IE with an error but returns typeof 'object'\r
922                 if (typeof context.createElement == 'undefined') \r
923                         context = context.ownerDocument || context[0] && context[0].ownerDocument || document;\r
924 \r
925                 jQuery.each(elems, function(i, elem){\r
926                         if ( !elem )\r
927                                 return;\r
928 \r
929                         if ( elem.constructor == Number )\r
930                                 elem = elem.toString();\r
931                         \r
932                         // Convert html string into DOM nodes\r
933                         if ( typeof elem == "string" ) {\r
934                                 // Fix "XHTML"-style tags in all browsers\r
935                                 elem = elem.replace(/(<(\w+)[^>]*?)\/>/g, function(all, front, tag){\r
936                                         return tag.match(/^(abbr|br|col|img|input|link|meta|param|hr|area|embed)$/i) ?\r
937                                                 all :\r
938                                                 front + "></" + tag + ">";\r
939                                 });\r
940 \r
941                                 // Trim whitespace, otherwise indexOf won't work as expected\r
942                                 var tags = jQuery.trim( elem ).toLowerCase(), div = context.createElement("div");\r
943 \r
944                                 var wrap =\r
945                                         // option or optgroup\r
946                                         !tags.indexOf("<opt") &&\r
947                                         [ 1, "<select multiple='multiple'>", "</select>" ] ||\r
948                                         \r
949                                         !tags.indexOf("<leg") &&\r
950                                         [ 1, "<fieldset>", "</fieldset>" ] ||\r
951                                         \r
952                                         tags.match(/^<(thead|tbody|tfoot|colg|cap)/) &&\r
953                                         [ 1, "<table>", "</table>" ] ||\r
954                                         \r
955                                         !tags.indexOf("<tr") &&\r
956                                         [ 2, "<table><tbody>", "</tbody></table>" ] ||\r
957                                         \r
958                                         // <thead> matched above\r
959                                         (!tags.indexOf("<td") || !tags.indexOf("<th")) &&\r
960                                         [ 3, "<table><tbody><tr>", "</tr></tbody></table>" ] ||\r
961                                         \r
962                                         !tags.indexOf("<col") &&\r
963                                         [ 2, "<table><tbody></tbody><colgroup>", "</colgroup></table>" ] ||\r
964 \r
965                                         // IE can't serialize <link> and <script> tags normally\r
966                                         jQuery.browser.msie &&\r
967                                         [ 1, "div<div>", "</div>" ] ||\r
968                                         \r
969                                         [ 0, "", "" ];\r
970 \r
971                                 // Go to html and back, then peel off extra wrappers\r
972                                 div.innerHTML = wrap[1] + elem + wrap[2];\r
973                                 \r
974                                 // Move to the right depth\r
975                                 while ( wrap[0]-- )\r
976                                         div = div.lastChild;\r
977                                 \r
978                                 // Remove IE's autoinserted <tbody> from table fragments\r
979                                 if ( jQuery.browser.msie ) {\r
980                                         \r
981                                         // String was a <table>, *may* have spurious <tbody>\r
982                                         var tbody = !tags.indexOf("<table") && tags.indexOf("<tbody") < 0 ?\r
983                                                 div.firstChild && div.firstChild.childNodes :\r
984                                                 \r
985                                                 // String was a bare <thead> or <tfoot>\r
986                                                 wrap[1] == "<table>" && tags.indexOf("<tbody") < 0 ?\r
987                                                         div.childNodes :\r
988                                                         [];\r
989                                 \r
990                                         for ( var j = tbody.length - 1; j >= 0 ; --j )\r
991                                                 if ( jQuery.nodeName( tbody[ j ], "tbody" ) && !tbody[ j ].childNodes.length )\r
992                                                         tbody[ j ].parentNode.removeChild( tbody[ j ] );\r
993                                         \r
994                                         // IE completely kills leading whitespace when innerHTML is used        \r
995                                         if ( /^\s/.test( elem ) )       \r
996                                                 div.insertBefore( context.createTextNode( elem.match(/^\s*/)[0] ), div.firstChild );\r
997                                 \r
998                                 }\r
999                                 \r
1000                                 elem = jQuery.makeArray( div.childNodes );\r
1001                         }\r
1002 \r
1003                         if ( elem.length === 0 && (!jQuery.nodeName( elem, "form" ) && !jQuery.nodeName( elem, "select" )) )\r
1004                                 return;\r
1005 \r
1006                         if ( elem[0] == undefined || jQuery.nodeName( elem, "form" ) || elem.options )\r
1007                                 ret.push( elem );\r
1008 \r
1009                         else\r
1010                                 ret = jQuery.merge( ret, elem );\r
1011 \r
1012                 });\r
1013 \r
1014                 return ret;\r
1015         },\r
1016         \r
1017         attr: function( elem, name, value ) {\r
1018                 // don't set attributes on text and comment nodes\r
1019                 if (!elem || elem.nodeType == 3 || elem.nodeType == 8)\r
1020                         return undefined;\r
1021 \r
1022                 var fix = jQuery.isXMLDoc( elem ) ?\r
1023                         {} :\r
1024                         jQuery.props;\r
1025 \r
1026                 // Safari mis-reports the default selected property of a hidden option\r
1027                 // Accessing the parent's selectedIndex property fixes it\r
1028                 if ( name == "selected" && jQuery.browser.safari )\r
1029                         elem.parentNode.selectedIndex;\r
1030                 \r
1031                 // Certain attributes only work when accessed via the old DOM 0 way\r
1032                 if ( fix[ name ] ) {\r
1033                         if ( value != undefined )\r
1034                                 elem[ fix[ name ] ] = value;\r
1035 \r
1036                         return elem[ fix[ name ] ];\r
1037 \r
1038                 } else if ( jQuery.browser.msie && name == "style" )\r
1039                         return jQuery.attr( elem.style, "cssText", value );\r
1040 \r
1041                 else if ( value == undefined && jQuery.browser.msie && jQuery.nodeName( elem, "form" ) && (name == "action" || name == "method") )\r
1042                         return elem.getAttributeNode( name ).nodeValue;\r
1043 \r
1044                 // IE elem.getAttribute passes even for style\r
1045                 else if ( elem.tagName ) {\r
1046 \r
1047                         if ( value != undefined ) {\r
1048                                 // We can't allow the type property to be changed (since it causes problems in IE)\r
1049                                 if ( name == "type" && jQuery.nodeName( elem, "input" ) && elem.parentNode )\r
1050                                         throw "type property can't be changed";\r
1051 \r
1052                                 // convert the value to a string (all browsers do this but IE) see #1070\r
1053                                 elem.setAttribute( name, "" + value );\r
1054                         }\r
1055 \r
1056                         if ( jQuery.browser.msie && /href|src/.test( name ) && !jQuery.isXMLDoc( elem ) ) \r
1057                                 return elem.getAttribute( name, 2 );\r
1058 \r
1059                         return elem.getAttribute( name );\r
1060 \r
1061                 // elem is actually elem.style ... set the style\r
1062                 } else {\r
1063                         // IE actually uses filters for opacity\r
1064                         if ( name == "opacity" && jQuery.browser.msie ) {\r
1065                                 if ( value != undefined ) {\r
1066                                         // IE has trouble with opacity if it does not have layout\r
1067                                         // Force it by setting the zoom level\r
1068                                         elem.zoom = 1; \r
1069         \r
1070                                         // Set the alpha filter to set the opacity\r
1071                                         elem.filter = (elem.filter || "").replace( /alpha\([^)]*\)/, "" ) +\r
1072                                                 (parseFloat( value ).toString() == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");\r
1073                                 }\r
1074         \r
1075                                 return elem.filter && elem.filter.indexOf("opacity=") >= 0 ?\r
1076                                         (parseFloat( elem.filter.match(/opacity=([^)]*)/)[1] ) / 100).toString() :\r
1077                                         "";\r
1078                         }\r
1079 \r
1080                         name = name.replace(/-([a-z])/ig, function(all, letter){\r
1081                                 return letter.toUpperCase();\r
1082                         });\r
1083 \r
1084                         if ( value != undefined )\r
1085                                 elem[ name ] = value;\r
1086 \r
1087                         return elem[ name ];\r
1088                 }\r
1089         },\r
1090         \r
1091         trim: function( text ) {\r
1092                 return (text || "").replace( /^\s+|\s+$/g, "" );\r
1093         },\r
1094 \r
1095         makeArray: function( array ) {\r
1096                 var ret = [];\r
1097 \r
1098                 // Need to use typeof to fight Safari childNodes crashes\r
1099                 if ( typeof array != "array" )\r
1100                         for ( var i = 0, length = array.length; i < length; i++ )\r
1101                                 ret.push( array[ i ] );\r
1102                 else\r
1103                         ret = array.slice( 0 );\r
1104 \r
1105                 return ret;\r
1106         },\r
1107 \r
1108         inArray: function( elem, array ) {\r
1109                 for ( var i = 0, length = array.length; i < length; i++ )\r
1110                         if ( array[ i ] == elem )\r
1111                                 return i;\r
1112 \r
1113                 return -1;\r
1114         },\r
1115 \r
1116         merge: function( first, second ) {\r
1117                 // We have to loop this way because IE & Opera overwrite the length\r
1118                 // expando of getElementsByTagName\r
1119 \r
1120                 // Also, we need to make sure that the correct elements are being returned\r
1121                 // (IE returns comment nodes in a '*' query)\r
1122                 if ( jQuery.browser.msie ) {\r
1123                         for ( var i = 0; second[ i ]; i++ )\r
1124                                 if ( second[ i ].nodeType != 8 )\r
1125                                         first.push( second[ i ] );\r
1126 \r
1127                 } else\r
1128                         for ( var i = 0; second[ i ]; i++ )\r
1129                                 first.push( second[ i ] );\r
1130 \r
1131                 return first;\r
1132         },\r
1133 \r
1134         unique: function( array ) {\r
1135                 var ret = [], done = {};\r
1136 \r
1137                 try {\r
1138 \r
1139                         for ( var i = 0, length = array.length; i < length; i++ ) {\r
1140                                 var id = jQuery.data( array[ i ] );\r
1141 \r
1142                                 if ( !done[ id ] ) {\r
1143                                         done[ id ] = true;\r
1144                                         ret.push( array[ i ] );\r
1145                                 }\r
1146                         }\r
1147 \r
1148                 } catch( e ) {\r
1149                         ret = array;\r
1150                 }\r
1151 \r
1152                 return ret;\r
1153         },\r
1154 \r
1155         grep: function( elems, callback, inv ) {\r
1156                 // If a string is passed in for the function, make a function\r
1157                 // for it (a handy shortcut)\r
1158                 if ( typeof callback == "string" )\r
1159                         callback = eval("false||function(a,i){return " + callback + "}");\r
1160 \r
1161                 var ret = [];\r
1162 \r
1163                 // Go through the array, only saving the items\r
1164                 // that pass the validator function\r
1165                 for ( var i = 0, length = elems.length; i < length; i++ )\r
1166                         if ( !inv && callback( elems[ i ], i ) || inv && !callback( elems[ i ], i ) )\r
1167                                 ret.push( elems[ i ] );\r
1168 \r
1169                 return ret;\r
1170         },\r
1171 \r
1172         map: function( elems, callback ) {\r
1173                 var ret = [];\r
1174 \r
1175                 // Go through the array, translating each of the items to their\r
1176                 // new value (or values).\r
1177                 for ( var i = 0, length = elems.length; i < length; i++ ) {\r
1178                         var value = callback( elems[ i ], i );\r
1179 \r
1180                         if ( value !== null && value != undefined ) {\r
1181                                 if ( value.constructor != Array )\r
1182                                         value = [ value ];\r
1183 \r
1184                                 ret = ret.concat( value );\r
1185                         }\r
1186                 }\r
1187 \r
1188                 return ret;\r
1189         }\r
1190 });\r
1191 \r
1192 var userAgent = navigator.userAgent.toLowerCase();\r
1193 \r
1194 // Figure out what browser is being used\r
1195 jQuery.browser = {\r
1196         version: (userAgent.match( /.+(?:rv|it|ra|ie)[\/: ]([\d.]+)/ ) || [])[1],\r
1197         safari: /webkit/.test( userAgent ),\r
1198         opera: /opera/.test( userAgent ),\r
1199         msie: /msie/.test( userAgent ) && !/opera/.test( userAgent ),\r
1200         mozilla: /mozilla/.test( userAgent ) && !/(compatible|webkit)/.test( userAgent )\r
1201 };\r
1202 \r
1203 var styleFloat = jQuery.browser.msie ?\r
1204         "styleFloat" :\r
1205         "cssFloat";\r
1206         \r
1207 jQuery.extend({\r
1208         // Check to see if the W3C box model is being used\r
1209         boxModel: !jQuery.browser.msie || document.compatMode == "CSS1Compat",\r
1210         \r
1211         props: {\r
1212                 "for": "htmlFor",\r
1213                 "class": "className",\r
1214                 "float": styleFloat,\r
1215                 cssFloat: styleFloat,\r
1216                 styleFloat: styleFloat,\r
1217                 innerHTML: "innerHTML",\r
1218                 className: "className",\r
1219                 value: "value",\r
1220                 disabled: "disabled",\r
1221                 checked: "checked",\r
1222                 readonly: "readOnly",\r
1223                 selected: "selected",\r
1224                 maxlength: "maxLength",\r
1225                 selectedIndex: "selectedIndex",\r
1226                 defaultValue: "defaultValue",\r
1227                 tagName: "tagName",\r
1228                 nodeName: "nodeName"\r
1229         }\r
1230 });\r
1231 \r
1232 jQuery.each({\r
1233         parent: "elem.parentNode",\r
1234         parents: "jQuery.dir(elem,'parentNode')",\r
1235         next: "jQuery.nth(elem,2,'nextSibling')",\r
1236         prev: "jQuery.nth(elem,2,'previousSibling')",\r
1237         nextAll: "jQuery.dir(elem,'nextSibling')",\r
1238         prevAll: "jQuery.dir(elem,'previousSibling')",\r
1239         siblings: "jQuery.sibling(elem.parentNode.firstChild,elem)",\r
1240         children: "jQuery.sibling(elem.firstChild)",\r
1241         contents: "jQuery.nodeName(elem,'iframe')?elem.contentDocument||elem.contentWindow.document:jQuery.makeArray(elem.childNodes)"\r
1242 }, function(name, fn){\r
1243         fn = eval("false||function(elem){return " + fn + "}");\r
1244 \r
1245         jQuery.fn[ name ] = function( selector ) {\r
1246                 var ret = jQuery.map( this, fn );\r
1247 \r
1248                 if ( selector && typeof selector == "string" )\r
1249                         ret = jQuery.multiFilter( selector, ret );\r
1250 \r
1251                 return this.pushStack( jQuery.unique( ret ) );\r
1252         };\r
1253 });\r
1254 \r
1255 jQuery.each({\r
1256         appendTo: "append",\r
1257         prependTo: "prepend",\r
1258         insertBefore: "before",\r
1259         insertAfter: "after",\r
1260         replaceAll: "replaceWith"\r
1261 }, function(name, original){\r
1262         jQuery.fn[ name ] = function() {\r
1263                 var args = arguments;\r
1264 \r
1265                 return this.each(function(){\r
1266                         for ( var i = 0, length = args.length; i < length; i++ )\r
1267                                 jQuery( args[ i ] )[ original ]( this );\r
1268                 });\r
1269         };\r
1270 });\r
1271 \r
1272 jQuery.each({\r
1273         removeAttr: function( name ) {\r
1274                 jQuery.attr( this, name, "" );\r
1275                 if (this.nodeType == 1) \r
1276                         this.removeAttribute( name );\r
1277         },\r
1278 \r
1279         addClass: function( classNames ) {\r
1280                 jQuery.className.add( this, classNames );\r
1281         },\r
1282 \r
1283         removeClass: function( classNames ) {\r
1284                 jQuery.className.remove( this, classNames );\r
1285         },\r
1286 \r
1287         toggleClass: function( classNames ) {\r
1288                 jQuery.className[ jQuery.className.has( this, classNames ) ? "remove" : "add" ]( this, classNames );\r
1289         },\r
1290 \r
1291         remove: function( selector ) {\r
1292                 if ( !selector || jQuery.filter( selector, [ this ] ).r.length ) {\r
1293                         // Prevent memory leaks\r
1294                         jQuery( "*", this ).add(this).each(function(){\r
1295                                 jQuery.event.remove(this);\r
1296                                 jQuery.removeData(this);\r
1297                         });\r
1298                         if (this.parentNode)\r
1299                                 this.parentNode.removeChild( this );\r
1300                 }\r
1301         },\r
1302 \r
1303         empty: function() {\r
1304                 // Remove element nodes and prevent memory leaks\r
1305                 jQuery( ">*", this ).remove();\r
1306                 \r
1307                 // Remove any remaining nodes\r
1308                 while ( this.firstChild )\r
1309                         this.removeChild( this.firstChild );\r
1310         }\r
1311 }, function(name, fn){\r
1312         jQuery.fn[ name ] = function(){\r
1313                 return this.each( fn, arguments );\r
1314         };\r
1315 });\r
1316 \r
1317 jQuery.each([ "Height", "Width" ], function(i, name){\r
1318         var type = name.toLowerCase();\r
1319         \r
1320         jQuery.fn[ type ] = function( size ) {\r
1321                 // Get window width or height\r
1322                 return this[0] == window ?\r
1323                         // Opera reports document.body.client[Width/Height] properly in both quirks and standards\r
1324                         jQuery.browser.opera && document.body[ "client" + name ] || \r
1325                         \r
1326                         // Safari reports inner[Width/Height] just fine (Mozilla and Opera include scroll bar widths)\r
1327                         jQuery.browser.safari && window[ "inner" + name ] ||\r
1328                         \r
1329                         // Everyone else use document.documentElement or document.body depending on Quirks vs Standards mode\r
1330                         document.compatMode == "CSS1Compat" && document.documentElement[ "client" + name ] || document.body[ "client" + name ] :\r
1331                 \r
1332                         // Get document width or height\r
1333                         this[0] == document ?\r
1334                                 // Either scroll[Width/Height] or offset[Width/Height], whichever is greater\r
1335                                 Math.max( \r
1336                                         Math.max(document.body["scroll" + name], document.documentElement["scroll" + name]), \r
1337                                         Math.max(document.body["offset" + name], document.documentElement["offset" + name]) \r
1338                                 ) :\r
1339 \r
1340                                 // Get or set width or height on the element\r
1341                                 size == undefined ?\r
1342                                         // Get width or height on the element\r
1343                                         (this.length ? jQuery.css( this[0], type ) : null) :\r
1344 \r
1345                                         // Set the width or height on the element (default to pixels if value is unitless)\r
1346                                         this.css( type, size.constructor == String ? size : size + "px" );\r
1347         };\r
1348 });\r