| 1 |
<?php |
| 2 |
/** |
| 3 |
* PFBC (PHP Form Builder Class) - Third-party library |
| 4 |
* @package PFBC |
| 5 |
*/ |
| 6 |
|
| 7 |
// phpcs:disable WordPress.Security.EscapeOutput, WordPress.NamingConventions.PrefixAllGlobals, PluginCheck.CodeAnalysis.Heredoc -- Third-party library |
| 8 |
|
| 9 |
class Element_Button extends Element { |
| 10 |
protected $attributes = array("type" => "submit", "value" => "Submit"); |
| 11 |
protected $icon; |
| 12 |
|
| 13 |
public function __construct($label = "Submit", $type = "", ?array $properties = null) { |
| 14 |
if(!is_array($properties)) |
| 15 |
$properties = array(); |
| 16 |
|
| 17 |
if(!empty($type)) |
| 18 |
$properties["type"] = $type; |
| 19 |
|
| 20 |
if(empty($properties["value"])) |
| 21 |
$properties["value"] = $label; |
| 22 |
|
| 23 |
parent::__construct($label, "", $properties); |
| 24 |
} |
| 25 |
|
| 26 |
public function jQueryDocumentReady() { |
| 27 |
/*Unless explicitly prevented, jQueryUI's button widget functionality is applied to |
| 28 |
the each Button element.*/ |
| 29 |
if(!in_array("jQueryUIButtons", $this->form->getPrevent())) { |
| 30 |
echo 'jQuery("#', $this->attributes["id"], '").button('; |
| 31 |
/*Any of the jQueryUI framework icons can be added to your buttons via the icon |
| 32 |
property. See http://jqueryui.com/themeroller/ for a complete list of available |
| 33 |
icons.*/ |
| 34 |
if(!empty($this->icon)) |
| 35 |
echo '{ icons: { primary: "ui-icon-', $this->icon, '" } }'; |
| 36 |
echo ');'; |
| 37 |
} |
| 38 |
} |
| 39 |
|
| 40 |
public function render() { |
| 41 |
/*The button tag is used instead of input b/c it functions better with jQueryUI's |
| 42 |
button widget - specifically the icon option.*/ |
| 43 |
echo '<button', $this->getAttributes(), '>', $this->label, '</button>'; |
| 44 |
} |
| 45 |
} |
| 46 |
|