Responsive.php
116 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customizer Control: kirki-responsive. |
| 4 | * |
| 5 | * @package kirki-responsive |
| 6 | * @since 1.0 |
| 7 | */ |
| 8 | |
| 9 | namespace Kirki\Control; |
| 10 | |
| 11 | use Kirki\Control\Base; |
| 12 | use Kirki\URL; |
| 13 | |
| 14 | // Exit if accessed directly. |
| 15 | if ( ! defined( 'ABSPATH' ) ) { |
| 16 | exit; |
| 17 | } |
| 18 | |
| 19 | /** |
| 20 | * Responsive control |
| 21 | */ |
| 22 | class Responsive extends Base { |
| 23 | |
| 24 | /** |
| 25 | * The control type. |
| 26 | * |
| 27 | * @since 1.0 |
| 28 | * @var string |
| 29 | */ |
| 30 | public $type = 'kirki-responsive'; |
| 31 | |
| 32 | /** |
| 33 | * The version. Used in scripts & styles for cache-busting. |
| 34 | * |
| 35 | * @since 1.0 |
| 36 | * @var string |
| 37 | */ |
| 38 | public static $control_ver = '1.0.0'; |
| 39 | |
| 40 | /** |
| 41 | * Enqueue control related styles/scripts. |
| 42 | * |
| 43 | * @since 1.0 |
| 44 | * @access public |
| 45 | */ |
| 46 | |
| 47 | |
| 48 | /** |
| 49 | * Refresh the parameters passed to the JavaScript via JSON. |
| 50 | * |
| 51 | * @access public |
| 52 | * @since 1.0 |
| 53 | * @see WP_Customize_Control::to_json() |
| 54 | * @return void |
| 55 | */ |
| 56 | public function to_json() { |
| 57 | |
| 58 | // Get the basics from the parent class. |
| 59 | parent::to_json(); |
| 60 | |
| 61 | $device_icons = [ |
| 62 | 'desktop' => 'dashicons-desktop', |
| 63 | 'tablet' => 'dashicons-tablet', |
| 64 | 'mobile' => 'dashicons-smartphone', |
| 65 | ]; |
| 66 | |
| 67 | $devices = isset( $this->choices['devices'] ) ? $this->choices['devices'] : []; |
| 68 | |
| 69 | $device_menu = ''; |
| 70 | $loop_index = 0; |
| 71 | |
| 72 | foreach ( $devices as $device ) { |
| 73 | $loop_index++; |
| 74 | |
| 75 | $device_menu .= ' |
| 76 | <li class="kirki-device-button kirki-device-button-' . $device . ( 1 === $loop_index ? ' is-active' : '' ) . '" data-kirki-device="' . esc_attr( $device ) . '"> |
| 77 | <i class="dashicons ' . esc_html( $device_icons[ $device ] ) . '"></i> |
| 78 | </li> |
| 79 | '; |
| 80 | } |
| 81 | |
| 82 | $this->json['deviceMenu'] = $device_menu; |
| 83 | |
| 84 | } |
| 85 | |
| 86 | /** |
| 87 | * An Underscore (JS) template for this control's content (but not its container). |
| 88 | * |
| 89 | * Class variables for this control class are available in the `data` JS object; |
| 90 | * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
| 91 | * |
| 92 | * @see WP_Customize_Control::print_template() |
| 93 | * @since 1.0 |
| 94 | */ |
| 95 | protected function content_template() { |
| 96 | ?> |
| 97 | |
| 98 | <div class="kirki-responsive" data-kirki-responsive-id="{{{ data.settings.default }}}"> |
| 99 | <div class="kirki-control-label"> |
| 100 | <div class="customize-control-title"> |
| 101 | <span>{{{ data.label }}}</span> |
| 102 | </div> |
| 103 | <# if (data.description) { #> |
| 104 | <div class="customize-control-description">{{{ data.description }}}</div> |
| 105 | <# } #> |
| 106 | </div> |
| 107 | <ul class="kirki-device-buttons"> |
| 108 | {{{ data.deviceMenu }}} |
| 109 | </ul> |
| 110 | </div> |
| 111 | |
| 112 | <?php |
| 113 | } |
| 114 | |
| 115 | } |
| 116 |