3 * Theme hooks for the Drupal Bootstrap base theme.
5 (function ($, Drupal
, Bootstrap
, Attributes
) {
8 * Fallback for theming an icon if the Icon API module is not installed.
10 if (!Drupal
.icon
) Drupal
.icon
= { bundles
: {} };
11 if (!Drupal
.theme
.icon
|| Drupal
.theme
.prototype.icon
) {
12 $.extend(Drupal
.theme
, /** @lends Drupal.theme */ {
16 * @param {string} bundle
17 * The bundle which the icon belongs to.
18 * @param {string} icon
19 * The name of the icon to render.
20 * @param {object|Attributes} [attributes]
21 * An object of attributes to also apply to the icon.
25 icon: function (bundle
, icon
, attributes
) {
26 if (!Drupal
.icon
.bundles
[bundle
]) return '';
27 attributes
= Attributes
.create(attributes
).addClass('icon').set('aria-hidden', 'true');
28 icon
= Drupal
.icon
.bundles
[bundle
](icon
, attributes
);
29 return '<span' + attributes
+ '></span>';
35 * Callback for modifying an icon in the "bootstrap" icon bundle.
37 * @param {string} icon
38 * The icon being rendered.
39 * @param {Attributes} attributes
40 * Attributes object for the icon.
42 Drupal
.icon
.bundles
.bootstrap = function (icon
, attributes
) {
43 attributes
.addClass(['glyphicon', 'glyphicon-' + icon
]);
47 * Add necessary theming hooks.
49 $.extend(Drupal
.theme
, /** @lends Drupal.theme */ {
52 * Renders a Bootstrap AJAX glyphicon throbber.
56 ajaxThrobber: function () {
57 return Drupal
.theme('bootstrapIcon', 'refresh', {'class': ['ajax-throbber', 'glyphicon-spin'] });
61 * Renders a button element.
63 * @param {object|Attributes} attributes
64 * An object of attributes to apply to the button. If it contains one of:
65 * - value: The label of the button.
66 * - context: The context type of Bootstrap button, can be one of:
77 button: function (attributes
) {
78 attributes
= Attributes
.create(attributes
).addClass('btn');
79 var context
= attributes
.get('context', 'default');
80 var label
= attributes
.get('value', '');
81 attributes
.remove('context').remove('value');
82 if (!attributes
.hasClass(['btn-default', 'btn-primary', 'btn-success', 'btn-info', 'btn-warning', 'btn-danger', 'btn-link'])) {
83 attributes
.addClass('btn-' + Bootstrap
.checkPlain(context
));
86 // Attempt to, intelligently, provide a default button "type".
87 if (!attributes
.exists('type')) {
88 attributes
.set('type', attributes
.hasClass('form-submit') ? 'submit' : 'button');
91 return '<button' + attributes
+ '>' + label
+ '</button>';
95 * Alias for "button" theme hook.
97 * @param {object|Attributes} attributes
98 * An object of attributes to apply to the button.
100 * @see Drupal.theme.button()
104 btn: function (attributes
) {
105 return Drupal
.theme('button', attributes
);
109 * Renders a button block element.
111 * @param {object|Attributes} attributes
112 * An object of attributes to apply to the button.
114 * @see Drupal.theme.button()
118 'btn-block': function (attributes
) {
119 return Drupal
.theme('button', Attributes
.create(attributes
).addClass('btn-block'));
123 * Renders a large button element.
125 * @param {object|Attributes} attributes
126 * An object of attributes to apply to the button.
128 * @see Drupal.theme.button()
132 'btn-lg': function (attributes
) {
133 return Drupal
.theme('button', Attributes
.create(attributes
).addClass('btn-lg'));
137 * Renders a small button element.
139 * @param {object|Attributes} attributes
140 * An object of attributes to apply to the button.
142 * @see Drupal.theme.button()
146 'btn-sm': function (attributes
) {
147 return Drupal
.theme('button', Attributes
.create(attributes
).addClass('btn-sm'));
151 * Renders an extra small button element.
153 * @param {object|Attributes} attributes
154 * An object of attributes to apply to the button.
156 * @see Drupal.theme.button()
160 'btn-xs': function (attributes
) {
161 return Drupal
.theme('button', Attributes
.create(attributes
).addClass('btn-xs'));
165 * Renders a glyphicon.
167 * @param {string} name
168 * The name of the glyphicon.
169 * @param {object|Attributes} [attributes]
170 * An object of attributes to apply to the icon.
174 bootstrapIcon: function (name
, attributes
) {
175 return Drupal
.theme('icon', 'bootstrap', name
, attributes
);
180 })(window
.jQuery
, window
.Drupal
, window
.Drupal
.bootstrap
, window
.Attributes
);