3 var ralpha = /alpha\([^)]*\)/,
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 // cache check for defaultView.getComputedStyle
16 getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
18 fcamelCase = function( all, letter ) {
19 return letter.toUpperCase();
22 jQuery.fn.css = function( name, value ) {
23 return jQuery.access( this, name, value, true, function( elem, name, value ) {
24 return jQuery.css( elem, name, value );
29 // Add in style property hooks for overriding the default
30 // behavior of getting and setting a style property
33 get: function( elem ) {
34 // We should always get a number back from opacity
35 var ret = curCSS( elem, "opacity", "opacity" );
36 return ret === "" ? "1" : ret;
41 // Exclude the following css properties to add px
50 // Add in properties whose names you wish to fix before
51 // setting or getting the value
53 // normalize float css property
54 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
57 // Get and set the style property on a DOM Node
58 style: function( elem, name, value, extra ) {
59 // Don't set styles on text and comment nodes
60 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
64 // Make sure that we're working with the right name
65 var ret, origName = name.replace( rdashAlpha, fcamelCase ),
66 style = elem.style, hooks = jQuery.cssHooks[ origName ];
68 name = jQuery.cssProps[ origName ] || origName;
70 // Check if we're setting a value
71 if ( value !== undefined ) {
72 // If a number was passed in, add 'px' to the (except for certain CSS properties)
73 if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
77 // If a hook was provided, use that value, otherwise just set the specified value
78 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
79 style[ name ] = value;
83 // If a hook was provided get the non-computed value from there
84 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
88 // Otherwise just get the value from the style object
93 css: function( elem, name, value, extra ) {
94 // Make sure that we're working with the right name
95 var ret, origName = name.replace( rdashAlpha, fcamelCase ),
96 hooks = jQuery.cssHooks[ origName ];
98 name = jQuery.cssProps[ origName ] || origName;
100 // Check if we're setting a value, just use jQuery.style (DEPRECATED)
101 if ( value !== undefined ) {
102 jQuery.style( elem, name, value );
104 // If a hook was provided get the computed value from there
105 } else if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
108 // Otherwise, if a way to get the computed value exists, use that
109 } else if ( curCSS ) {
110 return curCSS( elem, name, origName );
114 // A method for quickly swapping in/out CSS properties to get correct calculations
115 swap: function( elem, options, callback ) {
118 // Remember the old values, and insert the new ones
119 for ( var name in options ) {
120 old[ name ] = elem.style[ name ];
121 elem.style[ name ] = options[ name ];
124 callback.call( elem );
126 // Revert the old values
127 for ( name in options ) {
128 elem.style[ name ] = old[ name ];
133 jQuery.each(["height", "width"], function( i, name ) {
134 jQuery.cssHooks[ name ] = {
135 get: function( elem, computed, extra ) {
139 if ( elem.offsetWidth !== 0 ) {
140 val = getWH( elem, name, extra );
143 jQuery.swap( elem, cssShow, function() {
144 val = getWH( elem, name, extra );
152 set: function( elem, value ) {
153 if ( value !== "" ) {
154 // ignore negative width and height values #1599
155 value = parseFloat(value);
168 if ( !jQuery.support.opacity ) {
169 jQuery.cssHooks.opacity = {
170 get: function( elem, computed ) {
171 // IE uses filters for opacity
172 return ropacity.test((computed ? elem.currentStyle.filter : elem.style.filter) || "") ?
173 (parseFloat(RegExp.$1) / 100) + "" :
177 set: function( elem, value ) {
178 var style = elem.style;
180 // IE has trouble with opacity if it does not have layout
181 // Force it by setting the zoom level
184 // Set the alpha filter to set the opacity
185 var opacity = parseInt( value, 10 ) + "" === "NaN" ?
187 "alpha(opacity=" + value * 100 + ")";
189 var filter = style.filter || elem.currentStyle.filter || "";
191 style.filter = ralpha.test(filter) ?
192 filter.replace(ralpha, opacity) :
198 if ( getComputedStyle ) {
199 curCSS = function( elem, newName, name ) {
200 var ret, defaultView, computedStyle;
202 name = name.replace( rupper, "-$1" ).toLowerCase();
204 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
208 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
209 ret = computedStyle.getPropertyValue( name );
215 } else if ( document.documentElement.currentStyle ) {
216 curCSS = function( elem, name ) {
217 var left, rsLeft, ret = elem.currentStyle[ name ], style = elem.style;
219 // From the awesome hack by Dean Edwards
220 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
222 // If we're not dealing with a regular pixel number
223 // but a number that has a weird ending, we need to convert it to pixels
224 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
225 // Remember the original values
227 rsLeft = elem.runtimeStyle.left;
229 // Put in the new values to get a computed value out
230 elem.runtimeStyle.left = elem.currentStyle.left;
231 style.left = name === "fontSize" ? "1em" : (ret || 0);
232 ret = style.pixelLeft + "px";
234 // Revert the changed values
236 elem.runtimeStyle.left = rsLeft;
243 function getWH( elem, name, extra ) {
244 var which = name === "width" ? cssWidth : cssHeight,
245 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
247 if ( extra === "border" ) {
251 jQuery.each( which, function() {
253 val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
256 if ( extra === "margin" ) {
257 val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
260 val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
267 if ( jQuery.expr && jQuery.expr.filters ) {
268 jQuery.expr.filters.hidden = function( elem ) {
269 var width = elem.offsetWidth, height = elem.offsetHeight,
270 skip = elem.nodeName.toLowerCase() === "tr";
272 return width === 0 && height === 0 && !skip ?
274 width > 0 && height > 0 && !skip ?
276 (elem.style.display || jQuery.css( elem, "display" )) === "none";
279 jQuery.expr.filters.visible = function( elem ) {
280 return !jQuery.expr.filters.hidden( elem );