-
-
Notifications
You must be signed in to change notification settings - Fork 6.2k
Make external iframe render work #35730
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
+294
−92
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
f90d3ba
fix external render iframe
wxiaoguang 7ac96f3
fix test, fix open link (force push to make backport easier)
wxiaoguang 72b3eeb
Merge branch 'main' into fix-render-iframe
wxiaoguang 9c74528
fix sandbox (force push to update doc and fix test)
wxiaoguang ea28b33
fine tune
wxiaoguang 9e94317
new URL
wxiaoguang File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| /* dummy */ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import {generateElemId, queryElemChildren} from '../utils/dom.ts'; | ||
| import {isDarkTheme} from '../utils.ts'; | ||
|
|
||
| export async function loadRenderIframeContent(iframe: HTMLIFrameElement) { | ||
| const iframeSrcUrl = iframe.getAttribute('data-src'); | ||
| if (!iframe.id) iframe.id = generateElemId('gitea-iframe-'); | ||
|
|
||
| window.addEventListener('message', (e) => { | ||
| if (e.data && e.data.giteaIframeCmd === 'resize' && e.data.giteaIframeId === iframe.id) { | ||
| iframe.style.height = `${e.data.giteaIframeHeight}px`; | ||
| } | ||
| }); | ||
|
|
||
| let urlParams = ''; | ||
| urlParams += `&gitea-is-dark-theme=${isDarkTheme()}`; | ||
| urlParams += `&gitea-iframe-id=${iframe.id}`; | ||
| iframe.src = iframeSrcUrl + (iframeSrcUrl.includes('?') ? '&' : '?') + urlParams.substring(1); | ||
silverwind marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| } | ||
wxiaoguang marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
|
||
| export function initMarkupRenderIframe(el: HTMLElement) { | ||
| queryElemChildren(el, 'iframe.external-render-iframe', loadRenderIframeContent); | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,32 @@ | ||
| /* To manually test: | ||
|
|
||
| [markup.in-iframe] | ||
| ENABLED = true | ||
| FILE_EXTENSIONS = .in-iframe | ||
| RENDER_CONTENT_MODE = iframe | ||
| RENDER_COMMAND = `echo '<div style="width: 100%; height: 2000px; border: 10px solid red; box-sizing: border-box;">content</div>'` | ||
|
|
||
| */ | ||
|
|
||
| function mainExternalRenderIframe() { | ||
| const u = new URL(window.location.href); | ||
| const fn = () => window.parent.postMessage({ | ||
| giteaIframeCmd: 'resize', | ||
| giteaIframeId: u.searchParams.get('gitea-iframe-id'), | ||
| giteaIframeHeight: document.documentElement.scrollHeight, | ||
| }, '*'); | ||
| fn(); | ||
| window.addEventListener('DOMContentLoaded', fn); | ||
| setInterval(fn, 1000); | ||
|
|
||
| // make all absolute links open in new window (otherwise they would be blocked by all parents' frame-src) | ||
| document.body.addEventListener('click', (e) => { | ||
| const el = e.target as HTMLAnchorElement; | ||
| if (el.nodeName !== 'A') return; | ||
| const href = el.getAttribute('href'); | ||
| if (!href.startsWith('//') && !href.includes('://')) return; | ||
| el.target = '_blank'; | ||
| }, true); | ||
| } | ||
|
|
||
| mainExternalRenderIframe(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.