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 value !== undefined ?
25 jQuery.style( elem, name, value ) :
26 jQuery.css( elem, name );
31 // Add in style property hooks for overriding the default
32 // behavior of getting and setting a style property
35 get: function( elem ) {
36 // We should always get a number back from opacity
37 var ret = curCSS( elem, "opacity", "opacity" );
38 return ret === "" ? "1" : ret;
43 // Exclude the following css properties to add px
52 // Add in properties whose names you wish to fix before
53 // setting or getting the value
55 // normalize float css property
56 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
59 // Get and set the style property on a DOM Node
60 style: function( elem, name, value, extra ) {
61 // Don't set styles on text and comment nodes
62 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
66 // Make sure that we're working with the right name
67 var ret, origName = jQuery.camelCase( name ),
68 style = elem.style, hooks = jQuery.cssHooks[ origName ];
70 name = jQuery.cssProps[ origName ] || origName;
72 // Check if we're setting a value
73 if ( value !== undefined ) {
74 // If a number was passed in, add 'px' to the (except for certain CSS properties)
75 if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
79 // If a hook was provided, use that value, otherwise just set the specified value
80 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
81 style[ name ] = value;
85 // If a hook was provided get the non-computed value from there
86 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
90 // Otherwise just get the value from the style object
95 css: function( elem, name, extra ) {
96 // Make sure that we're working with the right name
97 var ret, origName = jQuery.camelCase( name ),
98 hooks = jQuery.cssHooks[ origName ];
100 name = jQuery.cssProps[ origName ] || origName;
102 // If a hook was provided get the computed value from there
103 if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
106 // Otherwise, if a way to get the computed value exists, use that
107 } else if ( curCSS ) {
108 return curCSS( elem, name, origName );
112 // A method for quickly swapping in/out CSS properties to get correct calculations
113 swap: function( elem, options, callback ) {
116 // Remember the old values, and insert the new ones
117 for ( var name in options ) {
118 old[ name ] = elem.style[ name ];
119 elem.style[ name ] = options[ name ];
122 callback.call( elem );
124 // Revert the old values
125 for ( name in options ) {
126 elem.style[ name ] = old[ name ];
130 camelCase: function( string ) {
131 return string.replace( rdashAlpha, fcamelCase );
135 // DEPRECATED, Use jQuery.css() instead
136 jQuery.curCSS = jQuery.css;
138 jQuery.each(["height", "width"], function( i, name ) {
139 jQuery.cssHooks[ name ] = {
140 get: function( elem, computed, extra ) {
144 if ( elem.offsetWidth !== 0 ) {
145 val = getWH( elem, name, extra );
148 jQuery.swap( elem, cssShow, function() {
149 val = getWH( elem, name, extra );
157 set: function( elem, value ) {
158 if ( rnumpx.test( value ) ) {
159 // ignore negative width and height values #1599
160 value = parseFloat(value);
173 if ( !jQuery.support.opacity ) {
174 jQuery.cssHooks.opacity = {
175 get: function( elem, computed ) {
176 // IE uses filters for opacity
177 return ropacity.test((computed ? elem.currentStyle.filter : elem.style.filter) || "") ?
178 (parseFloat(RegExp.$1) / 100) + "" :
182 set: function( elem, value ) {
183 var style = elem.style;
185 // IE has trouble with opacity if it does not have layout
186 // Force it by setting the zoom level
189 // Set the alpha filter to set the opacity
190 var opacity = parseInt( value, 10 ) + "" === "NaN" ?
192 "alpha(opacity=" + value * 100 + ")";
194 var filter = style.filter || elem.currentStyle.filter || "";
196 style.filter = ralpha.test(filter) ?
197 filter.replace(ralpha, opacity) :
203 if ( getComputedStyle ) {
204 curCSS = function( elem, newName, name ) {
205 var ret, defaultView, computedStyle;
207 name = name.replace( rupper, "-$1" ).toLowerCase();
209 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
213 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
214 ret = computedStyle.getPropertyValue( name );
220 } else if ( document.documentElement.currentStyle ) {
221 curCSS = function( elem, name ) {
222 var left, rsLeft, ret = elem.currentStyle[ name ], style = elem.style;
224 // From the awesome hack by Dean Edwards
225 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
227 // If we're not dealing with a regular pixel number
228 // but a number that has a weird ending, we need to convert it to pixels
229 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
230 // Remember the original values
232 rsLeft = elem.runtimeStyle.left;
234 // Put in the new values to get a computed value out
235 elem.runtimeStyle.left = elem.currentStyle.left;
236 style.left = name === "fontSize" ? "1em" : (ret || 0);
237 ret = style.pixelLeft + "px";
239 // Revert the changed values
241 elem.runtimeStyle.left = rsLeft;
248 function getWH( elem, name, extra ) {
249 var which = name === "width" ? cssWidth : cssHeight,
250 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
252 if ( extra === "border" ) {
256 jQuery.each( which, function() {
258 val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
261 if ( extra === "margin" ) {
262 val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
265 val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
272 if ( jQuery.expr && jQuery.expr.filters ) {
273 jQuery.expr.filters.hidden = function( elem ) {
274 var width = elem.offsetWidth, height = elem.offsetHeight,
275 skip = elem.nodeName.toLowerCase() === "tr";
277 return width === 0 && height === 0 && !skip ?
279 width > 0 && height > 0 && !skip ?
281 (elem.style.display || jQuery.css( elem, "display" )) === "none";
284 jQuery.expr.filters.visible = function( elem ) {
285 return !jQuery.expr.filters.hidden( elem );