Created
January 31, 2012 12:54
-
-
Save vbfox/1710352 to your computer and use it in GitHub Desktop.
Just reading around the full screen API and implementing as i read for fun a small wrapper
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
// http://hacks.mozilla.org/2012/01/using-the-fullscreen-api-in-web-browsers/ | |
function fullscreenMode() | |
{ | |
this.request = function() { | |
var documentElement = document.documentElement; | |
if (documentElement.requestFullscreen) { | |
return documentElement.requestFullscreen(); | |
} | |
else if (documentElement.mozRequestFullScreen) { | |
return documentElement.mozRequestFullScreen(); | |
} | |
else if (documentElement.webkitRequestFullScreen) { | |
return documentElement.webkitRequestFullScreen(); | |
} | |
}; | |
this.exit = function() { | |
if (document.exitFullscreen) { | |
return document.exitFullscreen(); | |
} | |
else if (document.mozCancelFullScreen) { | |
return document.mozCancelFullScreen(); | |
} | |
else if (document.webkitCancelFullScreen) { | |
return document.webkitCancelFullScreen(); | |
} | |
}; | |
this.isEnabled = function() { | |
var documentElement = document.documentElement; | |
if (documentElement.requestFullscreen) { | |
return document.fullscreen; | |
} | |
else if (documentElement.mozRequestFullScreen) { | |
return document.mozFullScreen; | |
} | |
else if (documentElement.webkitRequestFullScreen) { | |
return document.webkitIsFullScreen; | |
} | |
}; | |
this.onModeChange = function(f) { | |
document.addEventListener("fullscreenchange", function () { | |
f(this.isEnabled()); | |
}, false); | |
document.addEventListener("mozfullscreenchange", function () { | |
f(this.isEnabled()); | |
}, false); | |
document.addEventListener("webkitfullscreenchange", function () { | |
f(this.isEnabled()); | |
}, false); | |
}; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment