font.php 2.2 KB

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