Skip to content
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

Fix jQuery warnings as WordPress upgraded it from 1.12.4-wp to 3.5.1 #649

Merged
merged 4 commits into from
Jun 9, 2021

Conversation

htdat
Copy link
Member

@htdat htdat commented May 18, 2021

Fix #632


Description

This PR has done these changes to fix all warnings:

Old New Ref
jQuery.expr[':'] jQuery.expr.pseudos
.click(fn) .on("click", fn) Reference
.click() .trigger("click") Reference
.hover(fn1, fn2) .on("mouseenter", fn1).on("mouseleave", fn2) Reference
removeAttr('selected'); prop( 'selected', false ); Reference
.attr('selected'); .prop( 'selected', true ); Reference
.bind .on Reference
$('.myButton').live('click', function) $( document ).on('click', '.myButton', function) Reference

The following events are changed similarly to click above: blur, focus, focusin, focusout, resize, scroll, dblclick, mousedown, mouseup, mousemove, mouseover, mouseout, mouseenter, mouseleave, change, select, submit, keydown, keypress, keyup, and contextmenu. - ref

Steps to Test

Markup on 2021-06-03 at 13:58:07

  • Visit the following pages to see the issue:
  1. http://site.test/wp-admin/index.php?page=calendar
  2. http://site.test/wp-admin/index.php?page=story-budget
  3. All pages under Edit Flow menu in wp-admin http://site.test/wp-admin/admin.php?page=ef-settings
  4. Page listing all posts http://site.test/wp-admin/edit.php
  5. Block and Classic editor pages for a post
  • Apply this PR.
  • Open tab Console in your browser.
  • Vist all pages above
  • Expect that there is no more warning regarding Edit Flow in wp-admin, and no errors in Console tab.

Note

You may apply this diff so that we can avoid the cache busting issue in browsers.

Index: edit_flow.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
--- edit_flow.php	(revision 883e80484e860bbd12aced41c4d4eca733344027)
+++ edit_flow.php	(date 1621319608357)
@@ -46,7 +46,7 @@
 }
 
 // Define contants
-define( 'EDIT_FLOW_VERSION' , '0.9.6' );
+define( 'EDIT_FLOW_VERSION' , '0.9.7-dev-' . time() );
 define( 'EDIT_FLOW_ROOT' , dirname(__FILE__) );
 define( 'EDIT_FLOW_FILE_PATH' , EDIT_FLOW_ROOT . '/' . basename(__FILE__) );
 define( 'EDIT_FLOW_URL' , plugins_url( '/', __FILE__ ) );

@mikeyarce
Copy link
Member

@htdat I did test and I can see that the warnings no longer show up, that's great!

I'm wondering though, how can we make sure that all the functionality is still the same? Do you have any steps to test for each change, or do we have any automated tests for those?

Do we need to test across different browsers, operating systems, versions of WP?

Copy link
Member

@nielslange nielslange left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I still see the warnings on two pages.

  1. http://editflow.local/wp-admin/index.php?page=calendar:

⚠️ JQMIGRATE: jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos
⚠️ JQMIGRATE: jQuery.isArray is deprecated; use Array.isArray
⚠️ JQMIGRATE: jQuery.isFunction() is deprecated
⚠️ JQMIGRATE: jQuery.unique is deprecated; use jQuery.uniqueSort

  1. http://editflow.local/wp-admin/index.php?page=story-budget:

⚠️ JQMIGRATE: jQuery.expr[':'] is deprecated; use jQuery.expr.pseudos

Do these warning not appear on your end? I also added define( 'EDIT_FLOW_VERSION' , '0.9.7-dev-' . time() ); to ensure that I'm not facing a caching problem while testing. Yet, on these two pages, the warnings remain.

@htdat
Copy link
Member Author

htdat commented Jun 3, 2021

Thanks for your review, @nielslange!

I still see the warnings on two pages.

When looking at console trace, you can see that these warnings are not from Edit Flow. Therefore, we're not concerned about them:

Markup on 2021-06-03 at 13:51:21

@htdat
Copy link
Member Author

htdat commented Jun 3, 2021

@mikeyarce

I'm wondering though, how can we make sure that all the functionality is still the same? Do you have any steps to test for each change, or do we have any automated tests for those?

