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