Skip to content

Commit 97546a5

Browse files
giflwhenrikingo
authored andcommitted
Add fullscreen with support to remote presentation controller (impress#712)
- F5 to enter/exit - Escape to exit
1 parent 6db3f7c commit 97546a5

File tree

3 files changed

+116
-0
lines changed

3 files changed

+116
-0
lines changed

build.js

+1
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ buildify()
1414
'src/plugins/blackout/blackout.js',
1515
'src/plugins/extras/extras.js',
1616
'src/plugins/form/form.js',
17+
'src/plugins/fullscreen/fullscreen.js',
1718
'src/plugins/goto/goto.js',
1819
'src/plugins/help/help.js',
1920
'src/plugins/impressConsole/impressConsole.js',

js/impress.js

+58
Original file line numberDiff line numberDiff line change
@@ -1668,6 +1668,64 @@
16681668
} )( document );
16691669

16701670

1671+
/**
1672+
* Fullscreen plugin
1673+
*
1674+
* Press F5 to enter fullscreen and ESC to exit fullscreen mode.
1675+
*
1676+
* Copyright 2019 @giflw
1677+
* Released under the MIT license.
1678+
*/
1679+
/* global document */
1680+
1681+
( function( document ) {
1682+
"use strict";
1683+
1684+
function enterFullscreen() {
1685+
var elem = document.documentElement;
1686+
if ( !document.fullscreenElement ) {
1687+
elem.requestFullscreen();
1688+
}
1689+
}
1690+
1691+
function exitFullscreen() {
1692+
if ( document.fullscreenElement ) {
1693+
document.exitFullscreen();
1694+
}
1695+
}
1696+
1697+
// Wait for impress.js to be initialized
1698+
document.addEventListener( "impress:init", function( event ) {
1699+
var api = event.detail.api;
1700+
var root = event.target;
1701+
var gc = api.lib.gc;
1702+
var util = api.lib.util;
1703+
1704+
gc.addEventListener( document, "keydown", function( event ) {
1705+
1706+
// 116 (F5) is sent by presentation remote controllers
1707+
if ( event.code === "F5" ) {
1708+
event.preventDefault();
1709+
enterFullscreen();
1710+
util.triggerEvent( root.querySelector( ".active" ), "impress:steprefresh" );
1711+
}
1712+
1713+
// 27 (Escape) is sent by presentation remote controllers
1714+
if ( event.key === "Escape" || event.key === "F5" ) {
1715+
event.preventDefault();
1716+
exitFullscreen();
1717+
util.triggerEvent( root.querySelector( ".active" ), "impress:steprefresh" );
1718+
}
1719+
}, false );
1720+
1721+
util.triggerEvent( document, "impress:help:add",
1722+
{ command: "F5 / ESC", text: "Fullscreen: Enter / Exit", row: 200 } );
1723+
1724+
}, false );
1725+
1726+
} )( document );
1727+
1728+
16711729
/**
16721730
* Goto Plugin
16731731
*

src/plugins/fullscreen/fullscreen.js

+57
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
/**
2+
* Fullscreen plugin
3+
*
4+
* Press F5 to enter fullscreen and ESC to exit fullscreen mode.
5+
*
6+
* Copyright 2019 @giflw
7+
* Released under the MIT license.
8+
*/
9+
/* global document */
10+
11+
( function( document ) {
12+
"use strict";
13+
14+
function enterFullscreen() {
15+
var elem = document.documentElement;
16+
if ( !document.fullscreenElement ) {
17+
elem.requestFullscreen();
18+
}
19+
}
20+
21+
function exitFullscreen() {
22+
if ( document.fullscreenElement ) {
23+
document.exitFullscreen();
24+
}
25+
}
26+
27+
// Wait for impress.js to be initialized
28+
document.addEventListener( "impress:init", function( event ) {
29+
var api = event.detail.api;
30+
var root = event.target;
31+
var gc = api.lib.gc;
32+
var util = api.lib.util;
33+
34+
gc.addEventListener( document, "keydown", function( event ) {
35+
36+
// 116 (F5) is sent by presentation remote controllers
37+
if ( event.code === "F5" ) {
38+
event.preventDefault();
39+
enterFullscreen();
40+
util.triggerEvent( root.querySelector( ".active" ), "impress:steprefresh" );
41+
}
42+
43+
// 27 (Escape) is sent by presentation remote controllers
44+
if ( event.key === "Escape" || event.key === "F5" ) {
45+
event.preventDefault();
46+
exitFullscreen();
47+
util.triggerEvent( root.querySelector( ".active" ), "impress:steprefresh" );
48+
}
49+
}, false );
50+
51+
util.triggerEvent( document, "impress:help:add",
52+
{ command: "F5 / ESC", text: "Fullscreen: Enter / Exit", row: 200 } );
53+
54+
}, false );
55+
56+
} )( document );
57+

0 commit comments

Comments
 (0)