Skip to content

Commit 4b3b994

Browse files
committed
wip
1 parent f6d5bc2 commit 4b3b994

File tree

2 files changed

+18977
-3
lines changed

2 files changed

+18977
-3
lines changed

_layouts/post.html

Lines changed: 103 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,55 @@
1414
{% include seo_head.html %}
1515
<!-- MathJax Configuration (loaded early) -->
1616
{% if page.mathjax or site.mathjax %}
17+
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/svg-pan-zoom.min.js"></script>
18+
<style>
19+
.mermaid-modal {
20+
display: none;
21+
position: fixed;
22+
z-index: 10000;
23+
left: 0;
24+
top: 0;
25+
width: 100%;
26+
height: 100%;
27+
overflow: hidden;
28+
background-color: rgba(0,0,0,0.9);
29+
}
30+
.mermaid-modal-content {
31+
margin: auto;
32+
display: block;
33+
width: 95%;
34+
height: 95%;
35+
position: relative;
36+
top: 2.5%;
37+
background: white;
38+
border-radius: 4px;
39+
overflow: hidden;
40+
}
41+
.mermaid-modal-close {
42+
position: absolute;
43+
top: 10px;
44+
right: 25px;
45+
color: #f1f1f1;
46+
font-size: 35px;
47+
font-weight: bold;
48+
transition: 0.3s;
49+
z-index: 10001;
50+
cursor: pointer;
51+
}
52+
.mermaid-modal-close:hover,
53+
.mermaid-modal-close:focus {
54+
color: #bbb;
55+
text-decoration: none;
56+
cursor: pointer;
57+
}
58+
.mermaid svg {
59+
cursor: pointer;
60+
}
61+
</style>
62+
<div id="mermaid-modal" class="mermaid-modal">
63+
<span class="mermaid-modal-close">&times;</span>
64+
<div id="mermaid-modal-content" class="mermaid-modal-content"></div>
65+
</div>
1766
<script>
1867
window.MathJax = {
1968
tex: {
@@ -198,8 +247,8 @@ <h3>Related Posts</h3>
198247
</script>
199248

200249
<!-- Mermaid.js integration -->
201-
{% if page.mermaid or site.mermaid %}
202-
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
250+
{% if page.mermaid or site.mermaid %}
251+
<script src="https://cdn.jsdelivr.net/npm/mermaid@10/dist/mermaid.min.js"></script>
203252
<script>
204253
document.addEventListener('DOMContentLoaded', function() {
205254
mermaid.initialize({
@@ -226,7 +275,58 @@ <h3>Related Posts</h3>
226275
}
227276
});
228277
// Manually run Mermaid after transformations
229-
mermaid.run();
278+
mermaid.run().catch(err => console.error(err)).then(() => {
279+
const modal = document.getElementById('mermaid-modal');
280+
const modalContent = document.getElementById('mermaid-modal-content');
281+
const closeBtn = document.querySelector('.mermaid-modal-close');
282+
let panZoomInstance;
283+
284+
const closeModal = () => {
285+
modal.style.display = 'none';
286+
if (panZoomInstance) {
287+
panZoomInstance.destroy();
288+
panZoomInstance = null;
289+
}
290+
modalContent.innerHTML = '';
291+
};
292+
293+
closeBtn.onclick = closeModal;
294+
295+
window.onclick = function(event) {
296+
if (event.target == modal) {
297+
closeModal();
298+
}
299+
};
300+
301+
document.addEventListener('keydown', function(event) {
302+
if (event.key === "Escape" && modal.style.display === 'block') {
303+
closeModal();
304+
}
305+
});
306+
307+
document.querySelectorAll('.mermaid').forEach(div => {
308+
const svg = div.querySelector('svg');
309+
if (svg) {
310+
div.addEventListener('click', function() {
311+
modal.style.display = 'block';
312+
const clonedSvg = svg.cloneNode(true);
313+
clonedSvg.style.maxWidth = 'none';
314+
clonedSvg.style.maxHeight = 'none';
315+
clonedSvg.style.width = '100%';
316+
clonedSvg.style.height = '100%';
317+
modalContent.appendChild(clonedSvg);
318+
panZoomInstance = svgPanZoom(clonedSvg, {
319+
zoomEnabled: true,
320+
controlIconsEnabled: true,
321+
fit: true,
322+
center: true,
323+
minZoom: 0.1,
324+
maxZoom: 10
325+
});
326+
});
327+
}
328+
});
329+
});
230330
});
231331
</script>
232332
{% endif %}

0 commit comments

Comments
 (0)