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, computed ) {
37 // We should always get a number back from opacity
38 var ret = curCSS( elem, "opacity", "opacity" );
39 return ret === "" ? "1" : ret;
42 return elem.style.opacity;
48 // Exclude the following css properties to add px
57 // Add in properties whose names you wish to fix before
58 // setting or getting the value
60 // normalize float css property
61 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
64 // Get and set the style property on a DOM Node
65 style: function( elem, name, value, extra ) {
66 // Don't set styles on text and comment nodes
67 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
71 // Make sure that we're working with the right name
72 var ret, origName = jQuery.camelCase( name ),
73 style = elem.style, hooks = jQuery.cssHooks[ origName ];
75 name = jQuery.cssProps[ origName ] || origName;
77 // Check if we're setting a value
78 if ( value !== undefined ) {
79 // If a number was passed in, add 'px' to the (except for certain CSS properties)
80 if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
84 // If a hook was provided, use that value, otherwise just set the specified value
85 if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
86 style[ name ] = value;
90 // If a hook was provided get the non-computed value from there
91 if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
95 // Otherwise just get the value from the style object
100 css: function( elem, name, extra ) {
101 // Make sure that we're working with the right name
102 var ret, origName = jQuery.camelCase( name ),
103 hooks = jQuery.cssHooks[ origName ];
105 name = jQuery.cssProps[ origName ] || origName;
107 // If a hook was provided get the computed value from there
108 if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
111 // Otherwise, if a way to get the computed value exists, use that
112 } else if ( curCSS ) {
113 return curCSS( elem, name, origName );
117 // A method for quickly swapping in/out CSS properties to get correct calculations
118 swap: function( elem, options, callback ) {
121 // Remember the old values, and insert the new ones
122 for ( var name in options ) {
123 old[ name ] = elem.style[ name ];
124 elem.style[ name ] = options[ name ];
127 callback.call( elem );
129 // Revert the old values
130 for ( name in options ) {
131 elem.style[ name ] = old[ name ];
135 camelCase: function( string ) {
136 return string.replace( rdashAlpha, fcamelCase );
140 // DEPRECATED, Use jQuery.css() instead
141 jQuery.curCSS = jQuery.css;
143 jQuery.each(["height", "width"], function( i, name ) {
144 jQuery.cssHooks[ name ] = {
145 get: function( elem, computed, extra ) {
149 if ( elem.offsetWidth !== 0 ) {
150 val = getWH( elem, name, extra );
153 jQuery.swap( elem, cssShow, function() {
154 val = getWH( elem, name, extra );
162 set: function( elem, value ) {
163 if ( rnumpx.test( value ) ) {
164 // ignore negative width and height values #1599
165 value = parseFloat(value);
178 if ( !jQuery.support.opacity ) {
179 jQuery.cssHooks.opacity = {
180 get: function( elem, computed ) {
181 // IE uses filters for opacity
182 return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
183 (parseFloat(RegExp.$1) / 100) + "" :
187 set: function( elem, value ) {
188 var style = elem.style;
190 // IE has trouble with opacity if it does not have layout
191 // Force it by setting the zoom level
194 // Set the alpha filter to set the opacity
195 var opacity = jQuery.isNaN(value) ?
197 "alpha(opacity=" + value * 100 + ")",
198 filter = style.filter || "";
200 style.filter = ralpha.test(filter) ?
201 filter.replace(ralpha, opacity) :
207 if ( getComputedStyle ) {
208 curCSS = function( elem, newName, name ) {
209 var ret, defaultView, computedStyle;
211 name = name.replace( rupper, "-$1" ).toLowerCase();
213 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
217 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
218 ret = computedStyle.getPropertyValue( name );
224 } else if ( document.documentElement.currentStyle ) {
225 curCSS = function( elem, name ) {
226 var left, rsLeft, ret = elem.currentStyle && elem.currentStyle[ name ], style = elem.style;
228 // From the awesome hack by Dean Edwards
229 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
231 // If we're not dealing with a regular pixel number
232 // but a number that has a weird ending, we need to convert it to pixels
233 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
234 // Remember the original values
236 rsLeft = elem.runtimeStyle.left;
238 // Put in the new values to get a computed value out
239 elem.runtimeStyle.left = elem.currentStyle.left;
240 style.left = name === "fontSize" ? "1em" : (ret || 0);
241 ret = style.pixelLeft + "px";
243 // Revert the changed values
245 elem.runtimeStyle.left = rsLeft;
252 function getWH( elem, name, extra ) {
253 var which = name === "width" ? cssWidth : cssHeight,
254 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
256 if ( extra === "border" ) {
260 jQuery.each( which, function() {
262 val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
265 if ( extra === "margin" ) {
266 val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
269 val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
276 if ( jQuery.expr && jQuery.expr.filters ) {
277 jQuery.expr.filters.hidden = function( elem ) {
278 var width = elem.offsetWidth, height = elem.offsetHeight,
279 skip = elem.nodeName.toLowerCase() === "tr";
281 return width === 0 && height === 0 && !skip ?
283 width > 0 && height > 0 && !skip ?
285 (elem.style.display || jQuery.css( elem, "display" )) === "none";
288 jQuery.expr.filters.visible = function( elem ) {
289 return !jQuery.expr.filters.hidden( elem );