font.php (2269B)
1 <?php 2 namespace Elementor; 3 4 if ( ! defined( 'ABSPATH' ) ) { 5 exit; // Exit if accessed directly. 6 } 7 8 /** 9 * Elementor font control. 10 * 11 * A base control for creating font control. Displays font select box. The 12 * control allows you to set a list of fonts. 13 * 14 * @since 1.0.0 15 */ 16 class Control_Font extends Base_Data_Control { 17 18 /** 19 * Get font control type. 20 * 21 * Retrieve the control type, in this case `font`. 22 * 23 * @since 1.0.0 24 * @access public 25 * 26 * @return string Control type. 27 */ 28 public function get_type() { 29 return 'font'; 30 } 31 32 /** 33 * Get font control default settings. 34 * 35 * Retrieve the default settings of the font control. Used to return the default 36 * settings while initializing the font control. 37 * 38 * @since 1.0.0 39 * @access protected 40 * 41 * @return array Control default settings. 42 */ 43 protected function get_default_settings() { 44 return [ 45 'groups' => Fonts::get_font_groups(), 46 'options' => Fonts::get_fonts(), 47 ]; 48 } 49 50 /** 51 * Render font control output in the editor. 52 * 53 * Used to generate the control HTML in the editor using Underscore JS 54 * template. The variables for the class are available using `data` JS 55 * object. 56 * 57 * @since 1.0.0 58 * @access public 59 */ 60 public function content_template() { 61 ?> 62 <div class="elementor-control-field"> 63 <label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> 64 <div class="elementor-control-input-wrapper elementor-control-unit-5"> 65 <select id="<?php $this->print_control_uid(); ?>" class="elementor-control-font-family" data-setting="{{ data.name }}"> 66 <option value=""><?php echo esc_html__( 'Default', 'elementor' ); ?></option> 67 <# _.each( data.groups, function( group_label, group_name ) { 68 var groupFonts = getFontsByGroups( group_name ); 69 if ( ! _.isEmpty( groupFonts ) ) { #> 70 <optgroup label="{{ group_label }}"> 71 <# _.each( groupFonts, function( fontType, fontName ) { #> 72 <option value="{{ fontName }}">{{{ fontName }}}</option> 73 <# } ); #> 74 </optgroup> 75 <# } 76 }); #> 77 </select> 78 </div> 79 </div> 80 <# if ( data.description ) { #> 81 <div class="elementor-control-field-description">{{{ data.description }}}</div> 82 <# } #> 83 <?php 84 } 85 }