|
118 | 118 | })(); |
119 | 119 | </script> |
120 | 120 | <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) { |
137 | 122 | const popupWidth = 1; |
138 | 123 | const popupHeight = 1; |
139 | | - const left = screenWidth - popupWidth - 50; // 50px margin from edge |
140 | | - const top = screenHeight - popupHeight - 100; // 100px margin from edge |
141 | 124 |
|
142 | 125 | // Open the butterfly popup window |
143 | 126 | const butterflyWindow = window.open( |
|
154 | 137 |
|
155 | 138 | // Open butterfly window when the page loads |
156 | 139 | 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 | + |
157 | 150 | // 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; |
164 | 153 | } |
| 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); |
165 | 163 | }); |
166 | 164 |
|
| 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 | + } |
167 | 182 | </script> |
168 | 183 | <meta name="author" content="Max Bo, max@maxbo.me"> |
169 | 184 | <meta name="viewport" content="width=device-width, initial-scale=1"> |
@@ -889,7 +904,8 @@ <h1>Max Bo</h1> |
889 | 904 | |
890 | 905 |
|
891 | 906 | <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);" /> |
893 | 909 | </marquee> |
894 | 910 | <script type="module"> |
895 | 911 | renderAtom('atom.xml', 'ticker2'); |
@@ -1147,7 +1163,9 @@ <h2> |
1147 | 1163 | <article class="art bottom-align" style="position: relative;"> |
1148 | 1164 | <div style="position: relative; display: inline-block;"> |
1149 | 1165 | <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);" /> |
1151 | 1169 | </div> |
1152 | 1170 | </article> |
1153 | 1171 | <article class="listing" id="html-in-hyde"> |
@@ -2120,7 +2138,8 @@ <h2> |
2120 | 2138 | Sans</a>, |
2121 | 2139 | <a href="https://www.redaction.us/" style="font-family: 'Redaction 35', serif;">Redaction 35</a>, |
2122 | 2140 | <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>, |
2124 | 2143 | & a corrupted form of <a href="http://hershey-noailles.luuse.io/www/#Hershey-Noailles-Times-Triplex-Light" |
2125 | 2144 | style="font-family: 'hersheytimes', serif; font-size: 0.5em;"> |
2126 | 2145 | Hershey Times Triplex Light |
@@ -2182,7 +2201,8 @@ <h2> |
2182 | 2201 | </div> |
2183 | 2202 |
|
2184 | 2203 | <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);" /> |
2186 | 2206 | </marquee> |
2187 | 2207 | <script type="module"> |
2188 | 2208 | renderAtom('atom.xml', 'ticker'); |
|
0 commit comments