Example #1
0
 /**
  * Build the CSS rules for the custom fonts
  *
  * @since  1.0.0
  *
  * @return void
  */
 function ttfmake_css_fonts()
 {
     // Get relative sizes
     $percent = ttfmake_font_get_relative_sizes();
     /**
      * Body
      */
     $element = 'body';
     $selectors = array('body', '.font-body');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     // Links
     $link_font_weight = ttfmake_sanitize_choice(get_theme_mod('font-weight-body-link', ttfmake_get_default('font-weight-body-link')), 'font-weight-body-link');
     if ($link_font_weight !== ttfmake_get_default('font-weight-body-link')) {
         ttfmake_get_css()->add(array('selectors' => array('a'), 'declarations' => array('font-weight' => $link_font_weight)));
     }
     // Comments
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('#comments'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comments']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comments'])) . 'rem')));
         // Comment date
         ttfmake_get_css()->add(array('selectors' => array('.comment-date'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comment-date']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comment-date'])) . 'rem')));
     }
     /**
      * H1
      */
     $element = 'h1';
     $selectors = array('h1:not(.site-title)', 'h1:not(.site-title) a', '.font-header');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('h1:not(.site-title) a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * H2
      */
     $element = 'h2';
     $selectors = array('h2', 'h2 a');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('h2 a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     // Post title with two sidebars
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('.has-left-sidebar.has-right-sidebar .entry-title'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['post-title']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['post-title'])) . 'rem'), 'media' => 'screen and (min-width: 800px)'));
     }
     /**
      * H3
      */
     $element = 'h3';
     $selectors = array('h3', 'h3 a', '.builder-text-content .widget-title');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('h3 a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * H4
      */
     $element = 'h4';
     $selectors = array('h4', 'h4 a');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('h4 a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * H5
      */
     $element = 'h5';
     $selectors = array('h5', 'h5 a');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('h5 a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * H6
      */
     $element = 'h6';
     $selectors = array('h6', 'h6 a');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('h6 a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Site Title
      */
     $element = 'site-title';
     $selectors = array('.site-title', '.site-title a', '.font-site-title');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.site-title a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Site Tagline
      */
     $element = 'site-tagline';
     $selectors = array('.site-description', '.site-description a', '.font-site-tagline');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.site-description a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Menu Item
      */
     $menu_items_customized = false;
     $element = 'nav';
     $selectors = array('.site-navigation .menu li a', '.font-nav');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
         $menu_items_customized = true;
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.site-navigation .menu li a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     // Arrow size and grandchild arrow size and position
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .page_item_has_children a:after', '.site-navigation .menu .menu-item-has-children a:after'), 'declarations' => array('top' => '-' . ttfmake_get_relative_font_size($declarations['font-size-px'], 10) . 'px', 'font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], 72) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], 72)) . 'rem'), 'media' => 'screen and (min-width: 800px)'));
     }
     /**
      * Sub-Menu Item
      */
     $submenu_items_customized = false;
     $element = 'subnav';
     $selectors = array('.site-navigation .menu .sub-menu li a', '.site-navigation .menu .children li a');
     $declarations = ttfmake_parse_font_properties($element, $menu_items_customized);
     $simplify_mobile = (bool) get_theme_mod('font-' . $element . '-mobile', ttfmake_get_default('font-' . $element . '-mobile'));
     $media = 'all';
     if (true === $simplify_mobile) {
         $media = 'screen and (min-width: 800px)';
     }
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations, 'media' => $media));
         $submenu_items_customized = true;
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.site-navigation .menu .sub-menu li a', '.site-navigation .menu .children li a'));
     if (!empty($link_rule)) {
         $link_rule['media'] = $media;
         ttfmake_get_css()->add($link_rule);
     }
     // Grandchild arrow size
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .children .page_item_has_children a:after', '.site-navigation .menu .sub-menu .menu-item-has-children a:after'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], 72) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], 72)) . 'rem'), 'media' => 'screen and (min-width: 800px)'));
     }
     /**
      * Current Item
      */
     $current_item_weight = ttfmake_sanitize_choice(get_theme_mod('font-weight-nav-current-item', ttfmake_get_default('font-weight-nav-current-item')), 'font-weight-nav-current-item');
     if ($current_item_weight !== ttfmake_get_default('font-weight-nav-current-item') || true === $menu_items_customized || true === $submenu_items_customized) {
         ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu li.current_page_item > a', '.site-navigation .menu .children li.current_page_item > a', '.site-navigation .menu li.current-menu-item > a', '.site-navigation .menu .sub-menu li.current-menu-item > a'), 'declarations' => array('font-weight' => $current_item_weight)));
         ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu li.current_page_item > a', '.site-navigation .menu .children li.current_page_item > a', '.site-navigation .menu li.current_page_ancestor > a', '.site-navigation .menu li.current-menu-item > a', '.site-navigation .menu .sub-menu li.current-menu-item > a', '.site-navigation .menu li.current-menu-ancestor > a'), 'declarations' => array('font-weight' => $current_item_weight), 'media' => 'screen and (min-width: 800px)'));
     }
     /**
      * Header Bar Text
      */
     $element = 'header-bar-text';
     $selectors = array('.header-bar', '.header-text', '.header-bar .search-form input', '.header-bar .menu a');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.header-bar a', '.header-text a', '.header-bar .menu a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     // Header Bar Icons
     $header_icon_size = absint(get_theme_mod('font-size-header-bar-icon', ttfmake_get_default('font-size-header-bar-icon')));
     if ($header_icon_size !== ttfmake_get_default('font-size-header-bar-icon')) {
         ttfmake_get_css()->add(array('selectors' => array('.header-social-links li a'), 'declarations' => array('font-size-px' => $header_icon_size . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem($header_icon_size) . 'rem')));
         ttfmake_get_css()->add(array('selectors' => array('.header-social-links li a'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($header_icon_size, $percent['header-bar-icon']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($header_icon_size, $percent['header-bar-icon'])) . 'rem'), 'media' => 'screen and (min-width: 1100px)'));
     }
     /**
      * Sidebar Widget Title
      */
     $element = 'widget-title';
     $selectors = array('.sidebar .widget-title', '.sidebar .widgettitle', '.sidebar .widget-title a', '.sidebar .widgettitle a', '.font-widget-title');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.sidebar .widget-title a', '.sidebar .widgettitle a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Sidebar Widget Body
      */
     $element = 'widget';
     $selectors = array('.sidebar .widget', '.font-widget');
     $force = get_theme_mod('font-family-body', ttfmake_get_default('font-family-body')) !== ttfmake_get_default('font-family-body');
     $declarations = ttfmake_parse_font_properties($element, $force);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.sidebar .widget a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Footer Widget Title
      */
     $element = 'footer-widget-title';
     $selectors = array('.footer-widget-container .widget-title', '.footer-widget-container .widgettitle', '.footer-widget-container .widget-title a', '.footer-widget-container .widgettitle a');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.footer-widget-container .widget-title a', '.footer-widget-container .widgettitle a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Footer Widget Body
      */
     $element = 'footer-widget';
     $selectors = array('.footer-widget-container .widget');
     $force = get_theme_mod('font-family-body', ttfmake_get_default('font-family-body')) !== ttfmake_get_default('font-family-body');
     $declarations = ttfmake_parse_font_properties($element, $force);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.footer-widget-container .widget a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     /**
      * Footer Text
      */
     $element = 'footer-text';
     $selectors = array('.footer-text');
     $force = get_theme_mod('font-family-body', ttfmake_get_default('font-family-body')) !== ttfmake_get_default('font-family-body');
     $declarations = ttfmake_parse_font_properties($element, $force);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     $link_rule = ttfmake_parse_link_underline($element, array('.footer-text a'));
     if (!empty($link_rule)) {
         ttfmake_get_css()->add($link_rule);
     }
     // Footer Icons
     $footer_icon_size = absint(get_theme_mod('font-size-footer-icon', ttfmake_get_default('font-size-footer-icon')));
     if ($footer_icon_size !== ttfmake_get_default('font-size-footer-icon')) {
         ttfmake_get_css()->add(array('selectors' => array('.footer-social-links'), 'declarations' => array('font-size-px' => $footer_icon_size . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem($footer_icon_size) . 'rem')));
         ttfmake_get_css()->add(array('selectors' => array('.footer-social-links'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($footer_icon_size, $percent['footer-icon']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($footer_icon_size, $percent['footer-icon'])) . 'rem'), 'media' => 'screen and (min-width: 1100px)'));
     }
 }
