@@ -122,7 +122,7 @@ proto.createButton = function (config) {
122
122
button . setAttribute ( 'rel' , 'tooltip' ) ;
123
123
button . className = 'modebar-btn' ;
124
124
125
- button . setAttribute ( 'data-title' , config . title ) ;
125
+ button . setAttribute ( 'data-title' , config . title || '' ) ;
126
126
button . setAttribute ( 'data-gravity' , config . gravity || 'n' ) ;
127
127
128
128
if ( config . attr !== undefined ) button . setAttribute ( 'data-attr' , config . attr ) ;
@@ -133,14 +133,20 @@ proto.createButton = function (config) {
133
133
button . setAttribute ( 'data-val' , val ) ;
134
134
}
135
135
136
- button . addEventListener ( 'click' , function ( ) {
137
- _this [ config . click ] . apply ( _this , arguments ) ;
138
- } ) ;
136
+ var click = config . click ;
137
+ if ( typeof click !== 'function' ) {
138
+ throw new Error ( 'must provide button \'click\' function in button config' ) ;
139
+ }
140
+ else {
141
+ button . addEventListener ( 'click' , function ( ev ) {
142
+ config . click ( _this , ev ) ;
143
+ } ) ;
144
+ }
139
145
140
- button . setAttribute ( 'data-toggle' , config . toggle ) ;
146
+ button . setAttribute ( 'data-toggle' , config . toggle || false ) ;
141
147
if ( config . toggle ) button . classList . add ( 'active' ) ;
142
148
143
- button . appendChild ( this . createIcon ( Icons [ config . icon ] ) ) ;
149
+ button . appendChild ( this . createIcon ( Icons [ config . icon || 'tooltip_basic' ] ) ) ;
144
150
145
151
return button ;
146
152
} ;
@@ -183,7 +189,7 @@ proto.updateActiveButton = function(buttonClicked) {
183
189
this . buttonElements . forEach ( function ( button ) {
184
190
var thisval = button . getAttribute ( 'data-val' ) || true ,
185
191
dataAttr = button . getAttribute ( 'data-attr' ) ,
186
- isToggleButton = button . getAttribute ( 'data-toggle' ) === 'true' ,
192
+ isToggleButton = ( button . getAttribute ( 'data-toggle' ) === 'true' ) ,
187
193
button3 = d3 . select ( button ) ;
188
194
189
195
// Use 'data-toggle' and 'buttonClicked' to toggle buttons
0 commit comments