{% extends 'base0.html' %}
{% load markup %}
{% block page-content %}
{% filter restructuredtext %}
w3schools.com supplies an example; here is the full code:
https://www.w3schools.com/howto/tryit.asp?filename=tryhow_css_modal2
Isn't this too much fuss for such a simple task ?
.. figure:: /static/images/w3schools_example.png
:alt: w3school modal example
:scale: 80 %
w3school modal example
Well, actually it's not that bad.
Here is how it works:
- a semi-transparent and initially hidden "modal" element covers the whole html page,
thus providing a backdrop
- a nested "modal content" element has been given the style to look as a popup window
- you can show or hide the modal by playing with it's display CSS attribute
.. code:: javascript
<script language="javascript">
$(document).ready(function() {
// Get the modal
var modal = $('#my-modal');
// Open the modal
var button = $('#button-open-modal');
button.on('click', function(event) {
modal.css('display', 'block');
})
// Close the modal
var close_button = $('.close');
close_button.on('click', function(event) {
modal.css('display', 'none');
})
// When the user clicks anywhere outside of the modal, close it
$(window).on('click', function(event) {
if (event.target.id == modal.attr('id')) {
modal.css('display', 'none');
}
});
});
</script>
{% endfilter %}
<h2 class="code-sample">Code sample</h2>
<div>A basic modal box with pure Javascript ...</div>
<button id="button-open-modal" class="btn btn-primary">Open Modal</button>
<div id="my-modal" class="my-modal">
<div class="my-modal-content">
<div class="my-modal-header">
<span class="close">×</span>
<h2>Modal Header</h2>
</div>
<div class="my-modal-body">
<p>Some text in the Modal Body</p>
<p>Some other text...</p>
</div>
<div class="my-modal-footer">
<h3>Modal Footer</h3>
</div>
</div>
</div>
{% endblock page-content %}
{% block extrastyle %}
<style>
.my-modal {
display: none; /* Hidden by default */
position: fixed; /* Stay in place */
z-index: 1; /* Sit on top */
padding-top: 200px; /* Location of the box */
left: 0;
top: 0;
width: 100%; /* Full width */
height: 100%; /* Full height */
overflow: auto; /* Enable scroll if needed */
background-color: rgb(0,0,0); /* Fallback color */
background-color: rgba(0,0,0,0.4); /* Black w/ opacity */
}
.my-modal-content {
position: relative;
background-color: #fefefe;
margin: auto;
padding: 0;
border: 1px solid #888;
box-shadow: 0 4px 8px 0 rgba(0,0,0,0.2),0 6px 20px 0 rgba(0,0,0,0.19);
-webkit-animation-name: animatetop;
-webkit-animation-duration: 0.4s;
animation-name: animatetop;
animation-duration: 0.4s;
max-width: 400px;
}
.my-modal-header {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}
.my-modal-body {
padding: 40px;
}
.my-modal-footer {
padding: 2px 16px;
background-color: #5cb85c;
color: white;
}
/* The Close Button */
.close {
color: white;
float: right;
font-size: 28px;
font-weight: bold;
}
.close:hover,
.close:focus {
color: #000;
text-decoration: none;
cursor: pointer;
}
</style>
{% endblock extrastyle %}
{% block extrajs %}
<script type="text/javascript">
'use strict';
$(document).ready(function() {
// Get the modal
var modal = $('#my-modal');
// Open the modal
var button = $('#button-open-modal');
button.on('click', function(event) {
modal.css('display', 'block');
})
// Close the modal
var close_button = $('.close');
close_button.on('click', function(event) {
modal.css('display', 'none');
})
// When the user clicks anywhere outside of the modal, close it
$(window).on('click', function(event) {
if (event.target.id == modal.attr('id')) {
modal.css('display', 'none');
}
});
});
</script>
{% endblock %}