Example #1
0
 /**
  * Convert a string containing Typekit family ID and FVD to CSS properties
  */
 public static function to_css($str)
 {
     $object = Youxi_FVD::extract($str);
     if (isset($object['id'], $object['font-style'], $object['font-weight']) && ($family = self::get_family($object['id']))) {
         return array('font-family' => $family['css_stack'], 'font-style' => $object['font-style'], 'font-weight' => $object['font-weight']);
     }
     return null;
 }
    public function render_content($value)
    {
        $family_id = '';
        $variation = 'n4';
        $families = Youxi_Typekit::get_families();
        $variations = array();
        if ($value = Youxi_FVD::extract($value)) {
            $family_id = $value['id'];
            $variation = $value['fvd'];
            $variations = Youxi_Typekit::get_family_variations($family_id, true);
        }
        ?>
		<div class="youxi-webfont-form-control youxi-webfont-provider-family">
			<label class="customize-control-title"><?php 
        esc_html_e('Family', 'youxi');
        ?>
</label>
			<select>
				<option class="placeholder" selected disabled value=""><?php 
        esc_html_e('Select a Font Family', 'youxi');
        ?>
</option>
				<?php 
        foreach ((array) $families as $family) {
            ?>
				<option value="<?php 
            echo esc_attr($family['id']);
            ?>
"<?php 
            selected($family['id'], $family_id);
            ?>
><?php 
            echo esc_html($family['name']);
            ?>
</option>
				<?php 
        }
        ?>
			</select>
		</div>

		<div class="youxi-webfont-form-control youxi-webfont-provider-variation"<?php 
        if (!$family_id) {
            echo ' style="display: none;"';
        }
        ?>
>
			<label class="customize-control-title"><?php 
        esc_html_e('Variation', 'youxi');
        ?>
</label>
			<select>
				<?php 
        foreach ((array) $variations as $fvd => $label) {
            ?>
				<option value="<?php 
            echo esc_attr($fvd);
            ?>
"<?php 
            selected($fvd, $variation);
            ?>
><?php 
            echo esc_html($label);
            ?>
</option>
				<?php 
        }
        ?>
			</select>
		</div>
		<?php 
    }