##// END OF EJS Templates
Merge pull request #5114 from minrk/empty-button...
Jonathan Frederic -
r15350:8677e247 merge
parent child Browse files
Show More
@@ -488,6 +488,12 b' IPython.utils = (function (IPython) {'
488 488 };
489 489
490 490
491 var escape_html = function (text) {
492 // escape text to HTML
493 return $("<div/>").text(text).html();
494 }
495
496
491 497 var get_body_data = function(key) {
492 498 // get a url-encoded item from body.data and decode it
493 499 // we should never have any encoded URLs anywhere else in code
@@ -564,6 +570,7 b' IPython.utils = (function (IPython) {'
564 570 url_join_encode : url_join_encode,
565 571 encode_uri_components : encode_uri_components,
566 572 splitext : splitext,
573 escape_html : escape_html,
567 574 always_new : always_new,
568 575 browser : browser,
569 576 platform: platform,
@@ -56,7 +56,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
56 56 this.$checkbox.prop('disabled', disabled);
57 57
58 58 var description = this.model.get('description');
59 if (description.length === 0) {
59 if (description.trim().length === 0) {
60 60 this.$label.hide();
61 61 } else {
62 62 this.$label.text(description);
@@ -102,8 +102,8 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
102 102 this.$el.prop('disabled', disabled);
103 103
104 104 var description = this.model.get('description');
105 if (description.length === 0) {
106 this.$el.text(' '); // Preserve button height
105 if (description.trim().length === 0) {
106 this.$el.html("&nbsp;"); // Preserve button height
107 107 } else {
108 108 this.$el.text(description);
109 109 }
@@ -32,7 +32,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
32 32 // changed by another view or by a state update from the back-end.
33 33 var description = this.model.get('description');
34 34 if (description.length === 0) {
35 this.$el.text(' '); // Preserve button height
35 this.$el.html("&nbsp;"); // Preserve button height
36 36 } else {
37 37 this.$el.text(description);
38 38 }
@@ -137,7 +137,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager) {'
137 137 });
138 138 this.$title = $('<div />')
139 139 .addClass('widget-modal-title')
140 .text(' ')
140 .html("&nbsp;")
141 141 .appendTo(this.$title_bar);
142 142 this.$body = $('<div />')
143 143 .addClass('modal-body')
@@ -147,7 +147,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager) {'
147 147 .appendTo(this.$window);
148 148
149 149 this.$show_button = $('<button />')
150 .text(' ')
150 .html("&nbsp;")
151 151 .addClass('btn btn-info widget-modal-show')
152 152 .appendTo(this.$el)
153 153 .click(function(){
@@ -236,15 +236,15 b' define(["notebook/js/widgets/widget"], function(WidgetManager) {'
236 236 // Called when the model is changed. The model may have been
237 237 // changed by another view or by a state update from the back-end.
238 238 var description = this.model.get('description');
239 if (description.length === 0) {
240 this.$title.text(' '); // Preserve title height
239 if (description.trim().length === 0) {
240 this.$title.html("&nbsp;"); // Preserve title height
241 241 } else {
242 242 this.$title.text(description);
243 243 }
244 244
245 245 var button_text = this.model.get('button_text');
246 if (button_text.length === 0) {
247 this.$show_button.text(' '); // Preserve button height
246 if (button_text.trim().length === 0) {
247 this.$show_button.html("&nbsp;"); // Preserve button height
248 248 } else {
249 249 this.$show_button.text(button_text);
250 250 }
@@ -33,7 +33,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
33 33 this.$droplabel = $('<button />')
34 34 .addClass('btn')
35 35 .addClass('widget-combo-btn')
36 .text(' ')
36 .html("&nbsp;")
37 37 .appendTo(this.$buttongroup);
38 38 this.$dropbutton = $('<button />')
39 39 .addClass('btn')
@@ -58,8 +58,8 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
58 58
59 59 if (options === undefined || options.updated_view != this) {
60 60 var selected_item_text = this.model.get('value_name');
61 if (selected_item_text.length === 0) {
62 this.$droplabel.text(' ');
61 if (selected_item_text.trim().length === 0) {
62 this.$droplabel.html("&nbsp;");
63 63 } else {
64 64 this.$droplabel.text(selected_item_text);
65 65 }
@@ -233,18 +233,24 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
233 233 var items = this.model.get('value_names');
234 234 var disabled = this.model.get('disabled');
235 235 var that = this;
236 var item_html;
236 237 _.each(items, function(item, index) {
237 var item_query = ' :contains("' + item + '")';
238 if (that.$buttongroup.find(item_query).length === 0) {
239 $('<button />')
238 if (item.trim().length == 0) {
239 item_html = "&nbsp;";
240 } else {
241 item_html = IPython.utils.escape_html(item);
242 }
243 var item_query = '[data-value="' + item + '"]';
244 var $item_element = that.$buttongroup.find(item_query);
245 if (!$item_element.length) {
246 $item_element = $('<button/>')
240 247 .attr('type', 'button')
241 248 .addClass('btn')
242 .text(item)
249 .html(item_html)
243 250 .appendTo(that.$buttongroup)
251 .attr('data-value', item)
244 252 .on('click', $.proxy(that.handle_click, that));
245 253 }
246
247 var $item_element = that.$buttongroup.find(item_query);
248 254 if (that.model.get('value_name') == item) {
249 255 $item_element.addClass('active');
250 256 } else {
@@ -255,7 +261,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
255 261
256 262 // Remove items that no longer exist.
257 263 this.$buttongroup.find('button').each(function(i, obj) {
258 var value = $(obj).text();
264 var value = $(obj).data('value');
259 265 var found = false;
260 266 _.each(items, function(item, index) {
261 267 if (item == value) {
@@ -285,7 +291,7 b' define(["notebook/js/widgets/widget"], function(WidgetManager){'
285 291
286 292 // Calling model.set will trigger all of the other views of the
287 293 // model to update.
288 this.model.set('value_name', $(e.target).text(), {updated_view: this});
294 this.model.set('value_name', $(e.target).data('value'), {updated_view: this});
289 295 this.touch();
290 296 },
291 297 });
General Comments 0
You need to be logged in to leave comments. Login now