Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add additional option buttons to modal footer #59

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ Set up the modal with the following options:
- {Boolean} [options.focusOk] Wether the 'OK' button should have the focus or not. Default: true
- {Boolean} [options.okCloses] Wether the modal should close on 'OK' click or not. Default: true
- {String} [options.cancelText] Text for the cancel button. Default: 'Cancel'. If passed a falsey value, the button will be removed
- {Array} [options.optionButtons] Objects containing properties for additional buttons. {text: String, class: String, event: String}
- {Boolean} [options.allowCancel] Whether the modal can be closed, other than - OK. Default: true
- {Boolean} [options.escape] Whether the 'esc' key can dismiss the modal- true, but false if options.cancellable is true
- {Boolean} [options.animate] Whether to animate in/out. Default: false
Expand Down
19 changes: 19 additions & 0 deletions src/backbone.bootstrap-modal.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
/*jshint multistr: true */
/**
* Bootstrap Modal wrapper for use with Backbone.
*
Expand Down Expand Up @@ -34,6 +35,11 @@
<div class="modal-body">{{content}}</div>\
<% if (showFooter) { %>\
<div class="modal-footer">\
<% if (optionButtons.length > 0) { %>\
<% _.each(optionButtons, function(optionButton, index) { %>\
<a href="#" class="btn optionButton {{optionButton.class}}" data-event="{{optionButton.event}}">{{optionButton.text}}</a>\
<% }) %>\
<% } %>\
<% if (allowCancel) { %>\
<% if (cancelText) { %>\
<a href="#" class="btn cancel">{{cancelText}}</a>\
Expand All @@ -54,6 +60,17 @@
className: 'modal',

events: {
'click .optionButton': function(event) {
event.preventDefault();

var eventTrigger = $(event.target).data('event');

this.trigger(eventTrigger);

if (this.options.content && this.options.content.trigger) {
this.options.content.trigger(eventTrigger, this);
}
},
'click .close': function(event) {
event.preventDefault();

Expand Down Expand Up @@ -112,6 +129,7 @@
* @param {String} [options.title] Title. Default: none
* @param {String} [options.okText] Text for the OK button. Default: 'OK'
* @param {String} [options.cancelText] Text for the cancel button. Default: 'Cancel'. If passed a falsey value, the button will be removed
* @param {String} [options.optionButtons] Array of properties objects for additional buttons. {text: String, class: String, event: String}
* @param {Boolean} [options.allowCancel Whether the modal can be closed, other than by pressing OK. Default: true
* @param {Boolean} [options.escape] Whether the 'esc' key can dismiss the modal. Default: true, but false if options.cancellable is true
* @param {Boolean} [options.animate] Whether to animate in/out. Default: false
Expand All @@ -126,6 +144,7 @@
okCloses: true,
cancelText: 'Cancel',
showFooter: true,
optionButtons: [],
allowCancel: true,
escape: true,
animate: false,
Expand Down