[wp-trac] [WordPress Trac] #51621: jQuery Migrate throws error when an object is specified for the name parameter and number for the value parameter
WordPress Trac
noreply at wordpress.org
Sat Oct 24 18:42:27 UTC 2020
#51621: jQuery Migrate throws error when an object is specified for the name
parameter and number for the value parameter
--------------------------------------+------------------------------
Reporter: mweichert | Owner: (none)
Type: defect (bug) | Status: new
Priority: normal | Milestone: Awaiting Review
Component: Script Loader | Version: trunk
Severity: major | Resolution:
Keywords: has-patch has-unit-tests | Focuses: ui, javascript
--------------------------------------+------------------------------
Comment (by mweichert):
No, not exactly.
jQuery has deprecated number values being passed to jQuery.fn.css:
https://github.com/jquery/jquery-migrate/blob/master/warnings.md
#jqmigrate-number-typed-values-are-deprecated-for-jqueryfncss-property-
name-value-
E.g.
This call should trigger a "Number-typed values are deprecated for
jQuery.fn.css" warning:
{{{
jQuery('<div/>').css('width', 30); // implicit px
}}}
The above behaviour is working correctly.
However, you can also make these calls to jQuery.fn.css:
{{{
jQuery('<div/>').css({width: "30%"});
jQuery('<div/>').css({width: "30%"}, 300); // <- note this use
}}}
jQuery UI Slider will make use of the noted call above when the animate
setting is set. See this fiddle I created as an example:
https://jsfiddle.net/mweichert/784kjmoh/17/
Because Iris uses the animate setting for the slider, it will also trigger
this jQuery.fn.css call.
As a reminder, jQuery.fn.css accepts two parameters called "name" and
"value".
jQuery Migrate mistakenly assumes that "name" is a string when "value" is
a number, which will throw an exception when the .replace() method is
called on name via the camelCase function which jQuery Migrate provides:
{{{
jQuery.fn.css = function( name, value ) {
var camelName,
origThis = this;
if ( name && typeof name === "object" && !Array.isArray( name ) )
{
jQuery.each( name, function( n, v ) {
jQuery.fn.css.call( origThis, n, v );
} );
}
if ( typeof value === "number" ) {
camelName = camelCase( name ); // throws error because
name is not a string
if ( !isAutoPx( camelName ) && !jQuery.cssNumber[
camelName ] ) {
migrateWarn( "Number-typed values are deprecated
for jQuery.fn.css( \"" +
name + "\", value )" );
}
}
return oldFnCss.apply( this, arguments );
};
}}}
Hopefully that helps. Let me know if there's any more questions. I should
maybe also create an issue for jQuery UI Slider, as its also a fault on
their end, but for migration reasons, jquery-migrate needs to adjust here
as well as jQuery 1.12.1 and earlier will be commonly used for a while.
--
Ticket URL: <https://core.trac.wordpress.org/ticket/51621#comment:4>
WordPress Trac <https://core.trac.wordpress.org/>
WordPress publishing platform
More information about the wp-trac
mailing list