Well, that's tricky! We do not have automated tests for all of these jQuery changes. I am going to go through each of the changes and write up steps for testing. It looks like that for now https://d.pr/i/x8b4pQ

I have reviewed 5/12 files today. I am changing this PR to Draft. After finishing the reviews for all 12 files, I will move it back.

Do we need to test across different browsers, operating systems, versions of WP?

Basically, this PR follows up all official guidelines from jQuery, I think testing in one environment (one browser, OS, and WP) is enough. Otherwise, if an issue happens, its cause is likey from jQuery, browser, OS, or WP.

@htdat htdat marked this pull request as draft June 3, 2021 10:00
Copy link
Member Author

@htdat htdat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Write down all possible test cases.

@@ -6,19 +6,19 @@ inlineEditUsergroup = {

t.what = '#usergroup-';

$('.editinline').live('click', function(){
$( document ).on( 'click', '.editinline', function(){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ if we're able to see relevant fields to update this group.

Markup on 2021-06-03 at 14:07:50

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks good but I found a bug related to this: #654

inlineEditUsergroup.edit(this);
return false;
});

// prepare the edit row
row.keyup(function(e) { if(e.which == 27) return inlineEditUsergroup.revert(); });
row.on( 'keyup', function(e) { if(e.which == 27) return inlineEditUsergroup.revert(); });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ if we press Escape key and the Quick Edit fields are closed and their values are reset.

Note: e.which == 27 here is equal to pressing "Escapce" key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +17 to +19
$('a.cancel', row).on( 'click', function() { return inlineEditUsergroup.revert(); });
$('a.save', row).on( 'click', function() { return inlineEditUsergroup.save(this); });
$('input, select', row).on( 'keydown', function(e) { if(e.which == 13) return inlineEditUsergroup.save(this); });
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ if we click Cancel button and the Quick Edit fields are closed and their values are reset.
✅ if we click Update User Group button and the Quick Edit fields are saved then closed.
✅ if we press Enter key and the Quick Edit fields are saved then closed.

Note: e.which == 13 is for the Enter key.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.


$('#posts-filter input[type="submit"]').mousedown(function(e){
$('#posts-filter input[type="submit"]').on( 'mousedown', function(e){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This seems redundant as there is no element with this ID posts-filter in this page http://valet-vipgo-3279.test/wp-admin/admin.php?page=ef-user-groups-settings

Then this event is not triggered.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah this seems redundant. It looks like other pages like wp-admin/admin.php?page=ef-editorial-metadata-settings use this but not User Groups

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #664

Comment on lines +5 to +6
$("#toggle_details").on( 'click', function() {
$(".post-title > p").toggle('hidden');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

TODO

I am going to remove this function as I am not able to find any element for $("#toggle_details"):

jQuery("#toggle_details")

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like toggle_details was removed here:
95c6874

Safe to remove from this! ✅

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #663

@@ -50,7 +50,7 @@
var $filterTab = $('<li/>')
.text(filter.label)
.attr(options._filterIdAttr, i)
.bind('click', _filterTabEvent)
.on('click', _filterTabEvent)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Try editing a post.
  • Find the Notifications section at the bottom.

✅ if we can click All and Selected and they act properly.

Markup on 2021-06-04 at 15:41:44

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment on lines +68 to +70
.on('search', _filterInputSearch)
.on('keydown', _filterInputKeydown)
.on('keyup', _filterInputKeyup)
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Try editing a post.
  • Find the Notifications section at the bottom.

✅ if we type some letters in the Search field and the list below will be filtered in accordance with.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -76,7 +76,7 @@
$input
.addClass(options.inputPlaceholderClass)
.val(options.inputPlaceholder)
.focus(function() {
.on( 'focus', function() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

See the comment in the L74 above:

// Fallback for browsers that don't support placeholders

I think this is a very low risk and we do not need a test case for it. Because it's difficult to find a browser not supporting placeholder nowadays: https://caniuse.com/input-placeholder

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -14,7 +14,7 @@

// We need :contains to be case insensitive so lets redefine it as containsi (i for case insensitive)
// http://stackoverflow.com/questions/187537/is-there-a-case-insensitive-jquery-contains-selector
jQuery.expr[':'].containsi = function(a, i, m){
jQuery.expr.pseudos.containsi = function(a, i, m){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

  • Try editing a post.
  • Find the Notifications section at the bottom.
  • Search for both upper and lower cases for a specific user.

✅ if the filtered list always returns a result no matter the search input is upper or lower case.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@@ -251,7 +251,7 @@
if (o.altField) {
tp_inst.$altInput = $(o.altField).css({
cursor: 'pointer'
}).focus(function() {
}).on ( 'focus', function() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a library and it's being used for the Date field in Editorial Metadata module - related PR #169
We can see it in action when editing a post.

I see that the author has not changed this yet. I tried finding a way to test this file but it's not clear how I can replicate these events.

https://github.com/trentrichardson/jQuery-Timepicker-Addon/blob/7160ce59c660462f4d3379951f1e141131bcb02c/src/jquery-ui-timepicker-addon.js#L287

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hmmm yeah this is a tough one....

I think as long as the date picker works we're good. I tested it on the post editing screen and it worked for me.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The author no longer maintains this library so I've created a new GH issue on our end to replace it.

#660

@htdat htdat marked this pull request as ready for review June 4, 2021 10:19
@htdat
Copy link
Member Author

htdat commented Jun 4, 2021

@mikeyarce and @nielslange I've found out all the test cases for most changes here. Otherwise, I wrote down explanations and my researches for that.

For each of these test cases, I also commented on the code change to verify my test cases correct. I also look at browser console when testing and writing these tests.

To review those tests, it would be better to start here https://github.com/Automattic/Edit-Flow/pull/649/files
Finally, this takes time for manual testing so we can review this together in a call if possible.

@mikeyarce
Copy link
Member

@htdat excellent work with all these test cases and examples! I went through each one and tested them myself and I think this is good to go. I left a few comments about other things that I found but nothing to do with these changes.

I think after merging this what would be nice would be:

  1. Create an issue to track all the code we need to remove (all the unused JS for example)
  2. Create an issue about the datepicker as we might need to find a substitute eventually since that library seems to have not been updated since 2016

What do you think?

@nielslange
Copy link
Member

Thanks for your review, @nielslange!

I still see the warnings on two pages.

When looking at console trace, you can see that these warnings are not from Edit Flow. Therefore, we're not concerned about them:

Oh, I must have missed that, @htdat. In that case, the PR looks good to me.

Copy link
Member Author

@htdat htdat left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've created 4 issues: 661 -> 644 to report issues raised from this PR.

@@ -251,7 +251,7 @@
if (o.altField) {
tp_inst.$altInput = $(o.altField).css({
cursor: 'pointer'
}).focus(function() {
}).on ( 'focus', function() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The author no longer maintains this library so I've created a new GH issue on our end to replace it.

#660

@@ -169,11 +169,11 @@ jQuery(function ($) {

function focus_on_load()
{
$('input[rel="' + options.randomElement + '"]').get(0).focus();
$('input[rel="' + options.randomElement + '"]').get(0).trigger( 'focus' );
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created this issue #661

@@ -82,12 +82,12 @@ jQuery(document).ready(function() {
} else if ( jQuery('select[name="_status"]').length > 0 ) {
ef_append_to_dropdown('select[name="_status"]');
// Refresh the custom status dropdowns everytime Quick Edit is loaded
jQuery('#the-list a.editinline').bind( 'click', function() {
jQuery('#the-list a.editinline').on( 'click', function() {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #662

Comment on lines +5 to +6
$("#toggle_details").on( 'click', function() {
$(".post-title > p").toggle('hidden');
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #663


$('#posts-filter input[type="submit"]').mousedown(function(e){
$('#posts-filter input[type="submit"]').on( 'mousedown', function(e){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #664


$('#posts-filter input[type="submit"]').mousedown(function(e){
$('#posts-filter input[type="submit"]').on( 'mousedown', function(e){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #664


$('#posts-filter input[type="submit"]').mousedown(function(e){
$('#posts-filter input[type="submit"]').on( 'mousedown', function(e){
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Created #664

@htdat
Copy link
Member Author

htdat commented Jun 9, 2021

@mikeyarce and @nielslange - thanks for your reviews!

  1. Create an issue to track all the code we need to remove (all the unused JS for example)
  2. Create an issue about the datepicker as we might need to find a substitute eventually since that library seems to have not been updated since 2016

I've created issues #660 -> #664 to track them. I am going to merge this PR now. 🙌

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

jQuery and WP 5.6: fix warnings
3 participants