mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
CSS: Avoid filling jQuery.cssProps
Fixes gh-3986 Closes gh-4005 Avoids filling jQuery.cssProps by introducing a second internal prop cache. This allows jQuery Migrate to detect external usage.
This commit is contained in:
parent
b95e0da68e
commit
2b5f5d5e90
38
src/css.js
38
src/css.js
@ -13,12 +13,13 @@ define( [
|
||||
"./css/adjustCSS",
|
||||
"./css/addGetHookIf",
|
||||
"./css/support",
|
||||
"./css/finalPropName",
|
||||
|
||||
"./core/init",
|
||||
"./core/ready",
|
||||
"./selector" // contains
|
||||
], function( jQuery, pnum, access, camelCase, document, rcssNum, rnumnonpx, cssExpand,
|
||||
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support ) {
|
||||
getStyles, swap, curCSS, adjustCSS, addGetHookIf, support, finalPropName ) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@ -33,40 +34,7 @@ var
|
||||
cssNormalTransform = {
|
||||
letterSpacing: "0",
|
||||
fontWeight: "400"
|
||||
},
|
||||
|
||||
cssPrefixes = [ "Webkit", "Moz", "ms" ],
|
||||
emptyStyle = document.createElement( "div" ).style;
|
||||
|
||||
// Return a css property mapped to a potentially vendor prefixed property
|
||||
function vendorPropName( name ) {
|
||||
|
||||
// Shortcut for names that are not vendor prefixed
|
||||
if ( name in emptyStyle ) {
|
||||
return name;
|
||||
}
|
||||
|
||||
// Check for vendor prefixed names
|
||||
var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
|
||||
i = cssPrefixes.length;
|
||||
|
||||
while ( i-- ) {
|
||||
name = cssPrefixes[ i ] + capName;
|
||||
if ( name in emptyStyle ) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
|
||||
function setPositiveNumber( elem, value, subtract ) {
|
||||
|
||||
|
39
src/css/finalPropName.js
Normal file
39
src/css/finalPropName.js
Normal file
@ -0,0 +1,39 @@
|
||||
define( [ "../var/document" ], function( document ) {
|
||||
|
||||
"use strict";
|
||||
|
||||
var cssPrefixes = [ "Webkit", "Moz", "ms" ],
|
||||
emptyStyle = document.createElement( "div" ).style,
|
||||
vendorProps = {};
|
||||
|
||||
// Return a vendor-prefixed property or undefined
|
||||
function vendorPropName( name ) {
|
||||
|
||||
// Check for vendor prefixed names
|
||||
var capName = name[ 0 ].toUpperCase() + name.slice( 1 ),
|
||||
i = cssPrefixes.length;
|
||||
|
||||
while ( i-- ) {
|
||||
name = cssPrefixes[ i ] + capName;
|
||||
if ( name in emptyStyle ) {
|
||||
return name;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Return a potentially-mapped jQuery.cssProps or vendor prefixed property
|
||||
function finalPropName( name ) {
|
||||
var final = jQuery.cssProps[ name ] || vendorProps[ name ];
|
||||
|
||||
if ( final ) {
|
||||
return final;
|
||||
}
|
||||
if ( name in emptyStyle ) {
|
||||
return name;
|
||||
}
|
||||
return vendorProps[ name ] = vendorPropName( name ) || name;
|
||||
}
|
||||
|
||||
return finalPropName;
|
||||
|
||||
} );
|
@ -1,7 +1,9 @@
|
||||
define( [
|
||||
"../core",
|
||||
"../css/finalPropName",
|
||||
|
||||
"../css"
|
||||
], function( jQuery ) {
|
||||
], function( jQuery, finalPropName ) {
|
||||
|
||||
"use strict";
|
||||
|
||||
@ -84,9 +86,9 @@ Tween.propHooks = {
|
||||
// Use .style if available and use plain properties where available.
|
||||
if ( jQuery.fx.step[ tween.prop ] ) {
|
||||
jQuery.fx.step[ tween.prop ]( tween );
|
||||
} else if ( tween.elem.nodeType === 1 &&
|
||||
( tween.elem.style[ jQuery.cssProps[ tween.prop ] ] != null ||
|
||||
jQuery.cssHooks[ tween.prop ] ) ) {
|
||||
} else if ( tween.elem.nodeType === 1 && (
|
||||
jQuery.cssHooks[ tween.prop ] ||
|
||||
tween.elem.style[ finalPropName( tween.prop ) ] != null ) ) {
|
||||
jQuery.style( tween.elem, tween.prop, tween.now + tween.unit );
|
||||
} else {
|
||||
tween.elem[ tween.prop ] = tween.now;
|
||||
|
Loading…
Reference in New Issue
Block a user