diff --git a/docs/packages/h5p-react.md b/docs/packages/h5p-react.md index f8f23fb20..b36fc811c 100644 --- a/docs/packages/h5p-react.md +++ b/docs/packages/h5p-react.md @@ -294,6 +294,15 @@ display somewhere. Returns true if there is copyright information to be displayed. +### resize + +Signals the H5P content inside the component to resize itself according to the +dimensions of the container. Can be called if you have changed the size of the +container in an unusual fashion (e.g. by scaling it with CSS transform) and you +need to resize the content manually. The component already automatically calls +the resize function when its own size is changed, so this will rarely be the +case. + ### showCopyright Shows the copyright information in a window overlaying the H5P content. diff --git a/docs/packages/h5p-webcomponents.md b/docs/packages/h5p-webcomponents.md index b743ce9f0..883a15047 100644 --- a/docs/packages/h5p-webcomponents.md +++ b/docs/packages/h5p-webcomponents.md @@ -325,6 +325,15 @@ display somewhere. Returns true if there is copyright information to be displayed. +### resize + +Signals the H5P content inside the component to resize itself according to the +dimensions of the container. Can be called if you have changed the size of the +container in an unusual fashion (e.g. by scaling it with CSS transform) and you +need to resize the content manually. The component already automatically calls +the resize function when its own size is changed, so this will rarely be the +case. + ### showCopyright Shows the copyright information in a window overlaying the H5P content. diff --git a/packages/h5p-react/src/H5PPlayerUI.tsx b/packages/h5p-react/src/H5PPlayerUI.tsx index 97731afcf..23d6a75f9 100644 --- a/packages/h5p-react/src/H5PPlayerUI.tsx +++ b/packages/h5p-react/src/H5PPlayerUI.tsx @@ -121,6 +121,16 @@ export default class H5PPlayerUI extends React.Component<{ this.h5pPlayer.current?.showCopyright(); } + /** + * Asks the H5P content to resize itself inside the dimensions of the + * container. + * + * Has no effect until the H5P object has fully initialized. + */ + public resize(): void { + this.h5pPlayer.current?.resize(); + } + private loadContentCallbackWrapper = ( contentId: string ): Promise => this.props.loadContentCallback(contentId); diff --git a/packages/h5p-webcomponents/src/h5p-player.ts b/packages/h5p-webcomponents/src/h5p-player.ts index fe77bba3e..3fae6fdae 100644 --- a/packages/h5p-webcomponents/src/h5p-player.ts +++ b/packages/h5p-webcomponents/src/h5p-player.ts @@ -266,6 +266,19 @@ export class H5PPlayerComponent extends HTMLElement { return !!this.getCopyrightHtml(); } + /** + * Asks the H5P content to resize itself inside the dimensions of the + * container. + * + * Has no effect until the H5P object has fully initialized. + */ + public resize(): void { + if (!this.h5pInstance || !this.h5pInstance.trigger) { + return; + } + this.h5pInstance.trigger('resize'); + } + /** * Displays the copyright notice in the regular H5P way. */