-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfusilli.js
75 lines (71 loc) · 1.76 KB
/
fusilli.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* Fusilli.js by An - Distributed under MIT License - github.com/AnTheMaker/Fusilli.js */
const modalStyles = `
.modal{
display: none;
position: fixed;
top: 0;
left: 0;
right: 0;
bottom: 0;
background: rgba(0,0,0,.6);
justify-content: center;
align-items: center;
user-select: none;
z-index: 999;
}
.modal.open{
display: flex;
}
.modal_box{
background: white;
color: black;
margin: 7px;
padding: 18px 20px;
border-radius: 8px;
width: 450px;
min-height: 200px;
max-width: 100%;
max-height: calc(100% - 20px);
overflow: auto;
box-sizing: border-box;
z-index: 99;
user-select: auto;
pointer-events: auto;
}
.modal_close{
float: right;
margin: -6px -4px 0 10px;
background: white;
cursor: pointer;
font-size: 170%;
z-index: 999;
}
`;
window.addEventListener('load', function(){
var modalStyleSheet = document.createElement('style');
modalStyleSheet.type = 'text/css';
modalStyleSheet.innerText = modalStyles;
document.head.appendChild(modalStyleSheet);
var modals = [...document.getElementsByClassName('modal')];
modals.forEach(function(modal){
modal_box = modal.querySelector('.modal_box');
modal_box.insertAdjacentHTML('afterbegin', `<div id="close_`+modal.id+`" class="modal_close">×</div>`);
document.getElementById('close_'+modal.id).addEventListener('click', function(){
closeModal(modal);
});
modal.addEventListener('click', function(e){
closeModal(modal);
});
modal_box.addEventListener('click', function(e){
e.stopPropagation();
});
});
});
function openModal(modal){
modal.setAttribute('aria-hidden', 'false');
modal.classList.add('open');
}
function closeModal(modal){
modal.setAttribute('aria-hidden', 'true');
modal.classList.remove('open');
}