PluginProbe
QuadMenu – Mega Menu / 1.8.8
QuadMenu – Mega Menu v1.8.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 / lib / ReduxCore / inc / fields / spinner / field_spinner.php

field_spinner.php in QuadMenu – Mega Menu 1.8.8, at lib/ReduxCore/inc/fields/spinner/field_spinner.php

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