From 488496ca469d9ba09e23b689919615133382767c Mon Sep 17 00:00:00 2001 From: Jon Scheiding Date: Fri, 2 Dec 2022 11:26:09 -0500 Subject: [PATCH] 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 Tested-by: Service Cloud Jenkins QA-Review: Jon Scheiding Product-Review: Jon Scheiding --- .../enhance-user-content/instructure_helper.js | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/packages/canvas-rce/src/enhance-user-content/instructure_helper.js b/packages/canvas-rce/src/enhance-user-content/instructure_helper.js index b4f70d7f317..eb9e0499ba3 100644 --- a/packages/canvas-rce/src/enhance-user-content/instructure_helper.js +++ b/packages/canvas-rce/src/enhance-user-content/instructure_helper.js @@ -76,7 +76,7 @@ export function showFilePreview(event, opts = {}) { ) { showFilePreviewInOverlay(event, canvasOrigin) } 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 any modifier keys are pressed, do the browser default thing return @@ -139,17 +139,23 @@ export function showFilePreviewInline(event, disableGooglePreviews) { .then(data => { const attachment = data && data.attachment removeLoadingImage($link) + + let canvadoc_session_url = attachment.canvadoc_session_url + if ( attachment && - ((!disableGooglePreviews && isPreviewable(attachment.content_type)) || - attachment.canvadoc_session_url) + ((!disableGooglePreviews && isPreviewable(attachment.content_type)) || canvadoc_session_url) ) { $link.setAttribute('aria-expanded', 'true') + if (canvasOrigin) { + canvadoc_session_url = canvasOrigin + canvadoc_session_url + } + const $div = document.querySelector(`[id="${$link.getAttribute('aria-controls')}"]`) $div.style.display = 'block' loadDocPreview($div, { - canvadoc_session_url: attachment.canvadoc_session_url, + canvadoc_session_url, mimeType: attachment.content_type, public_url: attachment.public_url, attachment_preview_processing: