Skip to content

Commit ea59c76

Browse files
jukentandersy005
andauthored
Gallery modals (#81)
* first pass at modals * add javascript for modal * fix modal close * adjust modal-content margin * back to original css * change z-index * academind method * change js to absolute path * dev sesh 6/23 * add content to modal * height auto * important * add link * add image and fix top * make email and affiliation urls links * remove mailto: email lilnk * bold title in modal * change modal button text * Update content/_static/custom.js Co-authored-by: Anderson Banihirwe <axbanihirwe@ualr.edu> Co-authored-by: Anderson Banihirwe <axbanihirwe@ualr.edu>
1 parent ac63b30 commit ea59c76

File tree

4 files changed

+104
-6
lines changed

4 files changed

+104
-6
lines changed

content/_ext/yaml_gallery_generator.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ def build_from_items(items, filename, display_name, menu_html):
100100
affiliation_url_str = (
101101
''
102102
if affiliation_url is None
103-
else f'{affiliation} Site: {affiliation_url}'
103+
else f'{affiliation} Site: <{affiliation_url}>'
104104
)
105105

106106
panels_body.append(
@@ -110,17 +110,23 @@ def build_from_items(items, filename, display_name, menu_html):
110110
+++
111111
**{item["title"]}**
112112
113+
<button class="modal-btn">See Details</button>
114+
<div class="modal">
115+
<div class="content">
116+
<p>
117+
<img src={thumbnail} />
118+
119+
**{item["title"]}**
120+
113121
{authors_str}
114122
115123
{email_str}
116124
117125
{affiliation_str}
118126
119127
{affiliation_url_str}
120-
121-
```{{dropdown}} {item['description'][0:100]} ... <br> **See Full Description:**
128+
122129
{item['description']}
123-
```
124130
125131
```{{link-button}} {item["url"]}
126132
:type: url
@@ -129,8 +135,13 @@ def build_from_items(items, filename, display_name, menu_html):
129135
```
130136
131137
{tags}
132-
"""
133-
)
138+
</p>
139+
</div>
140+
</div>
141+
142+
{tags}
143+
""")
144+
134145
panels_body = '\n'.join(panels_body)
135146

136147
panels = f"""
@@ -143,8 +154,11 @@ def build_from_items(items, filename, display_name, menu_html):
143154
:card: +my-2
144155
:img-top-cls: w-75 m-auto p-2
145156
:body: d-none
157+
146158
{dedent(panels_body)}
147159
````
160+
<div class="backdrop"></div>
161+
<script src="/_static/custom.js"> </script>
148162
"""
149163

150164
pathlib.Path(f'pages/{filename}.md').write_text(panels)

content/_static/custom.css

+52
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
2+
/*modal*/
3+
.backdrop {
4+
display: none;
5+
position: fixed;
6+
background: rgba(0, 0, 0, 0.5);
7+
top: 0;
8+
height: 100vh;
9+
width: 100vw;
10+
z-index: 10000;
11+
}
12+
13+
.modal {
14+
display: none;
15+
position: fixed;
16+
background: white;
17+
padding: 10px;
18+
width: 260px;
19+
height: auto !important;
20+
top: 100px;
21+
left: calc(50% - 140px);
22+
z-index: 10001;
23+
}
24+
25+
.modal h1 {
26+
margin: 0;
27+
}
28+
29+
.modal button {
30+
background: #fa923f;
31+
color: white;
32+
border: 1px solid #521751;
33+
font: inherit;
34+
font-size: 12px;
35+
cursor: pointer;
36+
}
37+
38+
.modal button:hover,
39+
.modal button:active {
40+
background: #521751;
41+
}
42+
43+
.modal button:focus {
44+
outline: none;
45+
}
46+
47+
@media (min-width: 400px) {
48+
.modal {
49+
width: 360px;
50+
left: calc(50% - 190px);
51+
}
52+
}

content/_static/custom.js

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
var buttons = document.querySelectorAll('.modal-btn');
2+
var backdrop = document.querySelector('.backdrop');
3+
var modals = document.querySelectorAll('.modal');
4+
5+
function openModal(i) {
6+
backdrop.style.display = 'block';
7+
modals[i].style.display = 'block';
8+
}
9+
10+
function closeModal (i) {
11+
backdrop.style.display = 'none';
12+
modals[i].style.display = 'none';
13+
}
14+
15+
for (i = 0; i < buttons.length; i++) {
16+
buttons[i].addEventListener('click',
17+
function(j) {
18+
return function() {
19+
openModal(j);
20+
}
21+
} (i)
22+
);
23+
backdrop.addEventListener('click',
24+
function(j) {
25+
return function() {
26+
closeModal(j);
27+
}
28+
} (i)
29+
);
30+
}

content/conf.py

+2
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
# relative to this directory. They are copied after the builtin static files,
4343
# so a file named "default.css" will overwrite the builtin "default.css".
4444
html_static_path = ['_static']
45+
html_css_files = ["custom.css"]
46+
html_js_files = ["custom.js"]
4547
html_logo = '_static/images/ProjectPythia_Logo_Final-01-Blue.svg'
4648
html_title = ''
4749
# html_logo = '_static/images/ProjectPythia_Logo_Final-01-Blue-NoText.svg'

0 commit comments

Comments
 (0)