switcher.php 2.1 KB

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