File: //home/dorsetandsomersetairambulance.org.uk/public_html/wp-content/themes/dw-focus/inc/scripts.php
<?php
/**
* DW Focus Scripts & Styles
*
* @package DW Focus
* @since DW Focus 1.3.0
*/
function dw_focus_scripts() {
global $wp_version;
$version = wp_get_theme( wp_get_theme()->template )->get( 'Version' );
if ( defined( 'WP_ENV' ) && 'development' === WP_ENV ) {
$assets = array(
'css' => '/assets/css/dw-focus.css',
'js' => '/assets/js/dw-focus.js',
);
} else {
$assets = array(
'css' => '/assets/css/dw-focus.min.css',
'js' => '/assets/js/dw-focus.min.js',
);
}
wp_enqueue_style( 'dw-focus-main', get_template_directory_uri() . $assets['css'], array(), $version );
wp_enqueue_style( 'dw-focus-style', get_stylesheet_uri() );
wp_enqueue_style( 'dw-focus-print', get_template_directory_uri() . '/assets/css/print.css', array(), $version, 'print' );
if ( is_singular() && comments_open() && get_option( 'thread_comments' ) ) {
wp_enqueue_script( 'comment-reply' );
}
wp_enqueue_script( 'modernizr', get_template_directory_uri() . '/assets/js/modernizr.min.js', array(), $version, false );
wp_enqueue_script( 'jquery-mobile', get_template_directory_uri() . '/assets/js/jquery-mobile.min.js', array('jquery'), '1.3.2', false );
wp_enqueue_script( 'dw-focus-script', get_template_directory_uri() . $assets['js'], array( 'jquery' ), $version, true );
wp_localize_script('dw-focus-script', 'dw_focus', array( 'ajax_url' => admin_url( 'admin-ajax.php' ) ) );
}
add_action( 'wp_enqueue_scripts', 'dw_focus_scripts' );
function dw_widget_enqueue_script() {
global $pagenow;
if ( 'widgets.php' == $pagenow ) {
wp_enqueue_script( 'dw-widgets-js', get_template_directory_uri() . '/inc/widgets/js/dw-widget.js', array( 'jquery', 'jquery-ui-datepicker', 'jquery-ui-sortable', 'jquery-ui-sortable', 'jquery-ui-draggable', 'jquery-ui-droppable', 'admin-widgets' ), true );
wp_dequeue_script( 'admin-widgets' );
}
}
add_action( 'admin_enqueue_scripts', 'dw_widget_enqueue_script' );
if ( ! function_exists( 'dw_focus_custom_css' ) ) :
function dw_focus_custom_css() {
$custom_css = '';
$link_color = dw_focus_get_theme_option( 'link_color' );
if ( $link_color ) {
$custom_css .= 'a {color: ' . $link_color . '}';
}
$link_hover_color = dw_focus_get_theme_option( 'link_hover_color' );
if ( $link_hover_color ) {
$custom_css .= 'a:hover, a:active {color: ' . $link_hover_color . '}';
}
$dw_header_background = dw_focus_get_theme_option( 'dw_header_background' );
if ( $dw_header_background ) {
$custom_css .= '.site-header {background-color:' . $dw_header_background . '}';
}
// Footer
$footer_text_color = dw_focus_get_theme_option( 'footer_text_color' );
if ( $footer_text_color ) {
$custom_css .= '.site-footer {color: ' . $footer_text_color . '}';
}
$footer_link_color = dw_focus_get_theme_option( 'footer_link_color' );
if ( $footer_link_color ) {
$custom_css .= '.site-footer a {color: ' . $footer_link_color . '}';
}
$footer_link_hover_color = dw_focus_get_theme_option( 'footer_link_hover_color' );
if ( $footer_link_hover_color ) {
$custom_css .= '.site-footer a:hover, .site-footer a:active {color: ' . $footer_link_hover_color . '}';
}
$footer_widget_title_color = dw_focus_get_theme_option( 'footer_widget_title_color' );
if ( $footer_widget_title_color ) {
$custom_css .= '.site-footer #footer-widgets .widget-title {color: ' . $footer_widget_title_color . '}';
}
$footer_line_color = dw_focus_get_theme_option( 'footer_line_color' );
if ( $footer_line_color ) {
$custom_css .= '.site-footer .footer-navigation, #footer-widgets { border-color: ' . $footer_line_color . '}';
$custom_css .= '#footer-widgets .widget_nav_menu:after {background-color: ' . $footer_line_color . '}';
}
$dw_footer_background = dw_focus_get_theme_option( 'dw_footer_background' );
if ( $dw_footer_background ) {
$custom_css .= '.site-footer {background-color:' . $dw_footer_background . '}';
}
$dw_custom_css = dw_focus_get_theme_option( 'dw_custom_css' );
if ( $dw_custom_css ) {
$custom_css .= $dw_custom_css;
}
$text_font = dw_focus_get_theme_option( 'text_font' );
if ( $text_font ) {
$custom_css .= dw_options_typography_font_styles( $text_font , 'body' );
}
$heading_font = dw_focus_get_theme_option( 'heading_font' );
if ( $heading_font ) {
$custom_css .= dw_options_typography_font_styles( $heading_font , 'h1, h2, h3, h4, h5, h6, .dw_focus_widget_news_slider .carousel-title-indicators li, .widget_news-slider .carousel-title-indicators li, .post-navigation .nav-links, .dw_focus_widget_news_ticker a, .widget_news-ticker a' );
}
$font_size_h1 = dw_focus_get_theme_option( 'font_size_h1' );
if ( $font_size_h1 ) {
$custom_css .= 'h1 {font-size:' . $font_size_h1 . 'px}';
}
$font_size_h2 = dw_focus_get_theme_option( 'font_size_h2' );
if ( $font_size_h2 ) {
$custom_css .= 'h2 {font-size:' . $font_size_h2 . 'px}';
}
$font_size_h2 = dw_focus_get_theme_option( 'font_size_h2' );
if ( $font_size_h2 ) {
$custom_css .= 'h2 {font-size:' . $font_size_h2 . 'px}';
}
$font_size_h3 = dw_focus_get_theme_option( 'font_size_h3' );
if ( $font_size_h3 ) {
$custom_css .= 'h3 {font-size:' . $font_size_h3 . 'px}';
}
$font_size_h4 = dw_focus_get_theme_option( 'font_size_h4' );
if ( $font_size_h4 ) {
$custom_css .= 'h4 {font-size:' . $font_size_h4 . 'px}';
}
$font_size_h5 = dw_focus_get_theme_option( 'font_size_h5' );
if ( $font_size_h5 ) {
$custom_css .= 'h5 {font-size:' . $font_size_h5 . 'px}';
}
$font_size_h6 = dw_focus_get_theme_option( 'font_size_h6' );
if ( $font_size_h6 ) {
$custom_css .= 'h6 {font-size:' . $font_size_h6 . 'px}';
}
if ( $custom_css ) {
echo '<style type="text/css">' . esc_html( $custom_css ) . '</style>';
}
}
endif;
add_action( 'wp_head', 'dw_focus_custom_css' );
if ( ! function_exists( 'dw_focus_code_before_head' ) ) :
function dw_focus_code_before_head() {
$before_head = dw_focus_get_theme_option( 'dw_focus_code_before_head' );
if ( $before_head ) {
echo $before_head;
}
}
endif;
add_action( 'wp_head', 'dw_focus_code_before_head' );
if ( ! function_exists( 'dw_focus_code_before_body' ) ) :
function dw_focus_code_before_body() {
$before_body = dw_focus_get_theme_option( 'dw_focus_code_before_body' );
if ( $before_body ) {
echo $before_body;
}
}
endif;
add_action( 'wp_footer', 'dw_focus_code_before_body' );
function dw_options_typography_font_styles( $option, $selectors ) {
$output = $selectors . ' {';
if ( $option['color'] ) $output .= 'color:' . $option['color'] .';';
if ( $option['google_font'] == 1 ) {
$current_style = $option['variation'];
if ( $current_style === 'regular' ) {
$current_style = '400';
}
if ( $current_style == 'italic' ) {
$current_style = '400italic';
}
$output .= ( strpos( $current_style, 'italic' ) ) ? 'font-style: italic;' : '';
$output .= 'font-weight: ' . intval( $current_style ) . ';';
} else {
if ( $option['weight'] ) $output .= 'font-weight:' . $option['weight'] . ';';
}
if ( $option['weight'] ) $output .= 'font-weight:' . $option['weight'] . ';';
if ( $option['size'] ) $output .= 'font-size:' . $option['size'] . 'px;';
if ( $option['family'] ) $output .= 'font-family:' . $option['family'] . ';';
if ( $option['letter-spacing'] ) $output .= 'letter-spacing:' . $option['letter-spacing'] . ';';
if ( $option['line-height'] ) $output .= 'line-height:' . $option['line-height'] . ';';
$output .= '}';
return $output;
}
if ( ! function_exists( 'dw_focus_render_google_fonts' ) ) {
function dw_focus_render_google_fonts() {
$text_font = dw_focus_get_theme_option( 'text_font' );
$heading_font = dw_focus_get_theme_option( 'heading_font' );
$selected_fonts = array();
if ( $text_font && $text_font['google_font'] == 1 ) {
array_push( $selected_fonts, $text_font['family'] );
}
if ( $heading_font && $heading_font['google_font'] == 1 ) {
array_push( $selected_fonts, $heading_font['family'] );
}
$selected_fonts = array_unique($selected_fonts);
$selected_fonts = implode( '|', $selected_fonts );
$selected_fonts = str_replace( ' ', '+', $selected_fonts );
if ( '' != $selected_fonts ) {
wp_enqueue_style( 'dw-focus-fonts', '//fonts.googleapis.com/css?family=' . $selected_fonts, false, null, 'all' );
}
}
add_action( 'wp_enqueue_scripts', 'dw_focus_render_google_fonts' );
}