Skip to content

Instantly share code, notes, and snippets.

@arkadylukashov
Created December 19, 2012 04:01
Show Gist options
  • Select an option

  • Save arkadylukashov/4334298 to your computer and use it in GitHub Desktop.

Select an option

Save arkadylukashov/4334298 to your computer and use it in GitHub Desktop.

Revisions

  1. arkadylukashov revised this gist Dec 19, 2012. 2 changed files with 10 additions and 8 deletions.
    15 changes: 9 additions & 6 deletions jquery.fullscreen.js
    Original file line number Diff line number Diff line change
    @@ -15,8 +15,11 @@
    settings.full = selector[0].innerText;
    $(this).on('click',function() {
    if (!methods.is()) {
    selector[0].innerText = settings.exit;
    return methods.enter();
    if (methods.enter()) {
    selector[0].innerText = settings.exit;
    } else {
    settings.onFail();
    }
    } else {
    selector[0].innerText = settings.full;
    return methods.exit();
    @@ -33,16 +36,16 @@

    enter : function() {
    if (document.documentElement.requestFullscreen) {
    document.documentElement.requestFullscreen();
    document.documentElement.requestFullscreen(); return true;
    }
    else if (document.documentElement.mozRequestFullScreen) {
    document.documentElement.mozRequestFullScreen();
    document.documentElement.mozRequestFullScreen(); return true;
    }
    else if (document.documentElement.webkitRequestFullScreen) {
    document.documentElement.webkitRequestFullScreen();
    document.documentElement.webkitRequestFullScreen(); return true;
    }
    else {
    return settings.onFail();
    return false;
    }
    },

    3 changes: 1 addition & 2 deletions jquery.fullscreen.min.js
    Original file line number Diff line number Diff line change
    @@ -1,2 +1 @@
    (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();d[0].innerText=b.exit;return c.enter()});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(){if(document.documentElement.requestFullscreen)document.documentElement.requestFullscreen();else if(document.documentElement.mozRequestFullScreen)document.documentElement.mozRequestFullScreen();else if(document.documentElement.webkitRequestFullScreen)document.documentElement.webkitRequestFullScreen();else return b.onFail()},exit:function(){document.exitFullscreen?
    document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()}};return c.run.call(this)}})(jQuery);
    (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);
  2. arkadylukashov revised this gist Dec 19, 2012. 1 changed file with 2 additions and 0 deletions.
    2 changes: 2 additions & 0 deletions jquery.fullscreen.min.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,2 @@
    (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();d[0].innerText=b.exit;return c.enter()});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(){if(document.documentElement.requestFullscreen)document.documentElement.requestFullscreen();else if(document.documentElement.mozRequestFullScreen)document.documentElement.mozRequestFullScreen();else if(document.documentElement.webkitRequestFullScreen)document.documentElement.webkitRequestFullScreen();else return b.onFail()},exit:function(){document.exitFullscreen?
    document.exitFullscreen():document.mozCancelFullScreen?document.mozCancelFullScreen():document.webkitCancelFullScreen&&document.webkitCancelFullScreen()}};return c.run.call(this)}})(jQuery);
  3. arkadylukashov created this gist Dec 19, 2012.
    66 changes: 66 additions & 0 deletions jquery.fullscreen.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,66 @@
    (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()) {
    selector[0].innerText = settings.exit;
    return methods.enter();
    } 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();
    }
    else if (document.documentElement.mozRequestFullScreen) {
    document.documentElement.mozRequestFullScreen();
    }
    else if (document.documentElement.webkitRequestFullScreen) {
    document.documentElement.webkitRequestFullScreen();
    }
    else {
    return settings.onFail();
    }
    },

    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)