From 26ff54366b0e909e11dae6d73ba46d16cb5fb8b3 Mon Sep 17 00:00:00 2001 From: yanas Date: Thu, 13 Oct 2016 17:28:24 -0500 Subject: [PATCH] Moves full screen functions in UIUtil --- modules/UI/UI.js | 39 ++++------------------------- modules/UI/util/UIUtil.js | 52 ++++++++++++++++++++++++++++++++++----- 2 files changed, 51 insertions(+), 40 deletions(-) diff --git a/modules/UI/UI.js b/modules/UI/UI.js index 9e7389d03..95dec167e 100644 --- a/modules/UI/UI.js +++ b/modules/UI/UI.js @@ -140,36 +140,11 @@ function setupToolbars() { /** * Toggles the application in and out of full screen mode * (a.k.a. presentation mode in Chrome). - * @see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API */ UI.toggleFullScreen = function() { - let isFullScreen = document.fullscreenElement - || document.mozFullScreenElement // current working methods - || document.webkitFullscreenElement - || document.msFullscreenElement; - - if (isFullScreen) { - if (document.exitFullscreen) { - document.exitFullscreen(); - } else if (document.msExitFullscreen) { - document.msExitFullscreen(); - } else if (document.mozCancelFullScreen) { - document.mozCancelFullScreen(); - } else if (document.webkitExitFullscreen) { - document.webkitExitFullscreen(); - } - } else { - if (document.documentElement.requestFullscreen) { - document.documentElement.requestFullscreen(); - } else if (document.documentElement.msRequestFullscreen) { - document.documentElement.msRequestFullscreen(); - } else if (document.documentElement.mozRequestFullScreen) { - document.documentElement.mozRequestFullScreen(); - } else if (document.documentElement.webkitRequestFullscreen) { - document.documentElement - .webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); - } - } + (UIUtil.isFullScreen()) + ? UIUtil.exitFullScreen() + : UIUtil.enterFullScreen(); }; /** @@ -415,12 +390,8 @@ function bindEvents() { $(document).on( 'webkitfullscreenchange mozfullscreenchange fullscreenchange', () => { - let isFullScreen = document.fullscreenElement - || document.mozFullScreenElement - || document.webkitFullscreenElement - || document.msFullscreenElement; - - eventEmitter.emit(UIEvents.FULLSCREEN_TOGGLED, isFullScreen); + eventEmitter.emit( UIEvents.FULLSCREEN_TOGGLED, + UIUtil.isFullScreen()); onResize(); } diff --git a/modules/UI/util/UIUtil.js b/modules/UI/util/UIUtil.js index b7ff1fb0e..564483355 100644 --- a/modules/UI/util/UIUtil.js +++ b/modules/UI/util/UIUtil.js @@ -240,13 +240,53 @@ const TOOLTIP_POSITIONS = { window.location.href = url; }, - isFullScreen () { - return document.fullScreen - || document.mozFullScreen - || document.webkitIsFullScreen; - }, + /** + * Indicates if we're currently in full screen mode. + * + * @return {boolean} {true} to indicate that we're currently in full screen + * mode, {false} otherwise + */ + isFullScreen() { + return document.fullscreenElement + || document.mozFullScreenElement + || document.webkitFullscreenElement + || document.msFullscreenElement; + }, - /** + /** + * Exits full screen mode. + * @see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API + */ + exitFullScreen() { + if (document.exitFullscreen) { + document.exitFullscreen(); + } else if (document.msExitFullscreen) { + document.msExitFullscreen(); + } else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } else if (document.webkitExitFullscreen) { + document.webkitExitFullscreen(); + } + }, + + /** + * Enter full screen mode. + * @see https://developer.mozilla.org/en-US/docs/Web/API/Fullscreen_API + */ + enterFullScreen() { + if (document.documentElement.requestFullscreen) { + document.documentElement.requestFullscreen(); + } else if (document.documentElement.msRequestFullscreen) { + document.documentElement.msRequestFullscreen(); + } else if (document.documentElement.mozRequestFullScreen) { + document.documentElement.mozRequestFullScreen(); + } else if (document.documentElement.webkitRequestFullscreen) { + document.documentElement + .webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); + } + }, + + /** * Create html attributes string out of object properties. * @param {Object} attrs object with properties * @returns {String} string of html element attributes