Skip to content

Conversation

Crabcyborg
Copy link
Contributor

@Crabcyborg Crabcyborg commented Dec 7, 2020

This is a pretty good first go of the jquery deprecation warnings in the free plugin. I think some other shorthand stuff might be missing, but I looked over all of the previous deprecations and I think this covers mostly everything in our code (excluding some third party stuff we're using).

  • Changes jQuery( element ).submit() to just a new triggerSubmit function (vanilla solution).
  • Added a new function to replace https://api.jquery.com/jQuery.isNumeric/ as it is deprecated since 3.3
  • Changes .submit listeners which are now deprecated for .on( 'submit' that isn't (which is still jQuery), because jQuery.fn.submit() event shorthand is deprecated
  • Changes jQuery.trim() for vanilla string.trim() as it is deprecated since 3.5 https://api.jquery.com/jQuery.trim/
  • As of 3.4 pseudo selectors are all deprecated https://api.jquery.com/category/deprecated/deprecated-3.4/ including :lt, :first, and :last
  • loadFields was using the :lt selector, and isFunction (which is deprecated as of 3.3 https://api.jquery.com/jquery.isfunction/), and had much more jQuery dependency than that, and I've removed all of the jQuery from the initial logic 🎉
  • As of 3.0 https://api.jquery.com/jquery.parsejson/ has been deprecated (replaced for vanilla JSON.parse)
  • jQuery.fn.change() event shorthand is deprecated (replaced with .trigger( 'change' ), still jQuery for now)
  • https://api.jquery.com/bind/ is deprecated as of 3.0 (replaced with .on, still jQuery for now)
  • unbind is deprecated as of 3.0 (replaced with .off, still jQuery for now)
  • shorthand mousedown is deprecated (replaced with .on( 'mousedown', still jQuery for now)
  • shorthand click is deprecated (replaced with .trigger( 'click', and .on( 'click', still jQuery for now)
  • https://api.jquery.com/size/ has been removed as of jQuery 3.0 (replaced with jQuery .length)
  • andSelf is removed from jQuery 3.0 (https://api.jquery.com/category/removed/) so I replaced a call with https://api.jquery.com/add/ because I know we had a workaround for supporting andSelf/addBack, and I think this fix is less hacky.
  • Replace jQuery .click/.trigger( 'click' ) with vanilla js .click where the change is simple enough.

More about the shorthand deprecations can be found here jquery/jquery#3214 besides that I wasn't finding a lot of resources, but the warnings are all over the place.

I also made a few adjustments to move var declarations to the start of their function scopes to help reduce our number of warnings.

In an effort to reduce jQuery I made new functions triggerSubmit and triggerChange. triggerChange didn't look beautiful without jQuery (and several cases were sending jQuery objects as well), plus it's hard to test, so I'm keeping it dependent on jQuery for now, but it's better to have everything referencing one place that depends on jQuery than it is to have everything.

However, triggerSubmit seems to have a nice workable solution of inserting a hidden button and clicking it, so I've replaced our .submit() shorthands for vanilla js :)

Copy link
Contributor

@jairoprez jairoprez left a comment

Choose a reason for hiding this comment

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

These changes look good to me!

jQuery( document ).on( 'change', '#protect_files', function() {
if ( this.checked ) {
jQuery( '.hide_protect_files' ).fadeIn( 'slow' );
jQuery( '#edit_action' ).change();
Copy link
Contributor Author

@Crabcyborg Crabcyborg Dec 9, 2020

Choose a reason for hiding this comment

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

I just want to point out that I am intentionally just removing this line and a line shortly underneath it. I think I copied too much here when I added the protect files logic. These lines shouldn't have anything to do with file protection.

Copy link
Contributor

@stephywells stephywells left a comment

Choose a reason for hiding this comment

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

This looks good. Just making some notes for a few things we need to make sure get double tested:

  • load fields in builder with ajax with form with more than 20 fields
  • add two logic rows in a field, remove the first one, and add another. Do they both save correctly? Test the same process with watch lookup fields, form actions, form action logic, submit button logic, create post category & meta, order rows in a view, where rows in a view
  • add a page break and collapse page 1 in builder
  • save builder page when ajax save fails, and with ajax builder save turned off

Side note:
looks like some of this js should be copied into views and deprecated here (starting at line 4445)

@stephywells stephywells merged commit 430b5e4 into master Dec 11, 2020
@Crabcyborg Crabcyborg deleted the jquery_deprecation_updates branch March 26, 2021 15:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants