Created
July 31, 2013 22:42
-
-
Save andrewshatnyy/6126879 to your computer and use it in GitHub Desktop.
Basic Bootstrap Modal in backbone that will clean up after itself to avoid memory leaks. View triggered on button click => modalView = new BaseModalView();
modalView.show();
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
define(['underscore', 'backbone', ], function(_, Backbone) { | |
var BaseModalView = Backbone.View.extend({ | |
id: 'base-modal', | |
className: 'modal fade hide', | |
template: 'modals/BaseModal', | |
events: { | |
'hidden': 'teardown' | |
}, | |
initialize: function() { | |
_(this).bindAll(); | |
this.render(); | |
}, | |
show: function() { | |
this.$el.modal('show'); | |
}, | |
teardown: function() { | |
this.$el.data('modal', null); | |
this.remove(); | |
}, | |
render: function() { | |
this.getTemplate(this.template, this.renderView); | |
return this; | |
}, | |
renderView: function(template) { | |
this.$el.html(template()); | |
this.$el.modal({show:false}); // dont show modal on instantiation | |
} | |
}); | |
return BaseModalView; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
@eightyeight, @the1mills same see original thread https://stackoverflow.com/questions/16085852/rendering-bootstrap-modal-using-backbone/17982356. I didn't have my notifications turned on