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

Remove jQuery from CoBlocks #2276

Merged
merged 7 commits into from
Feb 16, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
44 changes: 0 additions & 44 deletions .dev/tests/phpunit/includes/test-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -353,48 +353,4 @@ public function test_typography_styles_loaded_with_core_quote_block() {

$this->assertContains( 'coblocks-frontend', $wp_styles->queue );
}

/**
* Test the frontend scripts masonry are enqueued correctly
*/
public function test_frontend_scripts_masonry() {
global $post, $wp_scripts;

$post_id = wp_insert_post( [
'post_author' => 1,
'post_content' => '<!-- wp:coblocks/gallery-masonry /-->',
'post_title' => 'CoBlocks Masonry',
'post_status' => 'publish',
] );

$this->go_to( "/?p={$post_id}" );
$post = get_post( $post_id );

$this->coblocks_block_assets->frontend_scripts();
do_action( 'wp_enqueue_scripts' );

$this->assertContains( 'coblocks-masonry', $wp_scripts->queue );
}

/**
* Test the frontend scripts carousel are enqueued correctly
*/
public function test_frontend_scripts_carousel() {
global $post, $wp_scripts;

$post_id = wp_insert_post( [
'post_author' => 1,
'post_content' => '<!-- wp:coblocks/gallery-carousel /-->',
'post_title' => 'CoBlocks Carousel',
'post_status' => 'publish',
] );

$this->go_to( "/?p={$post_id}" );
$post = get_post( $post_id );

$this->coblocks_block_assets->frontend_scripts();
do_action( 'wp_enqueue_scripts' );

$this->assertContains( 'coblocks-flickity', $wp_scripts->queue );
}
}
4 changes: 0 additions & 4 deletions .dev/tests/phpunit/test-class-coblocks.php
Original file line number Diff line number Diff line change
Expand Up @@ -189,16 +189,12 @@ public function test_final_build_assets_exist() {
'dist/js/coblocks-google-maps.js',
'dist/js/coblocks-google-recaptcha.js',
'dist/js/coblocks-lightbox.js',
'dist/js/coblocks-masonry.js',
'dist/js/vendors/flickity.js',
'dist/js/vendors/slick.js',
'src/js/coblocks-accordion-polyfill.js',
'src/js/coblocks-checkbox-required.js',
'src/js/coblocks-fromEntries.js',
'src/js/coblocks-google-maps.js',
'src/js/coblocks-google-recaptcha.js',
'src/js/coblocks-lightbox.js',
'src/js/coblocks-masonry.js',
],
'css' => [
'dist/coblocks-1.css',
Expand Down
29 changes: 0 additions & 29 deletions includes/class-coblocks-block-assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -352,17 +352,6 @@ public function frontend_scripts() {
true
);

// Masonry block.
if ( $this->is_page_gutenberg() || has_block( 'coblocks/gallery-masonry' ) || has_block( 'core/block' ) ) {
wp_enqueue_script(
'coblocks-masonry',
$dir . 'coblocks-masonry.js',
array( 'jquery', 'masonry', 'imagesloaded' ),
COBLOCKS_VERSION,
true
);
}
Comment on lines -356 to -364
Copy link
Member

Choose a reason for hiding this comment

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

I think we still need this because the v2 Masonry block is not compatible with WordPress version below 5.7.2. We allow users to use both versions of the block using a special wrapper and we need to keep the old logic around for that purpose.

Copy link
Member

Choose a reason for hiding this comment

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

No, we are good on this I suppose. Turns out the Masonry block broke with 5.6 somewhere along the way. Let us go ahead and get this in and then we will have to look at that Masonry block later.


// Carousel block.
if ( $this->is_page_gutenberg() || has_block( 'coblocks/gallery-carousel' ) || has_block( 'core/block' ) ) {
wp_enqueue_script(
Expand All @@ -380,24 +369,6 @@ public function frontend_scripts() {
COBLOCKS_VERSION,
true
);

wp_enqueue_script(
'coblocks-flickity',
$vendors_dir . '/flickity.js',
array( 'jquery' ),
COBLOCKS_VERSION,
true
);

if ( $this->is_page_gutenberg() || has_block( 'coblocks/accordion' ) || has_block( 'core/block' ) ) {
wp_enqueue_script(
'coblocks-accordion-carousel',
$dir . 'coblocks-accordion-carousel.js',
array( 'coblocks-flickity' ),
COBLOCKS_VERSION,
true
);
}
}

// Post Carousel block.
Expand Down
4 changes: 2 additions & 2 deletions includes/class-coblocks-form.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,15 +119,15 @@ public function form_recaptcha_assets() {
wp_enqueue_script(
'google-recaptcha',
'https://www.google.com/recaptcha/api.js?render=' . esc_attr( $recaptcha_site_key ),
array( 'jquery' ),
array(),
'3.0.0',
true
);

wp_enqueue_script(
'coblocks-google-recaptcha',
CoBlocks()->asset_source( 'js' ) . 'coblocks-google-recaptcha.js',
array( 'jquery', 'google-recaptcha' ),
array( 'google-recaptcha' ),
COBLOCKS_VERSION,
true
);
Expand Down
2 changes: 1 addition & 1 deletion includes/class-coblocks-google-map-block.php
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ public function map_assets() {
wp_enqueue_script(
$this->slug . '-google-maps',
$dir . $this->slug . '-google-maps.js',
array( 'jquery' ),
array(),
COBLOCKS_VERSION,
true
);
Expand Down
5 changes: 0 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,6 @@
"eslint-plugin-cypress": "^2.10.3",
"esm": "^3.2.25",
"expect-puppeteer": "^6.0.2",
"flickity": "^2.3.0",
"grunt": "^1.1.0",
"grunt-contrib-clean": "^2.0.0",
"grunt-contrib-compress": "^2.0.0",
Expand All @@ -143,7 +142,6 @@
"jest-environment-puppeteer": "^6.0.2",
"jest-junit": "13.0.0",
"jest-snapshot": "^27.4.5",
"jquery": "^3.4.1",
"jsdom": "^16.7.0",
"lint-staged": "^12.1.1",
"lodash": "^4.17.21",
Expand All @@ -153,12 +151,9 @@
"prettier": "^2.5.1",
"prop-types": "^15.8.1",
"puppeteer": ">=1.19.0",
"react-flickity-component": "^3.4.0",
"react-masonry-component": "^6.2.1",
"react-slick": "^0.28.1",
"rtlcss-webpack-plugin": "^4.0.6",
"simple-git": "^2.48.0",
"slick-carousel": "^1.8.1",
"tiny-swiper": "^2.1.2",
"uuid": "^8.3.2"
},
Expand Down
2 changes: 1 addition & 1 deletion src/blocks/icon/svgs-generated.js
Original file line number Diff line number Diff line change
Expand Up @@ -2836,7 +2836,7 @@ const svgs = {
/* translators: icon keyword */
__('person', 'coblocks'),
/* translators: icon keyword */
__('speech', 'coblocks'),
__('speach', 'coblocks'),
/* translators: icon keyword */
__('speak', 'coblocks'),
/* translators: icon keyword */
Expand Down
33 changes: 0 additions & 33 deletions src/js/coblocks-accordion-carousel.js

This file was deleted.

17 changes: 0 additions & 17 deletions src/js/coblocks-masonry.js

This file was deleted.

4 changes: 0 additions & 4 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ const path = require( 'path' );
const fs = require( 'fs' );

const scripts = [
'coblocks-accordion-carousel',
'coblocks-accordion-polyfill',
'coblocks-animation',
'coblocks-checkbox-required',
Expand All @@ -21,7 +20,6 @@ const scripts = [
'coblocks-google-maps',
'coblocks-google-recaptcha',
'coblocks-lightbox',
'coblocks-masonry',
'coblocks-post-carousel',
'coblocks-tinyswiper-initializer',
];
Expand All @@ -45,8 +43,6 @@ module.exports = {
}, {} ),

// Vendors
'js/vendors/flickity': path.resolve( process.cwd(), 'node_modules/flickity/dist/flickity.pkgd.js' ),
'js/vendors/slick': path.resolve( process.cwd(), 'node_modules/slick-carousel/slick/slick.js' ),
'js/vendors/tiny-swiper': path.resolve( process.cwd(), 'node_modules/tiny-swiper/lib/index.js' ),
},

Expand Down
Loading