Пример #1
0
function pb_enqueue_scripts()
{
    if (pb_is_custom_theme()) {
        $deps = array();
        if (!pb_custom_stylesheet_imports_base()) {
            // Use default stylesheet as base (to avoid horribly broken webbook)
            wp_register_style('pressbooks', PB_PLUGIN_URL . 'themes-book/pressbooks-book/style.css', array(), null, 'screen,print');
            wp_enqueue_style('pressbooks');
            $deps = array('pressbooks');
        }
        wp_register_style('pressbooks-custom-css', pb_get_custom_stylesheet_url(), $deps, get_option('pressbooks_last_custom_css'), 'screen');
        wp_enqueue_style('pressbooks-custom-css');
    } else {
        wp_register_style('pressbooks', get_bloginfo('stylesheet_url'), array(), null, 'screen,print');
        wp_enqueue_style('pressbooks');
    }
    if (!is_front_page()) {
        wp_enqueue_script('pressbooks-script', get_template_directory_uri() . "/js/script.js", array('jquery'), '1.0', false);
    }
    wp_enqueue_script('keyboard-nav', get_template_directory_uri() . '/js/keyboard-nav.js', array('jquery'), '20130306', true);
    if (is_single()) {
        wp_enqueue_script('pb-pop-out-toc', get_template_directory_uri() . '/js/pop-out.js', array('jquery'), '1.0', false);
    }
    $options = get_option('pressbooks_theme_options_web');
    if (@$options['toc_collapse']) {
        wp_enqueue_script('pressbooks_toc_collapse', get_template_directory_uri() . '/js/toc_collapse.js', array('jquery'));
        wp_enqueue_style('dashicons');
    }
    if (@$options['accessibility_fontsize']) {
        wp_enqueue_script('pressbooks-accessibility', get_template_directory_uri() . '/js/a11y.js', array('jquery'));
        wp_register_style('pressbooks-accessibility-toolbar', get_template_directory_uri() . '/css/a11y.css', array(), null, 'screen');
        wp_enqueue_style('pressbooks-accessibility-toolbar');
        wp_enqueue_style('dashicons');
    }
}
Пример #2
0
function pb_enqueue_scripts()
{
    if (pb_is_custom_theme()) {
        // Custom CSS
        $deps = array();
        if (!pb_custom_stylesheet_imports_base()) {
            // Use default stylesheet as base (to avoid horribly broken webbook)
            wp_register_style('pressbooks-book', PB_PLUGIN_URL . 'themes-book/pressbooks-book/style.css', array(), null, 'screen, print');
            wp_enqueue_style('pressbooks-book');
            $deps = array('pressbooks');
        }
        wp_register_style('pressbooks-custom-css', pb_get_custom_stylesheet_url(), $deps, get_option('pressbooks_last_custom_css'), 'screen');
        wp_enqueue_style('pressbooks-custom-css');
    } else {
        // Standard theme
        wp_register_style('pressbooks', PB_PLUGIN_URL . 'themes-book/pressbooks-book/style.css', array(), null, 'screen, print');
        wp_enqueue_style('pressbooks');
        // Use default stylesheet as base (to avoid horribly broken webbook)
        $deps = array('pressbooks');
        if (get_stylesheet() !== 'pressbooks-book') {
            // If not pressbooks-book, we need to register and enqueue the theme stylesheet too
            $fullpath = \PressBooks\Container::get('Sass')->pathToUserGeneratedCss() . '/style.css';
            if (is_file($fullpath)) {
                // Custom webbook style has been generated
                wp_register_style('pressbooks-theme', \PressBooks\Container::get('Sass')->urlToUserGeneratedCss() . '/style.css', $deps, null, 'screen, print');
                wp_enqueue_style('pressbooks-theme');
            } else {
                // Use the bundled stylesheet
                wp_register_style('pressbooks-theme', get_stylesheet_directory_uri() . '/style.css', $deps, null, 'screen, print');
                wp_enqueue_style('pressbooks-theme');
            }
        }
    }
    if (!is_front_page()) {
        wp_enqueue_script('pressbooks-script', get_template_directory_uri() . "/js/script.js", array('jquery'), '1.0', false);
    }
    wp_enqueue_script('keyboard-nav', get_template_directory_uri() . '/js/keyboard-nav.js', array('jquery'), '20130306', true);
    if (is_single()) {
        wp_enqueue_script('pb-pop-out-toc', get_template_directory_uri() . '/js/pop-out.js', array('jquery'), '1.0', false);
    }
    $options = get_option('pressbooks_theme_options_web');
    if (@$options['toc_collapse']) {
        wp_enqueue_script('pressbooks_toc_collapse', get_template_directory_uri() . '/js/toc_collapse.js', array('jquery'));
        wp_enqueue_style('dashicons');
    }
    if (@$options['accessibility_fontsize']) {
        wp_enqueue_script('pressbooks-accessibility', get_template_directory_uri() . '/js/a11y.js', array('jquery'));
        wp_register_style('pressbooks-accessibility-toolbar', get_template_directory_uri() . '/css/a11y.css', array(), null, 'screen');
        wp_enqueue_style('pressbooks-accessibility-toolbar');
        wp_enqueue_style('dashicons');
    }
}