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