Skip to content

Commit

Permalink
only forward resize messages in embed view (#2807)
Browse files Browse the repository at this point in the history
  • Loading branch information
emmachughes authored Nov 27, 2024
1 parent 29ab0d0 commit fb03924
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 21 deletions.
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>

0 comments on commit fb03924

Please sign in to comment.