Font-awesome icons for toggle buttons

This commit is contained in:
Sylvain Corlay 2015-02-15 02:20:58 -05:00
parent 829d25bdfd
commit a70b65b5b4
2 changed files with 11 additions and 2 deletions

View File

@ -307,17 +307,21 @@ define([
if (options === undefined || options.updated_view != this) {
// Add missing items to the DOM.
var items = this.model.get('_options_labels');
var icons = this.model.get('icons');
var previous_icons = this.model.previous('icons') || [];
var disabled = this.model.get('disabled');
var that = this;
var item_html;
_.each(items, function(item, index) {
if (item.trim().length === 0) {
if (item.trim().length === 0 && (!icons[index] ||
icons[index].trim().length === 0)) {
item_html = " ";
} else {
item_html = utils.escape_html(item);
}
var item_query = '[data-value="' + encodeURIComponent(item) + '"]';
var $item_element = that.$buttongroup.find(item_query);
var $icon_element = $item_element.find('.fa');
if (!$item_element.length) {
$item_element = $('<button/>')
.attr('type', 'button')
@ -329,6 +333,7 @@ define([
.attr('value', item)
.on('click', $.proxy(that.handle_click, that));
that.update_style_traits($item_element);
$icon_element = $('<i class="fa"></i>').prependTo($item_element);
}
if (that.model.get('selected_label') == item) {
$item_element.addClass('active');
@ -336,7 +341,10 @@ define([
$item_element.removeClass('active');
}
$item_element.prop('disabled', disabled);
$item_element.attr('title', that.model.get('tooltips')[index]);
$item_element.attr('title', that.model.get('tooltips')[index]);
$icon_element
.removeClass(previous_icons[index])
.addClass(icons[index]);
});
// Remove items that no longer exist.

View File

@ -201,6 +201,7 @@ class ToggleButtons(_Selection):
button can be toggled at any point in time."""
_view_name = Unicode('ToggleButtonsView', sync=True)
tooltips = List(Unicode(), sync=True)
icons = List(Unicode(), sync=True)
button_style = CaselessStrEnum(
values=['primary', 'success', 'info', 'warning', 'danger', ''],