Skip to content

Instantly share code, notes, and snippets.

@ajaxray
Last active August 29, 2015 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ajaxray/b245509903f107d8a47f to your computer and use it in GitHub Desktop.
Save ajaxray/b245509903f107d8a47f to your computer and use it in GitHub Desktop.
My version of Dialog/Modal/Popup region for Backbone.Marionette using Bootstrap modal
define([
'app',
'marionette'
], function(app, Marionette){
return Marionette.Region.extend({
onShow: function(view){
this.listenTo(view, "dialog:close", this.closeDialog);
var self = this;
this.$el.modal({
backdrop: true,
keyboard: true,
show: true
});
},
closeDialog: function(){
this.stopListening();
this.close();
this.$el.modal('hide');
}
});
});
define([
'marionette'
], function (Marionette) {
'use strict';
return Marionette.ItemView.extend({
template: 'modal_content_with_close_btn',
events: {
'click .close': function(e) {
e.preventDefault();
this.trigger('dialog:close');
}
}
});
});
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
<h4 class="modal-title"><i class="fa fa-life-ring"></i> Help</h4>
</div>
<div class="modal-body">
This is help text html.
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
<!--
Your layout html should contain the following html.
Then you have to use #dialog as the region element. For example -
app.addRegions({
main: '#main',
dialog: {
selector: "#dialog",
regionType: DialogRegion
}
});
-->
<div class="modal fade" id="dialog" tabindex="-1" role="dialog" aria-hidden="true">
</div><!-- /.modal -->
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment