Skip to content

Commit 05aaeae

Browse files
committed
onclick
1 parent 362db24 commit 05aaeae

File tree

1 file changed

+48
-28
lines changed

1 file changed

+48
-28
lines changed

index.html

Lines changed: 48 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -118,26 +118,9 @@
118118
})();
119119
</script>
120120
<script>
121-
function openButterflyWindow() {
122-
// Don't open butterfly popup on mobile devices (same breakpoint as CSS)
123-
if (window.innerWidth < 640) {
124-
return;
125-
}
126-
127-
// Don't open when page is loaded from the local filesystem (file:///...)
128-
if (window.location.protocol === 'file:') {
129-
return;
130-
}
131-
132-
// Get the current window dimensions
133-
const screenWidth = window.screen.width;
134-
const screenHeight = window.screen.height;
135-
136-
// Position the popup in the bottom right corner
121+
function openButterflyWindow(left, top) {
137122
const popupWidth = 1;
138123
const popupHeight = 1;
139-
const left = screenWidth - popupWidth - 50; // 50px margin from edge
140-
const top = screenHeight - popupHeight - 100; // 100px margin from edge
141124

142125
// Open the butterfly popup window
143126
const butterflyWindow = window.open(
@@ -154,16 +137,48 @@
154137

155138
// Open butterfly window when the page loads
156139
window.addEventListener('load', () => {
140+
// Don't open butterfly popup on mobile devices (same breakpoint as CSS)
141+
if (window.innerWidth < 640) {
142+
return;
143+
}
144+
145+
// Don't open when page is loaded from the local filesystem (file:///...)
146+
if (window.location.protocol === 'file:') {
147+
return;
148+
}
149+
157150
// Check if butterfly has already been shown this session
158-
if (!localStorage.getItem('butterflyShown')) {
159-
// Small delay to ensure page is fully loaded
160-
setTimeout(() => {
161-
openButterflyWindow();
162-
localStorage.setItem('butterflyShown', 'true');
163-
}, 500);
151+
if (localStorage.getItem('butterflyShown')) {
152+
return;
164153
}
154+
155+
// Small delay to ensure page is fully loaded
156+
setTimeout(() => {
157+
// Default to bottom right corner
158+
const left = window.screen.width - 1 - 50;
159+
const top = window.screen.height - 1 - 100;
160+
openButterflyWindow(left, top);
161+
localStorage.setItem('butterflyShown', 'true');
162+
}, 500);
165163
});
166164

165+
function onButterflyClick(event) {
166+
// Get the clicked element
167+
const butterfly = event.currentTarget;
168+
169+
// Get the position of the butterfly relative to the viewport
170+
const rect = butterfly.getBoundingClientRect();
171+
172+
// Calculate screen coordinates (viewport position + window position)
173+
const screenX = window.screenX + rect.left;
174+
const screenY = window.screenY + rect.top;
175+
176+
// Remove the butterfly from the DOM
177+
butterfly.remove();
178+
179+
// Open the butterfly window at the clicked position
180+
openButterflyWindow(screenX, screenY);
181+
}
167182
</script>
168183
<meta name="author" content="Max Bo, max@maxbo.me">
169184
<meta name="viewport" content="width=device-width, initial-scale=1">
@@ -889,7 +904,8 @@ <h1>Max Bo</h1>
889904
󱠡
890905

891906
<marquee id="ticker2" class="dindong" scrollamount="7" style="flex: 1">
892-
<img src="img/butterfly.gif" style="width: 16px; display: inline-block; cursor: pointer;" onclick="localStorage.removeItem('butterflyShown'); openButterflyWindow();" />
907+
<img src="img/butterfly.gif" style="width: 16px; display: inline-block; cursor: pointer;"
908+
onclick="onButterflyClick(event);" />
893909
</marquee>
894910
<script type="module">
895911
renderAtom('atom.xml', 'ticker2');
@@ -1147,7 +1163,9 @@ <h2>
11471163
<article class="art bottom-align" style="position: relative;">
11481164
<div style="position: relative; display: inline-block;">
11491165
<img src="img/plantstudio_flowers.webp" style="display: block;" />
1150-
<img src="img/butterfly/0.gif" style="position: absolute; bottom: 84%; right: 49%; width: 32px; cursor: pointer;" onclick="localStorage.removeItem('butterflyShown'); openButterflyWindow();" />
1166+
<img src="img/butterfly/0.gif"
1167+
style="position: absolute; bottom: 84%; right: 49%; width: 32px; cursor: pointer;"
1168+
onclick="onButterflyClick(event);" />
11511169
</div>
11521170
</article>
11531171
<article class="listing" id="html-in-hyde">
@@ -2120,7 +2138,8 @@ <h2>
21202138
Sans</a>,
21212139
<a href="https://www.redaction.us/" style="font-family: 'Redaction 35', serif;">Redaction 35</a>,
21222140
<a href="https://cinni.net/font" style="font-family: 'basiic', monospace;">basiic</a>,
2123-
<a href="http://hershey-noailles.luuse.io/www/#Hershey-Noailles-OldFrench-Bold" style="font-family: 'Hershey Noailles OldFrench Bold', serif;">Hershey Noailles OldFrench Bold</a>,
2141+
<a href="http://hershey-noailles.luuse.io/www/#Hershey-Noailles-OldFrench-Bold"
2142+
style="font-family: 'Hershey Noailles OldFrench Bold', serif;">Hershey Noailles OldFrench Bold</a>,
21242143
&amp; a corrupted form of <a href="http://hershey-noailles.luuse.io/www/#Hershey-Noailles-Times-Triplex-Light"
21252144
style="font-family: 'hersheytimes', serif; font-size: 0.5em;">
21262145
Hershey Times Triplex Light
@@ -2182,7 +2201,8 @@ <h2>
21822201
</div>
21832202

21842203
<marquee id="ticker" class="dindong" scrollamount="7">
2185-
<img src="img/butterfly.gif" style="width: 16px; display: inline-block; cursor: pointer;" onclick="localStorage.removeItem('butterflyShown'); openButterflyWindow();" />
2204+
<img src="img/butterfly.gif" style="width: 16px; display: inline-block; cursor: pointer;"
2205+
onclick="onButterflyClick(event);" />
21862206
</marquee>
21872207
<script type="module">
21882208
renderAtom('atom.xml', 'ticker');

0 commit comments

Comments
 (0)