Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow toolbar buttons to have short label #2433

Merged
merged 1 commit into from
Apr 25, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion notebook/static/notebook/js/maintoolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ define([
'jupyter-notebook:move-cell-down'
],
'move_up_down'],
[ ['jupyter-notebook:run-cell-and-select-next',
[ [new toolbar.Button('jupyter-notebook:run-cell-and-select-next',
{label: 'Run'}),
'jupyter-notebook:interrupt-kernel',
'jupyter-notebook:confirm-restart-kernel'
],
Expand Down
37 changes: 25 additions & 12 deletions notebook/static/notebook/js/toolbar.js
Original file line number Diff line number Diff line change
Expand Up @@ -82,26 +82,26 @@ define(['jquery'], function($) {
if( group_id !== undefined ) {
btn_group.attr('id',group_id);
}
for(var i=0; i < list.length; i++) {

// IIFE because javascript don't have loop scope so
// action_name would otherwise be the same on all iteration
// of the loop
(function(i,list){
var el = list[i];
list.forEach(function(el) {
var action_name;
var action;
if(typeof(el) === 'string'){
action = that.actions.get(el);
action_name = el;

} else if (el.action) {
action = that.actions.get(el.action);
action_name = el.action
}
var button = $('<button/>')
.addClass('btn btn-default')
.attr("title", el.label||action.help)
.append(
$("<i/>").addClass(el.icon||(action||{icon:'fa-exclamation-triangle'}).icon).addClass('fa')
);
if (el.label) {
var label = $('<span/>').text(el.label).addClass('toolbar-btn-label');
button.append(label);
}
var id = el.id;
if( id !== undefined ){
button.attr('id',id);
Expand All @@ -112,9 +112,7 @@ define(['jquery'], function($) {
};
button.click(fun);
btn_group.append(button);
})(i,list);
// END IIFE
}
});
$(this.selector).append(btn_group);
return btn_group;
};
Expand All @@ -131,5 +129,20 @@ define(['jquery'], function($) {
this.element.toggle();
};

return {'ToolBar': ToolBar};
/**
* A simple class to hold information defining one toolbar button.
* @class ToolBar
* @constructor
* @param action {String} name of a Jupyter action taken when pressed
* @param options.label {String} short label to display on the button
*/
var Button = function(action, options) {
this.action = action;
this.label = (options||{}).label;
};

return {
'ToolBar': ToolBar,
'Button': Button
};
});
4 changes: 4 additions & 0 deletions notebook/static/notebook/less/toolbar.less
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@
margin-left: 5px;
}

.toolbar-btn-label {
margin-left: 6px;
}

#maintoolbar {
margin-bottom: -3px;
margin-top: -8px;
Expand Down