slider.php 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. <?php if ( ! defined( 'ABSPATH' ) ) { die; } // Cannot access directly.
  2. /**
  3. *
  4. * Field: slider
  5. *
  6. * @since 1.0.0
  7. * @version 1.0.0
  8. *
  9. */
  10. if ( ! class_exists( 'CSF_Field_slider' ) ) {
  11. class CSF_Field_slider extends CSF_Fields {
  12. public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) {
  13. parent::__construct( $field, $value, $unique, $where, $parent );
  14. }
  15. public function render() {
  16. $args = wp_parse_args( $this->field, array(
  17. 'max' => 100,
  18. 'min' => 0,
  19. 'step' => 1,
  20. 'unit' => '',
  21. ) );
  22. $is_unit = ( ! empty( $args['unit'] ) ) ? ' csf--is-unit' : '';
  23. echo $this->field_before();
  24. echo '<div class="csf--wrap">';
  25. echo '<div class="csf-slider-ui"></div>';
  26. echo '<div class="csf--input">';
  27. echo '<input type="number" name="'. esc_attr( $this->field_name() ) .'" value="'. esc_attr( $this->value ) .'"'. $this->field_attributes( array( 'class' => 'csf-input-number'. esc_attr( $is_unit ) ) ) .' data-min="'. esc_attr( $args['min'] ) .'" data-max="'. esc_attr( $args['max'] ) .'" data-step="'. esc_attr( $args['step'] ) .'" step="any" />';
  28. echo ( ! empty( $args['unit'] ) ) ? '<span class="csf--unit">'. esc_attr( $args['unit'] ) .'</span>' : '';
  29. echo '</div>';
  30. echo '</div>';
  31. echo $this->field_after();
  32. }
  33. public function enqueue() {
  34. if ( ! wp_script_is( 'jquery-ui-slider' ) ) {
  35. wp_enqueue_script( 'jquery-ui-slider' );
  36. }
  37. }
  38. public function output() {
  39. $output = '';
  40. $elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] );
  41. $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : '';
  42. $mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width';
  43. $unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px';
  44. if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) {
  45. foreach ( $elements as $key_property => $element ) {
  46. if ( is_numeric( $key_property ) ) {
  47. if ( $mode ) {
  48. $output = implode( ',', $elements ) .'{'. $mode .':'. $this->value . $unit . $important .';}';
  49. }
  50. break;
  51. } else {
  52. $output .= $element .'{'. $key_property .':'. $this->value . $unit . $important .'}';
  53. }
  54. }
  55. }
  56. $this->parent->output_css .= $output;
  57. return $output;
  58. }
  59. }
  60. }