Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
86453a4
Container plugin functional
wrbright Nov 27, 2020
1d6f75f
Fullscreen plugin tested and karma testing added
wrbright Dec 4, 2020
4111c29
Readme header renamed
wrbright Dec 4, 2020
094219b
Package.json rollu moved back to origional version
wrbright Dec 4, 2020
06edf36
package-lock.json updated
wrbright Dec 4, 2020
c175dbe
Spacing corrected
wrbright Dec 4, 2020
b8c39b3
Git added typescript files. Built project again
wrbright Dec 4, 2020
919deb3
Built Again w/ e2e flag
wrbright Dec 4, 2020
03728ab
Trying to push fullscreen by adding a space
wrbright Dec 4, 2020
9c03330
Trying to break
wrbright Dec 4, 2020
8a3d544
Fixed the file
wrbright Dec 4, 2020
a411dad
Removed console logs
wrbright Dec 4, 2020
e5ea306
Added Changelog
wrbright Dec 8, 2020
173fd96
Git ignore addition and whitespace in readme removed
wrbright Dec 8, 2020
074c13d
Formatting, removed commenting, renamed typescript class
wrbright Dec 8, 2020
ee3e7fc
Changed class and how fullScreenElement is selected
wrbright Dec 18, 2020
b8cde17
Fullscreen class cleaned up, README updates
wrbright Dec 21, 2020
3c6ffd6
Testing Updated
wrbright Dec 21, 2020
b1e4435
Testing for fullscreen plugin updated
wrbright Dec 21, 2020
ec1f6b5
Testing and plugin updated
wrbright Dec 21, 2020
e81f300
Removed changes to userDataClass moved to new branch
wrbright Dec 22, 2020
f63c844
Removed typings brom this branch for userData additions
wrbright Dec 22, 2020
21ef5d2
pre-merge commit
wrbright Jan 8, 2021
75e4fe1
Merge pull request #1 from SpringRoll/develop
wrbright Jan 8, 2021
a285375
Changes from PR
wrbright Jan 11, 2021
05231bc
Testing updated
wrbright Jan 11, 2021
d255137
testing fixes
wrbright Jan 11, 2021
5270945
Changes from PR
wrbright Jan 11, 2021
26b8687
Prep for merge
wrbright Jan 11, 2021
accd3ef
Re-built
wrbright Jan 12, 2021
95d02dd
Merge branch 'develop' of https://github.com/SpringRoll/SpringRollCon…
wrbright Jan 12, 2021
f3a5d33
Merge branch 'SpringRoll-develop' into fullscreenPlugin
wrbright Jan 12, 2021
a9f55f9
More PR Changes
wrbright Jan 12, 2021
49fcf4c
Fixed redundant properties in plugin
wrbright Jan 12, 2021
58ea556
Readme Update
wrbright Jan 12, 2021
93a5240
Grammer
wrbright Jan 12, 2021
a4676b7
Changes from PR
wrbright Jan 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ node_modules
docs
.grunt
.env
.DS_Store
e2e/client.js
local.log
.DS_Store
Expand Down
7 changes: 6 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## [2.1.1] - UNRELEASED
### Added
- This CHANGELOG
- update NPM modules to remove security vulnerabilities
- Fullscreen Plugin. The ability to add in a fullscreen button within container
- Fullscreen Plugin Automated Testing
- Fullscreen Plugin Documentation


- update NPM modules to remove security vulnerabilities
50 changes: 50 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -359,6 +359,56 @@ container.openPath('game.html');
any unsupported values. See [the SpringRoll Application Class docs](https://github.com/SpringRoll/SpringRoll/tree/v2/src#handling-state-change)
for more information on the request format.

### Fullscreen Plugin
The fullscreen plugin hooks up an element or elements to set the iframe to full screen then communicates this through Bellhop. The plugin will also add the class ```'--fullScreen'``` to the element(s) given

```javascript
import { FullScreenPlugin, Container } from 'springroll-container';

const container = new Container('#game', {

plugins: [
// FullScreenPlugin expects the selector for the element(s) to hook onto
new FullScreenPlugin('#fullScreenButton'),
]
});

container.openPath('game.html');

```

The plugin will accept either a selector or an array of selectors as a parameter

```javascript
new FullScreenPlugin('#fullScreenButton');
new FullScreenPlugin(['#fullScreenButton', '.fullScreenButtonSideNav']);

// It will also accept one string with all selectors each seperated by a comma
new FullScreenPlugin('#fullScreenButton, .fullScreenButtonSideNav');


```

The typical html can look something like this however, the element may be positioned anywhere in the html as long as it is not inside the iframe


```html

<nav>
<!-- May be a button or any other element that can create an onclick event -->
<button id='fullScreenButton'>Fullscreen</button>
</nav>
<!-- The element cannot be inside the source file -->
<iframe id="game" scrolling="no"></iframe>


```
isFullScreen returns true if there is a fullscreen element
`` FullScreenPlugin.isFullScreen ``


---

### Multiple Plugin Controls
All Plugins accept one or more HTML elements as controls in their constructor.
For example the SoundPlugin can accept more than one volume slider or button if your set up requires it:
Expand Down
3 changes: 1 addition & 2 deletions dist/SpringRoll-Container-umd.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/SpringRoll-Container-umd.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/SpringRoll-umd.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/SpringRoll-umd.js.map

Large diffs are not rendered by default.

2 changes: 2 additions & 0 deletions dist/SpringRoll.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions dist/SpringRoll.js.map

Large diffs are not rendered by default.

3 changes: 1 addition & 2 deletions dist/index.js

Large diffs are not rendered by default.

1 change: 0 additions & 1 deletion dist/index.js.map

Large diffs are not rendered by default.

121 changes: 121 additions & 0 deletions src/plugins/FullScreenPlugin.js
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() {
return (document.fullscreenElement || // basic
document.webkitIsFullscreen || //Webkit browsers
document.mozFullScreen ) // Firefox
!= true; // Ensure boolean output
}

/**
* @readonly
* @static
* @memberof FullscreenPlugin
*/
static get fullscreenKey() {
return 'fullScreen';
}
}
57 changes: 57 additions & 0 deletions src/plugins/FullScreenPlugin.spec.js
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();

});
});
2 changes: 1 addition & 1 deletion src/plugins/UserDataPlugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ export class UserDataPlugin extends BasePlugin {
onUserDataWrite({ type, data: { name, value } }) {
SavedDataHandler.write(name, value, () => this.client.send(type));
}
}
}
Empty file.
1 change: 1 addition & 0 deletions src/plugins/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,5 @@ export * from './CompletionPercentagePlugin';
export * from './SpeedScalePlugin';
export * from './TimersScalePlugin';
export * from './InputCountPlugin';
export * from './FullScreenPlugin';

3 changes: 2 additions & 1 deletion src/plugins/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,5 @@ import './ObjectCountPlugin.spec';
import './CompletionPercentagePlugin.spec';
import './SpeedScalePlugin.spec';
import './TimersScalePlugin.spec';
import './InputCountPlugin.spec';
import './InputCountPlugin.spec';
import './FullScreenPlugin.spec';
18 changes: 18 additions & 0 deletions typings/plugins/FullScreenPlugin.d.ts
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;
}
1 change: 1 addition & 0 deletions typings/plugins/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,4 @@ export * from './CompletionPercentagePlugin';
export * from './SpeedScalePlugin';
export * from './TimersScalePlugin';
export * from './InputCountPlugin';
export * from './FullScreenPlugin';
Loading