From 66d38c2d663cd988d1623c0000af8404aad47caa 2015-03-02 19:54:06 From: Jonathan Frederic Date: 2015-03-02 19:54:06 Subject: [PATCH] Merge pull request #7725 from SylvainCorlay/fabutton Adding font-awesome icon to button and toggle button --- diff --git a/IPython/html/static/widgets/js/widget_bool.js b/IPython/html/static/widgets/js/widget_bool.js index 0234054..dc107ec 100644 --- a/IPython/html/static/widgets/js/widget_bool.js +++ b/IPython/html/static/widgets/js/widget_bool.js @@ -59,10 +59,9 @@ define([ this.$checkbox.prop('checked', this.model.get('value')); if (options === undefined || options.updated_view != this) { - var disabled = this.model.get('disabled'); - this.$checkbox.prop('disabled', disabled); + this.$checkbox.prop("disabled", this.model.get("disabled")); - var description = this.model.get('description'); + var description = this.model.get("description"); if (description.trim().length === 0) { this.$label.hide(); } else { @@ -113,7 +112,7 @@ define([ /** * Update the contents of this view * - * Called when the model is changed. The model may have been + * Called when the model is changed. The model may have been * changed by another view or by a state update from the back-end. */ if (this.model.get('value')) { @@ -123,16 +122,16 @@ define([ } if (options === undefined || options.updated_view != this) { - - var disabled = this.model.get('disabled'); - this.$el.prop('disabled', disabled); - - var description = this.model.get('description'); + this.$el.prop("disabled", this.model.get("disabled")); this.$el.attr("title", this.model.get("tooltip")); - if (description.trim().length === 0) { + + var description = this.model.get("description"); + var icon = this.model.get("icon"); + if (description.trim().length === 0 && icon.trim().length ===0) { this.$el.html(" "); // Preserve button height } else { this.$el.text(description); + $('').prependTo(this.$el).addClass(icon); } } return ToggleButtonView.__super__.update.apply(this); diff --git a/IPython/html/static/widgets/js/widget_button.js b/IPython/html/static/widgets/js/widget_button.js index c476581..a2e6bd4 100644 --- a/IPython/html/static/widgets/js/widget_button.js +++ b/IPython/html/static/widgets/js/widget_button.js @@ -27,21 +27,19 @@ define([ /** * Update the contents of this view * - * Called when the model is changed. The model may have been + * Called when the model is changed. The model may have been * changed by another view or by a state update from the back-end. */ - var description = this.model.get('description'); + this.$el.prop("disabled", this.model.get("disabled")); this.$el.attr("title", this.model.get("tooltip")); - if (description.length === 0) { + + var description = this.model.get("description"); + var icon = this.model.get("icon"); + if (description.trim().length === 0 && icon.trim().length ===0) { this.$el.html(" "); // Preserve button height } else { this.$el.text(description); - } - - if (this.model.get('disabled')) { - this.$el.attr('disabled','disabled'); - } else { - this.$el.removeAttr('disabled'); + $('').prependTo(this.$el).addClass(icon); } return ButtonView.__super__.update.apply(this); diff --git a/IPython/html/static/widgets/js/widget_selection.js b/IPython/html/static/widgets/js/widget_selection.js index c487834..1eb7550 100644 --- a/IPython/html/static/widgets/js/widget_selection.js +++ b/IPython/html/static/widgets/js/widget_selection.js @@ -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 = $('