]> iEval git - gruntmaster-page.git/blame - js/10-modal.js
Make JS a bit simpler
[gruntmaster-page.git] / js / 10-modal.js
CommitLineData
03720101 1let modal, backdrop, hiding;
0f578ab0 2
7093e9ba
MG
3function show_modal () {
4 modal.classList.remove('hidden');
03720101 5 backdrop.classList.remove('hidden');
7093e9ba
MG
6 setTimeout(function (){
7 document.body.classList.add('modal-open');
8 }, 20);
9}
0f578ab0 10
7093e9ba
MG
11function hide_modal () {
12 document.body.classList.remove('modal-open');
13}
0f578ab0 14
7093e9ba 15$(function() {
dee46c5b
MG
16 modal = q('.modal');
17 backdrop = q('.backdrop');
8345760a 18 $(modal).on('transitionend', el => {
7093e9ba
MG
19 if(!document.body.classList.contains('modal-open'))
20 modal.classList.add('hidden');
21 });
8345760a
MG
22 $('.backdrop,.modal').each(el => document.body.appendChild(el) );
23 $('#solution').on('click', e => {
74b0b0ab
MG
24 if(window.matchMedia("(min-width: 768px)").matches){
25 show_modal();
26 e.preventDefault();
27 }
7093e9ba
MG
28 });
29 $('.backdrop').on('click', hide_modal);
8345760a 30 window.onkeyup = event => {
7093e9ba
MG
31 if (event.keyCode === 27)
32 hide_modal();
33 }
34});
This page took 0.028074 seconds and 4 git commands to generate.