0

i'm trying to achieve this feature of this website:

http://flatfull.com/themes/note/index.html

if you click on the notebook logo in the top left corner you can see that on Safari on Mac OS X (i have tested only on it) put automatically the page in full screen, how i can achieve this feature?

Piero
  • 8,533
  • 18
  • 82
  • 153

1 Answers1

0

This will help you (name it fs.js) and :

/*global Element */
(function( window, document ) {
    'use strict';

    var keyboardAllowed = typeof Element !== 'undefined' && 'ALLOW_KEYBOARD_INPUT' in Element, // IE6 throws without typeof check

        fn = (function() {
            var fnMap = [
                [
                    'requestFullscreen',
                    'exitFullscreen',
                    'fullscreenchange',
                    'fullscreen',
                    'fullscreenElement',
                    'fullscreenerror'
                ],
                [
                    'webkitRequestFullScreen',
                    'webkitCancelFullScreen',
                    'webkitfullscreenchange',
                    'webkitIsFullScreen',
                    'webkitCurrentFullScreenElement',
                    'webkitfullscreenerror'

                ],
                [
                    'mozRequestFullScreen',
                    'mozCancelFullScreen',
                    'mozfullscreenchange',
                    'mozFullScreen',
                    'mozFullScreenElement',
                    'mozfullscreenerror'
                ]
            ],
            i = 0,
            l = fnMap.length,
            ret = {},
            val,
            valLength;

            for ( ; i < l; i++ ) {
                val = fnMap[ i ];
                if ( val && val[1] in document ) {
                    for ( i = 0, valLength = val.length; i < valLength; i++ ) {
                        ret[ fnMap[0][ i ] ] = val[ i ];
                    }
                    return ret;
                }
            }
            return false;
        })(),

        screenfull = {
            isFullscreen: document[ fn.fullscreen ],
            element: document[ fn.fullscreenElement ],

            request: function( elem ) {
                var request = fn.requestFullscreen;

                elem = elem || document.documentElement;

                // Work around Safari 5.1 bug: reports support for
                // keyboard in fullscreen even though it doesn't.
                // Browser sniffing, since the alternative with
                // setTimeout is even worse
                if ( /5\.1[\.\d]* Safari/.test( navigator.userAgent ) ) {
                    elem[ request ]();
                } else {
                    elem[ request ]( keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT );
                }
            },

            exit: function() {
                document[ fn.exitFullscreen ]();
            },

            toggle: function( elem ) {
                if ( this.isFullscreen ) {
                    this.exit();
                } else {
                    this.request( elem );
                }
            },

            onchange: function() {},
            onerror: function() {}
        };

    if ( !fn ) {
        window.screenfull = null;
        return;
    }

    document.addEventListener( fn.fullscreenchange, function( e ) {
        screenfull.isFullscreen = document[ fn.fullscreen ];
        screenfull.element = document[ fn.fullscreenElement ];
        screenfull.onchange.call( screenfull, e );
    });

    document.addEventListener( fn.fullscreenerror, function( e ) {
        screenfull.onerror.call( screenfull, e );
    });

    window.screenfull = screenfull;

})( window, document );
Thomas Ayoub
  • 27,208
  • 15
  • 85
  • 130
  • thanks for the answer, but how i can use it? after i put it in a js file, what i have to do to connect it with the href in html? – Piero Jun 17 '14 at 15:33
  • @Piero : you can see an example [on this site](http://paulund.developpez.com/tutoriels/jquery/full-screen-api/fichiers/demo.html) I let you browse the code. Tell me if you need more help. – Thomas Ayoub Jun 17 '14 at 15:36
  • thanks, i have tried to use it, but on safari doesn't work anything, on Chrome works, the link i provided in the question work both on safari and chrome... – Piero Jun 17 '14 at 15:39