@@ -75,12 +75,20 @@ proto.updateButtons = function(buttons) {
75
75
76
76
this . buttons = buttons ;
77
77
this . buttonElements = [ ] ;
78
+ this . buttonsNames = [ ] ;
78
79
79
80
this . buttons . forEach ( function ( buttonGroup ) {
80
81
var group = _this . createGroup ( ) ;
81
82
82
83
buttonGroup . forEach ( function ( buttonConfig ) {
84
+ var buttonName = buttonConfig . name ;
85
+ if ( ! buttonName ) {
86
+ throw new Error ( 'must provide button \'name\' in button config' ) ;
83
87
}
88
+ if ( _this . buttonsNames . indexOf ( buttonName ) !== - 1 ) {
89
+ throw new Error ( 'button name \'' , + buttonName + '\' is taken' ) ;
90
+ }
91
+ _this . buttonsNames . push ( buttonName ) ;
84
92
85
93
var button = _this . createButton ( buttonConfig ) ;
86
94
_this . buttonElements . push ( button ) ;
@@ -192,11 +200,10 @@ proto.updateActiveButton = function(buttonClicked) {
192
200
} ) ;
193
201
} ;
194
202
195
-
196
203
/**
197
204
* Check if modebar is configured as button configuration argument
198
205
*
199
- * @Param {object} buttons 2d array of grouped button names
206
+ * @Param {object} buttons 2d array of grouped button config objects
200
207
* @Return {boolean}
201
208
*/
202
209
proto . hasButtons = function ( buttons ) {
@@ -209,7 +216,7 @@ proto.hasButtons = function (buttons) {
209
216
for ( var i = 0 ; i < buttons . length ; ++ i ) {
210
217
if ( buttons [ i ] . length !== currentButtons [ i ] . length ) return false ;
211
218
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 ;
213
220
}
214
221
}
215
222
0 commit comments