forked from VisualAppeal/YiiBootstrap
-
Notifications
You must be signed in to change notification settings - Fork 1
/
EBootstrapButton.php
125 lines (105 loc) · 2.48 KB
/
EBootstrapButton.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
<?php
/*
* Class for creating a button
*
* @author Tim Helfensdörfer <tim@visualappeal.de>
* @version 0.3.2
* @package bootstrap
*/
class EBootstrapButton {
/*
* Button text
*/
public $text;
/*
* URL
*/
public $url;
/*
* Button type
*
* Possible values: primary|info|success|warning|danger|inverse. Leave empty for default
*/
public $type;
/*
* Size of the button
*
* Possible values: large|small|mini. Leave empty for default
*/
public $size;
/*
* Set true to disable the button
*/
public $disabled;
/*
* Icon
*/
public $icon;
/*
* Invert the icon color
*/
public $iconWhite;
/*
* HTML options
*/
public $htmlOptions;
/*
* Button type
*
* Possible values:
* a
* button
*/
public $element;
/*
* Construct a button element
*
* http://twitter.github.com/bootstrap/base-css.html#buttons
*
* @param string $text Label of the button
* @param string $url Url
* @param string $type primary|info|success|warning|danger|inverse. Leave empty for default
* @param string $size large|small|mini. Leave empty for default
* @param bool $disabled Default: false
* @param string $icon http://twitter.github.com/bootstrap/base-css.html#icons (e.g. 'shopping-cart', 'user', 'ok', etc.)
* @param bool $iconWhite Invert the icon color. Default: false
* @param array $htmlOptions
*/
public function __construct($text, $url = '#', $type = '', $size = '', $disabled = false, $icon = '', $iconWhite = false, $htmlOptions = array(), $element = 'a') {
$this->text = $text;
$this->url = $url;
$this->type = $type;
$this->size = $size;
$this->disabled = $disabled;
$this->icon = $icon;
$this->iconWhite = $iconWhite;
$this->htmlOptions = $htmlOptions;
$this->element = $element;
$class = array('btn');
EBootstrap::mergeClass($this->htmlOptions, $class);
}
/*
* Outputs the button
*/
public function __tostring() {
$class = array();
if (!empty($this->size))
$class[] = 'btn-'.$this->size;
if (!empty($this->type))
$class[] = 'btn-'.$this->type;
if ($this->disabled)
$class[] = 'disabled';
if (!empty($this->icon))
$this->text = EBootstrap::icon($this->icon, $this->iconWhite).' '.$this->text;
EBootstrap::mergeClass($this->htmlOptions, $class);
switch ($this->element) {
case 'button':
return EBootstrap::tag('button', $this->htmlOptions, $this->text)."\n";
break;
default:
return EBootstrap::link($this->text, $this->url, $this->htmlOptions)."\n";
break;
}
}
}
?>