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