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 );
31 get: function( elem ) {
32 // We should always get a number back from opacity
33 var ret = curCSS( elem, "opacity", "opacity" );
34 return ret === "" ? "1" : ret;
39 // exclude the following css properties to add px
49 // normalize float css property
50 "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
53 css: function( elem, name, value, force, extra ) {
54 // don't set styles on text and comment nodes
55 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
59 var ret, origName = name.replace( rdashAlpha, fcamelCase ),
60 style = elem.style || {}, hooks = jQuery.cssHooks[ origName ] || {};
62 name = jQuery.cssProps[ origName ] || origName;
64 if ( value !== undefined ) {
65 if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
69 if ( !("set" in hooks) || (value = hooks.set( elem, value )) === undefined ) {
70 style[ name ] = value;
74 if ( "get" in hooks && (ret = hooks.get( elem, force, extra )) !== undefined ) {
78 if ( !force && style && style[ name ] ) {
81 } else if ( curCSS ) {
82 ret = curCSS( elem, name, origName );
89 // A method for quickly swapping in/out CSS properties to get correct calculations
90 swap: function( elem, options, callback ) {
93 // Remember the old values, and insert the new ones
94 for ( var name in options ) {
95 old[ name ] = elem.style[ name ];
96 elem.style[ name ] = options[ name ];
99 callback.call( elem );
101 // Revert the old values
102 for ( name in options ) {
103 elem.style[ name ] = old[ name ];
108 jQuery.each(["height", "width"], function( i, name ) {
109 jQuery.cssHooks[ name ] = {
110 get: function( elem, force, extra ) {
113 if ( elem.offsetWidth !== 0 ) {
114 val = getWH( elem, name, extra );
117 jQuery.swap( elem, cssShow, function() {
118 val = getWH( elem, name, extra );
125 set: function( elem, value ) {
126 // ignore negative width and height values #1599
127 return Math.max( parseFloat(value), 0 ) + "px";
132 if ( !jQuery.support.opacity ) {
133 jQuery.cssHooks.opacity = {
134 get: function( elem, force ) {
135 // IE uses filters for opacity
136 return ropacity.test(elem.currentStyle.filter || "") ?
137 (parseFloat(RegExp.$1) / 100) + "" :
141 set: function( elem, value ) {
142 var style = elem.style;
144 // IE has trouble with opacity if it does not have layout
145 // Force it by setting the zoom level
148 // Set the alpha filter to set the opacity
149 var opacity = parseInt( value, 10 ) + "" === "NaN" ?
151 "alpha(opacity=" + value * 100 + ")";
153 var filter = style.filter || jQuery.css( elem, "filter" ) || "";
155 style.filter = ralpha.test(filter) ?
156 filter.replace(ralpha, opacity) :
162 if ( getComputedStyle ) {
163 curCSS = function( elem, newName, name ) {
164 var ret, defaultView, computedStyle;
166 name = name.replace( rupper, "-$1" ).toLowerCase();
168 if ( !(defaultView = elem.ownerDocument.defaultView) ) {
172 if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
173 ret = computedStyle.getPropertyValue( name );
179 } else if ( document.documentElement.currentStyle ) {
180 curCSS = function( elem, name ) {
181 var left, rsLeft, ret = elem.currentStyle[ name ], style = elem.style;
183 // From the awesome hack by Dean Edwards
184 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
186 // If we're not dealing with a regular pixel number
187 // but a number that has a weird ending, we need to convert it to pixels
188 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
189 // Remember the original values
191 rsLeft = elem.runtimeStyle.left;
193 // Put in the new values to get a computed value out
194 elem.runtimeStyle.left = elem.currentStyle.left;
195 style.left = name === "fontSize" ? "1em" : (ret || 0);
196 ret = style.pixelLeft + "px";
198 // Revert the changed values
200 elem.runtimeStyle.left = rsLeft;
207 function getWH( elem, name, extra ) {
208 var which = name === "width" ? cssWidth : cssHeight,
209 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
211 if ( extra === "border" ) {
215 jQuery.each( which, function() {
217 val -= parseFloat(jQuery.css( elem, "padding" + this, undefined, true)) || 0;
220 if ( extra === "margin" ) {
221 val += parseFloat(jQuery.css( elem, "margin" + this, undefined, true)) || 0;
224 val -= parseFloat(jQuery.css( elem, "border" + this + "Width", undefined, true)) || 0;
231 if ( jQuery.expr && jQuery.expr.filters ) {
232 jQuery.expr.filters.hidden = function( elem ) {
233 var width = elem.offsetWidth, height = elem.offsetHeight,
234 skip = elem.nodeName.toLowerCase() === "tr";
236 return width === 0 && height === 0 && !skip ?
238 width > 0 && height > 0 && !skip ?
240 jQuery.css(elem, "display") === "none";
243 jQuery.expr.filters.visible = function( elem ) {
244 return !jQuery.expr.filters.hidden( elem );