Esempio n. 1
0
/**
 * Takes the background color and works out contrasts for text and borders
 *
 * This uses Jetpack class.color.php if JetPack exists, otherwise it uses the bundled color.php
 *
 */
function tonal_style_output()
{
    // Check to see if JetPack class.color.php exists - we bundle one just incase
    if (!class_exists('Jetpack_Color')) {
        require_once dirname(__FILE__) . '/class.color.php';
    }
    // We are going to base everything from the background color so load that up
    $hexColor = get_background_color();
    if (empty($hexColor)) {
        $hexColor = 'ffffff';
    }
    // We are going to next declare an new object from the Jetpack_Color class
    $color = new Jetpack_Color($hexColor);
    // Will out put 000000 or ffffff so can use as a guide whether a dark or light background
    $contrastColor = $color->getMaxContrastColor();
    // If a dark background then load up the white background tones
    if ($contrastColor == "#000000") {
        $toneColor = $color->darken(10);
        $bodyColor = $color->getGrayscaleContrastingColor()->lighten(10);
        $headerColor = $color->getGrayscaleContrastingColor();
        tonal_tone('dark');
    } else {
        $toneColor = $color->lighten(10);
        $bodyColor = $color->getGrayscaleContrastingColor()->darken(10);
        $headerColor = $color->getGrayscaleContrastingColor()->darken();
        tonal_tone('light');
    }
    // Lets now output the CSS for creating the tonal effects
    ?>
	<style type="text/css">
		body {
			background: #<?php 
    echo $hexColor;
    ?>
;
		}
		#page{
			z-index: 9999;
		}
		#page:before, #page:after {
    		background-color: <?php 
    echo $toneColor;
    ?>
;
			z-index: 9999;
		}
		#page {
	    	border-left: 20px solid <?php 
    echo $toneColor;
    ?>
;
    		border-right: 20px solid <?php 
    echo $toneColor;
    ?>
;
			z-index: 9999;
		}
		h1,
		h2,
		h3,
		h4,
		h5,
		h6,
		a,
		a:visited {
			color: <?php 
    echo $headerColor;
    ?>
;
		}
		body,
		button,
		input,
		select,
		textarea,
		a:hover {
			color: <?php 
    echo $bodyColor;
    ?>
;
		}
	</style>
	<?php 
}
Esempio n. 2
0
 /**
  * Process user options to generate CSS needed to implement the choices.
  *
  * @since  1.0.0.
  *
  * @return void
  */
 function gather_styles()
 {
     // Primary Color
     $setting = 'primary-color';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod !== customizer_library_get_default($setting)) {
         $color = sanitize_hex_color($mod);
         $color_obj = new Jetpack_Color($color);
         // Link Styling
         Customizer_Library_Styles()->add(array('selectors' => array('a', '.site-title a'), 'declarations' => array('color' => $color)));
         // Button Styling
         Customizer_Library_Styles()->add(array('selectors' => array('button', '.button', 'input[type="button"]', 'input[type="reset"]', 'input[type="submit"]', '.masonry .entry-footer-meta a:hover'), 'declarations' => array('background-color' => $color)));
         // Button Hover State
         Customizer_Library_Styles()->add(array('selectors' => array('button:hover', '.button:hover', 'input[type="button"]:hover', 'input[type="reset"]:hover', 'input[type="submit"]:hover'), 'declarations' => array('background-color' => $color_obj->darken(5))));
         // Border Colors
         Customizer_Library_Styles()->add(array('selectors' => array('#content blockquote', '.page-header'), 'declarations' => array('border-color' => $mod)));
     }
     // Secondary Color
     $setting = 'secondary-color';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod !== customizer_library_get_default($setting)) {
         // Colors
         Customizer_Library_Styles()->add(array('selectors' => array('.site-title a:hover', '.bypostauthor .comment-author .fn:after'), 'declarations' => array('color' => sanitize_hex_color($color))));
     }
     // Primary Font
     $setting = 'primary-font';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     $stack = customizer_library_get_font_stack($mod);
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('body', '.site-description', '.widget-title', '.comments-title', '#reply-title'), 'declarations' => array('font-family' => $stack)));
     }
     // Secondary Font
     $setting = 'secondary-font';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     $stack = customizer_library_get_font_stack($mod);
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('h1, h2, h3, h4, h5, h6', '.comment-author'), 'declarations' => array('font-family' => $stack)));
     }
     // Menu Styling
     $menus = array('primary', 'secondary');
     foreach ($menus as $menu) {
         if (!has_nav_menu($menu)) {
             break;
         }
         if ($menu == 'primary') {
             $selector = '#primary-navigation' . ' ';
         }
         if ($menu == 'secondary') {
             $selector = '#secondary-navigation' . ' ';
         }
         // Background
         $setting = $menu . '-menu-background';
         $mod = get_theme_mod($setting, false);
         if ($mod) {
             Customizer_Library_Styles()->add(array('selectors' => array($selector, $selector . 'ul ul a:hover'), 'declarations' => array('background-color' => $mod)));
         }
         // Background Hover
         $setting = $menu . '-menu-background-hover';
         $mod = get_theme_mod($setting, false);
         if ($mod) {
             Customizer_Library_Styles()->add(array('selectors' => array($selector . 'a:hover', $selector . 'li:hover a'), 'declarations' => array('background-color' => $mod)));
         }
         // Navigation Text
         $setting = $menu . '-menu-color';
         $mod = get_theme_mod($setting, false);
         if ($mod) {
             Customizer_Library_Styles()->add(array('selectors' => array($selector . 'a', $selector . 'a:hover', $selector . 'li:hover a', $selector . '.dropdown-toggle:after'), 'declarations' => array('color' => $mod)));
         }
         // Border
         $setting = $menu . '-menu-border';
         $mod = get_theme_mod($setting, false);
         if ($mod) {
             Customizer_Library_Styles()->add(array('selectors' => array($selector . 'ul', $selector . 'a', $selector . '.dropdown-toggle', $selector . 'ul ul', $selector . 'ul ul a', $selector . 'ul li:hover ul a', $selector . 'ul ul ul'), 'declarations' => array('border-color' => $mod)));
         }
     }
     // Header Background Color
     $setting = 'header-background-color';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-branding'), 'declarations' => array('background-color' => $mod)));
     }
     // Header Background Image
     $setting = 'header-background-image';
     $mod = get_theme_mod($setting, false);
     if ($mod) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-branding'), 'declarations' => array('background-image' => 'url(' . $mod . ')')));
     }
     // Header Background Image Styles
     $setting = 'header-background-image-style';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-branding'), 'declarations' => array('background-size' => 'auto auto', 'background-repeat' => 'repeat', 'background-position' => '0 0')));
     }
     // Center Header Text
     $setting = 'center-branding';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-branding'), 'declarations' => array('text-align' => 'center')));
     }
     // Site Title Color
     $setting = 'site-title-color';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-title a'), 'declarations' => array('color' => $mod)));
     }
     // Site Title Color
     $setting = 'site-title-hover-color';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-title a:hover'), 'declarations' => array('color' => $mod)));
     }
     // Site Title Font
     $setting = 'site-title-font';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     $stack = customizer_library_get_font_stack($mod);
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-title'), 'declarations' => array('font-family' => $stack)));
     }
     // Site Tagline Color
     $setting = 'site-tagline-color';
     $mod = get_theme_mod($setting, customizer_library_get_default($setting));
     if ($mod != customizer_library_get_default($setting)) {
         Customizer_Library_Styles()->add(array('selectors' => array('.site-description'), 'declarations' => array('color' => $mod)));
     }
 }