Add fallback for mount failure

pull/332/head
zanllp 2023-07-22 20:16:41 +08:00
parent 1520013d7b
commit 6d18c04d4c
2 changed files with 40 additions and 22 deletions

View File

@ -70,19 +70,28 @@ Promise.resolve().then(async () => {
onUiTabChange(() => {
const el = get_uiCurrentTabContent()
if (el?.id.includes('infinite-image-browsing')) {
const topRect = gradioApp().querySelector('#iib_top').getBoundingClientRect()
wrap.style = `
top:${Math.max(48, topRect.top) - 10}px;
position: fixed;
left: 10px;
right: 10px;
z-index: 100;
width: unset;
bottom: 10px;`
try {
const iibTop = gradioApp().querySelector('#iib_top')
if (!iibTop) {
throw new Error("element '#iib_top' is not found")
}
const topRect = iibTop.getBoundingClientRect()
wrap.style = `
top:${Math.max(48, topRect.top) - 10}px;
position: fixed;
left: 10px;
right: 10px;
z-index: 100;
width: unset;
bottom: 10px;`
iframe.style = `width: 100%;height:100%`
} catch (error) {
console.error('Error mounting IIB. Running fallback.', error);
wrap.style = ''
iframe.style = `width: 100%;height:100vh`
}
}
})
iframe.style = `width: 100%;height:100%`
}
const imgTransferBus = new BroadcastChannel('iib-image-transfer-bus')

View File

@ -50,19 +50,28 @@ Promise.resolve().then(async () => {
onUiTabChange(() => {
const el = get_uiCurrentTabContent()
if (el?.id.includes('infinite-image-browsing')) {
const topRect = gradioApp().querySelector('#iib_top').getBoundingClientRect()
wrap.style = `
top:${Math.max(48, topRect.top) - 10}px;
position: fixed;
left: 10px;
right: 10px;
z-index: 100;
width: unset;
bottom: 10px;`
try {
const iibTop = gradioApp().querySelector('#iib_top')
if (!iibTop) {
throw new Error("element '#iib_top' is not found")
}
const topRect = iibTop.getBoundingClientRect()
wrap.style = `
top:${Math.max(48, topRect.top) - 10}px;
position: fixed;
left: 10px;
right: 10px;
z-index: 100;
width: unset;
bottom: 10px;`
iframe.style = `width: 100%;height:100%`
} catch (error) {
console.error('Error mounting IIB. Running fallback.', error);
wrap.style = ''
iframe.style = `width: 100%;height:100vh`
}
}
})
iframe.style = `width: 100%;height:100%`
}
const imgTransferBus = new BroadcastChannel('iib-image-transfer-bus')