Skip to content

Commit 1d3fe82

Browse files
removal of navbar for Venueless iframe (#104)
* script working in default.html when placed directly but not getting called properly from script file * Move iframe_compat.js to the assets/js folder. * Swap published with eleventyExcludeFromCollections E11venty doesn't have a published flag. --------- Co-authored-by: Tim Schilling <[email protected]>
1 parent dfb53ee commit 1d3fe82

File tree

3 files changed

+68
-0
lines changed

3 files changed

+68
-0
lines changed

src/_layouts/default.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,6 @@
110110
{%- include 'svg-social-icons.html' -%}
111111

112112
<script src="/assets/js/main.js"></script>
113+
<script src="/assets/js/iframe_compat.js"></script>
113114
</body>
114115
</html>

src/assets/js/iframe_compat.js

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
console.log("Navbar removal script starting");
2+
(function() {
3+
function isInIframe() {
4+
try {
5+
return window.self !== window.top;
6+
} catch (e) {
7+
return true;
8+
}
9+
}
10+
11+
function removeNavbar() {
12+
if (!isInIframe()) {
13+
console.log('Page is not in an iframe, keeping navbar');
14+
return;
15+
}
16+
17+
console.log('Page is in an iframe, attempting to remove navbar');
18+
var navbar = document.querySelector('nav');
19+
if (navbar) {
20+
console.log('Navbar found, removing');
21+
navbar.remove();
22+
} else {
23+
console.log('Navbar not found');
24+
}
25+
}
26+
27+
if (document.readyState === 'loading') {
28+
document.addEventListener('DOMContentLoaded', removeNavbar);
29+
} else {
30+
removeNavbar();
31+
}
32+
})();
33+
console.log("Navbar removal script ended");

src/iframe.html

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
---
2+
layout: null
3+
permalink: /iframe/
4+
eleventyExcludeFromCollections: true
5+
sitemap: false
6+
---
7+
8+
<!doctype html>
9+
<html class="no-js" lang="en">
10+
<head>
11+
<meta charset="utf-8">
12+
<meta http-equiv="x-ua-compatible" content="ie=edge">
13+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
14+
<style>
15+
iframe {
16+
width: 100%;
17+
height: 100vh;
18+
}
19+
</style>
20+
</head>
21+
<body>
22+
<p>This is a testing harness. Browse to
23+
<code>
24+
<a href="/iframe/?page=/conduct/">/iframe/?page=/conduct/</a>
25+
</code>
26+
to test the conduct page in an iframe.
27+
</p>
28+
<iframe id="iframe-test" src=""></iframe>
29+
</body>
30+
<script>
31+
const iframe = document.getElementById('iframe-test')
32+
iframe.src = 'http://localhost:8080'+(new URLSearchParams(window.location.search)).get('page')
33+
</script>
34+
</html>

0 commit comments

Comments
 (0)