Skip to content

Commit

Permalink
move 'shown' and 'hidden' listeners before modal is created - fix pow…
Browse files Browse the repository at this point in the history
  • Loading branch information
mattvoss committed Apr 27, 2013
1 parent 245149f commit 3e80d08
Showing 1 changed file with 23 additions and 22 deletions.
45 changes: 23 additions & 22 deletions src/backbone.bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -151,13 +151,7 @@
var self = this,
$el = this.$el;

//Create it
$el.modal(_.extend({
keyboard: this.options.allowCancel,
backdrop: this.options.allowCancel ? true : 'static'
}, this.options.modalOptions));

//Focus OK button
//Focus OK button - called when modal shown
$el.one('shown', function() {
if (self.options.focusOk) {
$el.find('.btn.ok').focus();
Expand All @@ -166,10 +160,31 @@
if (self.options.content && self.options.content.trigger) {
self.options.content.trigger('shown', self);
}

self.trigger('shown');
});

// listener for hidden
$el.one('hidden', function() {
// Ignore events propagated from interior objects, like bootstrap tooltips
if(e.target !== e.currentTarget){
return $el.one('hidden', onHidden);
}
self.remove();

if (self.options.content && self.options.content.trigger) {
self.options.content.trigger('hidden', self);
}

self.trigger('hidden');
});

//Create it
$el.modal(_.extend({
keyboard: this.options.allowCancel,
backdrop: this.options.allowCancel ? true : 'static'
}, this.options.modalOptions));

//Adjust the modal and backdrop z-index; for dealing with multiple modals
var numModals = Modal.count,
$backdrop = $('.modal-backdrop:eq('+numModals+')'),
Expand Down Expand Up @@ -224,20 +239,6 @@
return;
}

$el.one('hidden', function onHidden(e) {
// Ignore events propagated from interior objects, like bootstrap tooltips
if(e.target !== e.currentTarget){
return $el.one('hidden', onHidden);
}
self.remove();

if (self.options.content && self.options.content.trigger) {
self.options.content.trigger('hidden', self);
}

self.trigger('hidden');
});

$el.modal('hide');

Modal.count--;
Expand Down

0 comments on commit 3e80d08

Please sign in to comment.