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 = name.replace( rdashAlpha, fcamelCase ),
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 = name.replace( rdashAlpha, fcamelCase ),
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 ];
131 // DEPRECATED, Use jQuery.css() instead
132 jQuery.curCSS = jQuery.css;
134 jQuery.each(["height", "width"], function( i, name ) {
135 jQuery.cssHooks[ name ] = {
136 get: function( elem, computed, extra ) {
140 if ( elem.offsetWidth !== 0 ) {
141 val = getWH( elem, name, extra );
144 jQuery.swap( elem, cssShow, function() {
145 val = getWH( elem, name, extra );
153 set: function( elem, value ) {
154 if ( value !== "" ) {
155 // ignore negative width and height values #1599
156 value = parseFloat(value);
169 if ( !jQuery.support.opacity ) {
170 jQuery.cssHooks.opacity = {
171 get: function( elem, computed ) {
172 // IE uses filters for opacity
173 return ropacity.test((computed ? elem.currentStyle.filter : elem.style.filter) || "") ?
174 (parseFloat(RegExp.$1) / 100) + "" :
178 set: function( elem, value ) {
179 var style = elem.style;
181 // IE has trouble with opacity if it does not have layout
182 // Force it by setting the zoom level
185 // Set the alpha filter to set the opacity
186 var opacity = parseInt( value, 10 ) + "" === "NaN" ?
188 "alpha(opacity=" + value * 100 + ")";
190 var filter = style.filter || elem.currentStyle.filter || "";
192 style.filter = ralpha.test(filter) ?
193 filter.replace(ralpha, opacity) :
199 if ( getComputedStyle ) {
200 curCSS = function( elem, newName, name ) {
201 var ret, defaultView, computedStyle;
203 name = name.replace( rupper, "-$1" ).toLowerCase();
205 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
209 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
210 ret = computedStyle.getPropertyValue( name );
216 } else if ( document.documentElement.currentStyle ) {
217 curCSS = function( elem, name ) {
218 var left, rsLeft, ret = elem.currentStyle[ name ], style = elem.style;
220 // From the awesome hack by Dean Edwards
221 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
223 // If we're not dealing with a regular pixel number
224 // but a number that has a weird ending, we need to convert it to pixels
225 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
226 // Remember the original values
228 rsLeft = elem.runtimeStyle.left;
230 // Put in the new values to get a computed value out
231 elem.runtimeStyle.left = elem.currentStyle.left;
232 style.left = name === "fontSize" ? "1em" : (ret || 0);
233 ret = style.pixelLeft + "px";
235 // Revert the changed values
237 elem.runtimeStyle.left = rsLeft;
244 function getWH( elem, name, extra ) {
245 var which = name === "width" ? cssWidth : cssHeight,
246 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
248 if ( extra === "border" ) {
252 jQuery.each( which, function() {
254 val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
257 if ( extra === "margin" ) {
258 val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
261 val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
268 if ( jQuery.expr && jQuery.expr.filters ) {
269 jQuery.expr.filters.hidden = function( elem ) {
270 var width = elem.offsetWidth, height = elem.offsetHeight,
271 skip = elem.nodeName.toLowerCase() === "tr";
273 return width === 0 && height === 0 && !skip ?
275 width > 0 && height > 0 && !skip ?
277 (elem.style.display || jQuery.css( elem, "display" )) === "none";
280 jQuery.expr.filters.visible = function( elem ) {
281 return !jQuery.expr.filters.hidden( elem );