Socket
Book a DemoInstallSign in
Socket

fullscrn

Package Overview
Dependencies
Maintainers
0
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

fullscrn

Fullscreen API

1.3.8
latest
Source
npmnpm
Version published
Weekly downloads
437
161.68%
Maintainers
0
Weekly downloads
 
Created
Source

Fullscrn

Fullscreen API. This module injects APIs to the DOM. So, you don't have to consider about the prefix such as 'moz' or 'webkit'.

The implementation follows the standard specification at Fullscreen API - WHATWG.

See also this project page.

INSTALLATION

$ npm install --save fullscrn

REPOSITORY

  • npm
  • GitHub (gh-pages)

FILES

  • fullscrn.js - The script to include by script tag.
  • fullscrn.min.js - Minified one.
  • index.js - The source file of this module. This can be import using browserify.

APIs Injected to DOM

Properties

  • Document.fullscreenEnabled - The full screen API's availability.
  • Document.fullscreenElement - Indicates the full sized element.
  • Document.fullscreen - The equivalent value to (Document.fullscreenElement != null).

Methods

These methods returns promise.

  • Element.requestFullscreen() - Requests the fullscreen mode with the element.
  • Document.exitFullscreen() - Cancels the fullscreen mode of the element that is set to fullscreen at the time.

Events

Use document.addEventListener to handle events while this module does not supoort the event handlers - Document.onfullscreenchange and onfullscreenerror.

  • Document "fullscreenchange"
  • Document "fullscreenerror"

SAMPLE

sample/injected.html [live sample].

<body onload="main();">
    <button type="button" onclick="request1();"
    >Full&gt;&gt;</button>
    <span id="panel">
        <button type="button" onclick="request2();"
        >Full&gt;&gt;</button>
        <button type="button" id="exitButton"
        onclick="exit();">&lt;&lt;Exit</button>
    </span>
    <script src="../fullscrn.js"></script>
    <script>
        var panel = document.getElementById("panel");
        var exitButton = document.getElementById("exitButton");
        Fullscreen.debugMode(true);// Enables debug log
        function main() {
            // Handle change event
            document.addEventListener("fullscreenchange",
                function() {
                    var fse = document.fullscreenElement;
                    console.log("FULLSCREEN CHANGE: " +
                        ((fse == null)? "(null)": "#" + fse.id));
                });

            // Handle error event
            document.addEventListener("fullscreenerror",
                function() { console.log("FULLSCREEN ERROR"); });

            request1(); // This should be error
        }
        function request1() {
            panel.requestFullscreen().then(function(){
                console.log("request1 done.");
            }).catch(function(err) {
                console.error(err.message);
            });
        }
        function request2() {
            exitButton.requestFullscreen().then(function(){
                console.log("request2 done.");
            }).catch(function(err) {
                console.error(err.message);
            });
        }
        function exit() {
            document.exitFullscreen()
            .then(function(){
                console.log("exit done.");
            }).catch(function(err) {
                console.error(err.message);
            });
        }
    </script>
</body>

Exported APIs

If this module was included by script tag, the global object 'Fullscreen' is available (see the sample/sample.html below).

Properties

  • Fullscreen.enabled - indicates the fullscreen APIs are available.
  • Fullscreen.element - references the fullscreen element or null.

Methods

  • Fullscreen.request(element) - enter full screen mode with the element and returns a promise.
  • Fullscreen.exit(): exit full screen mode and returns a promise.

SAMPLE

sample/sample.html [live sample].

<body>
    <button type="button"
        onclick="requestFull();">Fullscreen</button>
    <button type="button" id="exitButton"
         style="display:none;"
         onclick="exitFull();">Exit</button>
    <script src="../fullscrn.js"></script>
    <script>
        function exitButton() {
            return document.getElementById("exitButton");
        }
        function requestFull() {
            var btn = exitButton();
            btn.style.display = "block";
            Fullscreen.request(btn);
        }
        function exitFull() {
            var btn = exitButton();
            btn.style.display = "none";
            Fullscreen.exit();
        }
    </script>
</body>

LICENSE

This software is released under the MIT License, see LICENSE

Keywords

fullscreen

FAQs

Package last updated on 28 Sep 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

About

Packages

Stay in touch

Get open source security insights delivered straight into your inbox.

  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc

U.S. Patent No. 12,346,443 & 12,314,394. Other pending.