Example #2
0
 /**
  * Build the CSS rules for the custom fonts
  *
  * @since  1.0.0
  *
  * @return void
  */
 function ttfmake_css_fonts()
 {
     // Use legacy function instead if no panel support
     if (!ttfmake_customizer_supports_panels()) {
         ttfmake_css_legacy_fonts();
         return;
     }
     // Get relative sizes
     $percent = ttfmake_font_get_relative_sizes();
     /**
      * Site Title
      */
     $element = 'site-title';
     $selectors = array('.site-title', '.font-site-title');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * Site Tagline
      */
     $element = 'site-tagline';
     $selectors = array('.site-description', '.font-site-tagline');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * Menu Item
      */
     $element = 'nav';
     $selectors = array('.site-navigation .menu li a', '.font-nav');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     // Grandchild arrow position
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('.site-navigation .menu .sub-menu .menu-item-has-children a:after', '.site-navigation .menu .children .menu-item-has-children a:after'), 'declarations' => array('top' => $declarations['font-size-px'] * 1.4 / 2 - 5 . 'px'), 'media' => 'screen and (min-width: 800px)'));
     }
     /**
      * Sub-Menu Item
      */
     $element = 'subnav';
     $selectors = array('.site-navigation .menu .sub-menu li a', '.site-navigation .menu .children li a');
     $simplify_mobile = (bool) get_theme_mod('font-' . $element . '-mobile', ttfmake_get_default('font-' . $element . '-mobile'));
     if (!$simplify_mobile) {
         $subnav_family = get_theme_mod('font-family-' . $element, ttfmake_get_default('font-family-' . $element));
         $subnav_size = get_theme_mod('font-size-' . $element, ttfmake_get_default('font-size-' . $element));
         $declarations = array('font-family' => ttfmake_get_font_stack($subnav_family), 'font-size-px' => absint($subnav_size) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem($subnav_size));
         $media = 'all';
     } else {
         $declarations = ttfmake_parse_font_properties($element);
         $media = 'screen and (min-width: 800px)';
     }
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations, 'media' => $media));
     }
     /**
      * H1
      */
     $element = 'h1';
     $selectors = array('h1', '.font-header');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * H2
      */
     $element = 'h2';
     $selectors = array('h2');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     // Post title with two sidebars
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('.has-left-sidebar.has-right-sidebar .entry-title'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['post-title']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['post-title'])) . 'rem'), 'media' => 'screen and (min-width: 800px)'));
     }
     /**
      * H3
      */
     $element = 'h3';
     $selectors = array('h3', '.builder-text-content .widget-title');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * H4
      */
     $element = 'h4';
     $selectors = array('h4');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * H5
      */
     $element = 'h5';
     $selectors = array('h5');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * H6
      */
     $element = 'h6';
     $selectors = array('h6');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     /**
      * Widgets
      */
     $element = 'widget';
     $selectors = array('.widget', '.font-widget');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     // Widget title
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('.widget-title'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['widget-title']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['widget-title'])) . 'rem')));
     }
     /**
      * Body
      */
     $element = 'body';
     $selectors = array('body', '.font-body');
     $declarations = ttfmake_parse_font_properties($element);
     if (!empty($declarations)) {
         ttfmake_get_css()->add(array('selectors' => $selectors, 'declarations' => $declarations));
     }
     // Comments
     if (isset($declarations['font-size-px'])) {
         ttfmake_get_css()->add(array('selectors' => array('#comments'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comments']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comments'])) . 'rem')));
         // Comment date
         ttfmake_get_css()->add(array('selectors' => array('.comment-date'), 'declarations' => array('font-size-px' => ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comment-date']) . 'px', 'font-size-rem' => ttfmake_convert_px_to_rem(ttfmake_get_relative_font_size($declarations['font-size-px'], $percent['comment-date'])) . 'rem')));
     }
 }