Skip to content

Instantly share code, notes, and snippets.

@johan
Created March 20, 2012 00:01
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 4 You must be signed in to fork a gist
  • Save johan/2128691 to your computer and use it in GitHub Desktop.
Save johan/2128691 to your computer and use it in GitHub Desktop.
HTML5 FullScreen API plugin for jQuery, based on http://johndyer.name/native-fullscreen-javascript-api-plus-jquery-plugin/
// jQuery.FullScreen plugin
// Triple-licensed: Public Domain, MIT and WTFPL license - share and enjoy!
(function($) {
function isFullScreen() {
return document[!prefix ? 'fullScreen' :
'webkit' === prefix ? 'webkitIsFullScreen' :
prefix + 'FullScreen'];
}
function cancelFullScreen() {
return document[prefix ? prefix + 'CancelFullScreen'
: 'cancelFullScreen']();
}
var supported = typeof document.cancelFullScreen !== 'undefined'
, prefixes = ['webkit', 'moz', 'o', 'ms', 'khtml']
, prefix = ''
, noop = function() {}
, i
;
if (!supported) {
for (i = 0; prefix = prefixes[i]; i++) {
if (typeof document[prefix + 'CancelFullScreen'] !== 'undefined') {
supported = true;
break;
}
}
}
if (supported) {
$.fn.requestFullScreen = function() {
return this.each(function() {
return this[prefix ? prefix + 'RequestFullScreen'
: 'requestFullScreen']();
});
};
$.fn.fullScreenChange = function(fn) {
var ar = [prefix + 'fullscreenchange'].concat([].slice.call(arguments, 0))
, $e = $(this);
return $e.bind.apply($e, ar);
};
$.FullScreen =
{ isFullScreen: isFullScreen
, cancelFullScreen: cancelFullScreen
};
}
else {
$.fn.requestFullScreen = $.fn.fullScreenChange = noop;
$.FullScreen =
{ isFullScreen: function() { return false; }
, cancelFullScreen: noop
};
}
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment