Skip to content

Commit

Permalink
Remove polyfills, T-14767
Browse files Browse the repository at this point in the history
  • Loading branch information
ronilaukkarinen committed Dec 4, 2024
1 parent b0e5e5f commit c5041bd
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 3,241 deletions.
1 change: 0 additions & 1 deletion .jshintignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ gulp/*.js
gulp/*/*.js
js/prod/*.js
js/dev/*.js
js/src/legacy.js
js/src/modules/lazyload.js
js/src/modules/sticky-nav.js
js/src/modules/navigation.js
4 changes: 0 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -218,10 +218,6 @@ All .js files in `/js/src/*` is built to production bundles in `/js/prod/` folde

If you want to add a piece of custom JS, create a file under `/js/src/modules/` and import or require it in `/js/src/front-end.js`. If you need a admin-specific JS, add a `/js/src/admin.js` and then enqueue `/js/dist/admin.js` with `enqueue_admin_scripts`

#### Legacy support

Our build uses babel to translate scripts to ES2015 compatible JS, so you can use modern JS syntax without thinking about backwards compatibility. There is a `/js/src/legacy.js` file, which contains the needed polyfills for browsers not supporting the ES2015 syntax and is automatically loaded on the header when such browser is detected.

#### Linter

We use [Airbnb](https://github.com/airbnb/javascript) es-lint presets spiced up with our own flavors.
Expand Down
1 change: 0 additions & 1 deletion inc/hooks.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@
* Scripts and styles associated hooks
*/
require get_theme_file_path( 'inc/hooks/scripts-styles.php' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_polyfills' );
add_action( 'wp_enqueue_scripts', __NAMESPACE__ . '\enqueue_theme_scripts' );

// NB! If you use ajax functionality in Gravity Forms, remove this line
Expand Down
28 changes: 0 additions & 28 deletions inc/hooks/scripts-styles.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,34 +61,6 @@ function enqueue_theme_scripts() {
wp_localize_script( 'scripts', 'air_light_externalLinkDomains', THEME_SETTINGS['external_link_domains_exclude'] );
} // end air_light_scripts

/**
* Load polyfills for legacy browsers
*/
function enqueue_polyfills() {
// Include polyfills
$script = '
var supportsES6 = (function () {
try {
new Function("(a = 0) => a");
return true;
} catch (err) {
return false;
}
}());
var legacyScript ="' . esc_url( get_theme_file_uri( get_asset_file( 'legacy.js' ) ) ) . '";
if (!supportsES6) {
var script = document.createElement("script");
script.src = legacyScript;
document.head.appendChild(script);
}';

if ( file_exists( get_theme_file_path( get_asset_file( 'legacy.js' ) ) ) ) {
wp_register_script( 'air_light_legacy', '', [], filemtime( get_theme_file_path( get_asset_file( 'legacy.js' ) ) ), false );
wp_enqueue_script( 'air_light_legacy' );
wp_add_inline_script( 'air_light_legacy', $script, true );
}
} // end enqueue_polyfills

/**
* Returns the built asset filename and path depending on
* current environment.
Expand Down
3,199 changes: 0 additions & 3,199 deletions js/dev/legacy.js

This file was deleted.

2 changes: 1 addition & 1 deletion js/prod/front-end.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion js/prod/legacy.js

This file was deleted.

6 changes: 0 additions & 6 deletions js/src/legacy.js

This file was deleted.

0 comments on commit c5041bd

Please sign in to comment.