* @license http://www.gnu.org/licenses/gpl-2.0.html
* @link https://github.com/maddisondesigns
*/
class Nighty_Google_Font_Select_Custom_Control extends WP_Customize_Control {
/**
* The type of control being rendered
*/
public $type = 'google_fonts';
/**
* The list of Google Fonts
*/
private $fontList = false;
/**
* The saved font values decoded from json
*/
private $fontValues = [];
/**
* The index of the saved font within the list of Google fonts
*/
private $fontListIndex = 0;
/**
* The number of fonts to display from the json file. Either positive integer or 'all'. Default = 'all'
*/
private $fontCount = 'all';
/**
* The font list sort order. Either 'alpha' or 'popular'. Default = 'alpha'
*/
private $fontOrderBy = 'alpha';
/**
* Get our list of fonts from the json file
*/
public function __construct( $manager, $id, $args = array(), $options = array() ) {
parent::__construct( $manager, $id, $args );
// Get the font sort order
if ( isset( $this->input_attrs['orderby'] ) && strtolower( $this->input_attrs['orderby'] ) === 'popular' ) {
$this->fontOrderBy = 'popular';
}
// Get the list of Google fonts
if ( isset( $this->input_attrs['font_count'] ) ) {
if ( 'all' != strtolower( $this->input_attrs['font_count'] ) ) {
$this->fontCount = ( abs( (int) $this->input_attrs['font_count'] ) > 0 ? abs( (int) $this->input_attrs['font_count'] ) : 'all' );
}
}
$this->fontList = $this->ova_getGoogleFontsx( 'all' );
$this->get_all_fonts = $this->ova_getGoogleFont( 'all' );
// Decode the default json font value
$this->fontValues = json_decode( $this->value() );
// Find the index of our default font within our list of Google fonts
$this->fontListIndex = $this->Ova_getFontIndex( $this->fontList, $this->fontValues->font );
}
/**
* Enqueue our scripts and styles
*/
public function enqueue() {
wp_enqueue_script( 'ova-custom-controls', NIGHTY_URI . '/customize/assets/customizer.js', array( 'jquery' ), '1.0', true );
wp_enqueue_style( 'ova-custom-controls', NIGHTY_URI . '/customize/assets/customizer.css', array(), '1.1', 'all' );
}
/**
* Export our List of Google Fonts to JavaScript
*/
public function to_json() {
parent::to_json();
$this->json['ovafontslist'] = $this->fontList;
}
/**
* Render the control in the customizer
*/
public function render_content() {
$fontCounter = 0;
$isFontInList = false;
$fontListStr = '';
if( !empty($this->fontList) ) {
?>