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