Fix inline preview to respect canvas origin

https://instructure.slack.com/archives/C02QHS4PWD8/p1669995264364199

test plan
- working nq setup
- working canvadocs setup
- create some content inside NQ that includes an inline link
- confirm that inline link renders correctly

Change-Id: I5099166065e5bc9e985b92dc1fbc9108ebe7be73
Reviewed-on: https://gerrit.instructure.com/c/canvas-lms/+/306484
Reviewed-by: Ed Schiebel <eschiebel@instructure.com>
Tested-by: Service Cloud Jenkins <svc.cloudjenkins@instructure.com>
QA-Review: Jon Scheiding <jon.scheiding@instructure.com>
Product-Review: Jon Scheiding <jon.scheiding@instructure.com>
This commit is contained in:
Jon Scheiding 2022-12-02 11:26:09 -05:00
parent 4c02449058
commit 488496ca46
1 changed files with 11 additions and 5 deletions

View File

@ -76,7 +76,7 @@ export function showFilePreview(event, opts = {}) {
) { ) {
showFilePreviewInOverlay(event, canvasOrigin) showFilePreviewInOverlay(event, canvasOrigin)
} else { } else {
showFilePreviewInline(event, disableGooglePreviews) showFilePreviewInline(event, canvasOrigin, disableGooglePreviews)
} }
} }
@ -105,7 +105,7 @@ export function showFilePreviewInOverlay(event, canvasOrigin) {
} }
} }
export function showFilePreviewInline(event, disableGooglePreviews) { export function showFilePreviewInline(event, canvasOrigin, disableGooglePreviews) {
if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) { if (event.ctrlKey || event.altKey || event.metaKey || event.shiftKey) {
// if any modifier keys are pressed, do the browser default thing // if any modifier keys are pressed, do the browser default thing
return return
@ -139,17 +139,23 @@ export function showFilePreviewInline(event, disableGooglePreviews) {
.then(data => { .then(data => {
const attachment = data && data.attachment const attachment = data && data.attachment
removeLoadingImage($link) removeLoadingImage($link)
let canvadoc_session_url = attachment.canvadoc_session_url
if ( if (
attachment && attachment &&
((!disableGooglePreviews && isPreviewable(attachment.content_type)) || ((!disableGooglePreviews && isPreviewable(attachment.content_type)) || canvadoc_session_url)
attachment.canvadoc_session_url)
) { ) {
$link.setAttribute('aria-expanded', 'true') $link.setAttribute('aria-expanded', 'true')
if (canvasOrigin) {
canvadoc_session_url = canvasOrigin + canvadoc_session_url
}
const $div = document.querySelector(`[id="${$link.getAttribute('aria-controls')}"]`) const $div = document.querySelector(`[id="${$link.getAttribute('aria-controls')}"]`)
$div.style.display = 'block' $div.style.display = 'block'
loadDocPreview($div, { loadDocPreview($div, {
canvadoc_session_url: attachment.canvadoc_session_url, canvadoc_session_url,
mimeType: attachment.content_type, mimeType: attachment.content_type,
public_url: attachment.public_url, public_url: attachment.public_url,
attachment_preview_processing: attachment_preview_processing: