From 2b5f5d5e90b37f4a735738a6d0b6f22affbea340 Mon Sep 17 00:00:00 2001 From: Dave Methvin Date: Sat, 24 Feb 2018 17:17:24 -0500 Subject: [PATCH] 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. --- src/css.js | 38 +++----------------------------------- src/css/finalPropName.js | 39 +++++++++++++++++++++++++++++++++++++++ src/effects/Tween.js | 10 ++++++---- 3 files changed, 48 insertions(+), 39 deletions(-) create mode 100644 src/css/finalPropName.js diff --git a/src/css.js b/src/css.js index 43e427472..bef7c7b73 100644 --- a/src/css.js +++ b/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 ) { diff --git a/src/css/finalPropName.js b/src/css/finalPropName.js new file mode 100644 index 000000000..e5c77b0b2 --- /dev/null +++ b/src/css/finalPropName.js @@ -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; + +} ); diff --git a/src/effects/Tween.js b/src/effects/Tween.js index 43eb8fa0b..bf501ead0 100644 --- a/src/effects/Tween.js +++ b/src/effects/Tween.js @@ -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; -- 2.39.5