-
Notifications
You must be signed in to change notification settings - Fork 29
Expand file tree
/
Copy pathEBootstrap.php
More file actions
323 lines (276 loc) · 9.71 KB
/
Copy pathEBootstrap.php
File metadata and controls
323 lines (276 loc) · 9.71 KB
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
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
<?php
/*
* Wrapper class for CHtml
* EBootstrap adds some bootstrap elements to CHtml
*
* @author Tim Helfensdörfer <tim@visualappeal.de>
* @version 0.3.0
* @package bootstrap
*/
class EBootstrap extends CHtml {
/*
* Merges the classes (i.e. htmlOptions) and another array of classes
*
* @param array $option Classes to modify
* @param array $add Classes to add
*/
public static function mergeClass(array &$option, array $add) {
if (isset($option['class']) and (!empty($option['class']))) {
foreach ($add as $k => $v) {
$option['class'] .= ' '.$v;
}
}
else
$option['class'] = implode(' ', $add);
}
/*
* Merges a class string (i.e. cssClassName) with an array of classes
*
* @param string $class Classes string
* @param array $add Classes to add
*/
public static function mergeClassString(&$class, array $add) {
if (!empty($class))
$class .= ' ';
$class .= implode(' ', $add);
}
/*
* Returns an inline label
*
* @param string $label Label
* @param string $type success|warning|important|info. Leave empty for default
* @param array $htmlOptions
*/
public static function ilabel($label, $type='', $htmlOptions=array()) {
$classes = array('label');
if (!empty($type))
$classes[] = 'label-'.$type;
self::mergeClass($htmlOptions, $classes);
return EBootstrap::tag('span', $htmlOptions, $label);
}
/*
* Returns an link-button
*
* 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 static function ibutton($text, $url = '#', $type = '', $size = '', $disabled = false, $icon = '', $iconWhite = false, $htmlOptions = array()) {
return new EBootstrapButton($text, $url, $type, $size, $disabled, $icon, $iconWhite, $htmlOptions);
}
/*
* Returns a group of buttons
*
* http://twitter.github.com/bootstrap/components.html#buttonGroups
*
* @param array $buttons Array of buttons. You can create them with the help of EBootstrap::ibutton();
* @param array $htmlOptions
*/
public static function buttonGroup($buttons, $htmlOptions = array()) {
$html = '';
if (is_array($buttons) and (count($buttons))) {
self::mergeClass($htmlOptions, array('btn-group'));
$html .= self::openTag('div', $htmlOptions)."\n";
foreach ($buttons as $button) {
$html .= $button."\n";
}
$html .= self::closeTag('div')."\n";
}
return $html;
}
/*
* Returns a toolbar with button groups
*
* http://twitter.github.com/bootstrap/components.html#buttonGroups
*
* @param array $buttonGroups Array of button groups. You can create them with the help of EBootstrap::buttonGroup();
* @param array $htmlOptions
*/
public static function buttonToolbar($buttonGroups, $htmlOptions = array()) {
$html = '';
if (is_array($buttonGroups) and (count($buttonGroups))) {
self::mergeClass($htmlOptions, array('btn-toolbar'));
$html .= self::openTag('div', $htmlOptions)."\n";
foreach ($buttonGroups as $group) {
$html .= $group."\n";
}
$html .= self::closeTag('div')."\n";
}
return $html;
}
/*
* Returns a toolbar with button groups
*
* @param EBootstrapButton $button You can create the button with the help of EBootstrap::ibutton();
* @param array $submenu Array of submenu items. Available options are text, url and htmlOptions
* @param bool $split If split is set to true, the carret ist next to the button and both elements can be clicked separately
* @param array $htmlOptions
*/
public static function buttonDropdown(EBootstrapButton $button, $submenuItems = array(), $split = false, $htmlOptions = array()) {
$html = '';
self::mergeClass($htmlOptions, array('btn-group'));
echo self::openTag('div', $htmlOptions);
if (!$split) {
$button->htmlOptions['data-toggle'] = "dropdown";
$button->url = "#";
$button->text .= ' <span class="caret"></span>';
self::mergeClass($button->htmlOptions, array('dropdown-toggle'));
$html .= $button."\n";
}
else {
$carret = new EBootstrapButton('<span class="caret"></span>', '#');
$carret->htmlOptions['data-toggle'] = "dropdown";
$carret->type = $button->type;
self::mergeClass($carret->htmlOptions, array('btn', 'dropdown-toggle'));
$html .= $button."\n";
$html .= $carret."\n";
}
if (is_array($submenuItems) and (count($submenuItems))) {
$html .= self::openTag('ul', array('class' => 'dropdown-menu'))."\n";
foreach ($submenuItems as $item) {
$html .= self::openTag('li')."\n";
$itemOptions = isset($item['htmlOptions']) ? $item['htmlOptions'] : array();
$html .= self::link($item['text'], $item['url'], $itemOptions)."\n";
$html .= self::closeTag('li')."\n";
}
$html .= self::closeTag('ul')."\n";
}
$html .= self::closeTag('div')."\n";
return $html;
}
/*
* Returns an icon
*
* http://twitter.github.com/bootstrap/base-css.html#icons
*
* @param string $icon e.g. 'shopping-cart', 'user', 'ok', etc.
* @param bool $iconWhite Invert the icon color. Default: false
*/
public static function icon($icon, $iconWhite = false) {
$return = '<i class="icon-'.$icon;
if ($iconWhite)
$return .= ' icon-white';
return $return.'"></i>';
}
/* IMAGES */
/*
* Returns an custom thumbnail src
*
* http://placehold.it/
*
* @param int $w Width
* @param int $h Height Default: $w
* @param string $bgColor Background color
* @param string $tColor Text color
* @param string $text Text to display on the image
* @param string $format png|gif|jpg Default: png
*/
public static function thumbnailSrc($w, $h = null, $bgColor = 'ccc', $tColor = '333', $text = null, $format = 'png') {
$src = 'http://placehold.it/'.$w;
if (!is_null($h))
$src .= 'x'.$h;
$src .= '/'.$bgColor.'/'.$tColor.'.'.$format;
if (!is_null($text))
$src .= '&text=' . urlencode($text);
return $src;
}
/*
* Returns an image link
*
* @param string $url Url
* @param string $src Image src
* @param string $alt Alternative text
* @param array $htmlOptions
*/
public static function thumbnailLink($url, $src, $alt = '', $htmlOptions = array()) {
$html = '';
$htmlOptions['href'] = $url;
self::mergeClass($htmlOptions, array('thumbnail'));
$html .= EBootstrap::openTag('a', $htmlOptions);
$html .= EBootstrap::tag('img', array('src' => $src, 'alt' => $alt));
$html .= EBootstrap::closeTag('a');
return $html;
}
/*
* Returns an image with a caption
*
* @param string $src Image src
* @param string $alt Alternative text
* @param string $caption Image caption
* @param string $body Text below the caption
* @param array $actions Array with actions which will be rendered below the body. All items has to be HTML
* @param array $htmlOptions
*/
public static function imageCaption($src, $alt='', $caption = '', $body = '', $actions = array(), $htmlOptions=array()) {
$html = '';
self::mergeClass($htmlOptions, array('thumbnail'));
$html .= self::openTag('div', $htmlOptions)."\n";
$htmlOptions = array();
$htmlOptions['src']=$src;
$htmlOptions['alt']=$alt;
$html .= self::tag('img',$htmlOptions)."\n";
if (!empty($caption) or !empty($body) or !empty($actions)) {
$html .= self::openTag('div', array('class' => 'caption'));
if (!empty($caption))
$html .= self::tag('h5', array(), $caption)."\n";
if (!empty($body))
$html .= self::tag('p', array(), $body)."\n";
if (!empty($actions)) {
$html .= self::openTag('p');
foreach ($actions as $button) {
$html .= $button." \n";
}
$html .= self::closeTag('p')."\n";
}
$html .= self::closeTag('div');
}
$html .= self::closeTag('div')."\n";
return $html;
}
/*
* Render an input field with a prepended text or icon
*
* @param CModel $model The model
* @param string $attribute The attribute
* @param string $prepend The text or icon to prepend
* @param array $htmlOptions
*/
public static function activeTextFieldPrepend($model,$attribute,$prepend,$htmlOptions=array()) {
$html = self::openTag('div', array('class' => 'input-prepend'))."\n";
$html .= self::tag('span', array('class' => 'add-on'), $prepend)."\n";
self::resolveNameID($model,$attribute,$htmlOptions);
self::clientChange('change',$htmlOptions);
$html .= self::activeInputField('text',$model,$attribute,$htmlOptions)."\n";
$html .= self::closeTag('div')."\n";
return $html;
}
/*
* Render an input field with a append text or icon
*
* @param CModel $model The model
* @param string $attribute The attribute
* @param string $append The text or icon to append
* @param array $htmlOptions
*/
public static function activeTextFieldAppend($model,$attribute,$prepend,$htmlOptions=array()) {
$html = self::openTag('div', array('class' => 'input-append'))."\n";
self::resolveNameID($model,$attribute,$htmlOptions);
self::clientChange('change',$htmlOptions);
$html .= self::activeInputField('text',$model,$attribute,$htmlOptions)."\n";
$html .= self::tag('span', array('class' => 'add-on'), $prepend)."\n";
$html .= self::closeTag('div')."\n";
return $html;
}
public static function searchField($name,$value='',$htmlOptions=array()) {
self::mergeClass($htmlOptions, array('form-search'));
return self::textField($name, $value, $htmlOptions);
}
}
?>