Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Version 1.0. Yeej!

commit f770ce9ec6ebb00852897488493000163b1b9fb2 1 parent 1913bb8
@sindresorhus authored
View
160 dist/screenfull.js
@@ -1,84 +1,110 @@
/*!
* screenfull.js
-* v0.9.0 - 2012-04-19
+* v1.0.0 - 2012-05-02
* https://github.com/sindresorhus/screenfull.js
* (c) Sindre Sorhus; MIT License
*/
-/*global Element:true*/
+/*global Element */
(function( window, document ) {
'use strict';
- var methods = (function() {
- var methodMap = [
- [
- 'requestFullscreen',
- 'exitFullscreen',
- 'fullscreenchange',
- 'fullscreen',
- 'fullscreenElement'
- ],
- [
- 'webkitRequestFullScreen',
- 'webkitCancelFullScreen',
- 'webkitfullscreenchange',
- 'webkitIsFullScreen',
- 'webkitCurrentFullScreenElement'
+ 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'
+ ],
],
- [
- 'mozRequestFullScreen',
- 'mozCancelFullScreen',
- 'mozfullscreenchange',
- 'mozFullScreen',
- 'mozFullScreenElement'
- ]
- ];
- for ( var i = 0, l = methodMap.length; i < l; i++ ) {
- var val = methodMap[i];
- if ( val[1] in document ) {
- return val;
+ 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;
+ elem[ request ]( keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT );
- if ( !methods ) {
- return window.screenfull = false;
+ // Work around Safari 5.1 bug: reports support for
+ // keyboard in fullscreen even though it doesn't.
+ if ( !document.isFullscreen ) {
+ elem[ request ]();
+ }
+ },
+
+ 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;
}
- var keyboardAllowed = 'ALLOW_KEYBOARD_INPUT' in Element;
-
- var screenfull = {
- init: function() {
- document.addEventListener( methods[2], function(e) {
- screenfull.isFullscreen = document[ methods[3] ];
- screenfull.element = document[ methods[4] ];
- screenfull.onchange(e);
- });
- return this;
- },
- isFullscreen: document[ methods[3] ],
- element: document[ methods[4] ],
- request: function( elem ) {
- elem = elem || document.documentElement;
- elem[ methods[0] ]( keyboardAllowed && Element.ALLOW_KEYBOARD_INPUT );
- // Work around Safari 5.1 bug: reports support for keyboard in fullscreen even though it doesn't.
- if ( !document.isFullscreen ) {
- elem[ methods[0] ]();
- }
- },
- exit: function() {
- document[ methods[1] ]();
- },
- toggle: function( elem ) {
- if ( this.isFullscreen ) {
- this.exit();
- } else {
- this.request( elem );
- }
- },
- onchange: function() {}
- };
+ 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.init();
+ window.screenfull = screenfull;
})( window, document );
View
4 dist/screenfull.min.js
@@ -1,7 +1,7 @@
/*!
* screenfull.js
-* v0.9.0 - 2012-04-19
+* v1.0.0 - 2012-05-02
* https://github.com/sindresorhus/screenfull.js
* (c) Sindre Sorhus; MIT License
*/
-(function(a,b){"use strict";var c=function(){var a=[["requestFullscreen","exitFullscreen","fullscreenchange","fullscreen","fullscreenElement"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitfullscreenchange","webkitIsFullScreen","webkitCurrentFullScreenElement"],["mozRequestFullScreen","mozCancelFullScreen","mozfullscreenchange","mozFullScreen","mozFullScreenElement"]];for(var c=0,d=a.length;c<d;c++){var e=a[c];if(e[1]in b)return e}}();if(!c)return a.screenfull=!1;var d="ALLOW_KEYBOARD_INPUT"in Element,e={init:function(){return b.addEventListener(c[2],function(a){e.isFullscreen=b[c[3]],e.element=b[c[4]],e.onchange(a)}),this},isFullscreen:b[c[3]],element:b[c[4]],request:function(a){a=a||b.documentElement,a[c[0]](d&&Element.ALLOW_KEYBOARD_INPUT),b.isFullscreen||a[c[0]]()},exit:function(){b[c[1]]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){}};a.screenfull=e.init()})(window,document);
+(function(a,b){"use strict";var c=typeof Element!="undefined"&&"ALLOW_KEYBOARD_INPUT"in Element,d=function(){var a=[["requestFullscreen","exitFullscreen","fullscreenchange","fullscreen","fullscreenElement","fullscreenerror"],["webkitRequestFullScreen","webkitCancelFullScreen","webkitfullscreenchange","webkitIsFullScreen","webkitCurrentFullScreenElement","webkitfullscreenerror"],["mozRequestFullScreen","mozCancelFullScreen","mozfullscreenchange","mozFullScreen","mozFullScreenElement","mozfullscreenerror"]],c=0,d=a.length,e={},f,g;for(;c<d;c++){f=a[c];if(f&&f[1]in b){for(c=0,g=f.length;c<g;c++)e[a[0][c]]=f[c];return e}}return!1}(),e={isFullscreen:b[d.fullscreen],element:b[d.fullscreenElement],request:function(a){var e=d.requestFullscreen;a=a||b.documentElement,a[e](c&&Element.ALLOW_KEYBOARD_INPUT),b.isFullscreen||a[e]()},exit:function(){b[d.exitFullscreen]()},toggle:function(a){this.isFullscreen?this.exit():this.request(a)},onchange:function(){},onerror:function(){}};if(!d){a.screenfull=null;return}b.addEventListener(d.fullscreenchange,function(a){e.isFullscreen=b[d.fullscreen],e.element=b[d.fullscreenElement],e.onchange.call(e,a)}),b.addEventListener(d.fullscreenerror,function(a){e.onerror.call(e,a)}),a.screenfull=e})(window,document);
View
2  package.json
@@ -1,6 +1,6 @@
{
"name": "screenfull.js",
- "version": "0.9.0",
+ "version": "1.0.0",
"description": "Simple wrapper for cross-browser usage of the Fullscreen API",
"keywords": [
"fullscreen"
View
2  readme.md
@@ -8,7 +8,7 @@ Simple wrapper for cross-browser usage of the JavaScript [Fullscreen API](https:
## Download
-Only 578 bytes gzipped (1321 bytes minified)
+Only 608 bytes gzipped (1380 bytes minified)
Download the [production version][min] or the [development version][max].
Please sign in to comment.
Something went wrong with that request. Please try again.