1 // exclude the following css properties to add px
2 var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
3 ralpha = /alpha\([^)]*\)/,
4 ropacity = /opacity=([^)]*)/,
6 rdashAlpha = /-([a-z])/ig,
8 rnumpx = /^\d+(?:px)?$/i,
11 // cache check for defaultView.getComputedStyle
12 getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
13 // normalize float css property
14 styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat",
15 fcamelCase = function(all, letter){
16 return letter.toUpperCase();
19 jQuery.fn.css = function( name, value ) {
20 return access( this, name, value, true, function( elem, name, value ) {
21 if (value === undefined) {
22 return jQuery.css( elem, name );
25 if ( typeof value === "number" && !rexclude.test(name) ) {
29 jQuery.style( elem, name, value );
34 style: function( elem, name, value ) {
35 // don't set styles on text and comment nodes
36 if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
40 // ignore negative width and height values #1599
41 if ( (name === "width" || name === "height") && parseFloat(value) < 0 ) {
45 var style = elem.style || elem, set = value !== undefined;
47 // IE uses filters for opacity
48 if ( !jQuery.support.opacity && name === "opacity" ) {
50 // IE has trouble with opacity if it does not have layout
51 // Force it by setting the zoom level
54 // Set the alpha filter to set the opacity
55 style.filter = (style.filter || "").replace( ralpha, "" ) +
56 (parseInt( value ) + '' === "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
59 return style.filter && style.filter.indexOf("opacity=") >= 0 ?
60 (parseFloat( ropacity.exec(style.filter)[1] ) / 100) + '':
64 // Make sure we're using the right name for getting the float value
65 if ( rfloat.test( name ) ) {
69 name = name.replace(rdashAlpha, fcamelCase);
72 style[ name ] = value;
78 css: function( elem, name, force, extra ) {
79 if ( name === "width" || name === "height" ) {
80 var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name === "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
83 val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
85 if ( extra === "border" ) { return; }
87 jQuery.each( which, function() {
89 val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
92 if ( extra === "margin" ) {
93 val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
95 val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
100 if ( elem.offsetWidth !== 0 ) {
103 jQuery.swap( elem, props, getWH );
106 return Math.max(0, Math.round(val));
109 return jQuery.curCSS( elem, name, force );
112 curCSS: function( elem, name, force ) {
113 var ret, style = elem.style, filter;
115 // IE uses filters for opacity
116 if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) {
117 ret = ropacity.test(elem.currentStyle.filter || "") ?
118 (parseFloat(RegExp.$1) / 100) + "" :
126 // Make sure we're using the right name for getting the float value
127 if ( rfloat.test( name ) ) {
131 if ( !force && style && style[ name ] ) {
134 } else if ( getComputedStyle ) {
136 // Only "float" is needed here
137 if ( rfloat.test( name ) ) {
141 name = name.replace( rupper, "-$1" ).toLowerCase();
143 var computedStyle = elem.ownerDocument.defaultView.getComputedStyle( elem, null );
145 if ( computedStyle ) {
146 ret = computedStyle.getPropertyValue( name );
149 // We should always get a number back from opacity
150 if ( name === "opacity" && ret === "" ) {
154 } else if ( elem.currentStyle ) {
155 var camelCase = name.replace(rdashAlpha, fcamelCase);
157 ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
159 // From the awesome hack by Dean Edwards
160 // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
162 // If we're not dealing with a regular pixel number
163 // but a number that has a weird ending, we need to convert it to pixels
164 if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
165 // Remember the original values
166 var left = style.left, rsLeft = elem.runtimeStyle.left;
168 // Put in the new values to get a computed value out
169 elem.runtimeStyle.left = elem.currentStyle.left;
170 style.left = camelCase === "fontSize" ? "1em" : (ret || 0);
171 ret = style.pixelLeft + "px";
173 // Revert the changed values
175 elem.runtimeStyle.left = rsLeft;
182 // A method for quickly swapping in/out CSS properties to get correct calculations
183 swap: function( elem, options, callback ) {
186 // Remember the old values, and insert the new ones
187 for ( var name in options ) {
188 old[ name ] = elem.style[ name ];
189 elem.style[ name ] = options[ name ];
192 callback.call( elem );
194 // Revert the old values
195 for ( var name in options ) {
196 elem.style[ name ] = old[ name ];
201 if ( jQuery.expr && jQuery.expr.filters ) {
202 jQuery.expr.filters.hidden = function(elem){
203 var width = elem.offsetWidth, height = elem.offsetHeight,
204 force = /^tr$/i.test( elem.nodeName ); // ticket #4512
205 return ( width === 0 && height === 0 && !force ) ?
207 ( width !== 0 && height !== 0 && !force ) ?
209 !!( jQuery.curCSS(elem, "display") === "none" );
212 jQuery.expr.filters.visible = function(elem){
213 return !jQuery.expr.filters.hidden(elem);