-// exclude the following css properties to add px
-var exclude = /z-?index|font-?weight|opacity|zoom|line-?height/i,
+(function( jQuery ) {
+
+var ralpha = /alpha\([^)]*\)/,
+ ropacity = /opacity=([^)]*)/,
+ rdashAlpha = /-([a-z])/ig,
+ rupper = /([A-Z])/g,
+ rnumpx = /^-?\d+(?:px)?$/i,
+ rnum = /^-?\d/,
+
+ cssShow = { position: "absolute", visibility: "hidden", display: "block" },
+ cssWidth = [ "Left", "Right" ],
+ cssHeight = [ "Top", "Bottom" ],
+ curCSS,
+
// cache check for defaultView.getComputedStyle
getComputedStyle = document.defaultView && document.defaultView.getComputedStyle,
- // normalize float css property
- styleFloat = jQuery.support.cssFloat ? "cssFloat" : "styleFloat",
- fcamelCase = function(all, letter){
+
+ fcamelCase = function( all, letter ) {
return letter.toUpperCase();
};
jQuery.fn.css = function( name, value ) {
- var options = name, isFunction = jQuery.isFunction( value );
-
- if ( typeof name === "string" ) {
- // Are we setting the style?
- if ( value === undefined ) {
- return this.length ?
- jQuery.css( this[0], name ) :
- null;
+ return jQuery.access( this, name, value, true, function( elem, name, value ) {
+ return jQuery.css( elem, name, value );
+ });
+};
- // Convert name, value params to options hash format
- } else {
- options = {};
- options[ name ] = value;
- }
- }
-
- var isFunction = {};
-
- // For each value, determine whether it's a Function so we don't
- // need to determine it again for each element
- for ( var prop in options )
- isFunction[prop] = jQuery.isFunction( options[prop] );
-
- // For each element...
- for ( var i = 0, l = this.length; i < l; i++ ) {
- var elem = this[i];
-
- // Set all the styles
- for ( var prop in options ) {
- value = options[prop];
-
- if ( isFunction[prop] ) value = value.call( elem, i );
-
- if ( typeof value === "number" && !exclude.test(prop) ) {
- value = value + "px";
+jQuery.extend({
+ cssHooks: {
+ opacity: {
+ get: function( elem ) {
+ // We should always get a number back from opacity
+ var ret = curCSS( elem, "opacity", "opacity" );
+ return ret === "" ? "1" : ret;
}
-
- jQuery.style( elem, prop, value );
}
- }
+ },
- return this;
-};
+ // exclude the following css properties to add px
+ cssNumber: {
+ "zIndex": true,
+ "fontWeight": true,
+ "opacity": true,
+ "zoom": true,
+ "lineHeight": true
+ },
-jQuery.extend({
- style: function( elem, name, value ) {
+ cssProps: {
+ // normalize float css property
+ "float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
+ },
+
+ css: function( elem, name, value, force, extra ) {
// don't set styles on text and comment nodes
- if (!elem || elem.nodeType == 3 || elem.nodeType == 8)
+ if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 ) {
return undefined;
+ }
- // ignore negative width and height values #1599
- if ( (name == 'width' || name == 'height') && parseFloat(value) < 0 )
- value = undefined;
-
- var style = elem.style || elem, set = value !== undefined;
+ var ret, origName = name.replace( rdashAlpha, fcamelCase ),
+ style = elem.style || {}, hooks = jQuery.cssHooks[ origName ] || {};
- // IE uses filters for opacity
- if ( !jQuery.support.opacity && name == "opacity" ) {
- if ( set ) {
- // IE has trouble with opacity if it does not have layout
- // Force it by setting the zoom level
- style.zoom = 1;
+ name = jQuery.cssProps[ origName ] || origName;
- // Set the alpha filter to set the opacity
- style.filter = (style.filter || "").replace( /alpha\([^)]*\)/, "" ) +
- (parseInt( value ) + '' == "NaN" ? "" : "alpha(opacity=" + value * 100 + ")");
+ if ( value !== undefined ) {
+ if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
+ value += "px";
}
- return style.filter && style.filter.indexOf("opacity=") >= 0 ?
- (parseFloat( /opacity=([^)]*)/.exec(style.filter)[1] ) / 100) + '':
- "";
- }
+ if ( !("set" in hooks) || (value = hooks.set( elem, value )) === undefined ) {
+ style[ name ] = value;
+ }
- // Make sure we're using the right name for getting the float value
- if ( /float/i.test( name ) )
- name = styleFloat;
+ } else {
+ if ( "get" in hooks && (ret = hooks.get( elem, force, extra )) !== undefined ) {
+ return ret;
+ }
- name = name.replace(/-([a-z])/ig, fcamelCase);
+ if ( !force && style && style[ name ] ) {
+ ret = style[ name ];
- if ( set )
- style[ name ] = value;
+ } else if ( curCSS ) {
+ ret = curCSS( elem, name, origName );
+ }
- return style[ name ];
+ return ret;
+ }
},
- css: function( elem, name, force, extra ) {
- if ( name == "width" || name == "height" ) {
- var val, props = { position: "absolute", visibility: "hidden", display:"block" }, which = name == "width" ? [ "Left", "Right" ] : [ "Top", "Bottom" ];
+ // A method for quickly swapping in/out CSS properties to get correct calculations
+ swap: function( elem, options, callback ) {
+ var old = {};
+
+ // Remember the old values, and insert the new ones
+ for ( var name in options ) {
+ old[ name ] = elem.style[ name ];
+ elem.style[ name ] = options[ name ];
+ }
- function getWH() {
- val = name == "width" ? elem.offsetWidth : elem.offsetHeight;
+ callback.call( elem );
- if ( extra === "border" )
- return;
+ // Revert the old values
+ for ( name in options ) {
+ elem.style[ name ] = old[ name ];
+ }
+ }
+});
- jQuery.each( which, function() {
- if ( !extra )
- val -= parseFloat(jQuery.curCSS( elem, "padding" + this, true)) || 0;
- if ( extra === "margin" )
- val += parseFloat(jQuery.curCSS( elem, "margin" + this, true)) || 0;
- else
- val -= parseFloat(jQuery.curCSS( elem, "border" + this + "Width", true)) || 0;
+jQuery.each(["height", "width"], function( i, name ) {
+ jQuery.cssHooks[ name ] = {
+ get: function( elem, force, extra ) {
+ var val;
+
+ if ( elem.offsetWidth !== 0 ) {
+ val = getWH( elem, name, extra );
+
+ } else {
+ jQuery.swap( elem, cssShow, function() {
+ val = getWH( elem, name, extra );
});
}
- if ( elem.offsetWidth !== 0 )
- getWH();
- else
- jQuery.swap( elem, props, getWH );
+ return val + "px";
+ },
- return Math.max(0, Math.round(val));
+ set: function( elem, value ) {
+ // ignore negative width and height values #1599
+ return Math.max( parseFloat(value), 0 ) + "px";
}
+ };
+});
- return jQuery.curCSS( elem, name, force );
- },
+if ( !jQuery.support.opacity ) {
+ jQuery.cssHooks.opacity = {
+ get: function( elem, force ) {
+ // IE uses filters for opacity
+ return ropacity.test(elem.currentStyle.filter || "") ?
+ (parseFloat(RegExp.$1) / 100) + "" :
+ "1";
+ },
- curCSS: function( elem, name, force ) {
- var ret, style = elem.style, filter;
+ set: function( elem, value ) {
+ var style = elem.style;
- // IE uses filters for opacity
- if ( !jQuery.support.opacity && name === "opacity" && elem.currentStyle ) {
- ret = /opacity=([^)]*)/.test(elem.currentStyle.filter || "") ?
- (parseFloat(RegExp.$1) / 100) + "" :
- "";
+ // 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
+ var opacity = parseInt( value, 10 ) + "" === "NaN" ?
+ "" :
+ "alpha(opacity=" + value * 100 + ")";
- return ret === "" ?
- "1" :
- ret;
+ var filter = style.filter || jQuery.css( elem, "filter" ) || "";
+
+ style.filter = ralpha.test(filter) ?
+ filter.replace(ralpha, opacity) :
+ opacity;
}
+ };
+}
- // Make sure we're using the right name for getting the float value
- if ( /float/i.test( name ) )
- name = styleFloat;
+if ( getComputedStyle ) {
+ curCSS = function( elem, newName, name ) {
+ var ret, defaultView, computedStyle;
- if ( !force && style && style[ name ] ) {
- ret = style[ name ];
+ name = name.replace( rupper, "-$1" ).toLowerCase();
- } else if ( getComputedStyle ) {
+ if ( !(defaultView = elem.ownerDocument.defaultView) ) {
+ return undefined;
+ }
- // Only "float" is needed here
- if ( /float/i.test( name ) )
- name = "float";
+ if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
+ ret = computedStyle.getPropertyValue( name );
+ }
- name = name.replace( /([A-Z])/g, "-$1" ).toLowerCase();
+ return ret;
+ };
- var computedStyle = elem.ownerDocument.defaultView.getComputedStyle( elem, null );
+} else if ( document.documentElement.currentStyle ) {
+ curCSS = function( elem, name ) {
+ var left, rsLeft, ret = elem.currentStyle[ name ], style = elem.style;
- if ( computedStyle )
- ret = computedStyle.getPropertyValue( name );
+ // From the awesome hack by Dean Edwards
+ // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
- // We should always get a number back from opacity
- if ( name == "opacity" && ret == "" )
- ret = "1";
+ // 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
+ if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
+ // Remember the original values
+ left = style.left;
+ rsLeft = elem.runtimeStyle.left;
- } else if ( elem.currentStyle ) {
- var camelCase = name.replace(/\-(\w)/g, fcamelCase);
+ // Put in the new values to get a computed value out
+ elem.runtimeStyle.left = elem.currentStyle.left;
+ style.left = name === "fontSize" ? "1em" : (ret || 0);
+ ret = style.pixelLeft + "px";
- ret = elem.currentStyle[ name ] || elem.currentStyle[ camelCase ];
+ // Revert the changed values
+ style.left = left;
+ elem.runtimeStyle.left = rsLeft;
+ }
- // From the awesome hack by Dean Edwards
- // http://erik.eae.net/archives/2007/07/27/18.54.15/#comment-102291
+ return ret;
+ };
+}
- // 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
- if ( !/^\d+(px)?$/i.test( ret ) && /^\d/.test( ret ) ) {
- // Remember the original values
- var left = style.left, rsLeft = elem.runtimeStyle.left;
+function getWH( elem, name, extra ) {
+ var which = name === "width" ? cssWidth : cssHeight,
+ val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
- // Put in the new values to get a computed value out
- elem.runtimeStyle.left = elem.currentStyle.left;
- style.left = ret || 0;
- ret = style.pixelLeft + "px";
+ if ( extra === "border" ) {
+ return val;
+ }
- // Revert the changed values
- style.left = left;
- elem.runtimeStyle.left = rsLeft;
- }
+ jQuery.each( which, function() {
+ if ( !extra ) {
+ val -= parseFloat(jQuery.css( elem, "padding" + this, undefined, true)) || 0;
}
- return ret;
- },
+ if ( extra === "margin" ) {
+ val += parseFloat(jQuery.css( elem, "margin" + this, undefined, true)) || 0;
- // A method for quickly swapping in/out CSS properties to get correct calculations
- swap: function( elem, options, callback ) {
- var old = {};
- // Remember the old values, and insert the new ones
- for ( var name in options ) {
- old[ name ] = elem.style[ name ];
- elem.style[ name ] = options[ name ];
+ } else {
+ val -= parseFloat(jQuery.css( elem, "border" + this + "Width", undefined, true)) || 0;
}
+ });
- callback.call( elem );
+ return val;
+}
- // Revert the old values
- for ( var name in options )
- elem.style[ name ] = old[ name ];
- }
-});
+if ( jQuery.expr && jQuery.expr.filters ) {
+ jQuery.expr.filters.hidden = function( elem ) {
+ var width = elem.offsetWidth, height = elem.offsetHeight,
+ skip = elem.nodeName.toLowerCase() === "tr";
+
+ return width === 0 && height === 0 && !skip ?
+ true :
+ width > 0 && height > 0 && !skip ?
+ false :
+ jQuery.css(elem, "display") === "none";
+ };
+
+ jQuery.expr.filters.visible = function( elem ) {
+ return !jQuery.expr.filters.hidden( elem );
+ };
+}
+
+})( jQuery );