Tabs.php
104 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Customizer Control: kirki-tab. |
| 4 | * |
| 5 | * @package kirki-tabs |
| 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 | * Tab control |
| 21 | */ |
| 22 | class Tabs extends Base { |
| 23 | |
| 24 | /** |
| 25 | * The control type. |
| 26 | * |
| 27 | * @since 1.0 |
| 28 | * @var string |
| 29 | */ |
| 30 | public $type = 'kirki-tab'; |
| 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.1'; |
| 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 | $tabs = isset( $this->choices['tabs'] ) ? $this->choices['tabs'] : []; |
| 62 | |
| 63 | $tab_menu = ''; |
| 64 | $loop_index = 0; |
| 65 | |
| 66 | foreach ( $tabs as $tab_id => $tab_args ) { |
| 67 | $loop_index++; |
| 68 | |
| 69 | $tab_menu .= ' |
| 70 | <li class="kirki-tab-menu-item' . ( 1 === $loop_index ? ' is-active' : '' ) . '" data-kirki-tab-menu-id="' . esc_attr( $tab_id ) . '"> |
| 71 | <a href="#" class="kirki-tab-link">' . esc_html( $tab_args['label'] ) . '</a> |
| 72 | </li> |
| 73 | '; |
| 74 | } |
| 75 | |
| 76 | $this->json['choices']['section'] = $this->section; |
| 77 | |
| 78 | $this->json['tabMenu'] = $tab_menu; |
| 79 | |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * An Underscore (JS) template for this control's content (but not its container). |
| 84 | * |
| 85 | * Class variables for this control class are available in the `data` JS object; |
| 86 | * export custom variables by overriding {@see WP_Customize_Control::to_json()}. |
| 87 | * |
| 88 | * @see WP_Customize_Control::print_template() |
| 89 | * @since 1.0 |
| 90 | */ |
| 91 | protected function content_template() { |
| 92 | ?> |
| 93 | |
| 94 | <div class="kirki-tab" data-kirki-tab-id="{{{ data.section }}}"> |
| 95 | <ul class="kirki-tab-menu"> |
| 96 | {{{ data.tabMenu }}} |
| 97 | </ul> |
| 98 | </div> |
| 99 | |
| 100 | <?php |
| 101 | } |
| 102 | |
| 103 | } |
| 104 |