2009-03-22 23:25:03 +00:00
|
|
|
// exclude the following css properties to add px
|
2009-07-19 16:13:45 +00:00
|
|
|
var rexclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
|
|
|
|
ralpha = /alpha\([^)]*\)/,
|
|
|
|
ropacity = /opacity=([^)]*)/,
|
|
|
|
rfloat = /float/i,
|
|
|
|
rdashAlpha = /-([a-z])/ig,
|
|
|
|
rupper = /([A-Z])/g,
|
2009-12-05 20:12:02 +00:00
|
|
|
rnumpx = /^-?\d+(?:px)?$/i,
|
|
|
|
rnum = /^-?\d/,
|
2009-07-19 16:13:45 +00:00
|
|
|
|
2009-12-22 00:58:13 +00:00
|
|
|
cssShow = { position: "absolute", visibility: "hidden", display:"block" },
|
|
|
|
cssWidth = [ "Left", "Right" ],
|
|
|
|
cssHeight = [ "Top", "Bottom" ],
|
|
|
|
|
2009-04-22 04:39:44 +00:00
|
|
|
// cache check for defaultView.getComputedStyle
|
|
|
|
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
|
2009-03-22 23:25:03 +00:00
|
|
|
// normalize float css property
|
2009-07-19 15:57:43 +00:00
|
|
|
styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat",
|
2009-12-22 00:58:13 +00:00
|
|
|
fcamelCase = function( all, letter ) {
|
2009-07-19 15:57:43 +00:00
|
|
|
return letter.toUpperCase();
|
|
|
|
};
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
jQuery.fn.css = function( name, value ) {
|
2009-09-09 21:14:28 +00:00
|
|
|
return access( this, name, value, true, function( elem, name, value ) {
|
2009-12-10 04:51:58 +00:00
|
|
|
if ( value === undefined ) {
|
|
|
|
return jQuery.curCSS( elem, name );
|
2009-03-22 23:25:03 +00:00
|
|
|
}
|
2009-09-09 21:14:28 +00:00
|
|
|
|
|
|
|
if ( typeof value === "number" && !rexclude.test(name) ) {
|
|
|
|
value += "px";
|
2009-03-22 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
2009-09-09 21:14:28 +00:00
|
|
|
jQuery.style( elem, name, value );
|
|
|
|
});
|
2009-03-22 23:25:03 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.extend({
|
|
|
|
style: function( elem, name, value ) {
|
|
|
|
// don't set styles on text and comment nodes
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
return undefined;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-04-22 05:23:53 +00:00
|
|
|
// ignore negative width and height values #1599
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( (name === "width" || name === "height") && parseFloat(value) < 0 ) {
|
2009-04-22 05:23:53 +00:00
|
|
|
value = undefined;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-04-22 05:23:53 +00:00
|
|
|
|
2009-03-22 23:25:03 +00:00
|
|
|
var style = elem.style || elem, set = value !== undefined;
|
|
|
|
|
|
|
|
// IE uses filters for opacity
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( !jQuery.support.opacity && name === "opacity" ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
if ( set ) {
|
|
|
|
// IE has trouble with opacity if it does not have layout
|
|
|
|
// Force it by setting the zoom level
|
|
|
|
style.zoom = 1;
|
|
|
|
|
|
|
|
// Set the alpha filter to set the opacity
|
2009-12-01 19:40:28 +00:00
|
|
|
var opacity = parseInt( value, 10 ) + '' === "NaN" ? "" : "alpha(opacity=" + value * 100 + ")";
|
2009-12-05 02:18:37 +00:00
|
|
|
var filter = style.filter || jQuery.curCSS( elem, 'filter' ) || "";
|
2009-12-01 19:40:28 +00:00
|
|
|
style.filter = ralpha.test(filter) ? filter.replace(ralpha, opacity) : opacity;
|
2009-03-22 23:25:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return style.filter && style.filter.indexOf("opacity=") >= 0 ?
|
2009-07-19 16:13:45 +00:00
|
|
|
(parseFloat( ropacity.exec(style.filter)[1] ) / 100) + '':
|
2009-03-22 23:25:03 +00:00
|
|
|
"";
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we're using the right name for getting the float value
|
2009-07-19 16:13:45 +00:00
|
|
|
if ( rfloat.test( name ) ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
name = styleFloat;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-07-19 16:13:45 +00:00
|
|
|
name = name.replace(rdashAlpha, fcamelCase);
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( set ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
style[ name ] = value;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
return style[ name ];
|
|
|
|
},
|
|
|
|
|
|
|
|
css: function( elem, name, force, extra ) {
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( name === "width" || name === "height" ) {
|
2009-12-22 00:58:13 +00:00
|
|
|
var val, props = cssShow, which = name === "width" ? cssWidth : cssHeight;
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
function getWH() {
|
2009-07-19 16:08:17 +00:00
|
|
|
val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-12-22 00:58:13 +00:00
|
|
|
if ( extra === "border" ) {
|
|
|
|
return;
|
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
jQuery.each( which, function() {
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( !extra ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( extra === "margin" ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
|
2009-07-19 16:08:17 +00:00
|
|
|
} else {
|
2009-03-22 23:25:03 +00:00
|
|
|
val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( elem.offsetWidth !== 0 ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
getWH();
|
2009-07-19 16:08:17 +00:00
|
|
|
} else {
|
2009-03-22 23:25:03 +00:00
|
|
|
jQuery.swap( elem, props, getWH );
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
return Math.max(0, Math.round(val));
|
|
|
|
}
|
|
|
|
|
|
|
|
return jQuery.curCSS( elem, name, force );
|
|
|
|
},
|
|
|
|
|
|
|
|
curCSS: function( elem, name, force ) {
|
2009-05-14 14:44:31 +00:00
|
|
|
var ret, style = elem.style, filter;
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
// IE uses filters for opacity
|
2009-05-14 18:46:58 +00:00
|
|
|
if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) {
|
2009-07-19 16:13:45 +00:00
|
|
|
ret = ropacity.test(elem.currentStyle.filter || "") ?
|
2009-05-14 18:46:58 +00:00
|
|
|
(parseFloat(RegExp.$1) / 100) + "" :
|
2009-03-22 23:25:03 +00:00
|
|
|
"";
|
|
|
|
|
|
|
|
return ret === "" ?
|
|
|
|
"1" :
|
|
|
|
ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Make sure we're using the right name for getting the float value
|
2009-07-19 16:13:45 +00:00
|
|
|
if ( rfloat.test( name ) ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
name = styleFloat;
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
if ( !force && style && style[ name ] ) {
|
|
|
|
ret = style[ name ];
|
|
|
|
|
2009-04-22 04:39:44 +00:00
|
|
|
} else if ( getComputedStyle ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
// Only "float" is needed here
|
2009-07-19 16:13:45 +00:00
|
|
|
if ( rfloat.test( name ) ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
name = "float";
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-07-19 16:13:45 +00:00
|
|
|
name = name.replace( rupper, "-$1" ).toLowerCase();
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-12-10 04:58:49 +00:00
|
|
|
var defaultView = elem.ownerDocument.defaultView;
|
|
|
|
|
|
|
|
if ( !defaultView ) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
var computedStyle = defaultView.getComputedStyle( elem, null );
|
2009-03-22 23:25:03 +00:00
|
|
|
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( computedStyle ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
ret = computedStyle.getPropertyValue( name );
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
// We should always get a number back from opacity
|
2009-07-19 16:08:17 +00:00
|
|
|
if ( name === "opacity" && ret === "" ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
ret = "1";
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
} else if ( elem.currentStyle ) {
|
2009-07-19 16:13:45 +00:00
|
|
|
var camelCase = name.replace(rdashAlpha, fcamelCase);
|
2009-03-22 23:25:03 +00:00
|
|
|
|
|
|
|
ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
|
|
|
|
|
|
|
|
// From the awesome hack by Dean Edwards
|
|
|
|
// http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
|
|
|
|
|
|
|
|
// If we're not dealing with a regular pixel number
|
|
|
|
// but a number that has a weird ending, we need to convert it to pixels
|
2009-07-19 16:13:45 +00:00
|
|
|
if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
// Remember the original values
|
|
|
|
var left = style.left, rsLeft = elem.runtimeStyle.left;
|
|
|
|
|
|
|
|
// Put in the new values to get a computed value out
|
|
|
|
elem.runtimeStyle.left = elem.currentStyle.left;
|
2009-11-11 19:17:16 +00:00
|
|
|
style.left = camelCase === "fontSize" ? "1em" : (ret || 0);
|
2009-03-22 23:25:03 +00:00
|
|
|
ret = style.pixelLeft + "px";
|
|
|
|
|
|
|
|
// Revert the changed values
|
|
|
|
style.left = left;
|
|
|
|
elem.runtimeStyle.left = rsLeft;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return ret;
|
|
|
|
},
|
|
|
|
|
|
|
|
// A method for quickly swapping in/out CSS properties to get correct calculations
|
|
|
|
swap: function( elem, options, callback ) {
|
|
|
|
var old = {};
|
2009-07-19 16:08:17 +00:00
|
|
|
|
2009-03-22 23:25:03 +00:00
|
|
|
// Remember the old values, and insert the new ones
|
|
|
|
for ( var name in options ) {
|
|
|
|
old[ name ] = elem.style[ name ];
|
|
|
|
elem.style[ name ] = options[ name ];
|
|
|
|
}
|
|
|
|
|
|
|
|
callback.call( elem );
|
|
|
|
|
|
|
|
// Revert the old values
|
2009-07-19 16:08:17 +00:00
|
|
|
for ( var name in options ) {
|
2009-03-22 23:25:03 +00:00
|
|
|
elem.style[ name ] = old[ name ];
|
2009-07-19 16:08:17 +00:00
|
|
|
}
|
2009-03-22 23:25:03 +00:00
|
|
|
}
|
2009-07-19 13:21:51 +00:00
|
|
|
});
|
2009-10-26 22:07:57 +00:00
|
|
|
|
|
|
|
if ( jQuery.expr && jQuery.expr.filters ) {
|
2009-12-05 20:02:45 +00:00
|
|
|
jQuery.expr.filters.hidden = function( elem ) {
|
2009-10-26 22:07:57 +00:00
|
|
|
var width = elem.offsetWidth, height = elem.offsetHeight,
|
2009-12-05 20:02:45 +00:00
|
|
|
skip = elem.nodeName.toLowerCase() === "tr";
|
2009-12-03 16:59:59 +00:00
|
|
|
|
2009-12-05 20:02:45 +00:00
|
|
|
return width === 0 && height === 0 && !skip ?
|
2009-10-26 22:07:57 +00:00
|
|
|
true :
|
2009-12-05 20:02:45 +00:00
|
|
|
width > 0 && height > 0 && !skip ?
|
|
|
|
false :
|
|
|
|
jQuery.curCSS(elem, "display") === "none";
|
2009-10-26 22:07:57 +00:00
|
|
|
};
|
|
|
|
|
2009-12-05 20:02:45 +00:00
|
|
|
jQuery.expr.filters.visible = function( elem ) {
|
|
|
|
return !jQuery.expr.filters.hidden( elem );
|
2009-10-26 22:07:57 +00:00
|
|
|
};
|
2009-11-11 19:17:16 +00:00
|
|
|
}
|