';
// Only need col-md for horizonal forms?
if (isset($attributes['label'])) {
$output .= Form::label($name,$attributes['label'],array('class'=>'control-label'));
unset($attributes['label']);
}
if (isset($attributes['help-block'])) {
$help = $attributes['help-block'];
unset($attributes['help-block']);
}
if (isset($attributes['add-on'])) {
$addon = $attributes['add-on'];
unset($attributes['add-on']);
}
$classdiv = FALSE;
if (isset($attributes['divclass'])) {
$output .= sprintf('
',$attributes['divclass']);
unset($attributes['divclass']);
$classdiv = TRUE;
}
$output .= '%s';
if (in_array('required',$attributes))
$output .= '
';
if ($classdiv)
$output .= '
';
if (isset($help))
$output .= sprintf('%s',$help);
if (isset($addon))
$output .= sprintf('%s',$addon);
$output .= '';
return $output;
}
public static function button($name,$body,array $attributes=NULL) {
return sprintf(self::_controlgroup($name,$attributes),parent::button($name,$body,$attributes));
}
/**
* Wrap our Form() functions with boostrap HTML
*
* @usedby Form::hidden
* @usedby Form::password
* @usedby Form::file
* @usedby Form::checkbox
* @usedby Form::radio
* @usedby Form::submit
* @usedby Form::image
*/
public static function input($name,$value=NULL,array $attributes=NULL) {
return (isset($attributes['type']) AND $attributes['type'] == 'hidden') ? parent::input($name,$value,$attributes) : sprintf(self::_controlgroup($name,$attributes),parent::input($name,$value,$attributes));
}
public static function select($name,array $options=NULL,$selected=NULL,array $attributes=NULL) {
// If only 1 record, dont show select, but a hidden attribute and a displayed value.
if (isset($attributes['oneonly']) AND $attributes['oneonly']) {
$attributes['disabled'] = 'disabled';
unset($attributes['oneonly']);
}
if (isset($attributes['sort']) AND $attributes['sort']) {
asort($options);
unset($attributes['sort']);
}
return sprintf(self::_controlgroup($name,$attributes),parent::select($name,$options,$selected,$attributes));
}
public static function textarea($name,$body='',array $attributes=NULL,$double_encode=TRUE) {
if (! isset($attributes['id']))
$attributes['id'] = preg_replace('/[\[\]]/','_',$name);
if (isset($attributes['editor'])) {
switch ($attributes['editor']) {
case 'tinymce':
Script::factory()
->type('file')
->data('media/vendor/tinymce/js/tinymce/jquery.tinymce.min.js');
Script::factory()
->type('stdin')
->data('$("#'.$attributes['id'].'").tinymce({
script_url : "'.URL::site('media/vendor/tinymce/js/tinymce/tinymce.min.js').'",
theme : "modern",
plugins: [ "code","link","image","preview","table" ],
menubar: "",
toolbar: "undo redo | styleselect | bold italic | link image | table | preview | code",
});');
break;
case 'wysihtml5':
Style::factory()
->type('file')
->data('media/theme/bootstrap/vendor/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.css');
Script::factory()
->type('file')
->data('media/theme/bootstrap/vendor/bootstrap-wysihtml5-0.0.2/libs/js/wysihtml5-0.3.0_rc2.min.js');
Script::factory()
->type('file')
->data('media/theme/bootstrap/vendor/bootstrap-wysihtml5-0.0.2/bootstrap-wysihtml5-0.0.2.min.js');
Script::factory()
->type('stdin')
->data('$("#'.$attributes['id'].'").wysihtml5({
html: true,
parserRules: {
tags: {
p: {},
strong: {},
table: {},
tbody: {},
thead: {},
tr: {},
td: {
check_attributes: {
colspan: "numbers",
rowspan: "numbers",
}
}
}
}
});');
break;
default:
throw new Kohana_Exception('Unknown editor :editor for textarea',array(':editor'=>$attributes['editor']));
}
unset($attributes['edit']);
}
return sprintf(self::_controlgroup($name,$attributes),parent::textarea($name,$body,$attributes,$double_encode));
}
public static function textarea_rows($textarea,$min=10,$char="\n") {
return ($x=count(explode($char,$textarea))) < $min ? $min : $x;
}
}
?>