Skip to content

Commit 7dac0a2

Browse files
authored
Merge pull request #2433 from takluyver/toolbar-btn-label
Allow toolbar buttons to have short label
2 parents 521f43f + af244a6 commit 7dac0a2

File tree

3 files changed

+31
-13
lines changed

3 files changed

+31
-13
lines changed

notebook/static/notebook/js/maintoolbar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,8 @@ define([
4949
'jupyter-notebook:move-cell-down'
5050
],
5151
'move_up_down'],
52-
[ ['jupyter-notebook:run-cell-and-select-next',
52+
[ [new toolbar.Button('jupyter-notebook:run-cell-and-select-next',
53+
{label: 'Run'}),
5354
'jupyter-notebook:interrupt-kernel',
5455
'jupyter-notebook:confirm-restart-kernel'
5556
],

notebook/static/notebook/js/toolbar.js

Lines changed: 25 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -82,26 +82,26 @@ define(['jquery'], function($) {
8282
if( group_id !== undefined ) {
8383
btn_group.attr('id',group_id);
8484
}
85-
for(var i=0; i < list.length; i++) {
86-
87-
// IIFE because javascript don't have loop scope so
88-
// action_name would otherwise be the same on all iteration
89-
// of the loop
90-
(function(i,list){
91-
var el = list[i];
85+
list.forEach(function(el) {
9286
var action_name;
9387
var action;
9488
if(typeof(el) === 'string'){
9589
action = that.actions.get(el);
9690
action_name = el;
97-
91+
} else if (el.action) {
92+
action = that.actions.get(el.action);
93+
action_name = el.action
9894
}
9995
var button = $('<button/>')
10096
.addClass('btn btn-default')
10197
.attr("title", el.label||action.help)
10298
.append(
10399
$("<i/>").addClass(el.icon||(action||{icon:'fa-exclamation-triangle'}).icon).addClass('fa')
104100
);
101+
if (el.label) {
102+
var label = $('<span/>').text(el.label).addClass('toolbar-btn-label');
103+
button.append(label);
104+
}
105105
var id = el.id;
106106
if( id !== undefined ){
107107
button.attr('id',id);
@@ -112,9 +112,7 @@ define(['jquery'], function($) {
112112
};
113113
button.click(fun);
114114
btn_group.append(button);
115-
})(i,list);
116-
// END IIFE
117-
}
115+
});
118116
$(this.selector).append(btn_group);
119117
return btn_group;
120118
};
@@ -131,5 +129,20 @@ define(['jquery'], function($) {
131129
this.element.toggle();
132130
};
133131

134-
return {'ToolBar': ToolBar};
132+
/**
133+
* A simple class to hold information defining one toolbar button.
134+
* @class ToolBar
135+
* @constructor
136+
* @param action {String} name of a Jupyter action taken when pressed
137+
* @param options.label {String} short label to display on the button
138+
*/
139+
var Button = function(action, options) {
140+
this.action = action;
141+
this.label = (options||{}).label;
142+
};
143+
144+
return {
145+
'ToolBar': ToolBar,
146+
'Button': Button
147+
};
135148
});

notebook/static/notebook/less/toolbar.less

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,10 @@
2828
margin-left: 5px;
2929
}
3030

31+
.toolbar-btn-label {
32+
margin-left: 6px;
33+
}
34+
3135
#maintoolbar {
3236
margin-bottom: -3px;
3337
margin-top: -8px;

0 commit comments

Comments
 (0)