/bower_components/jquery/src/css.js |
@@ -1,33 +1,32 @@ |
define( [ |
define([ |
"./core", |
"./var/pnum", |
"./core/access", |
"./css/var/rmargin", |
"./var/document", |
"./var/rcssNum", |
"./css/var/rnumnonpx", |
"./css/var/cssExpand", |
"./css/var/isHidden", |
"./css/var/getStyles", |
"./css/var/swap", |
"./css/curCSS", |
"./css/adjustCSS", |
"./css/defaultDisplay", |
"./css/addGetHookIf", |
"./css/support", |
"./data/var/data_priv", |
|
"./core/init", |
"./css/swap", |
"./core/ready", |
"./selector" // contains |
], function( jQuery, pnum, access, rmargin, document, rcssNum, rnumnonpx, cssExpand, |
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) { |
], function( jQuery, pnum, access, rmargin, rnumnonpx, cssExpand, isHidden, |
getStyles, curCSS, defaultDisplay, addGetHookIf, support, data_priv ) { |
|
"use strict"; |
|
var |
|
// Swappable if display is none or starts with table |
// except "table", "table-cell", or "table-caption" |
// Swappable if display is none or starts with table except "table", "table-cell", or "table-caption" |
// See here for display values: https://developer.mozilla.org/en-US/docs/CSS/display |
rdisplayswap = /^(none|table(?!-c[ea]).+)/, |
rnumsplit = new RegExp( "^(" + pnum + ")(.*)$", "i" ), |
rrelNum = new RegExp( "^([+-])=(" + pnum + ")", "i" ), |
|
cssShow = { position: "absolute", visibility: "hidden", display: "block" }, |
cssNormalTransform = { |
letterSpacing: "0", |
@@ -34,56 +33,49 @@ |
fontWeight: "400" |
}, |
|
cssPrefixes = [ "Webkit", "Moz", "ms" ], |
emptyStyle = document.createElement( "div" ).style; |
cssPrefixes = [ "Webkit", "O", "Moz", "ms" ]; |
|
// Return a css property mapped to a potentially vendor prefixed property |
function vendorPropName( name ) { |
function vendorPropName( style, name ) { |
|
// Shortcut for names that are not vendor prefixed |
if ( name in emptyStyle ) { |
if ( name in style ) { |
return name; |
} |
|
// Check for vendor prefixed names |
var capName = name[ 0 ].toUpperCase() + name.slice( 1 ), |
var capName = name[0].toUpperCase() + name.slice(1), |
origName = name, |
i = cssPrefixes.length; |
|
while ( i-- ) { |
name = cssPrefixes[ i ] + capName; |
if ( name in emptyStyle ) { |
if ( name in style ) { |
return name; |
} |
} |
|
return origName; |
} |
|
function setPositiveNumber( elem, value, subtract ) { |
|
// Any relative (+/-) values have already been |
// normalized at this point |
var matches = rcssNum.exec( value ); |
var matches = rnumsplit.exec( value ); |
return matches ? |
|
// Guard against undefined "subtract", e.g., when used as in cssHooks |
Math.max( 0, matches[ 2 ] - ( subtract || 0 ) ) + ( matches[ 3 ] || "px" ) : |
Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) : |
value; |
} |
|
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) { |
var i, |
var i = extra === ( isBorderBox ? "border" : "content" ) ? |
// If we already have the right measurement, avoid augmentation |
4 : |
// Otherwise initialize for horizontal or vertical properties |
name === "width" ? 1 : 0, |
|
val = 0; |
|
// 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; |
} |
|
for ( ; i < 4; i += 2 ) { |
|
// Both box models exclude margin, so add it if we want it |
if ( extra === "margin" ) { |
val += jQuery.css( elem, extra + cssExpand[ i ], true, styles ); |
@@ -90,7 +82,6 @@ |
} |
|
if ( isBorderBox ) { |
|
// border-box includes padding, so remove it if we want content |
if ( extra === "content" ) { |
val -= jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); |
@@ -101,7 +92,6 @@ |
val -= jQuery.css( elem, "border" + cssExpand[ i ] + "Width", true, styles ); |
} |
} else { |
|
// At this point, extra isn't content, so add padding |
val += jQuery.css( elem, "padding" + cssExpand[ i ], true, styles ); |
|
@@ -118,23 +108,15 @@ |
function getWidthOrHeight( elem, name, extra ) { |
|
// Start with offset property, which is equivalent to the border-box value |
var val, |
valueIsBorderBox = true, |
var valueIsBorderBox = true, |
val = name === "width" ? elem.offsetWidth : elem.offsetHeight, |
styles = getStyles( elem ), |
isBorderBox = jQuery.css( elem, "boxSizing", false, styles ) === "border-box"; |
|
// Support: IE <=11 only |
// Running getBoundingClientRect on a disconnected node |
// in IE throws an error. |
if ( elem.getClientRects().length ) { |
val = elem.getBoundingClientRect()[ name ]; |
} |
|
// Some non-html elements return undefined for offsetWidth, so check for null/undefined |
// svg - https://bugzilla.mozilla.org/show_bug.cgi?id=649285 |
// MathML - https://bugzilla.mozilla.org/show_bug.cgi?id=491668 |
if ( val <= 0 || val == null ) { |
|
// Fall back to computed then uncomputed css if necessary |
val = curCSS( elem, name, styles ); |
if ( val < 0 || val == null ) { |
@@ -142,7 +124,7 @@ |
} |
|
// Computed unit is not pixels. Stop here and return. |
if ( rnumnonpx.test( val ) ) { |
if ( rnumnonpx.test(val) ) { |
return val; |
} |
|
@@ -167,8 +149,59 @@ |
) + "px"; |
} |
|
jQuery.extend( { |
function showHide( elements, show ) { |
var display, elem, hidden, |
values = [], |
index = 0, |
length = elements.length; |
|
for ( ; index < length; index++ ) { |
elem = elements[ index ]; |
if ( !elem.style ) { |
continue; |
} |
|
values[ index ] = data_priv.get( elem, "olddisplay" ); |
display = elem.style.display; |
if ( show ) { |
// Reset the inline display of this element to learn if it is |
// being hidden by cascaded rules or not |
if ( !values[ index ] && display === "none" ) { |
elem.style.display = ""; |
} |
|
// Set elements which have been overridden with display: none |
// in a stylesheet to whatever the default browser style is |
// for such an element |
if ( elem.style.display === "" && isHidden( elem ) ) { |
values[ index ] = data_priv.access( elem, "olddisplay", defaultDisplay(elem.nodeName) ); |
} |
} else { |
hidden = isHidden( elem ); |
|
if ( display !== "none" || !hidden ) { |
data_priv.set( elem, "olddisplay", hidden ? display : jQuery.css( elem, "display" ) ); |
} |
} |
} |
|
// Set the display of most of the elements in a second loop |
// to avoid the constant reflow |
for ( index = 0; index < length; index++ ) { |
elem = elements[ index ]; |
if ( !elem.style ) { |
continue; |
} |
if ( !show || elem.style.display === "none" || elem.style.display === "" ) { |
elem.style.display = show ? values[ index ] || "" : "none"; |
} |
} |
|
return elements; |
} |
|
jQuery.extend({ |
|
// Add in style property hooks for overriding the default |
// behavior of getting and setting a style property |
cssHooks: { |
@@ -186,7 +219,6 @@ |
|
// Don't automatically add "px" to these possibly-unitless properties |
cssNumber: { |
"animationIterationCount": true, |
"columnCount": true, |
"fillOpacity": true, |
"flexGrow": true, |
@@ -220,8 +252,7 @@ |
origName = jQuery.camelCase( name ), |
style = elem.style; |
|
name = jQuery.cssProps[ origName ] || |
( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName ); |
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( style, origName ) ); |
|
// Gets hook for the prefixed version, then unprefixed version |
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; |
@@ -231,9 +262,8 @@ |
type = typeof value; |
|
// Convert "+=" or "-=" to relative numbers (#7345) |
if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) { |
value = adjustCSS( elem, name, ret ); |
|
if ( type === "string" && (ret = rrelNum.exec( value )) ) { |
value = ( ret[1] + 1 ) * ret[2] + parseFloat( jQuery.css( elem, name ) ); |
// Fixes bug #9237 |
type = "number"; |
} |
@@ -243,11 +273,12 @@ |
return; |
} |
|
// 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" ); |
// If a number, add 'px' to the (except for certain CSS properties) |
if ( type === "number" && !jQuery.cssNumber[ origName ] ) { |
value += "px"; |
} |
|
// Support: IE9-11+ |
// background-* props affect original clone's values |
if ( !support.clearCloneStyle && value === "" && name.indexOf( "background" ) === 0 ) { |
style[ name ] = "inherit"; |
@@ -254,18 +285,13 @@ |
} |
|
// If a hook was provided, use that value, otherwise just set the specified value |
if ( !hooks || !( "set" in hooks ) || |
( value = hooks.set( elem, value, extra ) ) !== undefined ) { |
|
if ( !hooks || !("set" in hooks) || (value = hooks.set( elem, value, extra )) !== undefined ) { |
style[ name ] = value; |
} |
|
} else { |
|
// If a hook was provided get the non-computed value from there |
if ( hooks && "get" in hooks && |
( ret = hooks.get( elem, false, extra ) ) !== undefined ) { |
|
if ( hooks && "get" in hooks && (ret = hooks.get( elem, false, extra )) !== undefined ) { |
return ret; |
} |
|
@@ -279,8 +305,7 @@ |
origName = jQuery.camelCase( name ); |
|
// Make sure that we're working with the right name |
name = jQuery.cssProps[ origName ] || |
( jQuery.cssProps[ origName ] = vendorPropName( origName ) || origName ); |
name = jQuery.cssProps[ origName ] || ( jQuery.cssProps[ origName ] = vendorPropName( elem.style, origName ) ); |
|
// Try prefixed name followed by the unprefixed name |
hooks = jQuery.cssHooks[ name ] || jQuery.cssHooks[ origName ]; |
@@ -303,13 +328,13 @@ |
// Make numeric if forced or a qualifier was provided and val looks numeric |
if ( extra === "" || extra ) { |
num = parseFloat( val ); |
return extra === true || isFinite( num ) ? num || 0 : val; |
return extra === true || jQuery.isNumeric( num ) ? num || 0 : val; |
} |
return val; |
} |
} ); |
}); |
|
jQuery.each( [ "height", "width" ], function( i, name ) { |
jQuery.each([ "height", "width" ], function( i, name ) { |
jQuery.cssHooks[ name ] = { |
get: function( elem, computed, extra ) { |
if ( computed ) { |
@@ -316,61 +341,41 @@ |
|
// Certain elements can have dimension info if we invisibly show them |
// but it must have a current display style that would benefit |
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 ); |
return rdisplayswap.test( jQuery.css( elem, "display" ) ) && elem.offsetWidth === 0 ? |
jQuery.swap( elem, cssShow, function() { |
return getWidthOrHeight( elem, name, extra ); |
}) : |
getWidthOrHeight( elem, name, extra ); |
} |
}, |
|
set: function( elem, value, extra ) { |
var matches, |
styles = extra && getStyles( elem ), |
subtract = extra && augmentWidthOrHeight( |
var styles = extra && getStyles( elem ); |
return setPositiveNumber( elem, value, extra ? |
augmentWidthOrHeight( |
elem, |
name, |
extra, |
jQuery.css( elem, "boxSizing", false, styles ) === "border-box", |
styles |
); |
|
// 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 ); |
) : 0 |
); |
} |
}; |
} ); |
}); |
|
jQuery.cssHooks.marginLeft = addGetHookIf( support.reliableMarginLeft, |
// Support: Android 2.3 |
jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight, |
function( elem, computed ) { |
if ( computed ) { |
return ( parseFloat( curCSS( elem, "marginLeft" ) ) || |
elem.getBoundingClientRect().left - |
swap( elem, { marginLeft: 0 }, function() { |
return elem.getBoundingClientRect().left; |
} ) |
) + "px"; |
return jQuery.swap( elem, { "display": "inline-block" }, |
curCSS, [ elem, "marginRight" ] ); |
} |
} |
); |
|
// These hooks are used by animate to expand properties |
jQuery.each( { |
jQuery.each({ |
margin: "", |
padding: "", |
border: "Width" |
@@ -381,7 +386,7 @@ |
expanded = {}, |
|
// Assumes a single number if not a string |
parts = typeof value === "string" ? value.split( " " ) : [ value ]; |
parts = typeof value === "string" ? value.split(" ") : [ value ]; |
|
for ( ; i < 4; i++ ) { |
expanded[ prefix + cssExpand[ i ] + suffix ] = |
@@ -395,9 +400,9 @@ |
if ( !rmargin.test( prefix ) ) { |
jQuery.cssHooks[ prefix + suffix ].set = setPositiveNumber; |
} |
} ); |
}); |
|
jQuery.fn.extend( { |
jQuery.fn.extend({ |
css: function( name, value ) { |
return access( this, function( elem, name, value ) { |
var styles, len, |
@@ -419,8 +424,27 @@ |
jQuery.style( elem, name, value ) : |
jQuery.css( elem, name ); |
}, name, value, arguments.length > 1 ); |
}, |
show: function() { |
return showHide( this, true ); |
}, |
hide: function() { |
return showHide( this ); |
}, |
toggle: function( state ) { |
if ( typeof state === "boolean" ) { |
return state ? this.show() : this.hide(); |
} |
|
return this.each(function() { |
if ( isHidden( this ) ) { |
jQuery( this ).show(); |
} else { |
jQuery( this ).hide(); |
} |
}); |
} |
} ); |
}); |
|
return jQuery; |
} ); |
}); |