diff --git a/course/assets/js/hovercard-setup.js b/course/assets/js/hovercard-setup.js new file mode 100644 index 0000000000..3eb6d86a41 --- /dev/null +++ b/course/assets/js/hovercard-setup.js @@ -0,0 +1,8 @@ +document.addEventListener('DOMContentLoaded', () => { + const hovercards = new Gravatar.Hovercards({}); + const elements = document.getElementsByClassName('wp-block-comments'); + + if (elements.length > 0) { + hovercards.attach(elements[0]); + } +}); diff --git a/course/functions.php b/course/functions.php index cf40477374..cf9c97ebe5 100644 --- a/course/functions.php +++ b/course/functions.php @@ -43,6 +43,29 @@ function course_scripts() { wp_register_style( 'course-style', get_stylesheet_directory_uri() . '/style.css', array(), wp_get_theme()->get( 'Version' ) ); wp_enqueue_script( 'course-header', get_template_directory_uri() . '/assets/js/header.js', array(), wp_get_theme()->get( 'Version' ), true ); wp_enqueue_style( 'course-style' ); + + // Load gravatar-hovercard related styles and scripts. + wp_enqueue_style( 'gravatar-hovercard-style', 'https://unpkg.com/@gravatar-com/hovercards@0.5.8/dist/style.css', array(), 'unversioned' ); + wp_register_script( + 'gravatar-hovercard-js', + 'https://unpkg.com/@gravatar-com/hovercards@0.5.8', + array(), + 'unversioned', + array( + 'in_footer' => false, + 'strategy' => 'defer', + ) + ); + wp_enqueue_script( + 'gravatar-hovercard-setup-js', + get_template_directory_uri() . '/assets/js/hovercard-setup.js', + array( 'gravatar-hovercard-js' ), + wp_get_theme()->get( 'Version' ), + array( + 'in_footer' => true, + 'strategy' => 'defer', + ) + ); } endif; diff --git a/course/readme.txt b/course/readme.txt index 31f794488f..c2e1974d9a 100644 --- a/course/readme.txt +++ b/course/readme.txt @@ -1,6 +1,6 @@ === Course === Contributors: Automattic -Requires at least: 6.2 +Requires at least: 6.3 Tested up to: 6.4 Requires PHP: 7.4 License: GPLv2 or later