PluginProbe
QuadMenu – Mega Menu / 3.3.8
QuadMenu – Mega Menu v3.3.8
3.3.8 3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 All 88 releases
quadmenu / redux / ReduxCore / inc / fields / spinner / field_spinner.php

field_spinner.php in QuadMenu – Mega Menu 3.3.8, at redux/ReduxCore/inc/fields/spinner/field_spinner.php

186 lines 4.9 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 // Exit if accessed directly
4 if ( ! defined( 'ABSPATH' ) ) {
5 exit;
6 }
7
8 if ( ! class_exists( 'ReduxFrameworkLegacy_spinner' ) ) {
9 class ReduxFrameworkLegacy_spinner {
10
11 public $parent;
12 public $field;
13 public $value;
14
15 /**
16 * Field Constructor.
17 * Required - must call the parent constructor, then assign field and value to vars, and obviously call the render field function
18 *
19 * @since ReduxFrameworkLegacy 3.0.0
20 */
21 function __construct( $field = array(), $value = '', $parent = null ) {
22 $this->parent = $parent;
23 $this->field = $field;
24 $this->value = $value;
25 } //function
26
27 /**
28 * Field Render Function.
29 * Takes the vars and outputs the HTML for the field in the settings
30 *
31 * @since ReduxFrameworkLegacy 3.0.0
32 */
33 function render() {
34
35 $params = array(
36 'min' => '',
37 'max' => '',
38 'step' => '',
39 'default' => '',
40 );
41
42 $this->field = wp_parse_args( $this->field, $params );
43 $data_string = '';
44 foreach ( $this->field as $key => $val ) {
45 if ( in_array( $key, array( 'min', 'max', 'step', 'default' ) ) ) {
46 $data_string .= ' data-' . $key . '="' . $val . '"';
47 }
48 }
49 $data_string .= ' data-val="' . $val . '"';
50
51 // Don't allow input edit if there's a step
52 $readonly = '';
53 if ( isset( $this->field['edit'] ) && $this->field['edit'] == false ) {
54 $readonly = ' readonly="readonly"';
55 }
56
57 echo '<div id="' . $this->field['id'] . '-spinner" class="redux_spinner" rel="' . $this->field['id'] . '">';
58 echo '<input type="text" ' . $data_string . ' name="' . $this->field['name'] . $this->field['name_suffix'] . '" id="' . $this->field['id'] . '" value="' . $this->value . '" class="mini spinner-input ' . $this->field['class'] . '"' . $readonly . '/>';
59 echo '</div>';
60 } //function
61
62 /**
63 * Clean the field data to the fields defaults given the parameters.
64 *
65 * @since Redux_Framework 3.1.1
66 */
67 function clean() {
68
69 if ( empty( $this->field['min'] ) ) {
70 $this->field['min'] = 0;
71 } else {
72 $this->field['min'] = intval( $this->field['min'] );
73 }
74
75 if ( empty( $this->field['max'] ) ) {
76 $this->field['max'] = intval( $this->field['min'] ) + 1;
77 } else {
78 $this->field['max'] = intval( $this->field['max'] );
79 }
80
81 if ( empty( $this->field['step'] ) || $this->field['step'] > $this->field['max'] ) {
82 $this->field['step'] = 1;
83 } else {
84 $this->field['step'] = intval( $this->field['step'] );
85 }
86
87 if ( empty( $this->value ) && ! empty( $this->field['default'] ) && intval( $this->field['min'] ) >= 1 ) {
88 $this->value = intval( $this->field['default'] );
89 }
90
91 if ( empty( $this->value ) && intval( $this->field['min'] ) >= 1 ) {
92 $this->value = intval( $this->field['min'] );
93 }
94
95 if ( empty( $this->value ) ) {
96 $this->value = 0;
97 }
98
99 // Extra Validation
100 if ( $this->value < $this->field['min'] ) {
101 $this->value = intval( $this->field['min'] );
102 } elseif ( $this->value > $this->field['max'] ) {
103 $this->value = intval( $this->field['max'] );
104 }
105 }
106
107 /**
108 * Enqueue Function.
109 * If this field requires any scripts, or css define this function and register/enqueue the scripts/css
110 *
111 * @since ReduxFrameworkLegacy 3.0.0
112 */
113 function enqueue() {
114
115 wp_enqueue_script(
116 'redux-field-spinner-custom-js',
117 ReduxFrameworkLegacy::$_url . 'inc/fields/spinner/vendor/spinner_custom.js',
118 array( 'jquery', 'redux-js' ),
119 time(),
120 true
121 );
122
123 wp_enqueue_script(
124 'redux-field-spinner-js',
125 ReduxFrameworkLegacy::$_url . 'inc/fields/spinner/field_spinner' . ReduxLegacy_Functions::isMin() . '.js',
126 array(
127 'jquery',
128 'redux-field-spinner-custom-js',
129 'jquery-ui-core',
130 'jquery-ui-dialog',
131 'redux-js',
132 ),
133 time(),
134 true
135 );
136
137 if ( $this->parent->args['dev_mode'] ) {
138 wp_enqueue_style(
139 'redux-field-spinner-css',
140 ReduxFrameworkLegacy::$_url . 'inc/fields/spinner/field_spinner.css',
141 array(),
142 time(),
143 'all'
144 );
145 }
146 }
147
148 public function output() {
149 $style = '';
150
151 if ( ! empty( $this->value ) ) {
152 if ( ! empty( $this->field['output'] ) && is_array( $this->field['output'] ) ) {
153 $css = $this->parseCSS( $this->value, $this->field['output'] );
154 $this->parent->outputCSS .= $css;
155 }
156
157 if ( ! empty( $this->field['compiler'] ) && is_array( $this->field['compiler'] ) ) {
158 $css = $this->parseCSS( $this->value, $this->field['compiler'] );
159 $this->parent->compilerCSS .= $css;
160
161 }
162 }
163 }
164
165 private function parseCSS( $value, $output ) {
166 // No notices
167 $css = '';
168
169 $unit = isset( $this->field['output_unit'] ) ? $this->field['output_unit'] : 'px';
170
171 // Must be an array
172 if ( is_numeric( $value ) ) {
173 if ( is_array( $output ) ) {
174 foreach ( $output as $mode => $selector ) {
175 if ( ! empty( $mode ) && ! empty( $selector ) ) {
176 $css .= $selector . '{' . $mode . ': ' . $value . $unit . ';}';
177 }
178 }
179 }
180 }
181
182 return $css;
183 }
184 }
185 }
186