Copyright (C) 2010 - 2019 All Rights Reserved. Contributor(s): Mark J Crane */ if (!class_exists('button')) { class button { public static $collapse = 'hide-md-dn'; static function create($array) { $button_icons = $_SESSION['theme']['button_icons']['text'] != '' ? $_SESSION['theme']['button_icons']['text'] : 'auto'; //parse styles into array if ($array['style']) { $tmp = explode(';',$array['style']); foreach ($tmp as $style) { if ($style) { $style = explode(':', $style); $styles[trim($style[0])] = trim($style[1]); } } $array['style'] = $styles; unset($styles); } //button: open $button = ""; //link if ($array['link']) { $anchor = " $value) { if (substr_count($property, 'margin')) { $styles .= $property.': '.$value.'; '; } } $anchor .= $styles ? "style=".self::quote($styles)." " : null; unset($styles); } $anchor .= $array['disabled'] ? "class='disabled' onclick='return false;' " : null; $anchor .= ">"; $button = $anchor.$button.""; } return $button; unset($button); } private static function quote($value) { return substr_count($value, "'") ? '"'.$value.'"' : "'".$value."'"; } } } /* //usage echo button::create(['type'=>'button','label'=>$text['button-label'],'icon'=>'icon','name'=>'btn','id'=>'btn','value'=>'value','link'=>'url','target'=>'_blank','onclick'=>'javascript','onmouseover'=>'javascript','onmouseout'=>'javascript','class'=>'name','style'=>'css','title'=>$text['button-label'],'collapse'=>'class','disabled'=>false]); echo button::create([ 'type'=>'button', 'label'=>$text['button-label'], 'icon'=>'icon', 'name'=>'btn', 'id'=>'btn', 'value'=>'value', 'link'=>'url', 'target'=>'_blank', 'onclick'=>'javascript', 'onmouseover'=>'javascript', 'onmouseout'=>'javascript', 'class'=>'name', 'style'=>'css', 'title'=>$text['button-label'], 'collapse'=>'class', 'disabled'=>false ]); //options type 'button' (default) | 'submit' | 'link' label button text icon name without vendor prefix (e.g. 'user' instead of 'fa-user') value submitted value (if type is also set to 'submit') target '_blank' | '_self' (default) | etc onclick javascript onmouseover javascript (actually uses onmouseenter so doesn't bubble to child elements) onmouseout javascript (actually uses onmouseleave so doesn't bubble to child elements) class css class[es] style css style[s] title tooltip text (if not set, defaults to value of label) collapse overide the default hide class ('hide-md-dn') disabled boolean true/false, or a value that evaluates to a boolean //notes 1) all parameters are optional, but at least set a value for label or icon 2) overide the default hide class ('hide-md-dn') for all buttons that follow by using... button::$collapse = '...'; 3) setting either collapse (instance or default) to false (boolean) will cause the button label to always be visible //example: enable/disable buttons with javascript //javascript onclick='button_enable('disabled_button'); //button echo button::create(['type'=>'button', ... ,'id'=>'disabled_button','disabled'=>true]); //javascript onclick='button_disable('enabled_button'); //button echo button::create(['type'=>'button', ... ,'id'=>'enabled_button']); //enable button class button echo "\n"; //disable button class button echo "\n"; //note: the javascript functions above are already contained in the template.php file. */ ?>