adding roots-scripts.php, now using wp_enqueue_script

This commit is contained in:
Ben Word
2012-01-15 19:31:14 -07:00
parent d6c0125fa9
commit eca31bd915
4 changed files with 108 additions and 65 deletions

View File

@@ -5,6 +5,7 @@ if (!defined('__DIR__')) define('__DIR__', dirname(__FILE__));
require_once locate_template('/inc/roots-activation.php'); // activation require_once locate_template('/inc/roots-activation.php'); // activation
require_once locate_template('/inc/roots-options.php'); // theme options require_once locate_template('/inc/roots-options.php'); // theme options
require_once locate_template('/inc/roots-cleanup.php'); // cleanup require_once locate_template('/inc/roots-cleanup.php'); // cleanup
require_once locate_template('/inc/roots-scripts.php'); // modified scripts output
require_once locate_template('/inc/roots-htaccess.php'); // rewrites for assets, h5bp htaccess require_once locate_template('/inc/roots-htaccess.php'); // rewrites for assets, h5bp htaccess
require_once locate_template('/inc/roots-hooks.php'); // hooks require_once locate_template('/inc/roots-hooks.php'); // hooks
require_once locate_template('/inc/roots-actions.php'); // actions require_once locate_template('/inc/roots-actions.php'); // actions
@@ -71,17 +72,15 @@ function roots_setup() {
add_action('after_setup_theme', 'roots_setup'); add_action('after_setup_theme', 'roots_setup');
// http://codex.wordpress.org/Function_Reference/register_sidebar // http://codex.wordpress.org/Function_Reference/register_sidebar
// hook into 'widgets_init' function with a lower priority in your
// child theme to remove these sidebars
function roots_register_sidebars() { function roots_register_sidebars() {
$sidebars = array( 'Sidebar', 'Footer' ); $sidebars = array('Sidebar', 'Footer');
foreach( $sidebars as $sidebar ) { foreach($sidebars as $sidebar) {
register_sidebar( register_sidebar(
array( array(
'id'=> 'roots-' . strtolower( $sidebar ), 'id'=> 'roots-' . strtolower($sidebar),
'name' => __( $sidebar, 'roots' ), 'name' => __($sidebar, 'roots'),
'description' => __( $sidebar, 'roots' ), 'description' => __($sidebar, 'roots'),
'before_widget' => '<article id="%1$s" class="widget %2$s"><div class="container">', 'before_widget' => '<article id="%1$s" class="widget %2$s"><div class="container">',
'after_widget' => '</div></article>', 'after_widget' => '</div></article>',
'before_title' => '<h3>', 'before_title' => '<h3>',

View File

@@ -21,8 +21,6 @@
<?php wp_head(); ?> <?php wp_head(); ?>
<?php roots_head(); ?> <?php roots_head(); ?>
<script defer src="<?php echo get_template_directory_uri(); ?>/js/plugins.js"></script>
<script defer src="<?php echo get_template_directory_uri(); ?>/js/script.js"></script>
</head> </head>
<body <?php body_class(roots_body_class()); ?>> <body <?php body_class(roots_body_class()); ?>>

View File

@@ -103,17 +103,11 @@ function roots_google_analytics() {
// 1140 specific // 1140 specific
if (roots_current_framework() === '1140') { if (roots_current_framework() === '1140') {
add_action('roots_head', 'roots_1140_head');
add_action('roots_header_before', 'roots_1140_header_before'); add_action('roots_header_before', 'roots_1140_header_before');
add_action('roots_header_after', 'roots_1140_header_after'); add_action('roots_header_after', 'roots_1140_header_after');
add_action('roots_footer_before', 'roots_1140_footer_before'); add_action('roots_footer_before', 'roots_1140_footer_before');
add_action('roots_footer_after', 'roots_1140_footer_after'); add_action('roots_footer_after', 'roots_1140_footer_after');
function roots_1140_head() {
$template_uri = get_template_directory_uri();
echo "\t<script src=\"$template_uri/js/libs/css3-mediaqueries.js\"></script>";
}
function roots_1140_header_before() { function roots_1140_header_before() {
echo '<div class="container"><div class="row">', "\n"; echo '<div class="container"><div class="row">', "\n";
} }
@@ -153,65 +147,16 @@ if (roots_current_framework() === 'adapt') {
echo "\t\t\t]\n"; echo "\t\t\t]\n";
echo "\t\t};\n"; echo "\t\t};\n";
echo "\t</script>\n"; echo "\t</script>\n";
echo "\t<script src=\"$template_uri/js/libs/adapt.min.js\"></script>";
}
}
// Foundation specific
if (roots_current_framework() === 'foundation') {
add_action('roots_head', 'roots_foundation_head');
function roots_foundation_head() {
$template_uri = get_template_directory_uri();
echo "\t<script src=\"$template_uri/js/foundation/jquery.reveal.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/foundation/jquery.orbit-1.3.0.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/foundation/forms.jquery.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/foundation/jquery.customforms.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/foundation/jquery.placeholder.min.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/foundation/app.js\"></script>\n";
} }
} }
// Bootstrap specific // Bootstrap specific
if (roots_current_framework() === 'bootstrap' || roots_current_framework() === 'bootstrap_less') { if (roots_current_framework() === 'bootstrap' || roots_current_framework() === 'bootstrap_less') {
add_action('roots_head', 'roots_bootstrap_head');
add_action('roots_header_before', 'roots_bootstrap_header_before'); add_action('roots_header_before', 'roots_bootstrap_header_before');
add_action('roots_header_after', 'roots_bootstrap_header_after'); add_action('roots_header_after', 'roots_bootstrap_header_after');
add_action('roots_footer_before', 'roots_bootstrap_footer_before'); add_action('roots_footer_before', 'roots_bootstrap_footer_before');
add_action('roots_footer_after', 'roots_bootstrap_footer_after'); add_action('roots_footer_after', 'roots_bootstrap_footer_after');
function roots_bootstrap_head() {
global $roots_options;
$roots_bootstrap_js = $roots_options['bootstrap_javascript'];
$roots_bootstrap_less_js = $roots_options['bootstrap_less_javascript'];
$template_uri = get_template_directory_uri();
if (roots_current_framework() === 'bootstrap_less') {
echo "\t<script src=\"$template_uri/js/bootstrap/less-1.1.3.min.js\"></script>\n";
}
if ($roots_bootstrap_js === true) {
$roots_options['bootstrap_less_javascript'] = false;
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-modal.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-alerts.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-twipsy.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-popover.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-dropdown.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-scrollspy.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-tabs.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-buttons.js\"></script>\n";
}
if ($roots_bootstrap_less_js === true) {
$roots_options['bootstrap_javascript'] = false;
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-modal.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-alerts.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-twipsy.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-popover.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-dropdown.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-scrollspy.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-tabs.js\"></script>\n";
echo "\t<script src=\"$template_uri/js/bootstrap/bootstrap-buttons.js\"></script>\n";
}
}
function roots_bootstrap_header_before() { function roots_bootstrap_header_before() {
echo '<div class="container">', "\n"; echo '<div class="container">', "\n";
} }
@@ -231,4 +176,4 @@ if (roots_current_framework() === 'bootstrap' || roots_current_framework() === '
} }
} }
?> ?>

101
inc/roots-scripts.php Normal file
View File

@@ -0,0 +1,101 @@
<?php
function roots_scripts() {
$template_uri = get_template_directory_uri();
wp_register_script('roots_plugins', ''.$template_uri.'/js/plugins.js', false, null, false);
wp_register_script('roots_script', ''.$template_uri.'/js/script.js', false, null, false);
wp_enqueue_script('roots_plugins');
wp_enqueue_script('roots_script');
if (roots_current_framework() === '1140') {
wp_register_script('css3-mediaqueries', ''.$template_uri.'/js/libs/css3-mediaqueries.js', false, null, false);
wp_enqueue_script('css3-mediaqueries');
}
if (roots_current_framework() === 'adapt') {
wp_register_script('adapt', ''.$template_uri.'/js/libs/adapt.min.js', false, null, false);
wp_enqueue_script('adapt');
}
if (roots_current_framework() === 'foundation') {
wp_register_script('foundation-jquery-reveal', ''.$template_uri.'/js/foundation/jquery.reveal.js', false, null, false);
wp_register_script('foundation-jquery-orbit', ''.$template_uri.'/js/foundation/jquery.orbit-1.3.0.js', false, null, false);
wp_register_script('foundation-forms-jquery', ''.$template_uri.'/js/foundation/forms.jquery.js', false, null, false);
wp_register_script('foundation-jquery-customforms', ''.$template_uri.'/js/foundation/jquery.customforms.js', false, null, false);
wp_register_script('foundation-jquery-placeholder', ''.$template_uri.'/js/foundation/jquery.placeholder.min.js', false, null, false);
wp_register_script('foundation-app', ''.$template_uri.'/js/foundation/app.js', false, null, false);
wp_enqueue_script('foundation-jquery-reveal');
wp_enqueue_script('foundation-jquery-orbit');
wp_enqueue_script('foundation-forms-jquery');
wp_enqueue_script('foundation-jquery-customforms');
wp_enqueue_script('foundation-jquery-placeholder');
wp_enqueue_script('foundation-app');
}
if (roots_current_framework() === 'bootstrap' || roots_current_framework() === 'bootstrap_less') {
global $roots_options;
$roots_bootstrap_js = $roots_options['bootstrap_javascript'];
$roots_bootstrap_less_js = $roots_options['bootstrap_less_javascript'];
$template_uri = get_template_directory_uri();
if (roots_current_framework() === 'bootstrap_less') {
wp_register_script('bootstrap-less', ''.$template_uri.'/js/bootstrap/less-1.1.3.min.js', false, null, false);
wp_enqueue_script('bootstrap-less');
}
if ($roots_bootstrap_js === true || $roots_bootstrap_less_js === true) {
$roots_options['bootstrap_less_javascript'] = false;
$roots_options['bootstrap_javascript'] = false;
wp_register_script('bootstrap-modal', ''.$template_uri.'/js/bootstrap/bootstrap-modal.js', false, null, false);
wp_register_script('bootstrap-alerts', ''.$template_uri.'/js/bootstrap/bootstrap-alerts.js', false, null, false);
wp_register_script('bootstrap-twipsy', ''.$template_uri.'/js/bootstrap/bootstrap-twipsy.js', false, null, false);
wp_register_script('bootstrap-popover', ''.$template_uri.'/js/bootstrap/bootstrap-popover.js', false, null, false);
wp_register_script('bootstrap-dropdown', ''.$template_uri.'/js/bootstrap/bootstrap-dropdown.js', false, null, false);
wp_register_script('bootstrap-scrollspy', ''.$template_uri.'/js/bootstrap/bootstrap-scrollspy.js', false, null, false);
wp_register_script('bootstrap-tabs', ''.$template_uri.'/js/bootstrap/bootstrap-tabs.js', false, null, false);
wp_register_script('bootstrap-buttons', ''.$template_uri.'/js/bootstrap/bootstrap-buttons.js', false, null, false);
wp_enqueue_script('bootstrap-modal');
wp_enqueue_script('bootstrap-alerts');
wp_enqueue_script('bootstrap-twipsy');
wp_enqueue_script('bootstrap-popover');
wp_enqueue_script('bootstrap-dropdown');
wp_enqueue_script('bootstrap-scrollspy');
wp_enqueue_script('bootstrap-tabs');
wp_enqueue_script('bootstrap-buttons');
}
}
}
add_action('wp_enqueue_scripts', 'roots_scripts');
if (!is_admin()) {
add_action('wp_print_scripts', 'roots_print_scripts');
}
function roots_print_scripts() {
global $wp_scripts;
$wp_scripts->all_deps($wp_scripts->queue);
$scripts = array();
foreach ($wp_scripts->queue as $key => $handle) {
$skip_scripts = array('jquery', 'roots_script', 'roots_plugins');
$src = $wp_scripts->registered[$handle]->src;
unset($wp_scripts->queue[$key]);
$wp_scripts->done[] = $handle;
if (!in_array($handle, $skip_scripts)) {
$scripts[] = '<script defer src="' . $src . '"></script>';
}
}
echo "\t" . implode("\n\t", $scripts) . "\n";
$template_uri = get_template_directory_uri();
echo "\t<script defer src=\"$template_uri/js/plugins.js\"></script>\n";
echo "\t<script defer src=\"$template_uri/js/script.js\"></script>\n";
$wp_scripts->reset();
return $wp_scripts->done;
}
?>