Skip to content

feat: render the maximum iframe height accordingly #1888

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
merged 1 commit into from
Apr 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion assets/js/autocomplete/autocomplete-list.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,18 @@ export function moveAutocompleteSelection (offset) {
setAutocompleteSelection(newAutocompleteIndex(offset))
}

function handlePreviewMessage (event) {
if (event.origin !== 'null' && event.origin !== window.location.origin) return

if (event.data.type === 'preview') {
const { maxHeight, contentHeight } = event.data
const previewContainer = qs('.autocomplete-preview')
if (previewContainer) {
previewContainer.style.height = `${Math.min(maxHeight, contentHeight + 32)}px`
}
}
}

export function setAutocompleteSelection (index) {
state.selectedIdx = index
const suggestionList = qs(AUTOCOMPLETE_SUGGESTION_LIST_SELECTOR)
Expand Down Expand Up @@ -150,12 +162,16 @@ export function showPreview (elementToSelect) {

if (elementToSelect) {
setAutocompleteSelection(parseInt(elementToSelect.dataset.index))
window.addEventListener('message', handlePreviewMessage)
}
}

function removePreview () {
const preview = qs('.autocomplete-preview')
if (preview) { preview.remove() }
if (preview) {
preview.remove()
window.removeEventListener('message', handlePreviewMessage)
}
}

function newAutocompleteIndex (offset) {
Expand Down
12 changes: 12 additions & 0 deletions assets/js/preview.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,18 @@ function preview (previewing) {
replaceContents(previewing)
makeLinksOpenInParent()
scrollToTop()
sendPreviewInfoToParent()
}

function sendPreviewInfoToParent () {
const maxHeight = document.body.scrollHeight
const contentHeight = document.getElementById('content').scrollHeight
const message = {
type: 'preview',
maxHeight,
contentHeight
}
window.parent.postMessage(message, '*')
}

function makeLinksOpenInParent () {
Expand Down
56 changes: 56 additions & 0 deletions formatters/html/dist/html-EN2IJ2EZ.js

Large diffs are not rendered by default.

56 changes: 0 additions & 56 deletions formatters/html/dist/html-Y7ASKYHF.js

This file was deleted.

Loading