PluginProbe ʕ •ᴥ•ʔ
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF / trunk
Robin Image Optimizer – Unlimited Image Optimization, WebP & AVIF vtrunk
2.0.5 trunk 1.3.7 1.4.0 1.4.1 1.4.2 1.4.6 1.5.0 1.5.3 1.5.6 1.5.8 1.6.5 1.6.6 1.6.9 1.7.0 1.7.4 1.8.1 1.8.2 1.9.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4
robin-image-optimizer / libs / factory / forms / controls / checkbox.php
robin-image-optimizer / libs / factory / forms / controls Last commit date
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
checkbox.php
181 lines
1 <?php
2
3 /**
4 * Checkbox Control
5 *
6 * Main options:
7 * name => a name of the control
8 * value => a value to show in the control
9 * default => a default value of the control if the "value" option is not specified
10 *
11 * @package factory-forms
12 * @since 1.0.0
13 */
14
15 // Exit if accessed directly
16 if ( ! defined( 'ABSPATH' ) ) {
17 exit;
18 }
19
20 if ( ! class_exists( 'Wbcr_FactoryForms600_CheckboxControl' ) ) {
21
22 class Wbcr_FactoryForms600_CheckboxControl extends Wbcr_FactoryForms600_Control {
23
24 public $type = 'checkbox';
25
26 public function getSubmitValue( $name, $sub_name ) {
27 $name_on_form = $this->getNameOnForm( $name );
28
29 return isset( $_POST[ $name_on_form ] ) && $_POST[ $name_on_form ] != 0
30 ? 1
31 : 0;
32 }
33
34 /**
35 * Shows the html markup of the control.
36 *
37 * @since 1.0.0
38 * @return void
39 */
40 public function html() {
41
42 $events_on_data = $this->getOption( 'eventsOn', [] );
43 $events_off_data = $this->getOption( 'eventsOff', [] );
44
45 if ( ! empty( $events_on_data ) || ! empty( $events_off_data ) ) {
46
47 $events_on_string_data = json_encode( $events_on_data );
48 $events_off_string_data = json_encode( $events_off_data );
49
50 $name_on_form = $this->getNameOnForm();
51 $value = $this->getValue();
52
53 $print_styles = '';
54
55 if ( $value ) {
56 $current_events_data = $events_on_data;
57 } else {
58 $current_events_data = $events_off_data;
59 }
60
61 foreach ( $current_events_data as $event_name => $selectors ) {
62 if ( $event_name == 'hide' ) {
63 $print_styles .= $selectors . '{display:none;}';
64 } elseif ( $event_name == 'show' ) {
65 $print_styles .= $selectors . '{display:block;}';
66 }
67 }
68
69 echo '<style>' . esc_html( $print_styles ) . '</style>';
70 ?>
71
72 <script>
73 // Onepress factory checkbox control events
74 if( void 0 === window.__factory_checkbox_control_events_on_data ) {
75 window.__factory_checkbox_control_events_on_data = {};
76 }
77 if( void 0 === window.__factory_checkbox_control_events_off_data ) {
78 window.__factory_checkbox_control_events_off_data = {};
79 }
80 window.__factory_checkbox_control_events_on_data['<?php echo esc_attr( $name_on_form ); ?>'] = <?php echo $events_on_string_data; ?>;
81 window.__factory_checkbox_control_events_off_data['<?php echo esc_attr( $name_on_form ); ?>'] = <?php echo $events_off_string_data; ?>;
82 </script>
83 <?php
84 }
85
86 if ( 'buttons' == $this->getOption( 'way' ) ) {
87 $this->buttonsHtml();
88 } else {
89 $this->defaultHtml();
90 }
91 }
92
93 /**
94 * Shows the Buttons Checkbox.
95 *
96 * @since 1.0.0
97 * @return void
98 */
99 protected function buttonsHtml() {
100 $value = esc_attr( $this->getValue() );
101 $name_on_form = $this->getNameOnForm();
102
103 $this->addCssClass( 'factory-buttons-way' );
104 $this->addCssClass( 'btn-group' );
105
106 if ( $this->getOption( 'tumbler', false ) ) {
107 $this->addCssClass( 'factory-tumbler' );
108 }
109
110 $tumbler_function = $this->getOption( 'tumblerFunction', false );
111 if ( $tumbler_function ) {
112 $this->addHtmlData( 'tumbler-function', $tumbler_function );
113 }
114
115 if ( $this->getOption( 'tumblerHint', false ) ) {
116 $this->addCssClass( 'factory-has-tumbler-hint' );
117
118 $delay = $this->getOption( 'tumblerDelay', 3000 );
119 $this->addHtmlData( 'tumbler-delay', $delay );
120 }
121
122 ?>
123 <div <?php $this->attrs(); ?>>
124 <button type="button" class="btn btn-default btn-small btn-sm factory-on
125 <?php
126 if ( $value ) {
127 echo 'active';
128 }
129 ?>
130 "><?php _e( 'On', 'robin-image-optimizer' ); ?></button>
131 <button type="button" class="btn btn-default btn-small btn-sm factory-off
132 <?php
133 if ( ! $value ) {
134 echo 'active';
135 }
136 ?>
137 " data-value="0"><?php _e( 'Off', 'robin-image-optimizer' ); ?></button>
138 <input type="checkbox" style="display: none" id="<?php echo esc_attr( $name_on_form ); ?>" class="factory-result" name="<?php echo esc_attr( $name_on_form ); ?>" value="<?php echo esc_attr( $value ); ?>"
139 <?php
140 if ( $value ) {
141 echo 'checked="checked"';
142 }
143 ?>
144 " />
145 </div>
146 <?php if ( $this->getOption( 'tumblerHint', false ) ) { ?>
147 <div class="factory-checkbox-tumbler-hint factory-tumbler-hint" style="display: none;">
148 <div class="factory-tumbler-content">
149 <?php echo esc_html( $this->getOption( 'tumblerHint' ) ); ?>
150 </div>
151 </div>
152 <?php } ?>
153 <?php
154 }
155
156 /**
157 * Shows the standart checkbox.
158 *
159 * @since 1.0.0
160 * @return void
161 */
162 protected function defaultHtml() {
163 $value = esc_attr( $this->getValue() );
164 $name_on_form = $this->getNameOnForm();
165
166 $this->addHtmlAttr( 'type', 'checkbox' );
167 $this->addHtmlAttr( 'id', $name_on_form );
168 $this->addHtmlAttr( 'name', $name_on_form );
169 $this->addHtmlAttr( 'value', $value );
170
171 if ( $value ) {
172 $this->addHtmlAttr( 'checked', 'checked' );
173 }
174 $this->addCssClass( 'factory-default-way' );
175
176 ?>
177 <input <?php $this->attrs(); ?>/>
178 <?php
179 }
180 }
181 }