Created
January 21, 2014 13:03
-
-
Save DanAntFerrari/8539621 to your computer and use it in GitHub Desktop.
Active fullscreen by key down
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function keyboardShortcuts(){ | |
// setup the keyboard shortcuts | |
console.log('keyboardShortcuts: listner ON'); | |
document.addEventListener('keyup', function(e) { | |
console.log('keyboardShortcuts: e.keyCode',e.keyCode); | |
switch(e.keyCode) { | |
case 70: | |
// F | |
// Make the body toggle full screen. | |
var isInFullScreen = (document.fullScreenElement && document.fullScreenElement !== null) || (document.mozFullScreen || document.webkitIsFullScreen); | |
var el = document.documentElement; // Make the body go full screen. | |
// window.console.firebug | |
if (isInFullScreen) { | |
cancelFullScreen(); | |
} else { | |
requestFullScreen(el); | |
} | |
break; | |
default: | |
break; | |
} | |
}, false); | |
} // keyboardShortcuts(); | |
function requestFullScreen(el){ | |
console.log('_requestFullScreen'); | |
// Supports most browsers and their versions. | |
//https://developer.mozilla.org/en-US/docs/Web/Guide/API/DOM/Using_full_screen_mode?redirectlocale=en-US&redirectslug=Web%2FGuide%2FDOM%2FUsing_full_screen_mode | |
var rfs = // for newer Webkit and Firefox | |
el.requestFullScreen | |
|| el.webkitRequestFullScreen | |
|| el.mozRequestFullScreen | |
|| el.msRequestFullScreen | |
; | |
if(typeof rfs!="undefined" && rfs){ | |
rfs.call(el); | |
} else if(typeof window.ActiveXObject!="undefined"){ | |
// for Internet Explorer | |
var wscript = new ActiveXObject("WScript.Shell"); | |
if (wscript!=null) { | |
wscript.SendKeys("{F11}"); | |
} | |
} | |
} // requestFullScreen(); | |
function cancelFullScreen(){ | |
console.log('_cancelFullScreen'); | |
// Exit full screen. | |
var el = document | |
,rfs = // for newer Webkit and Firefox | |
el.exitFullscreen | |
|| el.msExitFullscreen | |
|| el.mozCancelFullScreen | |
|| el.webkitExitFullscreen | |
; | |
if(typeof rfs!="undefined" && rfs){ | |
rfs.call(el); | |
} else if(typeof window.ActiveXObject!="undefined"){ | |
// for Internet Explorer | |
var wscript = new ActiveXObject("WScript.Shell"); | |
if (wscript!=null) { | |
wscript.SendKeys("{F11}"); | |
} | |
} | |
} // requestFullScreen(element); | |
// init keyboardShortcuts; | |
keyboardShortcuts(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment