API Docs for: 1.0.0-alpha.26
Show:

FullScreenManager Class

Overview

The FullScreenManager object offers a unified API for working with the experimental "fullscreen" mode of various modern browsers. It allows the user to view an element or the whole document in full screen without any visible UI elements.

Compatibility

The FullScreenManager library should work in Chrome 15+, Safari 5.1+, Opera 12.1+, Internet Explorer 11+ and Firefox 10+. It can also be manually enabled in Firefox 9 by setting fullscreen-api.enabled to true in about:config.

Linking and loading

Loading the library is very simple. You just need to link to it in your html file like so:

 <script src="FullScreenManager-1.0.0-alpha.26.min.js"></script>

Doing that will create the FullScreenManager variable in the global scope (under window). Since it's a singleton, there is no need to instantiate anything.

Note: if you are using RequireJS/AMD, nothing will be declared under the window object. Instead, you should simply require the library as usual:

 define(function (require) {
     var FullScreenManager = require('FullScreenManager');
 });

Usage

For security reasons, full screen mode can only be triggered from within an event listener tied to a user interaction. In other words, it can only be activated as a result of the user triggering a mouse or keyboard event. It is not possible to enable full screen mode automatically (during onload for example).

Here is an example of code that will listen for a click anywhere on the document and toggle full screen mode for the whole page:

document.documentElement.onclick = function() {
    FullScreenManager.toggle();
}

You can also specify which element should be made full screen. To do that, you simply pass the element or its id to the FullScreenManager.request() or FullScreenManager.toggle() method:

FullScreenManager.request("myElement");

You can also listen for events. For instance, if you wanted to do something after full screen mode was engaged, you could do that:

FullScreenManager.on('activation', onActivated);

function onActivated(e) {
    console.log("We are now in full screen mode!");
}

Other events such as "deactivation" and "error" also exist. Check the "events" section for more details.

Limitations

By design, navigating to another page, changing tabs, reloading the page, or switching to another application will exit full screen mode. This is a browser limitation.

To enter fullscreen mode from within an iframe, you need to add some attributes on the iframe tag.

<iframe src="x.html" webkitAllowFullScreen mozAllowFullScreen allowFullScreen></iframe>

Methods

activate

(
  • [element]
  • [options]
)
FullScreenManager | Null static chainable

Tries to activate full screen mode for the specified element. If no element is specified or the specified element is not found, the whole document will be used instead. The function accepts an actual Element or an element id.

If full screen mode cannot be activated, false will be returned.

Parameters:

  • [element] Element | String optional

    The id of the element or the actual Element object to make fullscreen.

  • [options] Object optional

    An object holding options to pass to FullScreenManager

    • [cssClass=fullscreen] String optional

      The CSS Class to add to a fullscreen element

    • [scaleMode=???] String optional

      The scaling mode to use

Returns:

FullScreenManager | Null:

The FullScreen object (to allow chaining)

addEventListener

(
  • type
  • listener
  • [data]
)
FullScreenManager static chainable

Attaches an event listener function that will be executed when the specified event occurs. The third parameter makes it possible to pass arbitrary data to the event handling function.

Parameters:

  • type String

    A string identifying the event to attach to. Check the "Events" section of the documentation for a list of supported events.

  • listener Function

    The function that will be executed when the matching event occurs.

  • [data] Object optional

    Arbitrary data to pass to the listener function when triggered.

Returns:

FullScreenManager:

The FullScreenManager object (to allow chaining)

deactivate

() FullScreenManager static chainable

Deactivates full screen mode and returns the browser and document to their normal viewing state.

Returns:

FullScreenManager:

The FullScreenManager object (to allow chaining)

hasEventListener

(
  • [type]
  • [listener]
)
static

Returns true if the specified event listener has been previously attached to the specified event. Returns falseotherwise. If only the type is specified, it returns true, if there is at least one listener defined for that type. If no parameters are defined, it returns true if at least one listener has been defined without regards the which type it was attached to.

Parameters:

  • [type] String optional

    The event type. Check the "Events" section of the documentation for a list of supported events.

  • [listener] Function optional

    The listener function that was previously attached

removeEventListener

(
  • [type]
  • [listener]
)
FullScreenManager static chainable

Removes a previously set event listener. If no parameters are specified, all listeners will be removed. If only the type is specified, all listeners attached to that type will be removed. Finally, if both parameters are specified only a specific listener attached to a specific event type will be removed.

Parameters:

  • [type] String optional

    The event type. Check the "Events" section of the documentation for a list of supported events.

  • [listener] Function optional

    The listener function to remove.

Returns:

FullScreenManager:

The FullScreenManager object (to allow chaining)

toggle

(
  • [element]
)
FullScreenManager static chainable

Toggles full screen mode on and off for the specified element. If no element is specified, full screen mode is toggled for the whole document.

Parameters:

  • [element] Element | String optional

    The id of the element or the actual Element to make fullscreen.

Returns:

FullScreenManager:

The FullScreenManager object (to allow chaining)

Properties

active

Boolean

[read-only] Indicates whether full screen mode is currently activated or not.

Default: false

available

Boolean

[read-only] Indicates whether full screen mode is available in the current environment or not. Typically, full screen mode is available only for a page that has no windowed plugins, and if all <iframe> elements which contain the document have their allowfullscreen attribute set.

cssClass

String

The CSS class that is applied to the fullscreen element. If this property is changed while in fullscreen mode, the fullscreen element will have its class changed.

Default: fullscreen

doNotAlterCss

Boolean

Controls whether the FullScreenManager will alter the CSS to include a class on the fullscreen element and modify its CSS properties to normalize behaviour between different browsers.

Default: false

element

Element

[read-only] The Element that is currently being shown full screen. If no element is currently full screen, this property will be null.

Default: null

keyboardInputAllowed

Boolean

[read-only] Indicates whether the keyboard can be used for input while in fullscreen. This is useful because not all platforms/versions support this.

version

String static

[read-only] Version of the FullScreenManager class.

Events

activation

final

Event triggered once fullscreen mode has been fully activated. You can watch this event by using the FullScreenManager.addEventListener() method.

Event Payload:

  • event Object
    • type String

      The type of event that occurred.

    • target Element

      The target element that triggered the event,

    • data Object

      The actual custom data that was specified when attaching the listener.

deactivation

final

Event triggered once fullscreen mode has been fully deactivated. You can watch this event by using the FullScreenManager.addEventListener() method.

Event Payload:

  • event Object
    • type String

      The type of event that occurred.

    • target Element

      The target element that triggered the event,

    • data Object

      The actual custom data that was specified when attaching the listener.

error

final

Event triggered when an error occurs. You can watch this event by using the FullScreenManager.addEventListener() method.

Event Payload:

  • event Object
    • type String

      The type of event that occurred.

    • target Element

      The target element that triggered the event,

    • error Object

      The actual error.

    • data Object

      The actual custom data that was specified when attaching the listener.