Git Product home page Git Product logo

bigscreen's Introduction

BigScreen npm

A simple library for using the JavaScript Fullscreen API.

Why should I use it?

BigScreen makes it easy to use full screen on your site or in your app. It smoothes out browser inconsistencies and bugs, especially if the element you're working with is inside of an <iframe>. It will also intelligently fall back to the older video full screen API if the element contains a <video> and the older API is available.

Download

BigScreen is ~1.4 kb minified and gzipped. Download it now.

Supported Browsers

  • Chrome 15+
  • Firefox 10+
  • Safari 5.1+
  • Internet Explorer 11
  • Opera 12.1+
  • Firefox for Android 18+
  • Chrome for Android 32

These browsers are also supported for video only:

  • Safari 5.0
  • iOS 4.2+
  • Android Browser 2.1+
  • Chrome for Android < 32

(See caniuse for always up-to-date info)

How do I use it?

Put the entire page in full screen

document.getElementById('button').addEventListener('click', function() {
	if (BigScreen.enabled) {
		BigScreen.toggle();
	}
	else {
		// fallback
	}
}, false);

Put any element in full screen

var element = document.getElementById('target');

document.getElementById('button').addEventListener('click', function() {
	if (BigScreen.enabled) {
		BigScreen.request(element, onEnter, onExit, onError);
		// You could also use .toggle(element, onEnter, onExit, onError)
	}
	else {
		// fallback for browsers that don't support full screen
	}
}, false);

Detecting full screen changes globally

BigScreen.onenter = function() {
	// called when the first element enters full screen
}

BigScreen.onchange = function() {
	// called any time the full screen element changes
}

BigScreen.onexit = function() {
	// called when all elements have exited full screen
}

Documentation

BigScreen.request(element[, onEnter, onExit, onError])

Request that an element go into full screen. If the element is falsy, the <body> will be used instead.

You can only call this from a user-initiated event, otherwise the browser will deny the request. That means key, touch, mouse, or pointer events.

In addition, if your page is inside an <iframe> it will need to have the allowfullscreen (and webkitallowfullscreen and mozallowfullscreen) attribute set on the <iframe>.

Finally, BigScreen will try to fall back to full screen for <video> if there is a child <video> in the element you pass and the browser supports it (see BigScreen.videoEnabled)). If BigScreen falls back, it will automatically load the metadata of the video so the video can enter full screen.

You can optionally pass callback functions for when this element enters or exits full screen, or if there is an error entering full screen. For all callbacks, the value of this will be set to the element that was requested. The actual element that entered full screen will be passed as the first parameter to onEnter.

BigScreen.exit()

Will exit full screen. Note that if there are multiple elements in full screen, only the last one will exit full screen.

BigScreen.toggle(element[, onEnter, onExit, onError])

Will request full screen if there is no element in full screen, otherwise it will exit full screen.

BigScreen.onenter(element)

Override to get notified when the first element goes into full screen. This will not fire if subsequent elements are added to the full screen stack (use onchange for that).

BigScreen.onchange(element)

Override to get notified any time the full screen element changes. The element that is currently displaying in full screen will be passed as the first argument.

BigScreen.onexit()

Override to get notified when fully exiting full screen (there are no more elements in full screen).

BigScreen.onerror(element, reason)

Override to get notified if there is an error sending an element into full screen. The possible values for reason are:

  • not_supported: full screen is not supported at all or for this element
  • not_enabled: request was made from a frame that does not have the allowfullscreen attribute, or the user has disabled full screen in their browser (but it is supported)
  • not_allowed: the request failed, probably because it was not called from a user-initiated event

These are the same values passed to individual onError callbacks as well.

BigScreen.element

Set to the element that is currently displaying full screen, or null if no element is in full screen.

BigScreen.enabled

A boolean that will tell you if it is possible to go into full screen. If your page is in an <iframe> it will need to have the allowfullscreen attribute set or this will be false.

BigScreen.videoEnabled(video)

