Created
December 19, 2012 04:01
-
-
Save arkadylukashov/4334298 to your computer and use it in GitHub Desktop.
Simple jQuery element based Fullscreen API 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
(function($) { | |
$.fn.fullscreen = function(options) { | |
var settings = $.extend({ | |
to: false, | |
exit: 'Normal size', | |
onScreenChange: $.noop, | |
onFail: $.noop | |
},options); | |
var methods = { | |
run: function() { | |
var selector = !settings.to ? this : $(this).find(settings.to); | |
settings.full = selector[0].innerText; | |
$(this).on('click',function() { | |
if (!methods.is()) { | |
if (methods.enter()) { | |
selector[0].innerText = settings.exit; | |
} else { | |
settings.onFail(); | |
} | |
} else { | |
selector[0].innerText = settings.full; | |
return methods.exit(); | |
} | |
}); | |
$(document).on('fullscreenchange mozfullscreenchange webkitfullscreenchange', function() { | |
return settings.onScreenChange( methods.is() ); | |
}) | |
}, | |
is : function() { | |
return document.fullscreen || document.fullscreenElement || document.mozFullScreen || document.webkitIsFullScreen || false; | |
}, | |
enter : function() { | |
if (document.documentElement.requestFullscreen) { | |
document.documentElement.requestFullscreen(); return true; | |
} | |
else if (document.documentElement.mozRequestFullScreen) { | |
document.documentElement.mozRequestFullScreen(); return true; | |
} | |
else if (document.documentElement.webkitRequestFullScreen) { | |
document.documentElement.webkitRequestFullScreen(); return true; | |
} | |
else { | |
return false; | |
} | |
}, | |
exit : function() { | |
if (document.exitFullscreen) { | |
document.exitFullscreen(); | |
} | |
else if (document.mozCancelFullScreen) { | |
document.mozCancelFullScreen(); | |
} | |
else if (document.webkitCancelFullScreen) { | |
document.webkitCancelFullScreen(); | |
} | |
} | |
}; | |
return methods.run.call(this); | |
} | |
})(jQuery) |
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(a){a.fn.fullscreen=function(e){var b=a.extend({to:!1,exit:"Normal size",onScreenChange:a.noop,onFail:a.noop},e),c={run:function(){var d=!b.to?this:a(this).find(b.to);b.full=d[0].innerText;a(this).on("click",function(){if(c.is())return d[0].innerText=b.full,c.exit();if(c.enter())d[0].innerText=b.exit;else b.onFail()});a(document).on("fullscreenchange mozfullscreenchange webkitfullscreenchange",function(){return b.onScreenChange(c.is())})},is:function(){return document.fullscreen||document.fullscreenElement||document.mozFullScreen||document.webkitIsFullScreen||!1},enter:function(){return document.documentElement.requestFullscreen?(document.documentElement.requestFullscreen(),!0):document.documentElement.mozRequestFullScreen?(document.documentElement.mozRequestFullScreen(),!0):document.documentElement.webkitRequestFullScreen?(document.documentElement.webkitRequestFullScreen(),!0):!1},exit:function(){document.exitFullscreen?document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()}};return c.run.call(this)}})(jQuery); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment