wholescreen.js
Version:
Minimal cross-browser wrapper of the Fullscreen API. Handles vendor prefixes for you!
31 lines (27 loc) • 1.25 kB
JavaScript
/*! wholescreen.js - detect.js v0.3.1 | (c) 2018 Albin Larsson | Licensed under MIT */
;
Object.defineProperty(exports, '__esModule', { value: true });
var prefix = ['', 'webkit', 'moz', 'ms', 'MS'];
var fullscreen = ['fullscreen', 'Fullscreen', 'FullScreen'];
function combine(parts) {
return parts.reduce(function (a, b) { return [].concat.apply([], a.map(function (str1) { return b.map(function (str2) { return "" + str1 + str2; }); })); }, ['']);
}
function getProp(props, path) {
if (typeof document !== 'object') {
return '';
}
var container = path ? document[path] : document;
return combine(props).find(function (prop) { return Boolean(container && prop && prop in container); }) || '';
}
var props = {
element: getProp([prefix, fullscreen, ['Element']]),
exit: getProp([prefix, ['Exit', 'exit', 'Cancel', 'cancel'], fullscreen]),
request: getProp([prefix, ['request', 'Request'], fullscreen], 'body'),
supported: getProp([prefix, fullscreen, ['Enabled']]),
};
var events = {
change: getProp([['on'], prefix, fullscreen, ['change', 'Change']]).slice(2),
error: getProp([['on'], prefix, fullscreen, ['error', 'Error']]).slice(2),
};
exports.events = events;
exports.props = props;