@@ -75,12 +75,20 @@ proto.updateButtons = function(buttons) {
7575
7676 this . buttons = buttons ;
7777 this . buttonElements = [ ] ;
78+ this . buttonsNames = [ ] ;
7879
7980 this . buttons . forEach ( function ( buttonGroup ) {
8081 var group = _this . createGroup ( ) ;
8182
8283 buttonGroup . forEach ( function ( buttonConfig ) {
84+ var buttonName = buttonConfig . name ;
85+ if ( ! buttonName ) {
86+ throw new Error ( 'must provide button \'name\' in button config' ) ;
8387 }
88+ if ( _this . buttonsNames . indexOf ( buttonName ) !== - 1 ) {
89+ throw new Error ( 'button name \'' , + buttonName + '\' is taken' ) ;
90+ }
91+ _this . buttonsNames . push ( buttonName ) ;
8492
8593 var button = _this . createButton ( buttonConfig ) ;
8694 _this . buttonElements . push ( button ) ;
@@ -192,11 +200,10 @@ proto.updateActiveButton = function(buttonClicked) {
192200 } ) ;
193201} ;
194202
195-
196203/**
197204 * Check if modebar is configured as button configuration argument
198205 *
199- * @Param {object} buttons 2d array of grouped button names
206+ * @Param {object} buttons 2d array of grouped button config objects
200207 * @Return {boolean}
201208 */
202209proto . hasButtons = function ( buttons ) {
@@ -209,7 +216,7 @@ proto.hasButtons = function (buttons) {
209216 for ( var i = 0 ; i < buttons . length ; ++ i ) {
210217 if ( buttons [ i ] . length !== currentButtons [ i ] . length ) return false ;
211218 for ( var j = 0 ; j < buttons [ i ] . length ; j ++ ) {
212- if ( buttons [ i ] [ j ] !== currentButtons [ i ] [ j ] ) return false ;
219+ if ( buttons [ i ] [ j ] . name !== currentButtons [ i ] [ j ] . name ) return false ;
213220 }
214221 }
215222
0 commit comments