Created
April 11, 2012 14:37
-
-
Save mxriverlynn/2359717 to your computer and use it in GitHub Desktop.
modal dialog with backbone
This file contains 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
<script id="modal-view-template" type="text/html"> | |
<div class="modal-header"> | |
<h2>This is a modal!</h2> | |
</div> | |
<div class="modal-body"> | |
<p>With some content in it!</p> | |
</div> | |
<div class="modal-footer"> | |
<button class="btn">cancel</button> | |
<button class="btn-default">Ok</button> | |
</div> | |
</script> | |
<div id="modal"></div> |
This file contains 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
var view = new MyView(); | |
view.render(); | |
var $modalEl = $("#modal"); | |
$modalEl.html(view.el); | |
$modalEl.modal(); |
This file contains 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
var ModalRegion = Backbone.Marionette.Region.extend({ | |
el: "#modal", | |
constructor: function(){ | |
_.bindAll(this); | |
Backbone.Marionette.Region.prototype.constructor.apply(this, arguments); | |
this.on("view:show", this.showModal, this); | |
}, | |
getEl: function(selector){ | |
var $el = $(selector); | |
$el.on("hidden", this.close); | |
return $el; | |
}, | |
showModal: function(view){ | |
view.on("close", this.hideModal, this); | |
this.$el.modal('show'); | |
}, | |
hideModal: function(){ | |
this.$el.modal('hide'); | |
} | |
}); |
This file contains 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
var App = new Backbone.Marionette.Application(); | |
App.addRegions({ | |
main: "#main-content", | |
modal: ModalRegion | |
}); | |
// somewhere else in the app | |
var view = new MyView(); | |
App.modal.show(view); |
I made a gist that worked for our current project with Bootstrap and Backbone 1.0 https://gist.github.com/insaciableslabs/6369107
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I think line 5 of
3.js
should be:otherwise,
bindAll
complains that it should be passed some function names.