Files
yeuchaybo/lib/js/load-scripts.php
Thuan Bui fd25f13a4f Initial
2018-06-26 11:09:22 +07:00

92 lines
2.2 KiB
PHP

<?php
/**
* Child Theme Library
*
* WARNING: This file is a part of the core Child Theme Library.
* DO NOT edit this file under any circumstances. Please use
* the functions.php file to make any theme modifications.
*
* @package SEOThemes\ChildThemeLibrary\JS
* @link https://github.com/seothemes/child-theme-library
* @author Thuan Bui
* @copyright Copyright © 2018 Thuan Bui
* @license GPL-2.0+
*/
// If this file is called directly, abort.
if ( ! defined( 'ABSPATH' ) ) {
die;
}
add_action( 'wp_enqueue_scripts', 'child_theme_load_scripts', 99 );
/**
* Enqueue theme scripts.
*
* @since 1.0.0
*
* @return void
*/
function child_theme_load_scripts() {
$scripts = child_theme_get_config( 'scripts' );
foreach ( $scripts as $script => $params ) {
wp_enqueue_script( 'child-theme-' . $script, $params['src'], explode( ',', $params['deps'] ), $params['ver'], $params['in_footer'] );
}
}
add_action( 'wp_enqueue_scripts', 'child_theme_menu_settings', 99 );
/**
* Localizes the responsive menu script
*
* @since 1.0.0
*
* @return void
*/
function child_theme_menu_settings() {
$menu_settings = child_theme_get_config( 'responsive-menu' );
wp_localize_script( 'child-theme-menu', 'genesis_responsive_menu', $menu_settings );
}
add_action( 'genesis_before', 'child_theme_js_nojs_script', 1 );
/**
* Echo out the script that changes 'no-js' class to 'js'.
*
* Adds a script on the genesis_before hook which immediately changes the
* class to js if JavaScript is enabled. This is how WP does things on
* the back end, to allow different styles for the same elements
* depending if JavaScript is active or not.
*
* Outputting the script immediately also reduces a flash of incorrectly
* styled content, as the page does not load with no-js styles, then
* switch to js once everything has finished loading.
*
* @since 1.0.0
*
* @author Gary Jones
* @link https://github.com/GaryJones/genesis-js-no-js
*
* @return void
*/
function child_theme_js_nojs_script() {
?>
<script>
//<![CDATA[
(function(){
var c = document.body.classList;
c.remove( 'no-js' );
c.add( 'js' );
})();
//]]>
</script>
<?php
}