Skip to content

Commit

Permalink
Merge additional buttons into existing groups if the group name match…
Browse files Browse the repository at this point in the history
…es an existing group. See #184
  • Loading branch information
ckosmowski committed Jun 15, 2015
1 parent a17d94d commit 9f63ef5
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion js/bootstrap-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,24 @@
// Merge the main & additional button groups together
var allBtnGroups = [];
if (options.buttons.length > 0) allBtnGroups = allBtnGroups.concat(options.buttons[0]);
if (options.additionalButtons.length > 0) allBtnGroups = allBtnGroups.concat(options.additionalButtons[0]);
if (options.additionalButtons.length > 0) {
// iterate the additional button groups
$.each(options.additionalButtons[0], function(idx, buttonGroup){

// see if the group name of the addional group matches an existing group
var matchingGroups = $.grep(allBtnGroups, function(allButtonGroup, allIdx){
return allButtonGroup.name === buttonGroup.name;
});

// if it matches add the addional buttons to that group, if not just add it to the all buttons group
if(matchingGroups.length > 0) {
matchingGroups[0].data = matchingGroups[0].data.concat(buttonGroup.data);
} else {
allBtnGroups.push(options.additionalButtons[0][idx]);
}

});
}

// Reduce and/or reorder the button groups
if (options.reorderButtonGroups.length > 0) {
Expand Down

0 comments on commit 9f63ef5

Please sign in to comment.