Newer
Older
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
/*
* Custom theme functions
*
*/
/**
* Returns HTML for a set of links.
*/
function theme_bootstrap_links($variables) {
$links = $variables['links'];
$attributes = $variables['attributes'];
$heading = $variables['heading'];
global $language_url;
$output = '';
if (count($links) > 0) {
$output = '';
$output .= '<ul' . drupal_attributes($attributes) . '>';
// Treat the heading first if it is present to prepend it to the
// list of links.
if (!empty($heading)) {
if (is_string($heading)) {
// Prepare the array that will be used when the passed heading
// is a string.
$heading = array(
'text' => $heading,
// Set the default level of the heading.
'level' => 'li',
);
}
$output .= '<' . $heading['level'];
if (!empty($heading['class'])) {
$output .= drupal_attributes(array('class' => $heading['class']));
}
$output .= '>' . check_plain($heading['text']) . '</' . $heading['level'] . '>';
}
$num_links = count($links);
$i = 1;
foreach ($links as $key => $link) {
$children = array();
if (isset($link['below'])) {
$children = $link['below'];
}
$attributes = array('class' => array($key));
// Add first, last and active classes to the list of links to help out themers.
if ($i == 1) {
$attributes['class'][] = 'first';
}
if ($i == $num_links) {
$attributes['class'][] = 'last';
}
if (isset($link['href']) && ($link['href'] == $_GET['q'] || ($link['href'] == '<front>' && drupal_is_front_page()))
&& (empty($link['language']) || $link['language']->language == $language_url->language)) {
$attributes['class'][] = 'active';
}
if (count($children) > 0) {
$attributes['class'][] = 'dropdown';
$link['attributes']['data-toggle'] = 'dropdown';
$link['attributes']['class'][] = 'dropdown-toggle';
}
if (!isset($link['attributes'])) {
$link['attributes'] = array();
}
$link['attributes'] = array_merge($link['attributes'], $attributes);
if (count($children) > 0) {
$link['attributes']['class'][] = 'dropdown';
}
$output .= '<li' . drupal_attributes($attributes) . '>';
if (isset($link['href'])) {
if (count($children) > 0) {
$link['html'] = TRUE;
$link['title'] .= ' <span class="caret"></span>';
$output .= '<a' . drupal_attributes($link['attributes']) . ' href="#">'. $link['title'] .'</a>';
}
else {
// Pass in $link as $options, they share the same keys.
$output .= l($link['title'], $link['href'], $link);
}
}
elseif (!empty($link['title'])) {
// Some links are actually not links, but we wrap these in <span> for adding title and class attributes.
if (empty($link['html'])) {
$link['title'] = check_plain($link['title']);
}
$span_attributes = '';
if (isset($link['attributes'])) {
$span_attributes = drupal_attributes($link['attributes']);
}
$output .= '<span' . $span_attributes . '>' . $link['title'] . '</span>';
}
$i++;
if(count($children) > 0) {
$attributes = array();
$attributes['class'] = array('dropdown-menu');
$output .= theme('bootstrap_links', array('links' => $children, 'attributes' => $attributes));
}
$output .= "</li>\n";
}
$output .= '</ul>';
}
return $output;
}
/**
* theme_bootstrap_btn_dropdown
*/
function theme_bootstrap_btn_dropdown($variables) {
$type_class = '';
$sub_links ='';
$variables['attributes']['class'][] = 'btn-group';
// Type class
if (isset($variables['type'])) {
$type_class = ' btn-'. $variables['type'];
}
// Start markup
$output = '<div'. drupal_attributes($variables['attributes']) .'>';
// Ad as string if its not a link
if (is_array($variables['label'])) {
$output .= l($variables['label']['title'], $$variables['label']['href'], $variables['label']);
}
$output .= '<a class="btn'. $type_class .' dropdown-toggle" data-toggle="dropdown" href="#">';
// Its a link so create one
if (is_string($variables['label'])) {
$output .= check_plain($variables['label']);
}
if (is_array($variables['links'])) {
$sub_links = theme('links', array('links' => $variables['links'],'attributes' => array('class' => array('dropdown-menu'))));
}
// Finish markup
$output .= '<span class="caret"></span></a>' . $sub_links . '</div>';
return $output;
}
/*
* Overwrites the default item list to make it prettier
*/
function bootstrap_item_list($variables) {
$items = $variables['items'];
$title = $variables['title'];
$type = $variables['type'];
$attributes = $variables['attributes'];
$output = '';
if (isset($title)) {
$output .= '<h3>' . $title . '</h3>';
}
if (!empty($items)) {
$output .= "<$type" . drupal_attributes($attributes) . '>';
$num_items = count($items);
Marcus Danillo M. Nunes
committed
$i = 0;
foreach ($items as $item) {
Marcus Danillo M. Nunes
committed
$i++;
if (is_array($item)) {
foreach ($item as $key => $value) {
if ($key == 'data') {
$data = $value;
}
elseif ($key == 'children') {
$children = $value;
}
else {
$attributes[$key] = $value;
}
}
}
else {
$data = $item;
}
if (count($children) > 0) {
// Render nested list.
$data .= theme_item_list(array('items' => $children, 'title' => NULL, 'type' => $type, 'attributes' => $attributes));
}
Marcus Danillo M. Nunes
committed
if ($i == 1) {
Marcus Danillo M. Nunes
committed
if ($i == $num_items) {
$attributes['class'][] = 'last';
}
$output .= '<li' . drupal_attributes($attributes) . '>' . $data . "</li>\n";
}
$output .= "</$type>";
}
return $output;
}
/**
* Returns HTML for status and/or error messages, grouped by type.
*/
function bootstrap_status_messages($variables) {
$display = $variables['display'];
$output = '';
$status_heading = array(
'status' => t('Status message'),
'error' => t('Error message'),
'warning' => t('Warning message'),
);
Fabiano Sant'Ana
committed
// Map Drupal message types to their corresponding Bootstrap classes.
// @see http://twitter.github.com/bootstrap/components.html#alerts
$status_class = array(
'status' => 'success',
'error' => 'error',
'warning' => 'info',
);
foreach (drupal_get_messages($display) as $type => $messages) {
$class = (isset($status_class[$type])) ? ' alert-' . $status_class[$type] : '';
$output .= "<div class=\"alert alert-block$class\">\n";
$output .= " <a class=\"close\" data-dismiss=\"alert\" href=\"#\">×</a>\n";
Fabiano Sant'Ana
committed
$output .= '<h2 class="element-invisible">' . $status_heading[$type] . "</h2>\n";
Fabiano Sant'Ana
committed
if (count($messages) > 1) {
$output .= " <ul>\n";
foreach ($messages as $message) {
$output .= ' <li>' . $message . "</li>\n";
}
$output .= " </ul>\n";
}
else {
$output .= $messages[0];
}
Fabiano Sant'Ana
committed
/**
* Implements hook_css_alter().
*/
function bootstrap_css_alter(&$css) {
Mark Halliwell
committed
// Load excluded CSS files from theme.
$excludes = _bootstrap_alter(bootstrap_theme_get_info('exclude'), 'css');
Mark Halliwell
committed
// Add the Bootstrap CDN CSS files.
if (theme_get_setting('cdn_bootstrap')){
$cdn_url = '//netdna.bootstrapcdn.com/twitter-bootstrap/'. theme_get_setting('cdn_bootstrap_version') .'/css/bootstrap-combined.min.css';
Frank Baele
committed
$css[$cdn_url]['data'] = $cdn_url;
$css[$cdn_url]['type'] = 'external';
$css[$cdn_url]['every_page'] = TRUE;
$css[$cdn_url]['media'] = 'all';
$css[$cdn_url]['preprocess'] = TRUE;
$css[$cdn_url]['group'] = CSS_THEME;
$css[$cdn_url]['weight'] = -1;
$css[$cdn_url]['browsers'] = array('IE' => TRUE, '!IE' => TRUE);
Frank Baele
committed
$css = array_diff_key($css, $excludes);
Fabiano Sant'Ana
committed
/**
* Implements hook_js_alter().
*/
function bootstrap_js_alter(&$js) {
$files = array();
Mark Halliwell
committed
// Load excluded JS files from theme.
$excludes = _bootstrap_alter(bootstrap_theme_get_info('exclude'), 'js');
// If bootstrap_ui available, we should not add js from theme info file.
if (module_exists('bootstrap_ui')) {
libraries_load('bootstrap', 'minified');
Fabiano Sant'Ana
committed
}
Mark Halliwell
committed
$theme_path = drupal_get_path('theme', 'bootstrap');
// Replace core progress bar JS with the Bootstrap equivilent.
if (isset($js['misc/progress.js']) && !empty($js['misc/progress.js'])) {
unset($js['misc/progress.js']);
Mark Halliwell
committed
$progress = $theme_path . '/js/progress.js';
$js[$progress] = drupal_js_defaults($progress);
}
Fabiano Sant'Ana
committed
Mark Halliwell
committed
// Fix broken Views AJAX pagers.
if (module_exists('views') && !empty($js[drupal_get_path('module', 'views') . '/js/ajax_view.js'])) {
// Override core ajax prototype function to append throbber inside links,
// instead of after it (floating issues).
$ajax = $theme_path . '/js/bootstrap_ajax.js';
$js[$ajax] = drupal_js_defaults($ajax);
$js[$ajax]['group'] = JS_THEME;
// Override views prototype function to bind to Bootstrap pagination.
$ajax_view = $theme_path . '/js/bootstrap_ajax_view.js';
$js[$ajax_view] = drupal_js_defaults($ajax_view);
$js[$ajax_view]['group'] = JS_THEME;
}
Fabiano Sant'Ana
committed
if (theme_get_setting('cdn_bootstrap')) {
$files[] = '//netdna.bootstrapcdn.com/twitter-bootstrap/'. theme_get_setting('cdn_bootstrap_version') .'/js/bootstrap.min.js';
}
// Rearrange / Add JS
$group = -50;
$weight = -100;
foreach ($files as $file) {
if (!isset($js[$file])) {
$js[$file] = drupal_js_defaults();
$js[$file]['data'] = $file;
$js[$file]['group'] = $group;
$js[$file]['weight'] = $weight;
$weight++;
}
}
function _bootstrap_alter($files, $type) {
Fabiano Sant'Ana
committed
if (isset($files[$key][$type])) {
foreach ($files[$key][$type] as $file => $name) {
$output[$name] = FALSE;
}
/**
* Returns HTML for Bootstrap's progress bar.
*/
function bootstrap_progress_bar($variables) {
$output .= '<div id="progress" class="progress-wrapper">';
$output .= ' <div class="progress progress-striped progress-info active">';
$output .= ' <div class="bar" style="width: ' . $variables['percent'] . '%"></div>';
$output .= ' </div>';
$output .= ' <div class="percentage pull-right">' . $variables['percent'] . '%</div>';
$output .= ' <div class="message">' . $variables['message'] . '</div>';
$output .= '</div>';
return $output;
}
/**
* Returns HTML for Bootstrap's modal.
*/
function bootstrap_bootstrap_modal($variables) {
$body = $variables['body'];
$links = $variables['footer'];
$heading = $variables['heading'];
$attributes = $variables['attributes'];
if (isset($variables['attributes']['class']) && is_string($variables['attributes']['class'])) { // Convert classes to an array.
$variables['attributes']['class'] = explode(' ', $variables['attributes']['class']);
}
$variables['attributes']['class'][] = 'modal';
$output = '<div'. drupal_attributes($variables['attributes']) .'>';
$output .= '<div class="modal-header"> <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>';
$output .= '<h3>'. $variables['html_heading']? $variables['heading'] : check_plain($variables['heading']) .'</h3>';
$output .= '</div>';
$output .= '<div class="modal-body">'. render($variables['body']) .'</div>';
$output .= '<div class="modal-footer">'. render($variables['footer']) .'</div>';
$output .= '</div>';
return $output;
}
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
/**
* Returns HTML for Bootstrap's Collapse/Accordion.
*/
function bootstrap_bootstrap_accordion($variables) {
$elements = $variables['elements'];
if (empty($variables['id'])) {
$accordion_id = 'accordion-'. md5($elements);
}
else {
$accordion_id = check_plain($variables['id']);
}
$output = '<div class="accordion" id="'.$accordion_id.'">';
foreach ($elements as $id => $item) {
$output .= '<div class="accordion-group"><div class="accordion-heading">';
$output .= '<a class="accordion-toggle" data-toggle="collapse" data-parent="#'. $accordion_id .'" href="#'. $id .'">'. check_plain($item['header']) .'</a></div>';
$output .= '<div id="'. $id .'" class="accordion-body collapse in"><div class="accordion-inner">';
$output .= render($item['content']);
$output .= '</div></div></div>';
}
$output .= '</div>';
return $output;
}
/**
* Add stripping to tables (in case they don't have .table-no-striping class)
*/
function bootstrap_preprocess_table(&$variables) {
if (isset($variables['attributes']['class']) && is_string($variables['attributes']['class'])) {
// Convert classes to an array.
$variables['attributes']['class'] = explode(' ', $variables['attributes']['class']);
}
Fabiano Sant'Ana
committed
if(!in_array('table-no-striping', $variables['attributes']['class'])) {
$variables['attributes']['class'][] = 'table-striped';
}