Replace deprecated jQuery methods
Before submitting an issue please check that you’ve completed the following steps:
- Made sure you’re on the latest version
- Used the search feature to ensure that the bug hasn’t been reported before
Describe the bug
When checking on WordPress 5.7 + SCRIPT_DEBUG defined, we're getting the following warnings:
JQMIGRATE: jQuery.fn.removeAttr no longer sets boolean properties: disabled in pricing-modal.js
JQMIGRATE: jQuery.fn.focus() event shorthand is deprecated in admin.js
To Reproduce Steps to reproduce the behavior:
- Update to WordPress 5.7 beta
- Add
define( 'SCRIPT_DEBUG', true );to wp-config.php - Go to the Imagify settings with JS console opened and click on the
What Plan do I need - See an error
Expected behavior We should be compatible with the new jQuery version
Additional context Wasn't able to find any other deprecations but we should recheck this carefully.
Backlog Grooming (for WP Media dev team use only)
- [x] Reproduce the problem
- [x] Identify the root cause
- [x] Scope a solution
- [x] Estimate the effort
Reproduced ✅
The jQuery.fn.removeAttr appears on page load.
In addition, on page load I get the following warning:
Source map error: Error: request failed with status 404
Resource URL: https://rocket.local/wp-content/plugins/imagify/assets/js/es6-promise.auto.js?ver=1616422431
Source Map URL: es6-promise.auto.map
The jQuery.fn.focus() warning is triggered when clicking the "What Plan do I Need" button.
Root Cause
- In the case of
jQuery.fn.removeAttrtheassets/js/pricing-modal.jsisdoing_it_wrongon L:244:
$('#imagify-modal-checkout-btn').removeAttr('disabled').removeClass('imagify-button-disabled');
incorrectly uses removeAttr(); it should be prop('disabled, false)
NOTE: Not in OP, and not currently causing a warning, but just above this on L:242 is also doing_it_wrong:
$('#imagify-modal-checkout-btn').attr('disabled', 'disabled').addClass('imagify-button-disabled');
should replace attr(...) with prop('disabled', true).
- In the case of
jQuery.fn.focus()theassets/js/admin.jsis using the deprecatedfocus()method on L:21. Updating to
} ).trigger('focus').removeAttr( 'tabindex' ).addClass( 'modal-is-open' );
resolves the deprecation.
There is a second use of focus() on L:21 -
} ).focus().removeAttr( 'tabindex' ).addClass( 'modal-is-open' );
Which should also be updated to:
} ).trigger('focus').removeAttr( 'tabindex' ).addClass( 'modal-is-open' );
- In the case of
es6-promise.auto.map, theassets/js/es6-promise.auto.map.jsincludes a reference to this map file from what appears to be the https://github.com/components/es6-promise package, but the map file is not included in the imagify assets. Since the reference to the map file is for debugging in the other package, the reference to it can be removed from the imagify version of the file to clear the 404.
Following these changes, the grunt js task should be run to recompile the minified js files for production.
Estimate Effort: [S]
can see the deprecation warnings on imagify 2.2.4