Encapsulate scope of `c` variable

By changing to auto invoking call the `c` variable will be encapsulated in its scope therefore not polluting the global scope and will continue to function as previously.

Fixes conflict and reassigning of already used variables when using other minified scripts. In my case the problem occurred with the Speed Booster Pack plugin.
This commit is contained in:
Martin Adamko 2020-09-08 09:20:18 +02:00 committed by GitHub
parent 6eb65cb40c
commit c2ab6a488d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -348,9 +348,11 @@ function wc_body_class( $classes ) {
function wc_no_js() {
?>
<script type="text/javascript">
var c = document.body.className;
c = c.replace(/woocommerce-no-js/, 'woocommerce-js');
document.body.className = c;
(function () {
var c = document.body.className;
c = c.replace(/woocommerce-no-js/, 'woocommerce-js');
document.body.className = c;
})()
</script>
<?php
}