-
Notifications
You must be signed in to change notification settings - Fork 6
Fullscreen plugin #80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
86453a4
1d6f75f
4111c29
094219b
06edf36
c175dbe
b8c39b3
919deb3
03728ab
9c03330
8a3d544
a411dad
e5ea306
173fd96
074c13d
ee3e7fc
b8cde17
3c6ffd6
b1e4435
ec1f6b5
e81f300
f63c844
21ef5d2
75e4fe1
a285375
05231bc
d255137
5270945
26b8687
accd3ef
95d02dd
f3a5d33
a9f55f9
49fcf4c
58ea556
93a5240
a4676b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3,6 +3,7 @@ node_modules | |
| docs | ||
| .grunt | ||
| .env | ||
| .DS_Store | ||
| e2e/client.js | ||
| local.log | ||
| .DS_Store | ||
|
|
||
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import { ButtonPlugin } from '../base-plugins/ButtonPlugin'; | ||
| import { Button } from '../ui-elements'; | ||
|
|
||
| /** | ||
| * A Springroll plugin to easily set up togglable fullscreen | ||
| */ | ||
| export class FullScreenPlugin extends ButtonPlugin { | ||
|
|
||
| /** | ||
| * Creates an instance of FullscreenPlugin | ||
| * | ||
| * @param {string | string[]} buttonSelector The selector for the element to be made fullscreen | ||
| */ | ||
| constructor(buttonSelector) { | ||
| super({ | ||
| name: FullScreenPlugin.fullscreenKey | ||
| }); | ||
|
|
||
| this._toggleButtons = []; | ||
| this.iFrame = null; | ||
|
|
||
| this.sendAllProperties = this.sendAllProperties.bind(this); | ||
|
|
||
| if (Array.isArray(buttonSelector)) { | ||
| // If input is an array, join the selectors into one string | ||
| buttonSelector = buttonSelector.join(', '); | ||
| } | ||
|
|
||
| console.log(buttonSelector); | ||
|
|
||
| this.toggleButton = document.querySelectorAll(buttonSelector); | ||
|
|
||
|
|
||
| this.toggleButton.forEach((button) => { | ||
| this._toggleButtons.push(new Button({ | ||
| button: button, | ||
| onClick: this.toggleFullScreen.bind(this), | ||
| channel: FullScreenPlugin.fullscreenKey | ||
| })); | ||
| }); | ||
|
|
||
|
|
||
| document.addEventListener('fullscreenchange', () => { | ||
| this.sendAllProperties(); | ||
|
|
||
| this._toggleButtons.forEach((button) => { | ||
| button.button.classList.toggle('--fullScreen'); | ||
| }); | ||
|
|
||
| }); | ||
| } | ||
|
|
||
| /** | ||
| * @memberof FullScreenPlugin | ||
| */ | ||
| init({ iframe }) { | ||
| this.iFrame = iframe; | ||
| // Handle the features request | ||
| this.client.on( | ||
| 'features', | ||
| function($event) { | ||
| for (let i = 0; i < this.fullscreenElement; i ++) { | ||
| this._toggleButtons[i].displayButton($event.data); | ||
| } | ||
|
|
||
| }.bind(this) | ||
| ); | ||
| } | ||
| /** | ||
| * @memberof FullScreenPlugin | ||
| */ | ||
| start() { | ||
| this.client.on('loaded', this.sendAllProperties); | ||
| this.client.on('loadDone', this.sendAllProperties); | ||
| } | ||
|
|
||
| /** | ||
| * | ||
| * Sends initial fullScreen properties to the application | ||
| * @memberof FullScreenTogglePlugin | ||
| */ | ||
| sendAllProperties() { | ||
| this.sendProperty(FullScreenPlugin.fullscreenKey, document.fullscreenElement != null ? 'true' : 'false'); | ||
| } | ||
|
|
||
| /** | ||
| * Toggles fullscreen on this.iFrame. Must be from a user generated event | ||
| */ | ||
| toggleFullScreen() { | ||
| if (!document.fullscreenElement) { | ||
| this.iFrame.requestFullscreen().then(() => { | ||
| this.sendAllProperties(); | ||
| }).catch((err) => { | ||
| console.log(err); | ||
| }); | ||
| } else { | ||
| document.exitFullscreen(); | ||
| this.sendAllProperties(); | ||
| } | ||
| } | ||
|
|
||
| /** | ||
| * Returns true if there is a fullscreen element and false if not | ||
| * @returns { boolean } | ||
| */ | ||
| get isFullScreen() { | ||
902seanryan marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| return (document.fullscreenElement || // basic | ||
| document.webkitIsFullscreen || //Webkit browsers | ||
| document.mozFullScreen ) // Firefox | ||
| != true; // Ensure boolean output | ||
| } | ||
|
|
||
| /** | ||
| * @readonly | ||
| * @static | ||
| * @memberof FullscreenPlugin | ||
| */ | ||
| static get fullscreenKey() { | ||
| return 'fullScreen'; | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,57 @@ | ||
| import { Container, FullScreenPlugin } from '../index'; | ||
| import { makeButton } from '../../TestingUtils'; | ||
| import { Bellhop } from 'bellhop-iframe'; | ||
|
|
||
| describe('FullScreenPlugin', () => { | ||
| let fs; | ||
| let iframe; | ||
|
|
||
| before(() => { | ||
| document.body.innerHTML = ''; | ||
| const toggleButton = makeButton('toggleButton'); | ||
| document.body.append(toggleButton); | ||
| }); | ||
|
|
||
| it('construct', () => { | ||
| iframe = document.createElement('iframe'); | ||
|
|
||
| iframe.id = 'fullscreen-plugin-iframe'; | ||
| iframe.setAttribute('allow', 'fullscreen'); | ||
|
|
||
| document.body.appendChild(iframe); | ||
|
|
||
| fs = new FullScreenPlugin('#toggleButton'); | ||
|
|
||
| new Container('#fullscreen-plugin-iframe', {plugins: [fs]}).client.trigger( | ||
| 'features' | ||
| ); | ||
|
|
||
| fs.init(document.getElementById('fullscreen-plugin-iframe')); | ||
| fs.preload({ client: new Bellhop() }); | ||
|
|
||
| }); | ||
|
|
||
| it('Plugin should work without any controls', () => { | ||
| //set up empty plugin | ||
| fs = new FullScreenPlugin(); | ||
| fs.preload({ client: new Bellhop() }); | ||
| fs.init(document.getElementById('fullscreen-plugin-iframe')); | ||
| fs.client.trigger('features', {}); | ||
| }); | ||
|
|
||
|
|
||
| it('Plugin should respond to the click event', () => { | ||
|
|
||
| document.body.appendChild(iframe); | ||
| const buttonOne = makeButton('toggleButton'); | ||
| document.body.appendChild(buttonOne); | ||
|
|
||
| fs = new FullScreenPlugin('toggleButton'); | ||
| fs.preload({ client: new Bellhop() }); | ||
|
|
||
| fs.init(document.getElementById('fullscreen-plugin-iframe')); | ||
|
|
||
| buttonOne.click(); | ||
|
|
||
| }); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,18 @@ | ||
|
|
||
| import { ButtonPlugin } from '../base-plugins'; | ||
| import { Button } from'../ui-elements'; | ||
|
|
||
| export class FullScreenPlugin extends ButtonPlugin { | ||
| constructor(buttonSelector: string | string[]); | ||
| toggleButton: HTMLButtonElement | HTMLButtonElement[]; | ||
| targetElement: HTMLElement; | ||
|
|
||
| get toggleButton(): HTMLButtonElement; | ||
| get targetElement(): HTMLButtonElement; | ||
|
|
||
| init(): void; | ||
| start(): void; | ||
|
|
||
| toggleFullScreen():void; | ||
| isFullscreen():void; | ||
| } |
Uh oh!
There was an error while loading. Please reload this page.