-
Notifications
You must be signed in to change notification settings - Fork 798
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Widgets: Migrate front-end jQuery code to vanilla JS #14910
Conversation
Thank you for the great PR description! When this PR is ready for review, please apply the Scheduled Jetpack release: April 7, 2020. |
568ea08
to
6e50664
Compare
@kienstra Could you please review this when you have a moment? |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var Milestone = function( args ) { | ||
var $widget = $( '#' + args.id ), | ||
var widget = document.getElementById( args.id ), | ||
id = args.id, | ||
refresh = args.refresh * 1000; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't about your work, but a general comment about the widget. This diff didn't cause the issue.
What do you think about exiting here if ! widget
?
if ( ! widget ) {
return;
}
It looks like in Twenty Twenty, widgets don't have an id:
...so the var widget = document.getElementById( args.id )
will be null
.
Though maybe this isn't a problem in other themes. For example, Twenty Sixteen works fine:
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah, nice! You're ahead of the game, sorry for missing that issue.
success: function( result ) { | ||
$widget.find( '.milestone-countdown' ).replaceWith( result.message ); | ||
refresh = result.refresh * 1000; | ||
xhr.onload = function() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice use of xhr
instead of $.ajax
, this worked well when stepping through this in the browser.
jetpackSearchModuleSorting(); | ||
} else { | ||
document.addEventListener( 'DOMContentLoaded', jetpackSearchModuleSorting ); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice alternative to jQuery( document ).ready()
orderBy.value = values[0]; | ||
order.value = values[1]; | ||
|
||
form.submit(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
PR Looks good to me!
I've tested all the scenarios described and everything worked as expected. I also looked at the code. All good.
I've opened #15009 to suggest an improvement to the widget. It's not related to this PR, but I found this out while testing it.
Caution: This PR has changes that must be merged to WordPress.com |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This tests well for me. Merging.
* Initial changelog entry * Changelog: add #14904 * Changelog: add #14910 * Changelog: add #14913 * Changelog: add #14916 * Changelog: add #14922 * Changelog: add #14924 * Changelog: add #14925 * Changelog: add #14928 * Changelog: add #14840 * Changelog: add #14841 * Changelog: add #14842 * Changelog: add #14826 * Changelog: add #14835 * Changelog: add #14859 * Changelog: add #14884 * Changelog: add #14888 * Changelog: add #14817 * Changelog: add #14814 * Changelog: add #14819 * Changelog;: add #14797 * Changelog: add #14798 * Changelog: add #14802 * Changelog: add #13676 * Changelog: add #13744 * Changelog: add #13777 * Changelog: add #14446 * Changelog: add #14739 * Changelog: add #14770 * Changelog: add #14784 * Changelog: add #14897 * Changelog: add #14898 * Changelog: add #14968 * Changelog: add #14985 * Changelog: add #15044 * Changelog: add #15052 * Update to remove Podcast since it remains in Beta * Changelog: add #14803 * Changelog: add #15028 * Changelog: add #15065 * Changelog:add #14886 * Changelog: add #15118 * Changelog: add #14990 * Changelog: add #14528 * Changelog: add #15120 * Changelog: add #15126 * Changelog: add #15049 * Chanegelog: add #14852 * Changelog: add #15090 * Changelog: add #15138 * Changelog: add #15124 * Changelog:add #15055 * Changelog: add #15017 * Changelog: add #15109 * Changelog: add #15145 * Changelog:add #15096 * Changelog:add #15153 * Changelog: add #15133 * Changelog: add #14960 * Changelog: add #15127 * Changelog: add #15056 * Copy current changelog to changelog archive. * Clarify changelog description
These pieces of the codebase have been reviewed:
/modules/widget-visibility
/modulels/widgets/*
These widgets are using jQuery in some capacity:
social-icons
: In the admin context only.simple-payments
: In the admin context only.contact-info
: In the admin context only.search
: Ordering + filters functionality on the front-end + admin context.eu-cookie-law
: In the admin context only. (Frontend handled by @kienstra in https://github.com/Automattic/jetpack/pull/14753/files)milestone
: Dynamic countdown on the front-end + admin context.gravatar-profile
: In the admin context only.gallery
: FE + admin context, but not addressed, because the widget is not available in WP 4.9+ (superseded by the core gallery widget).rsslinks
: In the admin context only.customizer-utils
: In the admin context only.twitter-timeline
: In the admin context only.The two widgets in bold have been converted to vanilla JS. Others are either not relevant anymore (
gallery
) or use jQuery in the admin context only, which was not in scope for this PR.It doesn't seem like a good use of development time to rewrite the admin jQuery scripts because jQuery is arguably going to remain to be loaded in the admin context for a long time. However if this assumption is incorrect and we want to fully strip all jQuery code, please let me know.
Fixes #14864
Changes proposed in this Pull Request:
search
andmilestone
widgets.Is this a new feature or does it add/remove features to an existing part of Jetpack?
Testing instructions:
twentytwenty
(and potentially other themes) and pick a there that exposes the widget ID. Failing to do that will lead to the widget not updating on the front-end.Tested in:
Proposed changelog entry for your changes: