forked from patricktalmadge/bootstrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsplitdropdownbutton.php
149 lines (132 loc) · 3.19 KB
/
splitdropdownbutton.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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<?php namespace Bootstrapper;
use \HTML;
/**
* SplitDropdownButton for creating Twitter Bootstrap style Split Dropdown Buttons.
*
* @package Bundles
* @subpackage Twitter
* @author Patrick Talmadge - Follow @patricktalmadge
*
* @see http://twitter.github.com/bootstrap/
*/
class SplitDropdownButton
{
/**
* Creates a SplitDropdownButton.
*
* @param string $type
* @param string $value
* @param array $list
* @param array $attributes
* @param bool $right
* @param bool $dropup
* @param bool $autoroute
* @return string
*/
protected static function show($type, $value, $list, $attributes = array(), $right = false, $dropup = false, $autoroute = true)
{
$attributes = Helpers::add_class($attributes, 'btn-group');
$list_attr = array();
if($right)
{
$list_attr['class'] = 'pull-right';
}
if($dropup)
{
$attributes['class'] .= ' dropup';
}
$html = '<div'.HTML::attributes($attributes).'>';
$html .= Form::button($value, array('class'=>$type));
$html .= Form::button('', array('class'=>$type), true);
$html .= Navigation::dropdown($list, $list_attr, $autoroute);
$html .= '</div>';
return $html;
}
/**
* Checks call to see if we can create a button from a magic call (for you wizards).
* normal, mini_primary, large_warning, danger, etc...
*
* @param string $method
* @param array $parameters
* @return mixed
*/
public static function __callStatic($method, $parameters)
{
$method_array = explode('_', strtolower($method));
$type = '';
foreach ($method_array as $s)
{
if($s != 'normal'){
$type .= ' btn-'.$s;
}
}
$value = '';
if(isset($parameters[0]))
{
$value = $parameters[0];
}
//Set default $list and check for a set value
$list = array();
if(isset($parameters[1]) && is_array($parameters[1]))
{
$list = $parameters[1];
}
else
{
throw new \Exception("SplitDropdownButton list is required parameter should be an array of links");
}
//Set default $attributes and check for a set value
$attributes = array();
if(isset($parameters[2]))
{
if(is_array($parameters[2]))
{
$attributes = $parameters[2];
}
else
{
throw new \Exception("SplitDropdownButton attributes parameter should be an array of attributes");
}
}
//Set default $right and check for a set value
$right = false;
if(isset($parameters[3]))
{
if(is_bool($parameters[3]))
{
$right = $parameters[3];
}
else
{
throw new \Exception("SplitDropdownButton right parameter should be a bool");
}
}
//Set default $dropup and check for a set value
$dropup = false;
if(isset($parameters[4]))
{
if(is_bool($parameters[4]))
{
$dropup = $parameters[4];
}
else
{
throw new \Exception("SplitDropdownButton dropup parameter should be a bool");
}
}
//Set default $autoroute and check for a set value
$autoroute = true;
if(isset($parameters[5]))
{
if(is_bool($parameters[5]))
{
$autoroute = $parameters[5];
}
else
{
throw new \Exception("DropdownButton autoroute parameter should be a bool");
}
}
return static::show($type, $value, $list, $attributes, $right, $dropup, $autoroute);
}
}