2010-09-08 18:00:29 +02:00
|
|
|
(function( jQuery ) {
|
|
|
|
|
2010-09-28 17:57:20 +02:00
|
|
|
var ralpha = /alpha\([^)]*\)/i,
|
2009-07-19 18:13:45 +02:00
|
|
|
ropacity = /opacity=([^)]*)/,
|
|
|
|
rdashAlpha = /-([a-z])/ig,
|
|
|
|
rupper = /([A-Z])/g,
|
2009-12-05 21:12:02 +01:00
|
|
|
rnumpx = /^-?\d+(?:px)?$/i,
|
|
|
|
rnum = /^-?\d/,
|
2009-07-19 18:13:45 +02:00
|
|
|
|
2010-09-05 17:01:27 +02:00
|
|
|
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
|
2009-12-22 01:58:13 +01:00
|
|
|
cssWidth = [ "Left", "Right" ],
|
|
|
|
cssHeight = [ "Top", "Bottom" ],
|
2010-09-05 06:04:37 +02:00
|
|
|
curCSS,
|
2009-12-22 01:58:13 +01:00
|
|
|
|
2010-11-03 20:39:28 +01:00
|
|
|
getComputedStyle,
|
|
|
|
currentStyle,
|
2010-09-05 17:01:27 +02:00
|
|
|
|
2009-12-22 01:58:13 +01:00
|
|
|
fcamelCase = function( all, letter ) {
|
2009-07-19 17:57:43 +02:00
|
|
|
return letter.toUpperCase();
|
|
|
|
};
|
2009-03-23 00:25:03 +01:00
|
|
|
|
|
|
|
jQuery.fn.css = function( name, value ) {
|
2010-09-28 17:53:09 +02:00
|
|
|
// Setting 'undefined' is a no-op
|
|
|
|
if ( arguments.length === 2 && value === undefined ) {
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
|
2010-03-23 17:12:16 +01:00
|
|
|
return jQuery.access( this, name, value, true, function( elem, name, value ) {
|
2010-09-17 20:41:28 +02:00
|
|
|
return value !== undefined ?
|
|
|
|
jQuery.style( elem, name, value ) :
|
|
|
|
jQuery.css( elem, name );
|
2009-09-09 23:14:28 +02:00
|
|
|
});
|
2009-03-23 00:25:03 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
jQuery.extend({
|
2010-09-16 16:00:56 +02:00
|
|
|
// Add in style property hooks for overriding the default
|
|
|
|
// behavior of getting and setting a style property
|
2010-09-05 17:01:27 +02:00
|
|
|
cssHooks: {
|
|
|
|
opacity: {
|
2010-09-27 17:51:01 +02:00
|
|
|
get: function( elem, computed ) {
|
|
|
|
if ( computed ) {
|
|
|
|
// We should always get a number back from opacity
|
|
|
|
var ret = curCSS( elem, "opacity", "opacity" );
|
|
|
|
return ret === "" ? "1" : ret;
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return elem.style.opacity;
|
|
|
|
}
|
2010-09-05 17:01:27 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// Exclude the following css properties to add px
|
2010-09-05 17:01:27 +02:00
|
|
|
cssNumber: {
|
|
|
|
"zIndex": true,
|
|
|
|
"fontWeight": true,
|
|
|
|
"opacity": true,
|
|
|
|
"zoom": true,
|
|
|
|
"lineHeight": true
|
|
|
|
},
|
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// Add in properties whose names you wish to fix before
|
|
|
|
// setting or getting the value
|
2010-09-05 17:01:27 +02:00
|
|
|
cssProps: {
|
|
|
|
// normalize float css property
|
|
|
|
"float": jQuery.support.cssFloat ? "cssFloat" : "styleFloat"
|
|
|
|
},
|
2010-09-03 04:06:40 +02:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// Get and set the style property on a DOM Node
|
|
|
|
style: function( elem, name, value, extra ) {
|
|
|
|
// Don't set styles on text and comment nodes
|
|
|
|
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
|
2010-10-09 16:52:53 +02:00
|
|
|
return;
|
2010-09-03 04:06:40 +02:00
|
|
|
}
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// Make sure that we're working with the right name
|
2010-09-17 20:53:10 +02:00
|
|
|
var ret, origName = jQuery.camelCase( name ),
|
2010-09-16 16:00:56 +02:00
|
|
|
style = elem.style, hooks = jQuery.cssHooks[ origName ];
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-05 17:01:27 +02:00
|
|
|
name = jQuery.cssProps[ origName ] || origName;
|
2010-09-03 04:06:40 +02:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// Check if we're setting a value
|
2010-09-05 16:17:18 +02:00
|
|
|
if ( value !== undefined ) {
|
2010-10-09 16:52:53 +02:00
|
|
|
// Make sure that NaN and null values aren't set. See: #7116
|
|
|
|
if ( typeof value === "number" && isNaN( value ) || value == null ) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// If a number was passed in, add 'px' to the (except for certain CSS properties)
|
2010-09-05 17:01:27 +02:00
|
|
|
if ( typeof value === "number" && !jQuery.cssNumber[ origName ] ) {
|
2010-09-05 16:17:18 +02:00
|
|
|
value += "px";
|
2010-09-03 04:06:40 +02:00
|
|
|
}
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// If a hook was provided, use that value, otherwise just set the specified value
|
|
|
|
if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value )) !== undefined ) {
|
2010-10-09 16:42:01 +02:00
|
|
|
// Wrapped to prevent IE from throwing errors when 'invalid' values are provided
|
|
|
|
// Fixes bug #5509
|
|
|
|
try {
|
|
|
|
style[ name ] = value;
|
|
|
|
} catch(e) {}
|
2009-07-19 18:08:17 +02:00
|
|
|
}
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-05 16:17:18 +02:00
|
|
|
} else {
|
2010-09-16 16:00:56 +02:00
|
|
|
// If a hook was provided get the non-computed value from there
|
|
|
|
if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) {
|
2010-09-05 16:17:18 +02:00
|
|
|
return ret;
|
2010-09-16 16:00:56 +02:00
|
|
|
}
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// Otherwise just get the value from the style object
|
|
|
|
return style[ name ];
|
|
|
|
}
|
|
|
|
},
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-17 20:41:28 +02:00
|
|
|
css: function( elem, name, extra ) {
|
2010-09-16 16:00:56 +02:00
|
|
|
// Make sure that we're working with the right name
|
2010-09-17 20:53:10 +02:00
|
|
|
var ret, origName = jQuery.camelCase( name ),
|
2010-09-16 16:00:56 +02:00
|
|
|
hooks = jQuery.cssHooks[ origName ];
|
|
|
|
|
|
|
|
name = jQuery.cssProps[ origName ] || origName;
|
2009-03-23 00:25:03 +01:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
// If a hook was provided get the computed value from there
|
2010-09-17 20:41:28 +02:00
|
|
|
if ( hooks && "get" in hooks && (ret = hooks.get( elem, true, extra )) !== undefined ) {
|
2010-09-03 04:06:40 +02:00
|
|
|
return ret;
|
2010-09-16 16:00:56 +02:00
|
|
|
|
|
|
|
// Otherwise, if a way to get the computed value exists, use that
|
|
|
|
} else if ( curCSS ) {
|
|
|
|
return curCSS( elem, name, origName );
|
2010-09-03 04:06:40 +02:00
|
|
|
}
|
2009-03-23 00:25:03 +01:00
|
|
|
},
|
|
|
|
|
|
|
|
// A method for quickly swapping in/out CSS properties to get correct calculations
|
|
|
|
swap: function( elem, options, callback ) {
|
|
|
|
var old = {};
|
2009-07-19 18:08:17 +02:00
|
|
|
|
2009-03-23 00:25:03 +01: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
|
2010-03-02 03:24:49 +01:00
|
|
|
for ( name in options ) {
|
2009-03-23 00:25:03 +01:00
|
|
|
elem.style[ name ] = old[ name ];
|
2009-07-19 18:08:17 +02:00
|
|
|
}
|
2010-09-17 20:53:10 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
camelCase: function( string ) {
|
|
|
|
return string.replace( rdashAlpha, fcamelCase );
|
2009-03-23 00:25:03 +01:00
|
|
|
}
|
2009-07-19 15:21:51 +02:00
|
|
|
});
|
2009-10-26 23:07:57 +01:00
|
|
|
|
2010-09-17 20:41:28 +02:00
|
|
|
// DEPRECATED, Use jQuery.css() instead
|
|
|
|
jQuery.curCSS = jQuery.css;
|
|
|
|
|
2010-09-05 16:17:18 +02:00
|
|
|
jQuery.each(["height", "width"], function( i, name ) {
|
|
|
|
jQuery.cssHooks[ name ] = {
|
2010-09-16 16:00:56 +02:00
|
|
|
get: function( elem, computed, extra ) {
|
2010-09-09 21:33:06 +02:00
|
|
|
var val;
|
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
if ( computed ) {
|
|
|
|
if ( elem.offsetWidth !== 0 ) {
|
2010-09-05 16:17:18 +02:00
|
|
|
val = getWH( elem, name, extra );
|
2010-09-09 21:33:06 +02:00
|
|
|
|
2010-09-16 16:00:56 +02:00
|
|
|
} else {
|
|
|
|
jQuery.swap( elem, cssShow, function() {
|
|
|
|
val = getWH( elem, name, extra );
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2010-10-22 08:39:06 +02:00
|
|
|
if ( val <= 0 ) {
|
2010-10-22 08:16:14 +02:00
|
|
|
val = curCSS( elem, name, name );
|
|
|
|
|
2010-11-03 20:39:28 +01:00
|
|
|
if ( val === "0px" && currentStyle ) {
|
|
|
|
val = currentStyle( elem, name, name );
|
|
|
|
}
|
|
|
|
|
2010-10-22 08:16:14 +02:00
|
|
|
if ( val != null ) {
|
2010-11-10 05:29:26 +01:00
|
|
|
// Should return "auto" instead of 0, use 0 for
|
|
|
|
// temporary backwards-compat
|
2010-11-10 05:33:18 +01:00
|
|
|
return val === "" || val === "auto" ? "0px" : val;
|
2010-10-22 08:16:14 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if ( val < 0 || val == null ) {
|
2010-11-02 00:04:59 +01:00
|
|
|
val = elem.style[ name ];
|
2010-11-10 05:29:26 +01:00
|
|
|
|
|
|
|
// Should return "auto" instead of 0, use 0 for
|
|
|
|
// temporary backwards-compat
|
2010-11-10 05:33:18 +01:00
|
|
|
return val === "" || val === "auto" ? "0px" : val;
|
2010-10-22 08:16:14 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return typeof val === "string" ? val : val + "px";
|
2010-09-16 16:00:56 +02:00
|
|
|
}
|
2010-09-05 16:17:18 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function( elem, value ) {
|
2010-09-21 23:12:42 +02:00
|
|
|
if ( rnumpx.test( value ) ) {
|
2010-09-17 19:51:12 +02:00
|
|
|
// ignore negative width and height values #1599
|
|
|
|
value = parseFloat(value);
|
2010-09-09 22:34:15 +02:00
|
|
|
|
2010-09-17 19:51:12 +02:00
|
|
|
if ( value >= 0 ) {
|
|
|
|
return value + "px";
|
|
|
|
}
|
|
|
|
|
|
|
|
} else {
|
|
|
|
return value;
|
2010-09-09 22:34:15 +02:00
|
|
|
}
|
2010-09-05 16:17:18 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
});
|
|
|
|
|
2010-09-05 06:04:37 +02:00
|
|
|
if ( !jQuery.support.opacity ) {
|
|
|
|
jQuery.cssHooks.opacity = {
|
2010-09-16 16:00:56 +02:00
|
|
|
get: function( elem, computed ) {
|
2010-09-05 06:04:37 +02:00
|
|
|
// IE uses filters for opacity
|
2010-09-27 16:38:13 +02:00
|
|
|
return ropacity.test((computed && elem.currentStyle ? elem.currentStyle.filter : elem.style.filter) || "") ?
|
2010-09-05 06:04:37 +02:00
|
|
|
(parseFloat(RegExp.$1) / 100) + "" :
|
2010-09-27 17:51:01 +02:00
|
|
|
computed ? "1" : "";
|
2010-09-05 06:04:37 +02:00
|
|
|
},
|
|
|
|
|
|
|
|
set: function( elem, value ) {
|
|
|
|
var style = elem.style;
|
|
|
|
|
|
|
|
// 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
|
2010-09-27 17:51:01 +02:00
|
|
|
var opacity = jQuery.isNaN(value) ?
|
2010-09-05 06:04:37 +02:00
|
|
|
"" :
|
2010-09-27 17:51:01 +02:00
|
|
|
"alpha(opacity=" + value * 100 + ")",
|
|
|
|
filter = style.filter || "";
|
2010-09-05 06:04:37 +02:00
|
|
|
|
|
|
|
style.filter = ralpha.test(filter) ?
|
|
|
|
filter.replace(ralpha, opacity) :
|
2010-09-30 20:24:59 +02:00
|
|
|
style.filter + ' ' + opacity;
|
2010-09-05 06:04:37 +02:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-11-03 20:39:28 +01:00
|
|
|
if ( document.defaultView && document.defaultView.getComputedStyle ) {
|
|
|
|
getComputedStyle = function( elem, newName, name ) {
|
2010-09-05 06:04:37 +02:00
|
|
|
var ret, defaultView, computedStyle;
|
|
|
|
|
|
|
|
name = name.replace( rupper, "-$1" ).toLowerCase();
|
|
|
|
|
|
|
|
if ( !(defaultView = elem.ownerDocument.defaultView) ) {
|
2010-09-05 17:01:27 +02:00
|
|
|
return undefined;
|
2010-09-05 06:04:37 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( (computedStyle = defaultView.getComputedStyle( elem, null )) ) {
|
|
|
|
ret = computedStyle.getPropertyValue( name );
|
2010-10-11 21:11:03 +02:00
|
|
|
if ( ret === "" && !jQuery.contains( elem.ownerDocument.documentElement, elem ) ) {
|
|
|
|
ret = jQuery.style( elem, name );
|
|
|
|
}
|
2010-09-05 06:04:37 +02:00
|
|
|
}
|
|
|
|
|
2010-11-03 23:59:55 +01:00
|
|
|
return ret;
|
2010-09-05 06:04:37 +02:00
|
|
|
};
|
2010-11-03 20:39:28 +01:00
|
|
|
}
|
2010-09-05 06:04:37 +02:00
|
|
|
|
2010-11-03 20:39:28 +01:00
|
|
|
if ( document.documentElement.currentStyle ) {
|
|
|
|
currentStyle = function( elem, name ) {
|
2011-01-05 19:32:59 +01:00
|
|
|
var left,
|
2010-11-09 17:09:07 +01:00
|
|
|
ret = elem.currentStyle && elem.currentStyle[ name ],
|
2011-01-05 19:32:59 +01:00
|
|
|
rsLeft = elem.runtimeStyle && elem.runtimeStyle[ name ],
|
2010-11-09 17:09:07 +01:00
|
|
|
style = elem.style;
|
2010-09-05 06:04:37 +02:00
|
|
|
|
|
|
|
// 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
|
|
|
|
if ( !rnumpx.test( ret ) && rnum.test( ret ) ) {
|
|
|
|
// Remember the original values
|
|
|
|
left = style.left;
|
|
|
|
|
|
|
|
// Put in the new values to get a computed value out
|
2011-01-05 19:32:59 +01:00
|
|
|
if ( rsLeft ) {
|
|
|
|
elem.runtimeStyle.left = elem.currentStyle.left;
|
|
|
|
}
|
2010-09-05 16:17:18 +02:00
|
|
|
style.left = name === "fontSize" ? "1em" : (ret || 0);
|
2010-09-05 06:04:37 +02:00
|
|
|
ret = style.pixelLeft + "px";
|
|
|
|
|
|
|
|
// Revert the changed values
|
|
|
|
style.left = left;
|
2011-01-05 19:32:59 +01:00
|
|
|
if ( rsLeft ) {
|
|
|
|
elem.runtimeStyle.left = rsLeft;
|
|
|
|
}
|
2010-09-05 06:04:37 +02:00
|
|
|
}
|
|
|
|
|
2010-11-02 00:04:59 +01:00
|
|
|
return ret === "" ? "auto" : ret;
|
2010-09-05 06:04:37 +02:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2010-11-03 20:39:28 +01:00
|
|
|
curCSS = getComputedStyle || currentStyle;
|
|
|
|
|
2010-03-01 18:44:56 +01:00
|
|
|
function getWH( elem, name, extra ) {
|
|
|
|
var which = name === "width" ? cssWidth : cssHeight,
|
|
|
|
val = name === "width" ? elem.offsetWidth : elem.offsetHeight;
|
|
|
|
|
|
|
|
if ( extra === "border" ) {
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
|
|
|
jQuery.each( which, function() {
|
|
|
|
if ( !extra ) {
|
2010-09-16 16:00:56 +02:00
|
|
|
val -= parseFloat(jQuery.css( elem, "padding" + this )) || 0;
|
2010-03-01 18:44:56 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if ( extra === "margin" ) {
|
2010-09-16 16:00:56 +02:00
|
|
|
val += parseFloat(jQuery.css( elem, "margin" + this )) || 0;
|
2010-03-01 18:44:56 +01:00
|
|
|
|
|
|
|
} else {
|
2010-09-16 16:00:56 +02:00
|
|
|
val -= parseFloat(jQuery.css( elem, "border" + this + "Width" )) || 0;
|
2010-03-01 18:44:56 +01:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
return val;
|
|
|
|
}
|
|
|
|
|
2009-10-26 23:07:57 +01:00
|
|
|
if ( jQuery.expr && jQuery.expr.filters ) {
|
2009-12-05 21:02:45 +01:00
|
|
|
jQuery.expr.filters.hidden = function( elem ) {
|
2010-11-09 17:09:07 +01:00
|
|
|
var width = elem.offsetWidth,
|
|
|
|
height = elem.offsetHeight;
|
2010-10-05 20:23:10 +02:00
|
|
|
|
|
|
|
return (width === 0 && height === 0) || (!jQuery.support.reliableHiddenOffsets && (elem.style.display || jQuery.css( elem, "display" )) === "none");
|
2009-10-26 23:07:57 +01:00
|
|
|
};
|
|
|
|
|
2009-12-05 21:02:45 +01:00
|
|
|
jQuery.expr.filters.visible = function( elem ) {
|
|
|
|
return !jQuery.expr.filters.hidden( elem );
|
2009-10-26 23:07:57 +01:00
|
|
|
};
|
2009-11-11 20:17:16 +01:00
|
|
|
}
|
2010-09-08 18:00:29 +02:00
|
|
|
|
|
|
|
})( jQuery );
|