MOBILE-3213 h5p: Fix resize in h5p.org packages

main
Dani Palou 2019-12-10 13:29:20 +01:00
parent 1137a1dd8f
commit 49d33fb9e4
2 changed files with 21 additions and 3 deletions

View File

@ -9,5 +9,5 @@
<core-download-refresh [status]="state" [enabled]="canDownload" [loading]="calculating" [canTrustDownload]="true" (action)="download()"></core-download-refresh> <core-download-refresh [status]="state" [enabled]="canDownload" [loading]="calculating" [canTrustDownload]="true" (action)="download()"></core-download-refresh>
</div> </div>
</div> </div>
<core-iframe *ngIf="showPackage" [src]="playerSrc" iframeHeight="auto"></core-iframe> <core-iframe *ngIf="showPackage" [src]="playerSrc" iframeHeight="auto" (loaded)="sendHello($event)"></core-iframe>
<script *ngIf="resizeScript && showPackage" type="text/javascript" [src]="resizeScript"></script> <script *ngIf="resizeScript && showPackage" type="text/javascript" [src]="resizeScript"></script>

View File

@ -106,8 +106,6 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
let promise; let promise;
this.addResizerScript();
if (this.canDownload && this.fileHelper.isStateDownloaded(this.state)) { if (this.canDownload && this.fileHelper.isStateDownloaded(this.state)) {
// Package is downloaded, use the local URL. // Package is downloaded, use the local URL.
promise = this.h5pProvider.getContentIndexFileUrl(this.urlParams.url, this.urlParams, this.siteId).catch(() => { promise = this.h5pProvider.getContentIndexFileUrl(this.urlParams.url, this.urlParams, this.siteId).catch(() => {
@ -145,6 +143,7 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
}); });
} }
}).finally(() => { }).finally(() => {
this.addResizerScript();
this.loading = false; this.loading = false;
this.showPackage = true; this.showPackage = true;
@ -211,6 +210,11 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
* Add the resizer script if it hasn't been added already. * Add the resizer script if it hasn't been added already.
*/ */
protected addResizerScript(): void { protected addResizerScript(): void {
if (document.head.querySelector('#core-h5p-resizer-script') != null) {
// Script already added, don't add it again.
return;
}
const script = document.createElement('script'); const script = document.createElement('script');
script.id = 'core-h5p-resizer-script'; script.id = 'core-h5p-resizer-script';
script.type = 'text/javascript'; script.type = 'text/javascript';
@ -264,6 +268,20 @@ export class CoreH5PPlayerComponent implements OnInit, OnChanges, OnDestroy {
}); });
} }
/**
* Send hello to the H5P iframe.
*
* @param iframe The iframe.
*/
sendHello(iframe?: HTMLIFrameElement): void {
const ready = {
context: 'h5p',
action: 'ready'
};
iframe.contentWindow.postMessage(ready, '*');
}
/** /**
* Component destroyed. * Component destroyed.
*/ */