fullscrn
v1.3.8
Published
Fullscreen API
Downloads
36
Readme
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
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>></button>
<span id="panel">
<button type="button" onclick="request2();"
>Full>></button>
<button type="button" id="exitButton"
onclick="exit();"><<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