| 1 |
<?php |
| 2 |
class AccuaForm_Element_Radio extends AccuaForm_OptionElement { |
| 3 |
protected $attributes = array("type" => "radio"); |
| 4 |
protected $inline; |
| 5 |
protected $maxheight; |
| 6 |
|
| 7 |
public function jQueryDocumentReady() { |
| 8 |
if(!empty($this->inline)) |
| 9 |
echo 'jQuery("#', $this->attributes["id"], ' .pfbc-radio:last").css("margin-right", "0");'; |
| 10 |
else |
| 11 |
echo 'jQuery("#', $this->attributes["id"], ' .pfbc-radio:last").css({ "padding-bottom": "0", "border-bottom": "none" });'; |
| 12 |
|
| 13 |
if(!empty($this->maxheight) && is_numeric($this->maxheight)) { |
| 14 |
echo <<<JS |
| 15 |
var radiobuttons = jQuery("#{$this->attributes["id"]} .pfbc-radio-buttons"); |
| 16 |
if(radiobuttons.outerHeight() > {$this->maxheight}) { |
| 17 |
radiobuttons.css({ |
| 18 |
"height": "{$this->maxheight}px", |
| 19 |
"overflow": "auto", |
| 20 |
"overflow-x": "hidden" |
| 21 |
}); |
| 22 |
} |
| 23 |
JS; |
| 24 |
} |
| 25 |
} |
| 26 |
|
| 27 |
public function render() { |
| 28 |
$count = 0; |
| 29 |
$checked = false; |
| 30 |
echo '<div id="', $this->attributes["id"], '"><div class="pfbc-radio-buttons">'; |
| 31 |
foreach($this->options as $value => $text) { |
| 32 |
$value = $this->getOptionValue($value); |
| 33 |
echo '<div class="pfbc-radio"><input id="', $this->attributes["id"], "-", $count, '"', $this->getAttributes(array("id", "value", "checked")), ' value="', $this->filter($value), '"'; |
| 34 |
if(isset($this->attributes["value"]) && $this->attributes["value"] == $value) |
| 35 |
echo ' checked="checked"'; |
| 36 |
echo '/> <label for="', $this->attributes["id"], "-", $count, '">', $text, '</label></div>'; |
| 37 |
++$count; |
| 38 |
} |
| 39 |
echo '</div>'; |
| 40 |
|
| 41 |
if(!empty($this->inline)) |
| 42 |
echo '<div style="clear: both;"></div>'; |
| 43 |
|
| 44 |
echo '</div>'; |
| 45 |
} |
| 46 |
|
| 47 |
public function renderCSS() { |
| 48 |
if(!empty($this->inline)) |
| 49 |
echo '#', $this->attributes["id"], ' .pfbc-radio { float: left; margin-right: 0.5em; }'; |
| 50 |
else |
| 51 |
echo '#', $this->attributes["id"], ' .pfbc-radio { padding: 0.5em 0; border-bottom: 1px solid #f4f4f4; }'; |
| 52 |
} |
| 53 |
} |
| 54 |
|