Safari 5.0 and iOS 4.2+ support putting <video> into full screen. BigScreen.enabled will report false in those browsers, but you can use this to check for <video> full screen support by passing the <video> itself, or an ancestor.

This function will report false if there is no child <video>, or if it is not possible to put a <video> in full screen. It will report 'maybe' if it is possible, but the video's metadata has not been loaded, and true if it will be able to enter full screen.

Known Fullscreen API Issues

Safari 6.0 does not work properly when putting multiple elements into full screen. Open Radar bug report.

There is currently a bug in Safari (was in WebKit, but has been fixed and has been merged into Chrome as of 22) that causes the webkitfullscreenchange event to fire incorrectly when inside an iframe. BigScreen is able to work around the issue though. (Safari Bug: rdar://problem/11927884)

Links

License

BigScreen is licensed under the Apache 2.0 license. Copyright 2013 Brad Dougherty.

bigscreen's People

Contributors

bdougherty avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

bigscreen's Issues

BigScreen.Enabled Not Correctly Set in Safari 5.1.x

I've noticed on my iframe content that document.webkitFullscreenEnabled is undefined when using the developer tools in Safari. Thus, using webkitFullscreenEnabled to determine if BigScreen.enabled is true will NOT work.

There may be a better way to fix it, but I would suggest just checking to see if the document.webkitIsFullScreen property exists to determine whether or not the fullscreen API is supported. Here's what I changed to the bigscreen source code to make it work properly in Safari:

Line 12: Added webkitIsFullScreen as one of the properties to check for enabled:

enabled: ['fullscreenEnabled', 'webkitFullscreenEnabled', 'mozFullScreenEnabled', 'msFullscreenEnabled', 'webkitIsFullScreen'],

Line 215: Added a check that enabled is not set to webkitIsFullScreen:

if (iframe && (document[fn.enabled] === false && fn.enabled !== "webkitIsFullScreen")) {

Under line 336, this was added:

if (fn.enabled === 'webkitIsFullScreen'){ return true; }

I've also attached my version to this post. Maybe there is a better way to check for fullscreen support in Safari. BigScreen.enabled should be true for me because 5.1.x does support it, but the document doesn't always have the webkitFullscreenEnabled property. It can be undefined (in my case with iframe content) which means BigScreen will incorrectly say that it does NOT support fullscreen when it does.
bigscreen_modified_safari_detection.zip

Gray screen of death in Safari when fullscreening multiple times

Hey Brad, I wanted to give you a heads up on a possible bug.

When entering and exiting fullscreen mode multiple times in Safari, sometimes a "gray screen of death" overtakes the window. Strangely, the content begin fullscreened still seems to execute (proved, in my case, by still-playing audio from a HTML5 video) but there is no UI anymore and you can't interact with the gray screen.

I believe this bug is separate from the layout issue you describe here: http://openradar.appspot.com/radar?id=1878403

Here's a video: https://www.youtube.com/watch?v=PUT0OAY7S3Q

Steps to reproduce:

  1. Go to multiple fullscreen demo page http://brad.is/reportingbugs/multiplefullscreen/
  2. Click the demo image multiple times

I'll update this issue if I make any progress. Thank you.

component.json to bower.json

Hello,

I am using Brunch witch support bower components, but it demand new version of config file. 'component.json' is deprecated. It should be now 'bower.json'. And compiler of brunch has error.

Could you change it to new supported version?

Iframe > Set Fullscreen Background Color

Having some trouble setting changing an iframe's background color to when in fullscreen mode. I understand that the default background color of the browsers visual environment is black when in fullscreen mode, but it seems it IS possible to override this with css.

http://stackoverflow.com/questions/16163089/background-element-goes-black-when-entering-fullscreen-with-html5

I have been trying to kung-fu this for the last day. Can someone please point me in the right direction?

Please allow other developers to pick up your work and to continue the BigScreen story

@bdougherty Brad, I understand you don't have time to continue work on this library. That's sad, but of course, it's OK Remains the question what to do with that. Would you mind to donate the library to someone else? For instance, I could step in. I'm an experienced open source developer, so I know what I'm offering. I'm offering leisure time I could use to do other things. Even so, I'd happily contribute some of my precious leisure time in order to revive your library.

If you've not ok with this, please do these two things:

  • Take your online demo offline (bad solution), or add a notice that you've abandoned the library and send developers to one of the alternative that are still alive (better solution).
  • Add a short notice to this GitHub project that you've abandoned the project. The readme.md is a good place for that.

Thanks in advance,
Stephan

v2.0.4 throwing "addEventListener" error in IE8

Hello,

I'll hack around it, but I wanted to let you know that I can't just test BigScreen.enabled in IE8 because there is an unchecked use of "addEventListener" in the code that is throwing an error. Therefore BigScreen doesn't exist, and a fatal error occurs when looking for a property on the undefined object.

Thanks!

Noah

onenter and onexit events not being fired in Firefox 45.0

I haven't nailed down why this is happening, but these events are not being fired. This issue affects Firefox only.

I tested this in Firefox 45.0 -- but I suspect this is happening in other versions also.

Here is a minimum test case with jQuery that will reproduce the issue:

function onEnterFullscreen() {
    alert("I don't fire in Firefox!");
}

function onExitFullscreen() {
    alert("I also don't fire in Firefox!");
}

$('#photo-demo img').on('click', function() {
    if (BigScreen.element !== this) {
        BigScreen.request(this, onEnterFullscreen, onExitFullscreen);
    }
    else {
        BigScreen.exit();
    }
}); 

I've tried to write a unit test to reproduce this issue, however the Unit Tests do not actually activate the Fullscreen API because use of the Fullscreen API requires User Interaction.

It is possible to simulate User Interaction with sendEvent in PhantomJS, but other browsers will require an some sort of event handler. I haven't found a way to tell the browser that it's okay to allow Fullscreen API requests without User Interaction.

For my purposes, I'm just going to use an onclick handler and make the test pass and use the resulting lib for my project. However, I'm wondering what solution you'd like me to implement so that the Unit Tests are actually testing the Fullscreen API. Do you use any CI tools? Is an onclick handler acceptable? Can I simulate User Interaction with PhantomJS for the CI tests if there are any?

Thanks!

Webkit issues with fullscreen inside a frameset

I am using an (old fashioned) frameset (not an IFrame). One frame is supposed to host the application and allows various elements to be fullscreened

works fine in firefox but not on webkit

Not working on nested iframe

Hello,

This plugin was working inside iframe but when 2 level of iframe nesting applying on it reruns false on BigScreen.enabled.

Any solution ?

BigScreen.element needs to check for all <video>s

It only checks for the one it knows about called explicitly through request(), but it's possible for a <video> to enter fullscreen automatically when it starts (for example, on the iPhone).

I think the best way is to select all videos when element is called and check each one. That means document[fn.element] should be checked first to avoid unnecessary DOM interaction.

Webkit bug exiting fullscreen from within an iframe.

There's a bug on exiting full screen from within a full-screened iframe nested in a previously full-screened document. This bug shows up in Webkit browsers like Chrome or Opera (I think Safari too). For example, if I have a Youtube video in the document of an iframe, and I make a parent document containing that iframe full screen via Fullscreen API first and then click "Full screen" button in a video then I can't exit the full screen mode properly. Please, see the simplified attached code.

fullscreen-api.zip

Is there a way to bypass this bug?

Foundation 5 (with Orbit Slider) versus BigScreen

Let me edit this into oblivion. Everything is working nicely... or acceptably if not perfectly. Thanks!

(the expanding element needs something like: width: 100%; height: 100%; in order to show nicely once you hit full screen in Chrome -- not required for other browsers, where other elements can be sized)

Your demos no longer work in modern browsers

Just wanted to let you know that the demos on http://brad.is/coding/BigScreen/ no longer work. It seems that you embed the JS files directly from the github repo.

Because GitHub was sick of acting like a faux-cdn, the files are sent with a mime-type of plain/text. Modern browsers will no longer attempt to execute JS that has the wrong mime-type.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.