|
1668 | 1668 | } )( document );
|
1669 | 1669 |
|
1670 | 1670 |
|
| 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 | + |
1671 | 1729 | /**
|
1672 | 1730 | * Goto Plugin
|
1673 | 1731 | *
|
|
0 commit comments