1
0
mirror of https://github.com/webslides/WebSlides.git synced 2025-08-17 18:37:00 +02:00

Merge pull request #84 from solilokiam/create-fullscreen-key

Fullscreen mode
This commit is contained in:
Antonio Laguna
2017-06-06 18:24:30 +02:00
committed by GitHub
5 changed files with 45 additions and 1 deletions

View File

@@ -417,6 +417,32 @@ export default class WebSlides {
return this.el.classList.contains(CLASSES.DISABLED); return this.el.classList.contains(CLASSES.DISABLED);
} }
/**
* Puts the browser into fullscreen
*/
fullscreen() {
const el = document.documentElement;
const isFullscreen = document.fullscreen
|| document.webkitIsFullScreen
|| document.mozFullScreen
|| document.msFullScreenElement;
if(!isFullscreen) {
const requestFullscreen = el.requestFullscreen
|| el.webkitRequestFullScreen
|| el.mozRequestFullScreen
|| el.msRequestFullscreen;
requestFullscreen.call(el);
} else {
const cancelFullscreen = document.exitFullScreen
|| document.webkitCancelFullScreen
|| document.mozCancelFullScreen
|| document.msExitFullscreen;
cancelFullscreen.call(document);
}
}
/** /**
* Registers a plugin to be loaded when the instance is created. It allows * Registers a plugin to be loaded when the instance is created. It allows
* (on purpose) to replace default plugins. * (on purpose) to replace default plugins.

View File

@@ -61,6 +61,9 @@ export default class Keyboard {
case Keys.RIGHT: case Keys.RIGHT:
method = !this.ws_.isVertical ? this.ws_.goNext : null; method = !this.ws_.isVertical ? this.ws_.goNext : null;
break; break;
case Keys.F:
method = this.ws_.fullscreen;
break;
} }
if (method) { if (method) {

View File

@@ -11,7 +11,8 @@ const Keys = {
DOWN: 40, DOWN: 40,
PLUS: [107, 171], PLUS: [107, 171],
MINUS: [109, 173], MINUS: [109, 173],
ESCAPE: 27 ESCAPE: 27,
F: 70
}; };
export default Keys; export default Keys;

View File

@@ -72,4 +72,14 @@ test('WebSlides utility', () => {
expect(webslides.isDisabled()).toBe(true); expect(webslides.isDisabled()).toBe(true);
webslides.enable(); webslides.enable();
expect(webslides.isDisabled()).toBe(false); expect(webslides.isDisabled()).toBe(false);
document.fullscreen = false;
document.documentElement.requestFullscreen = jest.fn();
document.exitFullScreen = jest.fn();
webslides.fullscreen();
expect(document.documentElement.requestFullscreen.mock.calls.length).toBe(1);
document.fullscreen = true;
webslides.fullscreen();
expect(document.exitFullScreen.mock.calls.length).toBe(1);
}); });

View File

@@ -22,6 +22,7 @@ test('Keyboard plugin', () => {
const goto = jest.fn(); const goto = jest.fn();
const next = jest.fn(); const next = jest.fn();
const prev = jest.fn(); const prev = jest.fn();
const fullscreen = jest.fn();
const ws = document.getElementById('webslides'); const ws = document.getElementById('webslides');
let disabled = true; let disabled = true;
@@ -31,6 +32,7 @@ test('Keyboard plugin', () => {
goNext: next, goNext: next,
goPrev: prev, goPrev: prev,
isVertical: false, isVertical: false,
fullscreen: fullscreen,
isDisabled: () => disabled, isDisabled: () => disabled,
el: ws el: ws
}; };
@@ -61,4 +63,6 @@ test('Keyboard plugin', () => {
expect(prev.mock.calls.length).toBe(2); expect(prev.mock.calls.length).toBe(2);
simulateKeyEvent(document, Keys.RIGHT); simulateKeyEvent(document, Keys.RIGHT);
expect(next.mock.calls.length).toBe(3); expect(next.mock.calls.length).toBe(3);
simulateKeyEvent(document, Keys.F);
expect(fullscreen.mock.calls.length).toBe(1);
}); });