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