|
298 | 298 | targetElement = targetElement.parentElement; |
299 | 299 | } |
300 | 300 |
|
301 | | - if (targetElement && targetElement.tagName === 'A' && (targetElement.target === '_blank')) { |
| 301 | + if (window.__PHOENIX_EMBED_INFO && window.__PHOENIX_EMBED_INFO.isTauri && |
| 302 | + targetElement && targetElement.tagName === 'A' && (targetElement.target === '_blank')) { |
| 303 | + // in desktop phoenix builds, tauri will not open anchor tags in browser if it is in |
| 304 | + // an iframe(except for the intel mac bug) |
| 305 | + // in normal browsers, we dont need to do this and the borwser will do its thing. |
302 | 306 | const href = getAbsoluteUrl(targetElement.getAttribute('href')); |
303 | 307 | window.parent.postMessage({ |
304 | 308 | handlerName: "ph-liveServer", |
305 | 309 | eventName: 'embeddedIframeHrefClick', |
306 | 310 | href: href |
307 | 311 | }, "*"); |
| 312 | + event.preventDefault(); // in intel mac desktop, tauri seems to open in browser |
| 313 | + // causing 2 tabs to open. in m1 macs its not there. so we prevent default behavior. |
308 | 314 | } |
309 | 315 | }); |
310 | 316 | document.addEventListener('contextmenu', function(event) { |
311 | 317 | (document.activeElement || document.body).focus(); |
312 | 318 | }); |
313 | 319 | document.addEventListener('keydown', function(event) { |
314 | | - if (event.key === 'Escape' || event.key === 'Esc') { // Check for Escape key |
315 | | - // Perform the desired action for the Escape key |
| 320 | + if (window.__PHOENIX_EMBED_INFO && |
| 321 | + (event.key === 'Escape' || event.key === 'Esc')) { // Check for Escape key |
| 322 | + // Perform the desired action for the Escape key only if its within iframe inside phoenix |
316 | 323 | window.parent.postMessage({ |
317 | 324 | handlerName: "ph-liveServer", |
318 | 325 | eventName: 'embeddedEscapeKeyPressed' |
319 | 326 | }, "*"); |
320 | 327 | } |
321 | 328 | }); |
| 329 | + |
| 330 | + // this is for managing who am i context in iframes embedded in phoenix to have special handling. |
| 331 | + window.addEventListener('message', function(event) { |
| 332 | + if (!TRANSPORT_CONFIG.TRUSTED_ORIGINS_EMBED[event.origin]) { |
| 333 | + return; // Ignore messages from unexpected origins |
| 334 | + } |
| 335 | + |
| 336 | + window.__PHOENIX_EMBED_INFO = { |
| 337 | + isTauri: event.data.isTauri |
| 338 | + }; |
| 339 | + }); |
| 340 | + if(window.self !== window.parent){ |
| 341 | + // in an iframe |
| 342 | + window.parent.postMessage({ |
| 343 | + handlerName: "ph-liveServer", |
| 344 | + eventName: 'whoAmIframePhoenix', |
| 345 | + href: location.href |
| 346 | + }, "*"); |
| 347 | + } |
322 | 348 | }(this)); |
0 commit comments