From 244be538d364c71c4a5e413682b505e6ac2eae91 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Tim=20D=C3=BCsterhus?= Date: Tue, 10 Jun 2014 17:35:50 +0200 Subject: [PATCH] Add WCF.System.Fullscreen to WCF.js --- wcfsetup/install/files/js/WCF.js | 93 ++++++++++++++++++++++++++++++++ 1 file changed, 93 insertions(+) diff --git a/wcfsetup/install/files/js/WCF.js b/wcfsetup/install/files/js/WCF.js index c0122c4b73..8c949e2c7a 100755 --- a/wcfsetup/install/files/js/WCF.js +++ b/wcfsetup/install/files/js/WCF.js @@ -7118,6 +7118,99 @@ WCF.System.DisableScrolling = { } }; +/** + * Puts an element into HTML 5 fullscreen mode. + */ +WCF.System.Fullscreen = { + /** + * Puts the given element into full screen mode. + * Note: This must be a raw HTMLElement, not a jQuery wrapped one. + * Note: This must be called from an user triggered event listener for + * security reasons. + * + * @param object Element to show full screen. + */ + enterFullscreen: function (element) { + if (element.requestFullscreen) { + element.requestFullscreen(); + } + else if (element.msRequestFullscreen) { + element.msRequestFullscreen(); + } + else if (element.mozRequestFullScreen) { + element.mozRequestFullScreen(); + } + else if (element.webkitRequestFullscreen) { + element.webkitRequestFullscreen(Element.ALLOW_KEYBOARD_INPUT); + } + }, + /** + * Toggles full screen mode. Either calls `enterFullscreen` with the given + * element, if full screen mode is not active. Calls `exitFullscreen` + * otherwise. + */ + toggleFullscreen: function (element) { + if (this.getFullscreenElement() === null) { + this.enterFullscreen(element); + } + else { + this.exitFullscreen(); + } + }, + /** + * Retrieves the element that is shown in full screen mode. + * Returns null if either full screen mode is not supported or + * if full screen mode is not active. + * + * @return object + */ + getFullscreenElement: function () { + if (document.fullscreenElement) { + return document.fullscreenElement; + } + else if (document.mozFullScreenElement) { + return document.mozFullScreenElement; + } + else if (document.webkitFullscreenElement) { + return document.webkitFullscreenElement; + } + else if (document.msFullscreenElement) { + return document.msFullscreenElement; + } + + return null; + }, + /** + * Exits full screen mode. + */ + exitFullscreen: function () { + if (document.exitFullscreen) { + document.exitFullscreen(); + } + else if (document.msExitFullscreen) { + document.msExitFullscreen(); + } + else if (document.mozCancelFullScreen) { + document.mozCancelFullScreen(); + } + else if (document.webkitExitFullscreen) { + document.webkitExitFullscreen(); + } + }, + /** + * Returns whether the full screen API is supported in this browser. + * + * @return boolean + */ + isSupported: function () { + if (document.documentElement.requestFullscreen || document.documentElement.msRequestFullscreen || document.documentElement.mozRequestFullScreen || document.documentElement.webkitRequestFullscreen) { + return true; + } + + return false; + } +}; + /** * Provides the 'jump to page' overlay. */ -- 2.20.1