← All changes
|
admin/views/sp-framework/fields/spinner/spinner.php
+39
-35
4.0.8
→
2.2.10
View file →
| @@ -1,39 +1,20 @@ | ||
| 1 | -<?php | |
| 1 | +<?php if ( ! defined( 'ABSPATH' ) ) { | |
| 2 | + die; } // Cannot access directly. | |
| 2 | 3 | /** |
| 3 | - * The framework spinner fields file. | |
| 4 | 4 | * |
| 5 | - * @package Smart_Post_Show | |
| 6 | - * @subpackage Smart_Post_Show/admin | |
| 5 | + * Field: spinner | |
| 6 | + * | |
| 7 | + * @since 1.0.0 | |
| 8 | + * @version 1.0.0 | |
| 7 | 9 | */ |
| 8 | - | |
| 9 | -if ( ! defined( 'ABSPATH' ) ) { | |
| 10 | - die; | |
| 11 | -} // Cannot access directly. | |
| 12 | - | |
| 13 | 10 | if ( ! class_exists( 'SP_PC_Field_spinner' ) ) { |
| 14 | - /** | |
| 15 | - * SP_PC_Field_spinner | |
| 16 | - */ | |
| 17 | 11 | class SP_PC_Field_spinner extends SP_PC_Fields { |
| 18 | - /** | |
| 19 | - * Field constructor. | |
| 20 | - * | |
| 21 | - * @param array $field The field type. | |
| 22 | - * @param string $value The values of the field. | |
| 23 | - * @param string $unique The unique ID for the field. | |
| 24 | - * @param string $where To where show the output CSS. | |
| 25 | - * @param string $parent The parent args. | |
| 26 | - */ | |
| 12 | + | |
| 27 | 13 | public function __construct( $field, $value = '', $unique = '', $where = '', $parent = '' ) { |
| 28 | 14 | parent::__construct( $field, $value, $unique, $where, $parent ); |
| 29 | 15 | } |
| 30 | - | |
| 31 | - /** | |
| 32 | - * Render | |
| 33 | - * | |
| 34 | - * @return void | |
| 35 | - */ | |
| 16 | + | |
| 36 | 17 | public function render() { |
| 37 | 18 | |
| 38 | 19 | $args = wp_parse_args( |
| 39 | 20 | $this->field, |
| @@ -44,19 +25,14 @@ | ||
| 44 | 25 | 'unit' => '', |
| 45 | 26 | ) |
| 46 | 27 | ); |
| 47 | 28 | |
| 48 | - echo wp_kses_post( $this->field_before() ); | |
| 49 | - echo '<div class="spf--spin"><input type="number" name="' . esc_attr( $this->field_name() ) . '" value="' . esc_attr( $this->value ) . '"' . wp_kses_post( $this->field_attributes( array( 'class' => 'spf-input-number' ) ) ) . ' data-max="' . esc_attr( $args['max'] ) . '" data-min="' . esc_attr( $args['min'] ) . '" data-step="' . esc_attr( $args['step'] ) . '" data-unit="' . esc_attr( $args['unit'] ) . '"/></div>'; | |
| 50 | - echo wp_kses_post( $this->field_after() ); | |
| 29 | + echo $this->field_before(); | |
| 30 | + echo '<div class="spf--spin"><input type="number" name="'. $this->field_name() .'" value="'. $this->value .'"'. $this->field_attributes( array( 'class' => 'spf-input-number' ) ) .' data-max="'. $args['max'] .'" data-min="'. $args['min'] .'" data-step="'. $args['step'] .'" data-unit="'. $args['unit'] .'"/></div>'; | |
| 31 | + echo $this->field_after(); | |
| 51 | 32 | |
| 52 | 33 | } |
| 53 | 34 | |
| 54 | - /** | |
| 55 | - * Enqueue jQuery UI Spinner. | |
| 56 | - * | |
| 57 | - * @return void | |
| 58 | - */ | |
| 59 | 35 | public function enqueue() { |
| 60 | 36 | |
| 61 | 37 | if ( ! wp_script_is( 'jquery-ui-spinner' ) ) { |
| 62 | 38 | wp_enqueue_script( 'jquery-ui-spinner' ); |
| @@ -62,6 +38,34 @@ | ||
| 62 | 38 | wp_enqueue_script( 'jquery-ui-spinner' ); |
| 63 | 39 | } |
| 64 | 40 | |
| 65 | 41 | } |
| 42 | + | |
| 43 | + public function output() { | |
| 44 | + | |
| 45 | + $output = ''; | |
| 46 | + $elements = ( is_array( $this->field['output'] ) ) ? $this->field['output'] : array_filter( (array) $this->field['output'] ); | |
| 47 | + $important = ( ! empty( $this->field['output_important'] ) ) ? '!important' : ''; | |
| 48 | + $mode = ( ! empty( $this->field['output_mode'] ) ) ? $this->field['output_mode'] : 'width'; | |
| 49 | + $unit = ( ! empty( $this->field['unit'] ) ) ? $this->field['unit'] : 'px'; | |
| 50 | + | |
| 51 | + if ( ! empty( $elements ) && isset( $this->value ) && $this->value !== '' ) { | |
| 52 | + foreach ( $elements as $key_property => $element ) { | |
| 53 | + if ( is_numeric( $key_property ) ) { | |
| 54 | + if ( $mode ) { | |
| 55 | + $output = implode( ',', $elements ) . '{' . $mode . ':' . $this->value . $unit . $important . ';}'; | |
| 56 | + } | |
| 57 | + break; | |
| 58 | + } else { | |
| 59 | + $output .= $element . '{' . $key_property . ':' . $this->value . $unit . $important . '}'; | |
| 60 | + } | |
| 61 | + } | |
| 62 | + } | |
| 63 | + | |
| 64 | + $this->parent->output_css .= $output; | |
| 65 | + | |
| 66 | + return $output; | |
| 67 | + | |
| 68 | + } | |
| 69 | + | |
| 66 | 70 | } |
| 67 | 71 | } |