Permalink
Find file Copy path
Fetching contributors…
Cannot retrieve contributors at this time
121 lines (101 sloc) 4.03 KB
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xml:lang="en" xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta content="text/html;charset=UTF-8" http-equiv="Content-Type"/>
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no"/>
<title>Stacked modal with Marionette</title>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/jquery/3.2.0/jquery.min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.js/1.3.3/backbone-min.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.radio/2.0.0/backbone.radio.js"></script>
<script type="text/javascript" src="//cdnjs.cloudflare.com/ajax/libs/backbone.marionette/3.2.0/backbone.marionette.js"></script>
<!-- Adding Backbone.Modal extension here -->
<link type="text/css" rel="stylesheet" href="/backbone.modal.css">
<link type="text/css" rel="stylesheet" href="/backbone.modal.theme.css">
<script type="text/javascript" src="/backbone.modal.js"></script>
<script type="text/javascript" src="/backbone.marionette.modals.js"></script>
<!-- Custom style -->
<link type="text/css" rel="stylesheet" href="/examples/css/style.css">
</head>
<body>
<a href="#" class="open-1">Open modal</a>
<div class="app"></div>
<!-- Region container -->
<script type="text/template" id="modals-template">
<div class="modals-container"></div>
</script>
<!-- Modal templates -->
<script type="text/template" id="modal-template1">
<div class="bbm-modal__topbar">
<h3 class="bbm-modal__title">Stacked modals with Backbone.Marionette</h3>
</div>
<div class="bbm-modal__section">
<p>Go ahead and open the <a href="#" class="open-2">second modal</a>.</p>
</div>
<div class="bbm-modal__bottombar">
<a href="#" class="bbm-button">Done</a>
</div>
</script>
<script type="text/template" id="modal-template2">
<div class="bbm-modal__topbar">
<h3 class="bbm-modal__title">The stacked modal</h3>
</div>
<div class="bbm-modal__section">
<p>By using Backbone.Marionette, your code stays simple and clean. So now we can create stacked modals, without doing any complex work.</p>
</div>
<div class="bbm-modal__bottombar">
<a href="#" class="bbm-button">Done</a>
</div>
</script>
<script>
jQuery(function($) {
// Create a layout class
var Layout = Backbone.Marionette.View.extend({
template: _.template($('#modals-template').html()),
regions: {
modals: {
el: '.modals-container',
regionClass: Backbone.Marionette.Modals
}
}
});
// Create a modal view class
var Modal1 = Backbone.Modal.extend({
template: _.template($('#modal-template1').html()),
submitEl: '.bbm-button',
events: {
'click .open-2': 'openModal'
},
onShow: function() {
console.log('open');
},
onDestroy: function() {
console.log('close');
},
onRender: function() {
console.log('render');
},
openModal: function(e) {
e.preventDefault();
modalsRegion.show(new Modal2());
}
});
var Modal2 = Backbone.Modal.extend({
template: _.template($('#modal-template2').html()),
submitEl: '.bbm-button'
});
// Render the layout
var myLayout = new Layout();
var modalsRegion = myLayout.getRegion('modals');
$('body').append(myLayout.render().el);
// Render modals on click
$('body').on('click', '.open-1', function(){
modalsRegion.show(new Modal1());
});
$('.open-1').click()
});
</script>
<!-- Do not include in your page -->
<script src="//localhost:35729/livereload.js"></script>
</body>
</html>