PluginProbe ʕ •ᴥ•ʔ
VikAppointments Services Booking Calendar / 1.2.21
VikAppointments Services Booking Calendar v1.2.21
1.2.21 1.2.20 trunk 1.2.17 1.2.18 1.2.19
vikappointments / site / helpers / libraries / widget / radio / ios.php
vikappointments / site / helpers / libraries / widget / radio Last commit date
index.html 3 days ago ios.php 3 days ago joomla.php 3 days ago radio.php 3 days ago
ios.php
112 lines
1 <?php
2 /**
3 * @package VikAppointments
4 * @subpackage core
5 * @author E4J s.r.l.
6 * @copyright Copyright (C) 2021 E4J s.r.l. All Rights Reserved.
7 * @license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL
8 * @link https://vikwp.com
9 */
10
11 // No direct access
12 defined('ABSPATH') or die('No script kiddies please!');
13
14 // load parent class
15 VAPLoader::import('libraries.widget.radio.radio');
16
17 /**
18 * This class provides the construction of a radio button (toggle) using the Apple iOS style.
19 * The radio button built from this class MUST have only 2 states: 1 and 0.
20 *
21 * @since 1.6
22 */
23 class UIRadioIOS extends UIRadio
24 {
25 /**
26 * Insert a radio button element.
27 * @override
28 *
29 * @param object $element The radio button element.
30 *
31 * @return UIRadio This object to support chaining.
32 */
33 public function addElement($element)
34 {
35 if (count(parent::getElements()) < 2)
36 {
37 parent::addElement($element);
38 }
39
40 return $this;
41 }
42
43 /**
44 * Adapt the given element.
45 *
46 * @param object $element The radio button element.
47 *
48 * @return object The adapted element.
49 */
50 protected function bind($element)
51 {
52 if (isset($element->htmlAttr) && stripos($element->htmlAttr, 'onclick') !== false)
53 {
54 // strip onclick and trim ending double quotes
55 $function = rtrim($element->htmlAttr, '"');
56 $function = str_replace('onClick="', '', $function);
57 $function = str_replace('onclick="', '', $function);
58
59 // the javascript function to call
60 $element->htmlAttr = $function;
61 }
62
63 if (empty($element->id))
64 {
65 $element->id = parent::getName() . '1';
66 }
67
68 if (empty($element->value))
69 {
70 $element->value = 1;
71 }
72
73 return $element;
74 }
75
76 /**
77 * Call this method to build and return the HTML of the input.
78 *
79 * @return string The input HTML.
80 */
81 public function display()
82 {
83 $elements = parent::getElements();
84
85 if (count($elements) != 2)
86 {
87 return '';
88 }
89
90 list($yes, $no) = $elements;
91
92 $checked = '';
93 if (!empty($yes->checked))
94 {
95 $checked = 'checked="checked"';
96 }
97
98 $onchange = '';
99 if (!empty($yes->htmlAttr) || !empty($no->htmlAttr))
100 {
101 $onchange = 'onchange="jQuery(this).is(\':checked\') ? function(){'.$yes->htmlAttr.'}() : function(){'.$no->htmlAttr.'}()"';
102 }
103
104 $html = '<span class="switch-ios">
105 <input type="checkbox" name="'.parent::getName().'" value="'.$yes->value.'" id="'.$yes->id.'" class="ios-toggle ios-toggle-round" '.$checked.' '.$onchange.'/>
106 <label for="'.$yes->id.'"></label>
107 </span>';
108
109 return $html;
110 }
111 }
112