Skip to content

Commit

Permalink
Handle deferrer script loading
Browse files Browse the repository at this point in the history
  • Loading branch information
MeliEve committed Nov 7, 2023
1 parent 70199fa commit b6380df
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions src/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,15 @@
/* global cf7a_settings, wpcf7 */
'use strict';

window.onload = function () {
function ready( fn ) {
if ( document.readyState !== 'loading' ) {
fn();
return;
}
document.addEventListener( 'DOMContentLoaded', fn );
}

ready( function () {
// disable cf7 antispam script if contact form is not loaded in this page
if ( ! window.wpcf7 ) return;

Expand Down Expand Up @@ -574,4 +582,4 @@ window.onload = function () {
}
}
}
};
} );

0 comments on commit b6380df

Please sign in to comment.