Skip to content
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

only forward resize messages in embed view #2807

Merged
merged 1 commit into from
Nov 27, 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
13 changes: 13 additions & 0 deletions sourcecode/hub/app/View/Components/LtiLaunch.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
use Illuminate\Contracts\Encryption\Encrypter;
use Illuminate\Contracts\View\View;
use Illuminate\Support\Facades\URL;
use Illuminate\Support\Str;
use Illuminate\View\Component;

use function view;
Expand All @@ -15,19 +16,31 @@ class LtiLaunch extends Component
{
public readonly string $url;

public readonly string $uniqueId;

/**
* @param string $logTo
* A selector for an element in which to log messages sent by the
* iframe.
* @param array<string, string> $parameters
*/
public function __construct(
private Encrypter $encrypter,
public \App\Lti\LtiLaunch $launch,
public string $method = 'GET',
public array $parameters = [],
public string $target = '_self',
public int $width = 640,
public int $height = 480,
public string $logTo = '',
public bool $forwardsResizeMessages = false,
public bool $direct = false,
) {
$this->url = URL::signedRoute('lti.launch', [
'launch' => $this->encrypter->encrypt($launch),
]);

$this->uniqueId = Str::uuid()->toString();
}

public function render(): View
Expand Down
5 changes: 3 additions & 2 deletions sourcecode/hub/resources/js/resize.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,9 @@ addEventListener('message', (event) => {
const border = iframe.getBoundingClientRect().height - iframe.scrollHeight;
iframe.height = String(event.data.scrollHeight + border);

if (window.parent) {
// forward to parent iframe
if (window.parent && iframe.closest('.forwards-resize-messages')) {
console.debug('Forwarding the resize request');

parent.postMessage({
action: 'resize',
scrollHeight: event.data.scrollHeight,
Expand Down
23 changes: 5 additions & 18 deletions sourcecode/hub/resources/views/components/launch.blade.php
Original file line number Diff line number Diff line change
@@ -1,25 +1,12 @@
@php use Illuminate\Support\Str; @endphp

@props([
'url' => 'about:blank',
'method' => 'GET',
'parameters' => [],
'target' => '_self',
'direct' => false,
'width' => 640,
'height' => 480,
'logTo' => '',
'uniqueId' => (string) Str::uuid(),
])

<iframe {{ $attributes->except('direct')->merge([
<iframe {{ $attributes->except(['direct', 'forwards-resize-messages'])->merge([
'src' => $direct ? 'about:blank' : $url,
'name' => 'launch-frame-' . $uniqueId,
'width' => $width,
'height' => $height,
'class' => 'lti-launch d-block',
'data-log-to' => $logTo,
'frameborder' => '0',
])->class([
'lti-launch',
'd-block',
'forwards-resize-messages' => $forwardsResizeMessages,
]) }}></iframe>

@if ($direct)
Expand Down
2 changes: 1 addition & 1 deletion sourcecode/hub/resources/views/content/embed.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,5 @@
<x-layout no-nav no-header no-footer expand>
<x-slot:title>{{ $version->title }}</x-slot:title>

<x-lti-launch :launch="$launch" class="w-100 h-100" />
<x-lti-launch :launch="$launch" class="w-100 h-100" forwards-resize-messages />
</x-layout>