PluginProbe
Contact Forms by Cimatti / 2.1.2
Contact Forms by Cimatti v2.1.2
2.3.6 2.3.5 2.3.0 2.2.32 2.2.4 2.2.0 2.1.2 2.1.1 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 1.3.4 1.3.5 1.3.6 1.3.7 1.3.8 1.3.9 1.4.0 1.4.1 All 62 releases
contact-forms / PFBC / Element / Checksort.php

Checksort.php in Contact Forms by Cimatti 2.1.2, at PFBC/Element/Checksort.php

94 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * PFBC (PHP Form Builder Class) - Third-party library
4 * @package PFBC
5 */
6 if ( ! defined( 'ABSPATH' ) ) exit;
7
8 // phpcs:disable WordPress.Security.EscapeOutput, WordPress.NamingConventions.PrefixAllGlobals, PluginCheck.CodeAnalysis.Heredoc -- Third-party library
9
10 class Element_Checksort extends Element_Sort {
11 protected $attributes = array("type" => "checkbox");
12 protected $inline;
13 protected $maxheight;
14
15 public function jQueryDocumentReady() {
16 parent::jQueryDocumentReady();
17 if(!empty($this->inline))
18 echo 'jQuery("#', $this->attributes["id"], ' .pfbc-checkbox:last").css("margin-right", "0");';
19 else
20 echo 'jQuery("#', $this->attributes["id"], ' .pfbc-checkbox:last").css({ "padding-bottom": "0", "border-bottom": "none" });';
21
22 if(!empty($this->maxheight) && is_numeric($this->maxheight)) {
23 echo <<<JS
24 var checkboxes = jQuery("#{$this->attributes["id"]} .pfbc-checkboxes");
25 if(checkboxes.outerHeight() > {$this->maxheight}) {
26 checkboxes.css({
27 "height": "{$this->maxheight}px",
28 "overflow": "auto",
29 "overflow-x": "hidden"
30 });
31 }
32 JS;
33 }
34 }
35
36 public function render() {
37 if(isset($this->attributes["value"])) {
38 if(!is_array($this->attributes["value"]))
39 $this->attributes["value"] = array($this->attributes["value"]);
40 }
41 else
42 $this->attributes["value"] = array();
43
44 if(substr($this->attributes["name"], -2) != "[]")
45 $this->attributes["name"] .= "[]";
46
47 $count = 0;
48 $existing = "";
49 echo '<div id="', $this->attributes["id"], '"><div class="pfbc-checkboxes">';
50 foreach($this->options as $value => $text) {
51 $value = $this->getOptionValue($value);
52 echo '<div class="pfbc-checkbox"><table cellpadding="0" cellspacing="0"><tr><td valign="top"><input id="', $this->attributes["id"], "-", $count, '"', $this->getAttributes(array("id", "value", "checked", "name", "onclick")), ' value="', $this->filter($value), '"';
53 if(in_array($value, $this->attributes["value"]))
54 echo ' checked="checked"';
55 echo ' onclick="updateChecksort(this, \'', $this->filter($text), '\');"/></td><td><label for="', $this->attributes["id"], "-", $count, '">', $text, '</label></td></tr></table></div>';
56
57 if(in_array($value, $this->attributes["value"]))
58 $existing .= '<li id="' . $this->attributes["id"] . "-sort-" . $count . '" class="ui-state-default"><input type="hidden" name="' . $this->attributes["name"] . '" value="' . $value . '"/>' . $text . '</li>';
59
60 ++$count;
61 }
62 echo '</div>';
63
64 if(!empty($this->inline))
65 echo '<div style="clear: both;"></div>';
66
67 echo '<ul>', $existing, '</ul></div>';
68 }
69
70 function renderJS() {
71 echo <<<JS
72 if(typeof updateChecksort != "function") {
73 function updateChecksort(element, text) {
74 var position = element.id.lastIndexOf("-");
75 var id = element.id.substr(0, position);
76 var index = element.id.substr(position + 1);
77 if(element.checked)
78 jQuery("#" + id + " ul").append('<li id="' + id + '-sort-' + index + '" class="ui-state-default"><input type="hidden" name="{$this->attributes["name"]}" value="' + element.value + '"/>' + text + '</li>');
79 else
80 jQuery("#" + id + "-sort-" + index).remove();
81 }
82 }
83 JS;
84 }
85
86 function renderCSS() {
87 if(!empty($this->inline))
88 echo '#', $this->attributes["id"], ' .pfbc-checkbox { float: left; margin-right: 0.5em; }';
89 else
90 echo '#', $this->attributes["id"], ' .pfbc-checkbox { padding: 0.5em 0; border-bottom: 1px solid #f4f4f4; }';
91 parent::renderCSS();
92 }
93 }
94