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

Pull Scripts out of PHP & Begin removing jQuery dependency #236

Merged
merged 49 commits into from May 3, 2021

Conversation

jblz
Copy link
Contributor

@jblz jblz commented Apr 19, 2021

This is the first pass at pulling the plugin JavaScript out of PHP files and into enqueued assets.

The widget script is not included in this change as this PR was already getting pretty large. In addition, rewriting it with vanilla JavaScript is not a trivial effort and we're considering re-working it anyhow.

As such, this does not fully complete #134 or #158, but it's at least a step in that direction.

Additionally, we're able to use the WordPress i18n tooling to wrap a string in the Admin page JS for translation (see 3c62c8d). Again, it doesn't fully satisfy #160, but it paves the way for doing so.

To Test

Automated Tests

  • changes should be correct and comprehensive
  • Automated tests should pass

Building the Assets

Test the plugin

  • The tracking pixel should be correctly enqueued
  • The API initialization script should be correctly enqueued
  • The Admin JS should be correctly enqueued
  • The Admin CSS should be correctly applied
  • The Recommended Content widget loading should be unaffected
  • Recommended content should be appropriately displayed
  • In general, there should be no changes that are noticeable to end users by virtue of this change (unless they open their dev tools panel 😄)

@jblz jblz self-assigned this Apr 19, 2021
@jblz jblz force-pushed the remove/jquery-dependency branch 4 times, most recently from 08d7f75 to 22f6e43 Compare April 22, 2021 17:57
@jblz jblz requested a review from a team April 22, 2021 18:02
@jblz jblz added this to the 2.5.0 milestone Apr 22, 2021
@jblz jblz marked this pull request as ready for review April 22, 2021 18:02
Comment on lines 1 to 7
function uuidProfileCall( { apikey, uuid } ) {
const profileScript = document.createElement( 'script' );
profileScript.src = `https://api.parsely.com/v2/profile?apikey=${ encodeURIComponent(
apikey
) }&uuid=${ uuid || '' }&url=${ window.location.href }&callback=&_=${ +new Date() }`;
document.querySelector( 'head' ).appendChild( profileScript );
}
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is the part I'm least confident about. I'm attempting to replace this "jsonp" call:

function uuidProfileCall() {
var rootUrl = 'https://api.parsely.com/v2/profile?apikey=<?php echo esc_html( $parsely_options['apikey'] ); ?>';
var uuid = '&uuid=' + PARSELY.config.parsely_site_uuid;
var requestUrl = rootUrl + uuid + '&url=' + window.location.href;
jQuery.ajax({
url: requestUrl,
dataType: "jsonp"
});
}

...which isn't obvious to me how it's used or what it does. @hbbtstar -- can you shed any light on this?

Copy link
Contributor

Choose a reason for hiding this comment

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

As per the internal P2 post, CORS support in browsers is now enough, that JSONP isn't needed any more.

@jblz jblz requested a review from jase-d-ace April 22, 2021 18:20
@jblz jblz changed the title WIP: Pull Scripts out of PHP & Begin removing jQuery dependency Pull Scripts out of PHP & Begin removing jQuery dependency Apr 22, 2021
Copy link
Contributor

@GaryJones GaryJones left a comment

Choose a reason for hiding this comment

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

I love where this is going!

Added a few comments, including 3-4 items that we may want to spin up into separate issues/PRs, if you don't want to address them in this one.

build/admin-page.asset.php Outdated Show resolved Hide resolved
class-parsely-recommended-widget.php Outdated Show resolved Hide resolved
package.json Outdated Show resolved Hide resolved
src/lib/admin-page/index.js Outdated Show resolved Hide resolved
tests/all-test.php Outdated Show resolved Hide resolved
tests/all-test.php Outdated Show resolved Hide resolved
tests/all-test.php Outdated Show resolved Hide resolved
wp-parsely.php Outdated Show resolved Hide resolved
wp-parsely.php Outdated Show resolved Hide resolved
wp-parsely.php Outdated
}

if ( $handle === 'wp-parsely-tracker' ) {
$tag = preg_replace( '/ id=(\"|\')wp-parsely-tracker-js\1/', ' id="parsely-cfg"', $tag );
Copy link
Contributor

Choose a reason for hiding this comment

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

Do we know why this change of ID is needed?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I really don't know. This is another case of trying to not break anything without understanding why it is the way it is.

@hbbtstar -- any thoughts as to the necessity of having particular id attributes to the script tags?

tests/class-testutils.php Outdated Show resolved Hide resolved
src/class-parsely.php Outdated Show resolved Hide resolved
src/js/lib/admin-page/index.js Outdated Show resolved Hide resolved
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.

None yet

3 participants