3 var ralpha = /alpha\([^)]*\)/i,
4 ropacity = /opacity=([^)]*)/,
5 rdashAlpha = /-([a-z])/ig,
7 rnumpx = /^-?\d+(?:px)?$/i,
10 cssShow = { position: "absolute", visibility: "hidden", display: "block" },
11 cssWidth = [ "Left", "Right" ],
12 cssHeight = [ "Top", "Bottom" ],
15 fcamelCase = function( all, letter ) {
16 return letter.toUpperCase();
19 jQuery.fn.css = function( name, value ) {
20 // Setting 'undefined' is a no-op
21 if ( arguments.length === 2 && value === undefined ) {
25 return jQuery.access( this, name, value, true, function( elem, name, value ) {
26 return value !== undefined ?
27 jQuery.style( elem, name, value ) :
28 jQuery.css( elem, name );
33 // Add in style property hooks for overriding the default
34 // behavior of getting and setting a style property
37 get: function( elem, computed ) {
39 // We should always get a number back from opacity
40 var ret = curCSS( elem, "opacity", "opacity" );
41 return ret === "" ? "1" : ret;
44 return elem.style.opacity;
50 // Exclude the following css properties to add px
59 // Add in properties whose names you wish to fix before
60 // setting or getting the value
62 // normalize float css property
63 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
66 // Get and set the style property on a DOM Node
67 style: function( elem, name, value, extra ) {
68 // Don't set styles on text and comment nodes
69 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
73 // Make sure that we're working with the right name
74 var ret, origName = jQuery.camelCase( name ),
75 style = elem.style, hooks = jQuery.cssHooks[ origName ];
77 name = jQuery.cssProps[ origName ] || origName;
79 // Check if we're setting a value
80 if ( value !== undefined ) {
81 // Make sure that NaN and null values aren't set. See: #7116
82 if ( typeof value === "number" && isNaN( value ) || value == null ) {
86 // If a number was passed in, add 'px' to the (except for certain CSS properties)
87 if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
91 // If a hook was provided, use that value, otherwise just set the specified value
92 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
93 // Wrapped to prevent IE from throwing errors when 'invalid' values are provided
96 style[ name ] = value;
101 // If a hook was provided get the non-computed value from there
102 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
106 // Otherwise just get the value from the style object
107 return style[ name ];
111 css: function( elem, name, extra ) {
112 // Make sure that we're working with the right name
113 var ret, origName = jQuery.camelCase( name ),
114 hooks = jQuery.cssHooks[ origName ];
116 name = jQuery.cssProps[ origName ] || origName;
118 // If a hook was provided get the computed value from there
119 if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
122 // Otherwise, if a way to get the computed value exists, use that
123 } else if ( curCSS ) {
124 return curCSS( elem, name, origName );
128 // A method for quickly swapping in/out CSS properties to get correct calculations
129 swap: function( elem, options, callback ) {
132 // Remember the old values, and insert the new ones
133 for ( var name in options ) {
134 old[ name ] = elem.style[ name ];
135 elem.style[ name ] = options[ name ];
138 callback.call( elem );
140 // Revert the old values
141 for ( name in options ) {
142 elem.style[ name ] = old[ name ];
146 camelCase: function( string ) {
147 return string.replace( rdashAlpha, fcamelCase );
151 // DEPRECATED, Use jQuery.css() instead
152 jQuery.curCSS = jQuery.css;
154 jQuery.each(["height", "width"], function( i, name ) {
155 jQuery.cssHooks[ name ] = {
156 get: function( elem, computed, extra ) {
160 if ( elem.offsetWidth !== 0 ) {
161 val = getWH( elem, name, extra );
164 jQuery.swap( elem, cssShow, function() {
165 val = getWH( elem, name, extra );
170 val = curCSS( elem, name, name );
173 // Should return "auto" instead of 0, use 0 for
174 // temporary backwards-compat
175 return val === "" || val === "auto" ? "0px" : val;
179 if ( val < 0 || val == null ) {
180 val = elem.style[ name ];
182 // Should return "auto" instead of 0, use 0 for
183 // temporary backwards-compat
184 return val === "" || val === "auto" ? "0px" : val;
187 return typeof val === "string" ? val : val + "px";
191 set: function( elem, value ) {
192 if ( rnumpx.test( value ) ) {
193 // ignore negative width and height values #1599
194 value = parseFloat(value);
207 if ( !jQuery.support.opacity ) {
208 jQuery.cssHooks.opacity = {
209 get: function( elem, computed ) {
210 // IE uses filters for opacity
211 return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
212 (parseFloat(RegExp.$1) / 100) + "" :
216 set: function( elem, value ) {
217 var style = elem.style;
219 // IE has trouble with opacity if it does not have layout
220 // Force it by setting the zoom level
223 // Set the alpha filter to set the opacity
224 var opacity = jQuery.isNaN(value) ?
226 "alpha(opacity=" + value * 100 + ")",
227 filter = style.filter || "";
229 style.filter = ralpha.test(filter) ?
230 filter.replace(ralpha, opacity) :
231 style.filter + ' ' + opacity;
236 if ( document.defaultView && document.defaultView.getComputedStyle ) {
237 curCSS = function( elem, newName, name ) {
238 var ret, defaultView, computedStyle;
240 name = name.replace( rupper, "-$1" ).toLowerCase();
242 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
246 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
247 ret = computedStyle.getPropertyValue( name );
248 if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
249 ret = jQuery.style( elem, name );
255 } else if ( document.documentElement.currentStyle ) {
256 curCSS = function( elem, name ) {
258 ret = elem.currentStyle && elem.currentStyle[ name ],
261 // From the awesome hack by Dean Edwards
262 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
264 // If we're not dealing with a regular pixel number
265 // but a number that has a weird ending, we need to convert it to pixels
266 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
267 // Remember the original values
269 rsLeft = elem.runtimeStyle.left;
271 // Put in the new values to get a computed value out
272 elem.runtimeStyle.left = elem.currentStyle.left;
273 style.left = name === "fontSize" ? "1em" : (ret || 0);
274 ret = style.pixelLeft + "px";
276 // Revert the changed values
278 elem.runtimeStyle.left = rsLeft;
281 return ret === "" ? "auto" : ret;
285 function getWH( elem, name, extra ) {
286 var which = name === "width" ? cssWidth : cssHeight,
287 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
289 if ( extra === "border" ) {
293 jQuery.each( which, function() {
295 val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
298 if ( extra === "margin" ) {
299 val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
302 val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
309 if ( jQuery.expr && jQuery.expr.filters ) {
310 jQuery.expr.filters.hidden = function( elem ) {
311 var width = elem.offsetWidth,
312 height = elem.offsetHeight;
314 return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style.display || jQuery.css( elem, "display" )) === "none");
317 jQuery.expr.filters.visible = function( elem ) {
318 return !jQuery.expr.filters.hidden( elem );