customs
5 months ago
holders
5 months ago
checkbox.php
5 months ago
color-and-opacity.php
5 months ago
color.php
5 months ago
datepicker-range.php
5 months ago
dropdown-and-colors.php
5 months ago
dropdown.php
5 months ago
font.php
5 months ago
google-font.php
5 months ago
gradient.php
5 months ago
hidden.php
5 months ago
index.php
5 months ago
integer.php
5 months ago
list.php
5 months ago
multiple-textbox.php
5 months ago
paddings-editor.php
5 months ago
pattern.php
5 months ago
radio-colors.php
5 months ago
radio.php
5 months ago
textarea.php
5 months ago
textbox.php
5 months ago
url.php
5 months ago
wp-editor.php
5 months ago
integer.php
166 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Integer Control |
| 5 | * Main options: |
| 6 | * name => a name of the control |
| 7 | * way => Тип значения 'slider' - слайдер, 'checkbox-slider' - чекбокс активирует слайдер, по умолчанию input |
| 8 | * checkbox => Указывается если, 'way' имеет значение 'checkbox-slider' |
| 9 | * Пример: |
| 10 | * array( |
| 11 | * 'on' => __('Show shadow', 'bizpanda'), |
| 12 | * 'off' => __('Hide shadow', 'bizpanda'), |
| 13 | * ) |
| 14 | * title => Заголовок контрола |
| 15 | * slider-title => Заголовок слайдера( Только если 'way' имеет значение 'checkbox-slider' ) |
| 16 | * range => Диапазон значений, указывается если 'way' имеет значение 'slider' или 'checkbox-slider' |
| 17 | * Пример: array(0,100) |
| 18 | * units => Единицы измерения(px,pt,em,%) |
| 19 | * isActive => Включение, отключение поля |
| 20 | * value => a value to show in the control |
| 21 | * default => a default value of the control if the "value" option is not specified |
| 22 | * |
| 23 | * @package factory-forms |
| 24 | * @since 1.0.0 |
| 25 | */ |
| 26 | |
| 27 | // Exit if accessed directly |
| 28 | if ( ! defined( 'ABSPATH' ) ) { |
| 29 | exit; |
| 30 | } |
| 31 | |
| 32 | if ( ! class_exists( 'Wbcr_FactoryForms600_IntegerControl' ) ) { |
| 33 | |
| 34 | class Wbcr_FactoryForms600_IntegerControl extends Wbcr_FactoryForms600_Control { |
| 35 | |
| 36 | public $type = 'integer'; |
| 37 | |
| 38 | /** |
| 39 | * Converting string to integer. |
| 40 | * |
| 41 | * @since 1.0.0 |
| 42 | * @return integer |
| 43 | */ |
| 44 | public function html() { |
| 45 | |
| 46 | $name = $this->getNameOnForm(); |
| 47 | $value = esc_attr( $this->getValue() ); |
| 48 | $step = 1; |
| 49 | $range = $checkbox = []; |
| 50 | $is_active = $this->getOption( 'isActive', 1 ); |
| 51 | $unit = esc_attr( $this->getOption( 'units' ) ); |
| 52 | |
| 53 | $way = $this->getOption( 'way' ); |
| 54 | |
| 55 | if ( empty( $way ) ) { |
| 56 | $way = 'text'; |
| 57 | } |
| 58 | |
| 59 | $has_slider = false; |
| 60 | |
| 61 | if ( in_array( $way, [ 'slider', 'checkbox-slider' ] ) ) { |
| 62 | $range = $this->getOption( 'range', [ 0, 99 ] ); |
| 63 | $slider_title = $this->getOption( 'slider-title' ); |
| 64 | $checkbox = $this->getOption( 'checkbox' ); |
| 65 | $step = $this->getOption( 'step', 1 ); |
| 66 | $has_slider = true; |
| 67 | } |
| 68 | |
| 69 | $this->addCssClass( 'factory-way-' . $way ); |
| 70 | |
| 71 | if ( $has_slider ) { |
| 72 | $this->addCssClass( 'factory-has-slider' ); |
| 73 | } |
| 74 | ?> |
| 75 | |
| 76 | <div <?php $this->attrs(); ?>> |
| 77 | <?php if ( $has_slider ) { ?> |
| 78 | |
| 79 | <?php if ( 'checkbox-slider' == $way ) { ?> |
| 80 | |
| 81 | <div> |
| 82 | <label for="<?php echo esc_attr( $name ); ?>_checker"> |
| 83 | <?php |
| 84 | echo $is_active |
| 85 | ? $checkbox['off'] |
| 86 | : $checkbox['on']; |
| 87 | ?> |
| 88 | </label><br> |
| 89 | <input type="checkbox" id="<?php echo esc_attr( $name ); ?>_checker" class="factory-checkbox" name="<?php echo esc_attr( $name ); ?>_checker" |
| 90 | <?php |
| 91 | echo $is_active |
| 92 | ? 'checked' |
| 93 | : '' |
| 94 | ?> |
| 95 | > |
| 96 | </div> |
| 97 | |
| 98 | <?php } ?> |
| 99 | |
| 100 | <div |
| 101 | data-units="<?php echo esc_attr( $unit ); ?>" |
| 102 | data-range-start="<?php echo esc_attr( $range[0] ); ?>" |
| 103 | data-range-end="<?php echo esc_attr( $range[1] ); ?>" |
| 104 | data-step="<?php echo esc_attr( $step ); ?>" |
| 105 | <?php |
| 106 | echo ! $is_active |
| 107 | ? ' style="display:none;"' |
| 108 | : '' |
| 109 | ?> |
| 110 | class="factory-slider-container factory-slider-container-<?php echo esc_attr( $name ); ?>"> |
| 111 | <?php if ( ! empty( $slider_title ) ) : ?> |
| 112 | <label class="factory-title"> |
| 113 | <?php echo esc_html( $this->getOption( 'slider-title' ) ); ?> |
| 114 | </label> |
| 115 | <?php endif; ?> |
| 116 | |
| 117 | <div class="factory-slider"> |
| 118 | <div class="factory-bar"></div> |
| 119 | <span class="factory-visible-value"> |
| 120 | <?php echo esc_html( $value ); ?><?php echo esc_html( $unit ); ?> |
| 121 | </span> |
| 122 | </div> |
| 123 | <input type="hidden" name="<?php echo esc_attr( $name ); ?>" class="factory-result" value="<?php echo esc_attr( $value ); ?>"/> |
| 124 | </div> |
| 125 | |
| 126 | <?php } else { ?> |
| 127 | |
| 128 | <input type="number" id="<?php echo esc_attr( $name ); ?>" name="<?php echo esc_attr( $name ); ?>" value="<?php echo esc_attr( $value ); ?>" class="factory-input-text"/> |
| 129 | <span class="factory-units"><?php echo esc_html( $unit ); ?></span> |
| 130 | |
| 131 | <?php } ?> |
| 132 | </div><!-- .factory-integer --> |
| 133 | <?php |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Форматирует значение без единиц измерения |
| 138 | * |
| 139 | * @param string $values |
| 140 | * @param string $unit |
| 141 | * @return string |
| 142 | */ |
| 143 | public function valueFormatWithoutUnit( $values, $unit ) { |
| 144 | if ( ! is_numeric( $values ) ) { |
| 145 | return str_replace( $unit, '', $values ); |
| 146 | } else { |
| 147 | return $values; |
| 148 | } |
| 149 | } |
| 150 | |
| 151 | /** |
| 152 | * Форматирует значение c единицами измерения |
| 153 | * |
| 154 | * @param string $values |
| 155 | * @param string $unit |
| 156 | * @return string |
| 157 | */ |
| 158 | public function valueFormatWithUnit( $values, $unit ) { |
| 159 | if ( is_numeric( $values ) ) { |
| 160 | return $values . $unit; |
| 161 | } else { |
| 162 | return $values; |
| 163 | } |
| 164 | } |
| 165 | } |
| 166 | } |