Skip to content

Commit 3e6ea37

Browse files
feat: render the maximum iframe height accordingly (#1888)
1 parent 2acde00 commit 3e6ea37

File tree

4 files changed

+85
-57
lines changed

4 files changed

+85
-57
lines changed

assets/js/autocomplete/autocomplete-list.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,18 @@ export function moveAutocompleteSelection (offset) {
8383
setAutocompleteSelection(newAutocompleteIndex(offset))
8484
}
8585

86+
function handlePreviewMessage (event) {
87+
if (event.origin !== 'null' && event.origin !== window.location.origin) return
88+
89+
if (event.data.type === 'preview') {
90+
const { maxHeight, contentHeight } = event.data
91+
const previewContainer = qs('.autocomplete-preview')
92+
if (previewContainer) {
93+
previewContainer.style.height = `${Math.min(maxHeight, contentHeight + 32)}px`
94+
}
95+
}
96+
}
97+
8698
export function setAutocompleteSelection (index) {
8799
state.selectedIdx = index
88100
const suggestionList = qs(AUTOCOMPLETE_SUGGESTION_LIST_SELECTOR)
@@ -150,12 +162,16 @@ export function showPreview (elementToSelect) {
150162

151163
if (elementToSelect) {
152164
setAutocompleteSelection(parseInt(elementToSelect.dataset.index))
165+
window.addEventListener('message', handlePreviewMessage)
153166
}
154167
}
155168

156169
function removePreview () {
157170
const preview = qs('.autocomplete-preview')
158-
if (preview) { preview.remove() }
171+
if (preview) {
172+
preview.remove()
173+
window.removeEventListener('message', handlePreviewMessage)
174+
}
159175
}
160176

161177
function newAutocompleteIndex (offset) {

assets/js/preview.js

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,18 @@ function preview (previewing) {
1212
replaceContents(previewing)
1313
makeLinksOpenInParent()
1414
scrollToTop()
15+
sendPreviewInfoToParent()
16+
}
17+
18+
function sendPreviewInfoToParent () {
19+
const maxHeight = document.body.scrollHeight
20+
const contentHeight = document.getElementById('content').scrollHeight
21+
const message = {
22+
type: 'preview',
23+
maxHeight,
24+
contentHeight
25+
}
26+
window.parent.postMessage(message, '*')
1527
}
1628

1729
function makeLinksOpenInParent () {

formatters/html/dist/html-EN2IJ2EZ.js

Lines changed: 56 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

formatters/html/dist/html-Y7ASKYHF.js

Lines changed: 0 additions & 56 deletions
This file was deleted.

0 commit comments

Comments
 (0)