Created
February 7, 2012 10:47
-
-
Save pete-otaqui/1759069 to your computer and use it in GitHub Desktop.
HTML 5 FullScreen API jQuery Plugin
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($) { | |
var body = document.body, | |
_standard = !!(body.requestFullScreen && document.cancelFullScreen), | |
_mz_style = !!(body.mozRequestFullScreen && document.mozCancelFullScreen), | |
_wk_style = !!(body.webkitRequestFullScreen && document.webkitCancelFullScreen), | |
_requestFullScreen, _cancelFullScreen, _fullScreenData; | |
$.fn.requestFullScreen = function() { | |
_requestFullScreen(this[0]); | |
return this; | |
}; | |
$.fn.cancelFullScreen = function() { | |
_cancelFullScreen(this[0]); | |
return this; | |
}; | |
$.fn.toggleFullScreen = function() { | |
var fs = $.fullScreenData().fullScreen; | |
if ( fs ) { | |
this.cancelFullScreen(); | |
} else { | |
this.requestFullScreen(); | |
} | |
}; | |
$.fullScreenData = function() { | |
return _fullScreenData(); | |
}; | |
_requestFullScreen = function(el) { | |
if ( _standard ) { | |
return el.requestFullScreen(); | |
} else if ( _mz_style ) { | |
return el.mozRequestFullScreen(); | |
} else if ( _wk_style ) { | |
return el.webkitRequestFullScreen(); | |
} | |
}; | |
_cancelFullScreen = function(el) { | |
if ( _standard ) { | |
return document.cancelFullScreen(); | |
} else if ( _mz_style ) { | |
return document.mozCancelFullScreen(); | |
} else if ( _wk_style ) { | |
return document.webkitCancelFullScreen(); | |
} | |
}; | |
_fullScreenData = function() { | |
var fs, ele, fse; | |
fs = | |
(_standard) ? document.fullScreen : | |
(_mz_style) ? document.mozFullScreen : | |
(_wk_style) ? document.wekitIsFullScreen : | |
false; | |
ele = | |
(_standard) ? document.fullScreenElement : | |
(_mz_style) ? document.mozFullScreenElement : | |
(_wk_style) ? document.webkitFullScreenElement : | |
null; | |
fse = | |
(_standard) ? document.fullScreenEnabled : | |
(_mz_style) ? document.mozFullScreenEnabled : | |
(_wk_style) ? document.webkitFullScreenEnabled : | |
false; | |
return { | |
fullScreen: fs, | |
fullScreenElement: ele, | |
fullScreenEnabled: fse | |
}; | |
}; | |
})(jQuery); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment