aboutsummaryrefslogtreecommitdiffstats
path: root/src/css.js
diff options
context:
space:
mode:
Diffstat (limited to 'src/css.js')
-rw-r--r--src/css.js51
1 files changed, 31 insertions, 20 deletions
diff --git a/src/css.js b/src/css.js
index 859985f9d..8a86ef55c 100644
--- a/src/css.js
+++ b/src/css.js
@@ -1,4 +1,4 @@
-define([
+define( [
"./core",
"./var/pnum",
"./core/access",
@@ -23,6 +23,7 @@ define([
isHidden, getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, showHide ) {
var
+
// 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
@@ -47,7 +48,7 @@ function vendorPropName( name ) {
}
// Check for vendor prefixed names
- var capName = name[0].toUpperCase() + name.slice(1),
+ var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
i = cssPrefixes.length;
while ( i-- ) {
@@ -61,6 +62,7 @@ function vendorPropName( name ) {
function setPositiveNumber( elem, value, subtract ) {
var matches = rnumsplit.exec( value );
return matches ?
+
// Guard against undefined "subtract", e.g., when used as in cssHooks
Math.max( 0, matches[ 1 ] - ( subtract || 0 ) ) + ( matches[ 2 ] || "px" ) :
value;
@@ -68,20 +70,24 @@ function setPositiveNumber( elem, value, subtract ) {
function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
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;
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 );
}
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 );
@@ -92,6 +98,7 @@ function augmentWidthOrHeight( elem, name, extra, isBorderBox, styles ) {
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 );
@@ -131,6 +138,7 @@ function getWidthOrHeight( elem, name, extra ) {
// 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 ) {
@@ -138,7 +146,7 @@ function getWidthOrHeight( elem, name, extra ) {
}
// Computed unit is not pixels. Stop here and return.
- if ( rnumnonpx.test(val) ) {
+ if ( rnumnonpx.test( val ) ) {
return val;
}
@@ -163,7 +171,7 @@ function getWidthOrHeight( elem, name, extra ) {
) + "px";
}
-jQuery.extend({
+jQuery.extend( {
// Add in style property hooks for overriding the default
// behavior of getting and setting a style property
@@ -226,8 +234,9 @@ jQuery.extend({
type = typeof value;
// Convert "+=" or "-=" to relative numbers (#7345)
- if ( type === "string" && (ret = rcssNum.exec( value )) && ret[ 1 ] ) {
+ if ( type === "string" && ( ret = rcssNum.exec( value ) ) && ret[ 1 ] ) {
value = adjustCSS( elem, name, ret );
+
// Fixes bug #9237
type = "number";
}
@@ -249,16 +258,17 @@ jQuery.extend({
}
// 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 ) {
+ ( ret = hooks.get( elem, false, extra ) ) !== undefined ) {
return ret;
}
@@ -301,9 +311,9 @@ jQuery.extend({
}
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 ) {
@@ -311,6 +321,7 @@ jQuery.each([ "height", "width" ], function( i, name ) {
// 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.
@@ -320,7 +331,7 @@ jQuery.each([ "height", "width" ], function( i, name ) {
( !elem.getClientRects().length || !elem.getBoundingClientRect().width ) ?
swap( elem, cssShow, function() {
return getWidthOrHeight( elem, name, extra );
- }) :
+ } ) :
getWidthOrHeight( elem, name, extra );
}
},
@@ -338,7 +349,7 @@ jQuery.each([ "height", "width" ], function( i, name ) {
);
}
};
-});
+} );
// Support: Android 2.3
jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
@@ -351,7 +362,7 @@ jQuery.cssHooks.marginRight = addGetHookIf( support.reliableMarginRight,
);
// These hooks are used by animate to expand properties
-jQuery.each({
+jQuery.each( {
margin: "",
padding: "",
border: "Width"
@@ -362,7 +373,7 @@ jQuery.each({
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 ] =
@@ -376,9 +387,9 @@ jQuery.each({
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,
@@ -412,15 +423,15 @@ jQuery.fn.extend({
return state ? this.show() : this.hide();
}
- return this.each(function() {
+ return this.each( function() {
if ( isHidden( this ) ) {
jQuery( this ).show();
} else {
jQuery( this ).hide();
}
- });
+ } );
}
-});
+} );
return jQuery;
-});
+} );