@@ -122,7 +122,7 @@ proto.createButton = function (config) {
122122 button . setAttribute ( 'rel' , 'tooltip' ) ;
123123 button . className = 'modebar-btn' ;
124124
125- button . setAttribute ( 'data-title' , config . title ) ;
125+ button . setAttribute ( 'data-title' , config . title || '' ) ;
126126 button . setAttribute ( 'data-gravity' , config . gravity || 'n' ) ;
127127
128128 if ( config . attr !== undefined ) button . setAttribute ( 'data-attr' , config . attr ) ;
@@ -133,14 +133,20 @@ proto.createButton = function (config) {
133133 button . setAttribute ( 'data-val' , val ) ;
134134 }
135135
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+ }
139145
140- button . setAttribute ( 'data-toggle' , config . toggle ) ;
146+ button . setAttribute ( 'data-toggle' , config . toggle || false ) ;
141147 if ( config . toggle ) button . classList . add ( 'active' ) ;
142148
143- button . appendChild ( this . createIcon ( Icons [ config . icon ] ) ) ;
149+ button . appendChild ( this . createIcon ( Icons [ config . icon || 'tooltip_basic' ] ) ) ;
144150
145151 return button ;
146152} ;
@@ -183,7 +189,7 @@ proto.updateActiveButton = function(buttonClicked) {
183189 this . buttonElements . forEach ( function ( button ) {
184190 var thisval = button . getAttribute ( 'data-val' ) || true ,
185191 dataAttr = button . getAttribute ( 'data-attr' ) ,
186- isToggleButton = button . getAttribute ( 'data-toggle' ) === 'true' ,
192+ isToggleButton = ( button . getAttribute ( 'data-toggle' ) === 'true' ) ,
187193 button3 = d3 . select ( button ) ;
188194
189195 // Use 'data-toggle' and 'buttonClicked' to toggle buttons
0 commit comments