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 // 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 // Setting 'undefined' is a no-op
24 if ( arguments.length === 2 && value === undefined ) {
28 return jQuery.access( this, name, value, true, function( elem, name, value ) {
29 return value !== undefined ?
30 jQuery.style( elem, name, value ) :
31 jQuery.css( elem, name );
36 // Add in style property hooks for overriding the default
37 // behavior of getting and setting a style property
40 get: function( elem, computed ) {
42 // We should always get a number back from opacity
43 var ret = curCSS( elem, "opacity", "opacity" );
44 return ret === "" ? "1" : ret;
47 return elem.style.opacity;
53 // Exclude the following css properties to add px
62 // Add in properties whose names you wish to fix before
63 // setting or getting the value
65 // normalize float css property
66 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
69 // Get and set the style property on a DOM Node
70 style: function( elem, name, value, extra ) {
71 // Don't set styles on text and comment nodes
72 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
76 // Make sure that we're working with the right name
77 var ret, origName = jQuery.camelCase( name ),
78 style = elem.style, hooks = jQuery.cssHooks[ origName ];
80 name = jQuery.cssProps[ origName ] || origName;
82 // Check if we're setting a value
83 if ( value !== undefined ) {
84 // If a number was passed in, add 'px' to the (except for certain CSS properties)
85 if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
89 // If a hook was provided, use that value, otherwise just set the specified value
90 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
91 // Wrapped to prevent IE from throwing errors when 'invalid' values are provided
94 style[ name ] = value;
99 // If a hook was provided get the non-computed value from there
100 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
104 // Otherwise just get the value from the style object
105 return style[ name ];
109 css: function( elem, name, extra ) {
110 // Make sure that we're working with the right name
111 var ret, origName = jQuery.camelCase( name ),
112 hooks = jQuery.cssHooks[ origName ];
114 name = jQuery.cssProps[ origName ] || origName;
116 // If a hook was provided get the computed value from there
117 if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
120 // Otherwise, if a way to get the computed value exists, use that
121 } else if ( curCSS ) {
122 return curCSS( elem, name, origName );
126 // A method for quickly swapping in/out CSS properties to get correct calculations
127 swap: function( elem, options, callback ) {
130 // Remember the old values, and insert the new ones
131 for ( var name in options ) {
132 old[ name ] = elem.style[ name ];
133 elem.style[ name ] = options[ name ];
136 callback.call( elem );
138 // Revert the old values
139 for ( name in options ) {
140 elem.style[ name ] = old[ name ];
144 camelCase: function( string ) {
145 return string.replace( rdashAlpha, fcamelCase );
149 // DEPRECATED, Use jQuery.css() instead
150 jQuery.curCSS = jQuery.css;
152 jQuery.each(["height", "width"], function( i, name ) {
153 jQuery.cssHooks[ name ] = {
154 get: function( elem, computed, extra ) {
158 if ( elem.offsetWidth !== 0 ) {
159 val = getWH( elem, name, extra );
162 jQuery.swap( elem, cssShow, function() {
163 val = getWH( elem, name, extra );
171 set: function( elem, value ) {
172 if ( rnumpx.test( value ) ) {
173 // ignore negative width and height values #1599
174 value = parseFloat(value);
187 if ( !jQuery.support.opacity ) {
188 jQuery.cssHooks.opacity = {
189 get: function( elem, computed ) {
190 // IE uses filters for opacity
191 return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
192 (parseFloat(RegExp.$1) / 100) + "" :
196 set: function( elem, value ) {
197 var style = elem.style;
199 // IE has trouble with opacity if it does not have layout
200 // Force it by setting the zoom level
203 // Set the alpha filter to set the opacity
204 var opacity = jQuery.isNaN(value) ?
206 "alpha(opacity=" + value * 100 + ")",
207 filter = style.filter || "";
209 style.filter = ralpha.test(filter) ?
210 filter.replace(ralpha, opacity) :
211 style.filter + ' ' + opacity;
216 if ( getComputedStyle ) {
217 curCSS = function( elem, newName, name ) {
218 var ret, defaultView, computedStyle;
220 name = name.replace( rupper, "-$1" ).toLowerCase();
222 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
226 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
227 ret = computedStyle.getPropertyValue( name );
233 } else if ( document.documentElement.currentStyle ) {
234 curCSS = function( elem, name ) {
235 var left, rsLeft, ret = elem.currentStyle && elem.currentStyle[ name ], style = elem.style;
237 // From the awesome hack by Dean Edwards
238 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
240 // If we're not dealing with a regular pixel number
241 // but a number that has a weird ending, we need to convert it to pixels
242 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
243 // Remember the original values
245 rsLeft = elem.runtimeStyle.left;
247 // Put in the new values to get a computed value out
248 elem.runtimeStyle.left = elem.currentStyle.left;
249 style.left = name === "fontSize" ? "1em" : (ret || 0);
250 ret = style.pixelLeft + "px";
252 // Revert the changed values
254 elem.runtimeStyle.left = rsLeft;
261 function getWH( elem, name, extra ) {
262 var which = name === "width" ? cssWidth : cssHeight,
263 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
265 if ( extra === "border" ) {
269 jQuery.each( which, function() {
271 val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
274 if ( extra === "margin" ) {
275 val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
278 val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
285 if ( jQuery.expr && jQuery.expr.filters ) {
286 jQuery.expr.filters.hidden = function( elem ) {
287 var width = elem.offsetWidth, height = elem.offsetHeight,
288 skip = elem.nodeName.toLowerCase() === "tr";
290 return width === 0 && height === 0 && !skip ?
292 width > 0 && height > 0 && !skip ?
294 (elem.style.display || jQuery.css( elem, "display" )) === "none";
297 jQuery.expr.filters.visible = function( elem ) {
298 return !jQuery.expr.filters.hidden( elem );