forked from patricktalmadge/bootstrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
buttons.php
128 lines (112 loc) · 3.44 KB
/
buttons.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
<?php namespace Bootstrapper;
use \HTML;
/**
* Buttons methods for creating Twitter Bootstrap buttons.
*
* @package Bundles
* @subpackage Twitter
* @author Patrick Talmadge - Follow @patricktalmadge
*
* @see http://twitter.github.com/bootstrap/
*/
class Buttons
{
/**
* Create a HTML submit input element.
* Overriding the default input submit button from Laravel\Form
*
* @param string $value
* @param array $attributes
* @param bool $hasDropdown
* @return string
*/
public static function submit($value, $attributes = array(), $hasDropdown = false)
{
$attributes['type'] = 'submit';
return static::normal($value, $attributes, $hasDropdown);
}
/**
* Create a HTML reset input element.
* Overriding the default input reset button from Laravel\Form
*
* @param string $value
* @param array $attributes
* @param bool $hasDropdown
* @return string
*/
public static function reset($value, $attributes = array(), $hasDropdown = false)
{
$attributes['type'] = 'reset';
return static::normal($value, $attributes, $hasDropdown);
}
/**
* Create a HTML button element.
* Overriding the default button to add the correct class from Laravel\Form
*
* @param string $value
* @param array $attributes
* @param bool $hasDropdown
* @return string
*/
public static function normal($value, $attributes = array(), $hasDropdown = false)
{
if(!isset($attributes['type'])){ $attributes['type'] = 'button'; }
$attributes = Helpers::add_class($attributes, 'btn');
$extra = '';
if ($hasDropdown)
{
$attributes = Helpers::add_class($attributes, 'dropdown-toggle');
$extra = ' <span class="caret"></span>';
$attributes['data-toggle'] = 'dropdown';
}
return '<button'.HTML::attributes($attributes).'>'.HTML::entities($value).$extra.'</button>';
}
/**
* Create a HTML anchor tag styled like a button element.
*
* @param string $value
* @param string $value
* @param array $attributes
* @param bool $hasDropdown
* @return string
*/
public static function link($value, $url, $attributes = array(), $hasDropdown = false)
{
$attributes['href'] = \URL::to($url);
$attributes = Helpers::add_class($attributes, 'btn');
$extra = '';
if ($hasDropdown)
{
$attributes = Helpers::add_class($attributes, 'dropdown-toggle');
$extra = ' <span class="caret"></span>';
$attributes['data-toggle'] = 'dropdown';
}
return '<a'.HTML::attributes($attributes).'>'.HTML::entities($value).$extra.'</a>';
}
/**
* Checks call to see if we can create a button from a magic call (for you wizards).
* success_button, mini_primary_button, large_warning_submit, danger_reset, etc...
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
$method_array = explode('_', strtolower($method));
$btn_types = array('normal', 'submit', 'reset', 'link');
$type_found = array_intersect($method_array, $btn_types);
if(count($type_found) > 0)
{
$function = $type_found[key($type_found)];
//Set default attributes index
$attr_index = $function != 'link' ? 1 : 2;
$parameters = Helpers::set_multi_class_attributes($function, $method_array, $parameters, $attr_index, 'btn-', 'disabled');
if(in_array('disabled', $method_array))
{
$parameters[$attr_index]['disabled'] = 'disabled';
}
return call_user_func_array('static::'.$function, $parameters);
}
}
}