ffffng/app/bower_components/jquery/src/css.js

439 lines
11 KiB
JavaScript
Raw Normal View History

2017-05-13 13:25:33 +02:00
define( [
2014-05-12 20:08:19 +02:00
"./core",
"./var/pnum",
"./core/access",
"./css/var/rmargin",
2017-05-13 13:25:33 +02:00
"./var/document",
"./var/rcssNum",
2014-05-12 20:08:19 +02:00
"./css/var/rnumnonpx",
"./css/var/cssExpand",
"./css/var/getStyles",
2017-05-13 13:25:33 +02:00
"./css/var/swap",
2014-05-12 20:08:19 +02:00
"./css/curCSS",
2017-05-13 13:25:33 +02:00
"./css/adjustCSS",
2014-05-12 20:08:19 +02:00
"./css/addGetHookIf",
"./css/support",
"./core/init",
"./core/ready",
"./selector" // contains
2017-05-13 13:25:33 +02:00
], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand,
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) {
"use strict";
2014-05-12 20:08:19 +02:00
var
2017-05-13 13:25:33 +02:00
// Swappable if display is none or starts with table
// except "table", "table-cell", or "table-caption"
2016-05-16 13:33:49 +02:00
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display
2014-05-12 20:08:19 +02:00
rdisplayswap = /^(none|table(?!-c[ea]).+)/,
2017-05-13 13:25:33 +02:00
rcustomProp = /^--/,
2014-05-12 20:08:19 +02:00
cssShow = { position: "absolute", visibility: "hidden", display: "block" },
cssNormalTransform = {
letterSpacing: "0",
fontWeight: "400"
},
2017-05-13 13:25:33 +02:00
cssPrefixes = [ "Webkit", "Moz", "ms" ],
emptyStyle = document.createElement( "div" ).style;
2014-05-12 20:08:19 +02:00
2016-05-16 13:33:49 +02:00
// Return a css property mapped to a potentially vendor prefixed property
2017-05-13 13:25:33 +02:00
function vendorPropName( name ) {
2014-05-12 20:08:19 +02:00
2016-05-16 13:33:49 +02:00
// Shortcut for names that are not vendor prefixed
2017-05-13 13:25:33 +02:00
if ( name in emptyStyle ) {
2014-05-12 20:08:19 +02:00
return name;
}
2016-05-16 13:33:49 +02:00
// Check for vendor prefixed names
2017-05-13 13:25:33 +02:00
var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
2014-05-12 20:08:19 +02:00
i = cssPrefixes.length;
while ( i-- ) {
name = cssPrefixes[ i ] + capName;
2017-05-13 13:25:33 +02:00
if ( name in emptyStyle ) {
2014-05-12 20:08:19 +02:00
return name;
}
}
2017-05-13 13:25:33 +02:00
}
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
// Return a property mapped along what jQuery.cssProps suggests or to
// a vendor prefixed property.
function finalPropName( name ) {
var ret = jQuery.cssProps[ name ];
if ( !ret ) {
ret = jQuery.cssProps[ name ] = vendorPropName( name ) || name;
}
return ret;
2014-05-12 20:08:19 +02:00
}
function setPositiveNumber( elem, value, subtract ) {
2017-05-13 13:25:33 +02:00
// Any relative (+/-) values have already been
// normalized at this point
var matches = rcssNum.exec( value );
2014-05-12 20:08:19 +02:00
return matches ?
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// Guard against undefined "subtract", e.g., when used as in cssHooks
2017-05-13 13:25:33 +02:00
Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) :
2014-05-12 20:08:19 +02:00
value;
}
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
2017-05-13 13:25:33 +02:00
var i,
2014-05-12 20:08:19 +02:00
val = 0;
2017-05-13 13:25:33 +02:00
// If we already have the right measurement, avoid augmentation
if ( extra === ( isBorderBox ? "border" : "content" ) ) {
i = 4;
// Otherwise initialize for horizontal or vertical properties
} else {
i = name === "width" ? 1 : 0;
}
2014-05-12 20:08:19 +02:00
for ( ; i < 4; i += 2 ) {
2017-05-13 13:25:33 +02:00
2016-05-16 13:33:49 +02:00
// Both box models exclude margin, so add it if we want it
2014-05-12 20:08:19 +02:00
if ( extra === "margin" ) {
val += jQuery.css( elem, extra + cssExpand[ i ], true, styles );
}
if ( isBorderBox ) {
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// border-box includes padding, so remove it if we want content
if ( extra === "content" ) {
val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
}
2016-05-16 13:33:49 +02:00
// At this point, extra isn't border nor margin, so remove border
2014-05-12 20:08:19 +02:00
if ( extra !== "margin" ) {
val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
}
} else {
2017-05-13 13:25:33 +02:00
2016-05-16 13:33:49 +02:00
// At this point, extra isn't content, so add padding
2014-05-12 20:08:19 +02:00
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles );
2016-05-16 13:33:49 +02:00
// At this point, extra isn't content nor padding, so add border
2014-05-12 20:08:19 +02:00
if ( extra !== "padding" ) {
val += jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles );
}
}
}
return val;
}
function getWidthOrHeight( elem, name, extra ) {
2017-05-13 13:25:33 +02:00
// Start with computed style
var valueIsBorderBox,
2014-05-12 20:08:19 +02:00
styles = getStyles( elem ),
2017-05-13 13:25:33 +02:00
val = curCSS( elem, name, styles ),
2014-05-12 20:08:19 +02:00
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box";
2017-05-13 13:25:33 +02:00
// Computed unit is not pixels. Stop here and return.
if ( rnumnonpx.test( val ) ) {
return val;
}
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
// Check for style in case a browser which returns unreliable values
// for getComputedStyle silently falls back to the reliable elem.style
valueIsBorderBox = isBorderBox &&
( support.boxSizingReliable() || val === elem.style[ name ] );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
// Fall back to offsetWidth/Height when value is "auto"
// This happens for inline elements with no explicit setting (gh-3571)
if ( val === "auto" ) {
val = elem[ "offset" + name[ 0 ].toUpperCase() + name.slice( 1 ) ];
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
// Normalize "", auto, and prepare for extra
val = parseFloat( val ) || 0;
2016-05-16 13:33:49 +02:00
// Use the active box-sizing model to add/subtract irrelevant styles
2014-05-12 20:08:19 +02:00
return ( val +
augmentWidthOrHeight(
elem,
name,
extra || ( isBorderBox ? "border" : "content" ),
valueIsBorderBox,
styles
)
) + "px";
}
2017-05-13 13:25:33 +02:00
jQuery.extend( {
2016-05-16 13:33:49 +02:00
2014-05-12 20:08:19 +02:00
// Add in style property hooks for overriding the default
// behavior of getting and setting a style property
cssHooks: {
opacity: {
get: function( elem, computed ) {
if ( computed ) {
2016-05-16 13:33:49 +02:00
2014-05-12 20:08:19 +02:00
// We should always get a number back from opacity
var ret = curCSS( elem, "opacity" );
return ret === "" ? "1" : ret;
}
}
}
},
// Don't automatically add "px" to these possibly-unitless properties
cssNumber: {
2017-05-13 13:25:33 +02:00
"animationIterationCount": true,
2014-05-12 20:08:19 +02:00
"columnCount": true,
"fillOpacity": true,
"flexGrow": true,
"flexShrink": true,
"fontWeight": true,
"lineHeight": true,
"opacity": true,
"order": true,
"orphans": true,
"widows": true,
"zIndex": true,
"zoom": true
},
// Add in properties whose names you wish to fix before
// setting or getting the value
cssProps: {
"float": "cssFloat"
},
// Get and set the style property on a DOM Node
style: function( elem, name, value, extra ) {
2016-05-16 13:33:49 +02:00
2014-05-12 20:08:19 +02:00
// Don't set styles on text and comment nodes
if ( !elem || elem.nodeType === 3 || elem.nodeType === 8 || !elem.style ) {
return;
}
// Make sure that we're working with the right name
var ret, type, hooks,
origName = jQuery.camelCase( name ),
2017-05-13 13:25:33 +02:00
isCustomProp = rcustomProp.test( name ),
2014-05-12 20:08:19 +02:00
style = elem.style;
2017-05-13 13:25:33 +02:00
// Make sure that we're working with the right name. We don't
// want to query the value if it is a CSS custom property
// since they are user-defined.
if ( !isCustomProp ) {
name = finalPropName( origName );
}
2014-05-12 20:08:19 +02:00
2016-05-16 13:33:49 +02:00
// Gets hook for the prefixed version, then unprefixed version
2014-05-12 20:08:19 +02:00
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
// Check if we're setting a value
if ( value !== undefined ) {
type = typeof value;
2016-05-16 13:33:49 +02:00
// Convert "+=" or "-=" to relative numbers (#7345)
2017-05-13 13:25:33 +02:00
if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
value = adjustCSS( elem, name, ret );
2014-05-12 20:08:19 +02:00
// Fixes bug #9237
type = "number";
}
2016-05-16 13:33:49 +02:00
// Make sure that null and NaN values aren't set (#7116)
2014-05-12 20:08:19 +02:00
if ( value == null || value !== value ) {
return;
}
2017-05-13 13:25:33 +02:00
// If a number was passed in, add the unit (except for certain CSS properties)
if ( type === "number" ) {
value += ret && ret[ 3 ] || ( jQuery.cssNumber[ origName ] ? "" : "px" );
2014-05-12 20:08:19 +02:00
}
2016-05-16 13:33:49 +02:00
// background-* props affect original clone's values
2014-05-12 20:08:19 +02:00
if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) {
style[ name ] = "inherit";
}
// If a hook was provided, use that value, otherwise just set the specified value
2017-05-13 13:25:33 +02:00
if ( !hooks || !( "set" in hooks ) ||
( value = hooks.set( elem, value, extra ) ) !== undefined ) {
if ( isCustomProp ) {
style.setProperty( name, value );
} else {
style[ name ] = value;
}
2014-05-12 20:08:19 +02:00
}
} else {
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
// If a hook was provided get the non-computed value from there
2017-05-13 13:25:33 +02:00
if ( hooks && "get" in hooks &&
( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
2014-05-12 20:08:19 +02:00
return ret;
}
// Otherwise just get the value from the style object
return style[ name ];
}
},
css: function( elem, name, extra, styles ) {
var val, num, hooks,
2017-05-13 13:25:33 +02:00
origName = jQuery.camelCase( name ),
isCustomProp = rcustomProp.test( name );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
// Make sure that we're working with the right name. We don't
// want to modify the value if it is a CSS custom property
// since they are user-defined.
if ( !isCustomProp ) {
name = finalPropName( origName );
}
2014-05-12 20:08:19 +02:00
2016-05-16 13:33:49 +02:00
// Try prefixed name followed by the unprefixed name
2014-05-12 20:08:19 +02:00
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ];
// If a hook was provided get the computed value from there
if ( hooks && "get" in hooks ) {
val = hooks.get( elem, true, extra );
}
// Otherwise, if a way to get the computed value exists, use that
if ( val === undefined ) {
val = curCSS( elem, name, styles );
}
2016-05-16 13:33:49 +02:00
// Convert "normal" to computed value
2014-05-12 20:08:19 +02:00
if ( val === "normal" && name in cssNormalTransform ) {
val = cssNormalTransform[ name ];
}
2016-05-16 13:33:49 +02:00
// Make numeric if forced or a qualifier was provided and val looks numeric
2014-05-12 20:08:19 +02:00
if ( extra === "" || extra ) {
num = parseFloat( val );
2017-05-13 13:25:33 +02:00
return extra === true || isFinite( num ) ? num || 0 : val;
2014-05-12 20:08:19 +02:00
}
2017-05-13 13:25:33 +02:00
2014-05-12 20:08:19 +02:00
return val;
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
jQuery.each( [ "height", "width" ], function( i, name ) {
2014-05-12 20:08:19 +02:00
jQuery.cssHooks[ name ] = {
get: function( elem, computed, extra ) {
if ( computed ) {
2016-05-16 13:33:49 +02:00
// Certain elements can have dimension info if we invisibly show them
// but it must have a current display style that would benefit
2017-05-13 13:25:33 +02:00
return rdisplayswap.test( jQuery.css( elem, "display" ) ) &&
// Support: Safari 8+
// Table columns in Safari have non-zero offsetWidth & zero
// getBoundingClientRect().width unless display is changed.
// Support: IE <=11 only
// Running getBoundingClientRect on a disconnected node
// in IE throws an error.
( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
swap( elem, cssShow, function() {
return getWidthOrHeight( elem, name, extra );
} ) :
getWidthOrHeight( elem, name, extra );
2014-05-12 20:08:19 +02:00
}
},
set: function( elem, value, extra ) {
2017-05-13 13:25:33 +02:00
var matches,
styles = extra && getStyles( elem ),
subtract = extra && augmentWidthOrHeight(
2014-05-12 20:08:19 +02:00
elem,
name,
extra,
jQuery.css( elem, "boxSizing", false, styles ) === "border-box",
styles
2017-05-13 13:25:33 +02:00
);
// Convert to pixels if value adjustment is needed
if ( subtract && ( matches = rcssNum.exec( value ) ) &&
( matches[ 3 ] || "px" ) !== "px" ) {
elem.style[ name ] = value;
value = jQuery.css( elem, name );
}
return setPositiveNumber( elem, value, subtract );
2014-05-12 20:08:19 +02:00
}
};
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft,
2014-05-12 20:08:19 +02:00
function( elem, computed ) {
if ( computed ) {
2017-05-13 13:25:33 +02:00
return ( parseFloat( curCSS( elem, "marginLeft" ) ) ||
elem.getBoundingClientRect().left -
swap( elem, { marginLeft: 0 }, function() {
return elem.getBoundingClientRect().left;
} )
) + "px";
2014-05-12 20:08:19 +02:00
}
}
);
// These hooks are used by animate to expand properties
2017-05-13 13:25:33 +02:00
jQuery.each( {
2014-05-12 20:08:19 +02:00
margin: "",
padding: "",
border: "Width"
}, function( prefix, suffix ) {
jQuery.cssHooks[ prefix + suffix ] = {
expand: function( value ) {
var i = 0,
expanded = {},
2016-05-16 13:33:49 +02:00
// Assumes a single number if not a string
2017-05-13 13:25:33 +02:00
parts = typeof value === "string" ? value.split( " " ) : [ value ];
2014-05-12 20:08:19 +02:00
for ( ; i < 4; i++ ) {
expanded[ prefix + cssExpand[ i ] + suffix ] =
parts[ i ] || parts[ i - 2 ] || parts[ 0 ];
}
return expanded;
}
};
if ( !rmargin.test( prefix ) ) {
jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber;
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
2017-05-13 13:25:33 +02:00
jQuery.fn.extend( {
2014-05-12 20:08:19 +02:00
css: function( name, value ) {
return access( this, function( elem, name, value ) {
var styles, len,
map = {},
i = 0;
2017-05-13 13:25:33 +02:00
if ( Array.isArray( name ) ) {
2014-05-12 20:08:19 +02:00
styles = getStyles( elem );
len = name.length;
for ( ; i < len; i++ ) {
map[ name[ i ] ] = jQuery.css( elem, name[ i ], false, styles );
}
return map;
}
return value !== undefined ?
jQuery.style( elem, name, value ) :
jQuery.css( elem, name );
}, name, value, arguments.length > 1 );
}
2017-05-13 13:25:33 +02:00
} );
2014-05-12 20:08:19 +02:00
return jQuery;
2017-05-13 13:25:33 +02:00
} );