Skip to content

Commit

Permalink
Merge pull request #45 from emagnier/reorder-grp-btns
Browse files Browse the repository at this point in the history
Add an option to reorder the button groups
  • Loading branch information
toopay committed Mar 12, 2014
2 parents 9a4baa6 + ddf3a29 commit 30a48fe
Showing 1 changed file with 20 additions and 6 deletions.
26 changes: 20 additions & 6 deletions js/bootstrap-markdown.js
Original file line number Diff line number Diff line change
Expand Up @@ -195,14 +195,27 @@
'class': 'md-header btn-toolbar'
})

// Build the main buttons
if (options.buttons.length > 0) {
editorHeader = this.__buildButtons(options.buttons, editorHeader)
// 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])

// Reduce and/or reorder the button groups
if (options.reorderButtonGroups.length > 0) {
allBtnGroups = allBtnGroups
.filter(function(btnGroup) {
return options.reorderButtonGroups.indexOf(btnGroup.name) > -1
})
.sort(function(a, b) {
if (options.reorderButtonGroups.indexOf(a.name) < options.reorderButtonGroups.indexOf(b.name)) return -1
if (options.reorderButtonGroups.indexOf(a.name) > options.reorderButtonGroups.indexOf(b.name)) return 1
return 0
})
}

// Build the additional buttons
if (options.additionalButtons.length > 0) {
editorHeader = this.__buildButtons(options.additionalButtons, editorHeader)
// Build the buttons
if (allBtnGroups.length > 0) {
editorHeader = this.__buildButtons([allBtnGroups], editorHeader)
}

editor.append(editorHeader)
Expand Down Expand Up @@ -928,6 +941,7 @@
}]
],
additionalButtons:[], // Place to hook more buttons by code
reorderButtonGroups:[],

/* Events hook */
onShow: function (e) {},
Expand Down

0 comments on commit 30a48fe

Please sign in to comment.