@@ -82,26 +82,26 @@ define(['jquery'], function($) {
82
82
if ( group_id !== undefined ) {
83
83
btn_group . attr ( 'id' , group_id ) ;
84
84
}
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 ) {
92
86
var action_name ;
93
87
var action ;
94
88
if ( typeof ( el ) === 'string' ) {
95
89
action = that . actions . get ( el ) ;
96
90
action_name = el ;
97
-
91
+ } else if ( el . action ) {
92
+ action = that . actions . get ( el . action ) ;
93
+ action_name = el . action
98
94
}
99
95
var button = $ ( '<button/>' )
100
96
. addClass ( 'btn btn-default' )
101
97
. attr ( "title" , el . label || action . help )
102
98
. append (
103
99
$ ( "<i/>" ) . addClass ( el . icon || ( action || { icon :'fa-exclamation-triangle' } ) . icon ) . addClass ( 'fa' )
104
100
) ;
101
+ if ( el . label ) {
102
+ var label = $ ( '<span/>' ) . text ( el . label ) . addClass ( 'toolbar-btn-label' ) ;
103
+ button . append ( label ) ;
104
+ }
105
105
var id = el . id ;
106
106
if ( id !== undefined ) {
107
107
button . attr ( 'id' , id ) ;
@@ -112,9 +112,7 @@ define(['jquery'], function($) {
112
112
} ;
113
113
button . click ( fun ) ;
114
114
btn_group . append ( button ) ;
115
- } ) ( i , list ) ;
116
- // END IIFE
117
- }
115
+ } ) ;
118
116
$ ( this . selector ) . append ( btn_group ) ;
119
117
return btn_group ;
120
118
} ;
@@ -131,5 +129,20 @@ define(['jquery'], function($) {
131
129
this . element . toggle ( ) ;
132
130
} ;
133
131
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
+ } ;
135
148
} ) ;
0 commit comments