no duplicate buttons...

Signed-off-by: Alex A. Naanou <alex.nanou@gmail.com>
This commit is contained in:
Alex A. Naanou 2017-02-08 05:30:18 +03:00
parent e4282bc4f5
commit 48f88faa85

View File

@ -695,7 +695,7 @@ function(list, options){
var buttons = options.buttons = (options.buttons || []).slice() var buttons = options.buttons = (options.buttons || []).slice()
// options buttons... // buttons: options...
// NOTE: the order here is important... // NOTE: the order here is important...
if(editable && !options.sort){ if(editable && !options.sort){
// up/down... // up/down...
@ -714,7 +714,7 @@ function(list, options){
&& buttons.indexOf('TO_BOTTOM') < 0 && buttons.indexOf('TO_BOTTOM') < 0
&& buttons.push('TO_BOTTOM') && buttons.push('TO_BOTTOM')
} }
// 'x' button... // remove...
editable editable
&& options.delete_button !== false && options.delete_button !== false
&& buttons.indexOf('REMOVE') < 0 && buttons.indexOf('REMOVE') < 0
@ -779,19 +779,31 @@ function(list, options){
} }
// replace the button placeholders... // replace the button placeholders...
// NOTE: only the first button instance is used, also not that all
// the config buttons are pushed to the end of the list thus
// they will be overridden buy user buttons...
var seen = []
buttons = options.buttons = buttons = options.buttons =
buttons buttons
.map(function(button){ .map(function(button){
var key = button instanceof Array ? button[1] : button
// skip seen buttons...
if(seen.indexOf(key) >= 0){
return key
}
var res = button in __buttons ? var res = button in __buttons ?
__buttons[button] __buttons[button]
: button[1] in __buttons ? : button[1] in __buttons ?
[button[0], __buttons[button[1]][1]] [button[0], __buttons[button[1]][1]]
: button.slice() : button
// group if at least one sort button is present... // group if at least one sort button is present...
if(res !== button){ if(res !== button){
options.groupList = true options.groupList = true
// avoid duplicates...
seen.push(key)
} }
return res return res.slice()
}) })
// clear out the unused button placeholders... // clear out the unused button placeholders...
.filter(function(b){ .filter(function(b){