3 * Theme hooks for the Drupal Bootstrap base theme.
5 (function ($, Drupal, Bootstrap) {
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(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(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));
85 return '<button' + attributes + '>' + label + '</button>';
89 * Alias for "button" theme hook.
91 * @param {object|Attributes} attributes
92 * An object of attributes to apply to the button.
94 * @see Drupal.theme.button()
98 btn: function (attributes) {
99 return Drupal.theme('button', attributes);
103 * Renders a button block element.
105 * @param {object|Attributes} attributes
106 * An object of attributes to apply to the button.
108 * @see Drupal.theme.button()
112 'btn-block': function (attributes) {
113 return Drupal.theme('button', Attributes(attributes).addClass('btn-block'));
117 * Renders a large button element.
119 * @param {object|Attributes} attributes
120 * An object of attributes to apply to the button.
122 * @see Drupal.theme.button()
126 'btn-lg': function (attributes) {
127 return Drupal.theme('button', Attributes(attributes).addClass('btn-lg'));
131 * Renders a small button element.
133 * @param {object|Attributes} attributes
134 * An object of attributes to apply to the button.
136 * @see Drupal.theme.button()
140 'btn-sm': function (attributes) {
141 return Drupal.theme('button', Attributes(attributes).addClass('btn-sm'));
145 * Renders an extra small button element.
147 * @param {object|Attributes} attributes
148 * An object of attributes to apply to the button.
150 * @see Drupal.theme.button()
154 'btn-xs': function (attributes) {
155 return Drupal.theme('button', Attributes(attributes).addClass('btn-xs'));
159 * Renders a glyphicon.
161 * @param {string} name
162 * The name of the glyphicon.
163 * @param {object|Attributes} [attributes]
164 * An object of attributes to apply to the icon.
168 bootstrapIcon: function (name, attributes) {
169 return Drupal.theme('icon', 'bootstrap', name, attributes);
174 })(window.jQuery, window.Drupal, window.Drupal.bootstrap);