Skip to content

Commit

Permalink
Merge pull request #2 from powmedia/master
Browse files Browse the repository at this point in the history
merge from powmedia
  • Loading branch information
stephanebachelier committed Sep 11, 2012
2 parents a5f0ddb + aa8f4b8 commit fd2f4e6
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 20 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,8 @@ Set up the modal with the following options:
- {Function} [options.template] Compiled underscore template to override the default one


###modal.open()
Renders and opens the modal
###modal.open([cb])
Renders and opens the modal, running the optional callback if the 'OK' button is pressed


###modal.close()
Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
module.exports = require('./src/backbone.bootstrap-modal');
34 changes: 16 additions & 18 deletions src/backbone.bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -54,13 +54,11 @@
event.preventDefault();

this.trigger('cancel');
this.close();
},
'click .cancel': function(event) {
event.preventDefault();

this.trigger('cancel');
this.close();
},
'click .ok': function(event) {
event.preventDefault();
Expand Down Expand Up @@ -126,8 +124,10 @@

/**
* Renders and shows the modal
*
* @param {Function} [cb] Optional callback that runs only when OK is pressed.
*/
open: function() {
open: function(cb) {
if (!this.isRendered) this.render();

var self = this,
Expand All @@ -154,29 +154,27 @@

$backdrop.css('z-index', backdropIndex + numModals);
this.$el.css('z-index', elIndex + numModals);

var that = this;

if (this.options.allowCancel) {

$backdrop.click(function() {
that.trigger('cancel');
});
$backdrop.one('click', function() {
self.trigger('cancel');
});

$(document).one('keyup.dismiss.modal', function (e) {
e.which == 27 && self.trigger('cancel');
});
}

$(document).on('keyup.dismiss.modal', function ( e ) {
e.which == 27 && that.trigger('cancel');
});

$el.one('hide', function() {
$(document).off('keyup.dismiss.modal');
});

this.on('cancel', function() {
that.close();
self.close();
});

Modal.count++;

//Run callback on OK if provided
if (cb) {
self.on('ok', cb);
}

return this;
},
Expand Down

0 comments on commit fd2f4e6

Please sign in to comment.