|
17 | 17 | <style> |
18 | 18 | {{{GFM_CSS}}} |
19 | 19 | </style> |
| 20 | + <script> |
| 21 | + {{{TRUSTED_ORIGINS_EMBED}}} |
| 22 | + // this is for managing who am i context in iframes embedded in phoenix to have special handling. |
| 23 | + window.addEventListener('message', function(event) { |
| 24 | + if (!TRUSTED_ORIGINS_EMBED[event.origin]) { |
| 25 | + return; // Ignore messages from unexpected origins |
| 26 | + } |
| 27 | + |
| 28 | + window.__PHOENIX_EMBED_INFO = { |
| 29 | + isTauri: event.data.isTauri |
| 30 | + }; |
| 31 | + }); |
| 32 | + if(window.self !== window.parent){ |
| 33 | + // in an iframe |
| 34 | + window.parent.postMessage({ |
| 35 | + handlerName: "ph-liveServer", |
| 36 | + eventName: 'whoAmIframePhoenix', |
| 37 | + href: location.href |
| 38 | + }, "{{{PARENT_ORIGIN}}}"); |
| 39 | + } |
| 40 | + </script> |
20 | 41 | <script type="text/javascript"> |
21 | 42 | function inIframe () { |
22 | 43 | try { |
|
31 | 52 | // It will confuse the use seeing the browser save dialog inside phoenix. |
32 | 53 | document.savePageCtrlSDisabledByPhoenix = true; |
33 | 54 | document.addEventListener("keydown", function(e) { |
34 | | - if (e.key === 's' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) { |
| 55 | + if (window.__PHOENIX_EMBED_INFO && |
| 56 | + e.key === 's' && (navigator.platform.match("Mac") ? e.metaKey : e.ctrlKey)) { |
| 57 | + // we only do this in iframes embedded directly inside phoenix, in popped out iframes |
| 58 | + // we don't need to capture anything. |
35 | 59 | e.preventDefault(); |
36 | 60 | } |
37 | 61 | }, false); |
|
46 | 70 | return absoluteUrl.href; |
47 | 71 | } |
48 | 72 | document.addEventListener('click', function(event) { |
49 | | - if (event.target.tagName === 'A' && (event.target.target === '_blank')) { |
50 | | - const href = getAbsoluteUrl(event.target.getAttribute('href')); |
51 | | - window.parent.postMessage({ |
52 | | - handlerName: "ph-liveServer", |
53 | | - eventName: 'embeddedIframeHrefClick', |
54 | | - href: href |
55 | | - }, "{{{PARENT_ORIGIN}}}"); |
| 73 | + // in desktop phoenix builds, tauri will not open anchor tags in browser if it is in |
| 74 | + // an iframe(except for the intel mac bug) |
| 75 | + // in normal browsers, we dont need to do this. |
| 76 | + if (window.__PHOENIX_EMBED_INFO && window.__PHOENIX_EMBED_INFO.isTauri && |
| 77 | + event.target.tagName === 'A' && (event.target.target === '_blank')) { |
| 78 | + const href = getAbsoluteUrl(event.target.getAttribute('href')); |
| 79 | + window.parent.postMessage({ |
| 80 | + handlerName: "ph-liveServer", |
| 81 | + eventName: 'embeddedIframeHrefClick', |
| 82 | + href: href |
| 83 | + }, "{{{PARENT_ORIGIN}}}"); |
| 84 | + event.preventDefault(); // in intel mac desktop, tauri seems to open in browser |
| 85 | + // causing 2 tabs to open. in m1 macs its not there. so we prevent default behavior. |
56 | 86 | } |
57 | 87 | }); |
58 | 88 | } |
|
0 commit comments