H5P Guides
Using fullscreen
In this section, we'll have a look at how you can get your content type into full screen.
As a library developer, there are two ways you can add fullscreen support to your content type.
- The simplest way is to just set the fullscreen property in your library.json to 1, like so:
{ ... "runnable": 1, "fullscreen": 1, ... }
This will enable the default fullscreen button that is integrated with H5P. It will be put on top of your content. - The second way is to create your own full-screen button and use H5P's fullscreen API when clicking it.
// First we check if full screen is supported if (H5P.canHasFullScreen !== false) { // We create a function that is used to enter or // exit full screen when our button is pressed var toggleFullScreen = function () { if (H5P.isFullscreen) { H5P.exitFullScreen(); } else { H5P.fullScreen($myContainer, this); } }; // Create the custom full screen button var $fullScreenButton = $('<button/>', { 'class': 'h5p-my-fullscreen-button', title: params.l10n.enterFullScreen, on: { click: toggleFullScreen }, appendTo: $myContainer }); // Respond to enter full screen event this.on('enterFullScreen', function () { $fullScreenButton.attr('title', params.l10n.exitFullScreen); }); // Respond to exit full screen event this.on('exitFullScreen', function () { $fullScreenButton.attr('title', params.l10n.enterFullScreen); }); }
Events must be used to detect if the browser enters or exits fullscreen mode. This is in case there are multiple fullscreen buttons, or if the user presses the ESC-key to exit the fullscreen.
When full screen is enabled your $container will automatically get the h5p-fullscreen or h5p-semi-fullscreen class, which you can use for custom styling./* Full screen button styling */ .h5p-my-content .h5p-my-fullscreen-button { color: blue; content: "o"; } /* Full screen enabled styling */ .h5p-my-content.h5p-fullscreen .h5p-my-fullscreen-button, .h5p-my-content.h5p-semi-fullscreen .h5p-my-fullscreen-button { color: pink; content: "x"; }
Semi-fullscreen is a solution used when normal fullscreen isn't available in the browsers. In the time of writing such a solution is only one available on iPad.
Comments
papi Jo
Wed, 12/21/2016 - 16:41
Permalink
Can't get H5P's fullscreen API method to work
Hi there,
Using H5P in WordPress.
Trying to add togglefullscreen buttons to my own version of Drag & Drop activity, using the second method explained above.
I do get the $fullScreenButton button displayed but when I click on it nothing happens. Examining the console I see this error: "Uncaught TypeError: Cannot read property 'get' of undefined" in file /wp-content/plugins/h5p/h5p-php-library/js/h5p.js?ver=1.7.7 at line 668.
It looks like $element[0] is undefined.
Any pointers?
icc
Wed, 12/21/2016 - 17:37
Permalink
Do you have a URL where I
Do you have a URL where I could look at it?
I'm guessing that the $myContainer sent to H5P.fullScreen() might be empty.
papi Jo
Wed, 12/21/2016 - 18:18
Permalink
Actually, the $myContainer
Actually, the $myContainer sent to H5P.fullScreen() is not empty. It is correctly sent as $element to H5P.fullScreen = function ($element, instance,...). But $element seems to be emptied at line 532:
532 $element = $iframe.parent(); // Put iframe wrapper in fullscreen, not container.
I will try to set up an online development WP site soon to put my tests.
icc
Thu, 12/22/2016 - 09:51
Permalink
Check that the iframeSelector
Check that the iframeSelector variable matches the ID of the iframe.
papi Jo
Thu, 12/22/2016 - 23:21
Permalink
iframeSelector not working
You're right, icc, iframeSelector does not work. The problem is line 530:
var iframeSelector = '#h5p-iframe-' + $element.parent().data('content-id');
When H5P.fullScreen function is called in h5p-php-library/js/h5p.js from my Drag & drop question, $element.parent is not located in the correct place. Maybe because I do not attach the $fullScreenButton in the right place with appendTo: $myContainer?
For you to check I have put a test version here: http://www.rezeau.org/wp-garden/en/drag-drop-fullscreen-test/ where the FullScreen selector lies at the bottom right of the activity frame.
You can also download the activity and the test library from there.
icc
Wed, 12/28/2016 - 15:01
Permalink
Yes, currently the first
Yes, currently the first parameter for H5P.fullscreen() has to be the element with the 'h5p-container' classname. With the current implementation, it's only possible to put the whole H5P into fullscreen mode and not a component inside the H5P. You can, of course, hide things using CSS when the fullscreen class is added.
I hope this helps you solve the issue.
papi Jo
Thu, 12/29/2016 - 12:31
Permalink
Thanks for your reply, which
Thanks for your reply, which encouraged me to look further into the problem. In the drag & drop activity, $this.container is actually defined as:
this.$container = $('<div class="h5p-inner"></div>');
So, sending this.$container to H5P.fullScreen as the first parameter actually sends the 'h5p-inner' classname, which is wrong. In order for H5P.fullScreen to get the expected element with the 'h5p-container' classname one must send it with this parameter:
H5P.fullScreen($myContainer.parent().parent(), this);
EDIT.- Unfortunately this only works once.
Uncaught TypeError: window.parent.H5P.exitFullScreen is not a function
PS.- Currently only 2 H5P activities have a full screen feature (Course Presentation & Interactive Video). Why not include this feature as default for ALL activities? Maybe with a "behaviour" setting to allow the activity creator to enable/disable the feature?
icc
Thu, 01/05/2017 - 09:31
Permalink
So far so good. The issue now
So far so good. The issue now appears to be the 'this' parameter sent to H5P.fullScreen which reference the button that is clicked and not the H5P instance. Without the reference to the H5P instance, the framework doesn't really know that the H5P has exited the fullscreen(it has only been requested). You should be able to fix it doing something like this:
Let me know if that works better for you.
Previously, more content types had a default fullscreen button available, but due to confusion when the content changed height and you got a scrollbar in fullscreen – it was removed.
papi Jo
Thu, 01/05/2017 - 22:41
Permalink
Thanks for your help. This
Thanks for your help. This seems to work fine.
Re the availability of the fullscreen feature, I think it really depends on the page where an H5P activity is displayed. For example, on my WP sites I use a theme which restricts the width of the page, and also a page can be cluttered with various elements, so for me the possibility to display an activity in full screen is important. Maybe it would be useful to make Fullscreen an option in those activities where it might be useful, so that the activity creator could decide on an instance basis whether to switch the feature on/off?
icc
Fri, 01/06/2017 - 08:35
Permalink
I'm glad that you got it
I'm glad that you got it working!
I agree on the fullscreen, this would be a useful option for many sites to have. Do you want to create a feature request for this or should I do it? https://h5p.org/feature-request-list
papi Jo
Sat, 01/07/2017 - 15:40
Permalink
I have finally managed to get
I have finally managed to get the fullscreen feature to work as I wanted for the Drag & Drop activity. You can view the result on the test page of my "garden site", same address as already given above, http://www.rezeau.org/wp-garden/en/drag-drop-fullscreen-test/
The sample d & d activity can be downloaded from there so you can examine the components of the Drag and Drop Test library.
Originally I had attached my fullscreen button to the container, but found that it might get covered by an element (drag zone or draggable element). I found that the prependTo method allowed me to place the fullscreen button outside of the container, thus avoiding any potential overlap problem. Here is the extract from the dragquestion.js script, placed inside C.prototype.registerDomElements = function () {...}:
Also added some rules in dragquestion.css:
Question
How can I post formatted js code here which looks like the code chunks you post yourself?
icc
Mon, 01/09/2017 - 10:17
Permalink
Good that you got it working,
Good that you got it working, and thanks for sharing the solution!
I've enabled the button for inserting syntax highlighted code for everyone.
papi Jo
Tue, 01/10/2017 - 10:04
Permalink
Thanks!
See next message!
papi Jo
Tue, 01/10/2017 - 10:03
Permalink
Thanks!
icc
Wed, 01/11/2017 - 11:45
Permalink
Hehe, no problem!
Hehe, no problem!
masoudvafaei
Thu, 12/28/2017 - 10:09
Permalink
Automatic switch to full screen
Hi is there any trick that automatically switch to fullscreen after page load?
I do something like above code, but no result.
BV52
Thu, 12/28/2017 - 14:21
Permalink
Hi masoudvafaei,I'm sorry for
Hi masoudvafaei,
I'm sorry for the delay in answering your question due to the holidays. We will get back to you as soon possible.
-BV52
icc
Tue, 01/02/2018 - 11:53
Permalink
Unfortunately, this is not
Unfortunately, this is not possible in the browser due to security issues. Fullscreen has to be initiated by the user.
tidus1492
Fri, 02/09/2018 - 03:35
Permalink
Javascript vs graphical GUI?
How do I get to the javascript editing area rather than graphical GUI on the h5p website? Do I need to host on another website?
BV52
Fri, 02/09/2018 - 06:34
Permalink
Hi tidus1492,I'm afraid this
Hi tidus1492,
I'm afraid this is not possible in H5P.org. You will have to host your own site using one of the 3 supported framworks (Drupal, Moodle or Wordpress).
-BV52
Jeff Ruth
Wed, 02/13/2019 - 17:55
Permalink
Full screen in Moodle?
I made a Course Presentation in H5P.com and it has a working button for full screen viewing. When I import that file to my Moodle instance, the full screen button isn't there. Any help? I thought that perhaps some activity types do not have the full screen option, but it seems to be more specific to Moodle. Thank you.
BV52
Thu, 02/14/2019 - 06:38
Permalink
Hi Jeff,I created a separate
Hi Jeff,
I created a separate post for this here.
-BV52
mohammadnabil
Fri, 01/10/2020 - 17:53
Permalink
h5p in moodle mobile app can not go into fullscreen
h5p in moodle mobile app can not go into fullscreen ( no button for switch to full screen)
Usapuka
Tue, 12/01/2020 - 17:47
Permalink
Full screen button in Agamotto
Hi,
For Aggamoto I added "full screen": 1, in the library.json and nothing happened.
Please tell me were I should write the script of solution 2.
Thank you!
otacke
Tue, 03/09/2021 - 08:52
Permalink
Hi!You can compare your
Hi!
You can compare your solution with the code of the latest version of Agamotto that now features a fullscreen mode: https://github.com/otacke/h5p-agamotto/compare/1.5.4...1.6.0
Best,
Oliver