├── .gitignore ├── README.md ├── webpack.config.js ├── package.json ├── LICENSE ├── index.js ├── index.html └── example.js /.gitignore: -------------------------------------------------------------------------------- 1 | *~ 2 | node_modules 3 | browser-bundle.js -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | react-fullscreen-component 2 | ========================== 3 | 4 | Simple component that let's you create fullscreen toggles 5 | 6 | Run `npm install` and `npm start` to compile the example, then open index.html. -------------------------------------------------------------------------------- /webpack.config.js: -------------------------------------------------------------------------------- 1 | module.exports = { 2 | cache: true, 3 | entry: './example', 4 | output: { 5 | filename: 'browser-bundle.js' 6 | }, 7 | module: { 8 | loaders: [ 9 | {test: /\.js$/, loader: 'jsx-loader'} 10 | ] 11 | } 12 | }; -------------------------------------------------------------------------------- /package.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "react-fullscreen-component", 3 | "version": "0.0.5", 4 | "description": "Simple component that let's you create fullscreen toggles", 5 | "main": "index.js", 6 | "repository": "jeroencoumans/react-fullscreen-component", 7 | "scripts": { 8 | "start": "webpack --progress --colors --watch", 9 | "test": "echo \"Error: no test specified\" && exit 1" 10 | }, 11 | "author": "Jeroen Coumans ", 12 | "license": "MIT", 13 | "dependencies": { 14 | "envify": "^1.*", 15 | "react": "^0.*", 16 | "screenfull": "jeroencoumans/screenfull.js#gh-pages" 17 | }, 18 | "devDependencies": { 19 | "webpack": "^1.*", 20 | "jsx-loader": "^0.*" 21 | } 22 | } 23 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Jeroen Coumans 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. -------------------------------------------------------------------------------- /index.js: -------------------------------------------------------------------------------- 1 | var screenfull = require('screenfull'); 2 | 3 | var FullscreenMixin = { 4 | 5 | getInitialState: function() { 6 | return { 7 | hasFullscreen: false 8 | }; 9 | }, 10 | 11 | componentDidMount: function () { 12 | var enabled = screenfull.enabled; 13 | 14 | if (enabled) { 15 | document.addEventListener(screenfull.raw.fullscreenchange, this.onChangeFullscreen); 16 | 17 | this.setState({ 18 | hasFullscreen: enabled, 19 | isFullscreen: screenfull.isFullscreen, 20 | fullScreenElement: screenfull.element 21 | }); 22 | } 23 | }, 24 | 25 | requestFullscreen: function (ref) { 26 | if (ref && ref.getDOMNode) { 27 | var elem = ref.getDOMNode(); 28 | screenfull.request(elem); 29 | } else { 30 | screenfull.request(); 31 | } 32 | }, 33 | 34 | exitFullscreen: function () { 35 | screenfull.exit(); 36 | }, 37 | 38 | onChangeFullscreen: function (e) { 39 | var isFullscreen = screenfull.isFullscreen; 40 | this.setState({ 41 | isFullscreen: isFullscreen, 42 | fullScreenElement: screenfull.element 43 | }); 44 | 45 | if (isFullscreen) { 46 | typeof this.onEnterFullscreen === 'function' && this.onEnterFullscreen(e); 47 | } else { 48 | typeof this.onExitFullscreen === 'function' && this.onExitFullscreen(e); 49 | } 50 | } 51 | }; 52 | 53 | module.exports = FullscreenMixin; 54 | -------------------------------------------------------------------------------- /index.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | React Fullscreen component 5 | 99 | 100 | 101 |
102 | 103 | 104 | -------------------------------------------------------------------------------- /example.js: -------------------------------------------------------------------------------- 1 | /** @jsx React.DOM */ 2 | var React = require('react'); 3 | var FullscreenMixin = require('./index'); 4 | 5 | if (typeof window !== undefined) { 6 | window.React = React; 7 | } 8 | 9 | var MyComponent = React.createClass({ 10 | mixins: [FullscreenMixin], 11 | getInitialState: function () { 12 | return { 13 | hasIframe: false 14 | } 15 | }, 16 | toggleFullscreen: function (e, ref) { 17 | e.preventDefault(); 18 | 19 | this.state.isFullscreen ? this.exitFullscreen() : this.requestFullscreen(ref ? ref : this.refs.container); 20 | }, 21 | onEnterFullscreen: function (e) { 22 | console.log('Entered fullscreen', e); 23 | }, 24 | onExitFullscreen: function (e) { 25 | console.log('Exited fullscreen', e); 26 | if (this.state.hasIframe) { 27 | this.setState({ hasIframe: false }); 28 | document.body.style.overflow = 'auto'; 29 | } 30 | }, 31 | handleRequest: function () { 32 | this.requestFullscreen(this.refs.container); 33 | }, 34 | handleImg: function (e) { 35 | this.toggleFullscreen(e, this.refs.demoImg); 36 | }, 37 | handleVideo: function (e) { 38 | this.toggleFullscreen(e, this.refs.demoVideo); 39 | }, 40 | handleIframe: function (e) { 41 | if (this.state.isFullscreen) { 42 | this.setState({ hasIframe: true }); 43 | document.body.style.overflow = 'hidden'; 44 | } 45 | }, 46 | renderIframe: function () { 47 | var style = { 48 | 'position': 'absolute', 49 | 'top:': 0, 50 | 'left': 0, 51 | 'bottom': 0, 52 | 'right': 0, 53 | 'width': '100%', 54 | 'height': '100%', 55 | 'display': this.state.hasIframe ? 'block' : 'none' 56 | } 57 | 58 | return this.state.hasIframe ? ( 59 |