switcher.php (2126B)
1 <?php 2 namespace Elementor; 3 4 if ( ! defined( 'ABSPATH' ) ) { 5 exit; // Exit if accessed directly. 6 } 7 8 /** 9 * Elementor switcher control. 10 * 11 * A base control for creating switcher control. Displays an on/off switcher, 12 * basically a fancy UI representation of a checkbox. 13 * 14 * @since 1.0.0 15 */ 16 class Control_Switcher extends Base_Data_Control { 17 18 /** 19 * Get switcher control type. 20 * 21 * Retrieve the control type, in this case `switcher`. 22 * 23 * @since 1.0.0 24 * @access public 25 * 26 * @return string Control type. 27 */ 28 public function get_type() { 29 return 'switcher'; 30 } 31 32 /** 33 * Render switcher control output in the editor. 34 * 35 * Used to generate the control HTML in the editor using Underscore JS 36 * template. The variables for the class are available using `data` JS 37 * object. 38 * 39 * @since 1.0.0 40 * @access public 41 */ 42 public function content_template() { 43 ?> 44 <div class="elementor-control-field"> 45 <label for="<?php $this->print_control_uid(); ?>" class="elementor-control-title">{{{ data.label }}}</label> 46 <div class="elementor-control-input-wrapper"> 47 <label class="elementor-switch elementor-control-unit-2"> 48 <input id="<?php $this->print_control_uid(); ?>" type="checkbox" data-setting="{{ data.name }}" class="elementor-switch-input" value="{{ data.return_value }}"> 49 <span class="elementor-switch-label" data-on="{{ data.label_on }}" data-off="{{ data.label_off }}"></span> 50 <span class="elementor-switch-handle"></span> 51 </label> 52 </div> 53 </div> 54 <# if ( data.description ) { #> 55 <div class="elementor-control-field-description">{{{ data.description }}}</div> 56 <# } #> 57 <?php 58 } 59 60 /** 61 * Get switcher control default settings. 62 * 63 * Retrieve the default settings of the switcher control. Used to return the 64 * default settings while initializing the switcher control. 65 * 66 * @since 1.0.0 67 * @access protected 68 * 69 * @return array Control default settings. 70 */ 71 protected function get_default_settings() { 72 return [ 73 'label_off' => esc_html__( 'No', 'elementor' ), 74 'label_on' => esc_html__( 'Yes', 'elementor' ), 75 'return_value' => 'yes', 76 ]; 77 } 78 }