Skip to content

Commit

Permalink
Refactored destory method, make sure destoyed event is always called
Browse files Browse the repository at this point in the history
  • Loading branch information
Jordan Schroter committed Mar 4, 2014
1 parent 7adfa45 commit 1d82317
Showing 1 changed file with 13 additions and 16 deletions.
29 changes: 13 additions & 16 deletions js/bootstrap-modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -294,29 +294,26 @@

destroy: function () {
var e = $.Event('destroy');

this.$element.trigger(e);
if (e.isDefaultPrevented()) return;

this.teardown();
},
if (e.isDefaultPrevented()) return;

teardown: function () {
if (!this.$parent.length){
this.$element
.off('.modal')
.removeData('modal')
.removeClass('in')
.attr('aria-hidden', true);

if (this.$parent !== this.$element.parent()) {
this.$element.appendTo(this.$parent);
} else if (!this.$parent.length) {
// modal is not part of the DOM so remove it.
this.$element.remove();
this.$element = null;
return;
}

if (this.$parent !== this.$element.parent()){
this.$element.appendTo(this.$parent);
}

this.$element.off('.modal');
this.$element.removeData('modal');
this.$element
.removeClass('in')
.attr('aria-hidden', true)
.trigger('destroyed');
this.$element.trigger('destroyed');
}
};

Expand Down

0 comments on commit 1d82317

Please sign in to comment.