mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-12 11:45:38 +08:00
Merge pull request #5114 from minrk/empty-button
use non-breaking space for button with no description
This commit is contained in:
commit
a7fb5e1e55
@ -488,6 +488,12 @@ IPython.utils = (function (IPython) {
|
||||
};
|
||||
|
||||
|
||||
var escape_html = function (text) {
|
||||
// escape text to HTML
|
||||
return $("<div/>").text(text).html();
|
||||
}
|
||||
|
||||
|
||||
var get_body_data = function(key) {
|
||||
// get a url-encoded item from body.data and decode it
|
||||
// we should never have any encoded URLs anywhere else in code
|
||||
@ -564,6 +570,7 @@ IPython.utils = (function (IPython) {
|
||||
url_join_encode : url_join_encode,
|
||||
encode_uri_components : encode_uri_components,
|
||||
splitext : splitext,
|
||||
escape_html : escape_html,
|
||||
always_new : always_new,
|
||||
browser : browser,
|
||||
platform: platform,
|
||||
|
@ -56,7 +56,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
this.$checkbox.prop('disabled', disabled);
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length === 0) {
|
||||
if (description.trim().length === 0) {
|
||||
this.$label.hide();
|
||||
} else {
|
||||
this.$label.text(description);
|
||||
@ -102,8 +102,8 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
this.$el.prop('disabled', disabled);
|
||||
|
||||
var description = this.model.get('description');
|
||||
if (description.length === 0) {
|
||||
this.$el.text(' '); // Preserve button height
|
||||
if (description.trim().length === 0) {
|
||||
this.$el.html(" "); // Preserve button height
|
||||
} else {
|
||||
this.$el.text(description);
|
||||
}
|
||||
|
@ -32,7 +32,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
// changed by another view or by a state update from the back-end.
|
||||
var description = this.model.get('description');
|
||||
if (description.length === 0) {
|
||||
this.$el.text(' '); // Preserve button height
|
||||
this.$el.html(" "); // Preserve button height
|
||||
} else {
|
||||
this.$el.text(description);
|
||||
}
|
||||
|
@ -137,7 +137,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager) {
|
||||
});
|
||||
this.$title = $('<div />')
|
||||
.addClass('widget-modal-title')
|
||||
.text(' ')
|
||||
.html(" ")
|
||||
.appendTo(this.$title_bar);
|
||||
this.$body = $('<div />')
|
||||
.addClass('modal-body')
|
||||
@ -147,7 +147,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager) {
|
||||
.appendTo(this.$window);
|
||||
|
||||
this.$show_button = $('<button />')
|
||||
.text(' ')
|
||||
.html(" ")
|
||||
.addClass('btn btn-info widget-modal-show')
|
||||
.appendTo(this.$el)
|
||||
.click(function(){
|
||||
@ -236,15 +236,15 @@ define(["notebook/js/widgets/widget"], function(WidgetManager) {
|
||||
// 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');
|
||||
if (description.length === 0) {
|
||||
this.$title.text(' '); // Preserve title height
|
||||
if (description.trim().length === 0) {
|
||||
this.$title.html(" "); // Preserve title height
|
||||
} else {
|
||||
this.$title.text(description);
|
||||
}
|
||||
|
||||
var button_text = this.model.get('button_text');
|
||||
if (button_text.length === 0) {
|
||||
this.$show_button.text(' '); // Preserve button height
|
||||
if (button_text.trim().length === 0) {
|
||||
this.$show_button.html(" "); // Preserve button height
|
||||
} else {
|
||||
this.$show_button.text(button_text);
|
||||
}
|
||||
|
@ -33,7 +33,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
this.$droplabel = $('<button />')
|
||||
.addClass('btn')
|
||||
.addClass('widget-combo-btn')
|
||||
.text(' ')
|
||||
.html(" ")
|
||||
.appendTo(this.$buttongroup);
|
||||
this.$dropbutton = $('<button />')
|
||||
.addClass('btn')
|
||||
@ -58,8 +58,8 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
|
||||
if (options === undefined || options.updated_view != this) {
|
||||
var selected_item_text = this.model.get('value_name');
|
||||
if (selected_item_text.length === 0) {
|
||||
this.$droplabel.text(' ');
|
||||
if (selected_item_text.trim().length === 0) {
|
||||
this.$droplabel.html(" ");
|
||||
} else {
|
||||
this.$droplabel.text(selected_item_text);
|
||||
}
|
||||
@ -233,18 +233,24 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
var items = this.model.get('value_names');
|
||||
var disabled = this.model.get('disabled');
|
||||
var that = this;
|
||||
var item_html;
|
||||
_.each(items, function(item, index) {
|
||||
var item_query = ' :contains("' + item + '")';
|
||||
if (that.$buttongroup.find(item_query).length === 0) {
|
||||
$('<button />')
|
||||
if (item.trim().length == 0) {
|
||||
item_html = " ";
|
||||
} else {
|
||||
item_html = IPython.utils.escape_html(item);
|
||||
}
|
||||
var item_query = '[data-value="' + item + '"]';
|
||||
var $item_element = that.$buttongroup.find(item_query);
|
||||
if (!$item_element.length) {
|
||||
$item_element = $('<button/>')
|
||||
.attr('type', 'button')
|
||||
.addClass('btn')
|
||||
.text(item)
|
||||
.html(item_html)
|
||||
.appendTo(that.$buttongroup)
|
||||
.attr('data-value', item)
|
||||
.on('click', $.proxy(that.handle_click, that));
|
||||
}
|
||||
|
||||
var $item_element = that.$buttongroup.find(item_query);
|
||||
if (that.model.get('value_name') == item) {
|
||||
$item_element.addClass('active');
|
||||
} else {
|
||||
@ -255,7 +261,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
|
||||
// Remove items that no longer exist.
|
||||
this.$buttongroup.find('button').each(function(i, obj) {
|
||||
var value = $(obj).text();
|
||||
var value = $(obj).data('value');
|
||||
var found = false;
|
||||
_.each(items, function(item, index) {
|
||||
if (item == value) {
|
||||
@ -285,7 +291,7 @@ define(["notebook/js/widgets/widget"], function(WidgetManager){
|
||||
|
||||
// Calling model.set will trigger all of the other views of the
|
||||
// model to update.
|
||||
this.model.set('value_name', $(e.target).text(), {updated_view: this});
|
||||
this.model.set('value_name', $(e.target).data('value'), {updated_view: this});
|
||||
this.touch();
|
||||
},
|
||||
});
|
||||
|
Loading…
Reference in New Issue
Block a user