Skip to content
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

Control text fullscreen fix on ESC #3485

Closed
wants to merge 10 commits into from
20 changes: 17 additions & 3 deletions src/js/control-bar/fullscreen-toggle.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@ import Component from '../component.js';
*/
class FullscreenToggle extends Button {

constructor(player, options) {
super(player, options);
this.on(player, 'fullscreenchange', this.handleFullscreenChange);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

new line after this and before the next comment.


/**
* Allow sub components to stack CSS class names
*
Expand All @@ -21,7 +26,18 @@ class FullscreenToggle extends Button {
buildCSSClass() {
return `vjs-fullscreen-control ${super.buildCSSClass()}`;
}

/**
* Handles Fullscreenchange on the component and change control text accordingly
*
* @method handleFullscreenChange
*/
handleFullscreenChange() {
if (this.player_.isFullscreen()) {
this.controlText('Non-Fullscreen');
} else {
this.controlText('Fullscreen');
}
}
/**
* Handles click for full screen
*
Expand All @@ -30,10 +46,8 @@ class FullscreenToggle extends Button {
handleClick() {
if (!this.player_.isFullscreen()) {
this.player_.requestFullscreen();
this.controlText('Non-Fullscreen');
} else {
this.player_.exitFullscreen();
this.controlText('Fullscreen');
}
}

Expand Down
12 changes: 12 additions & 0 deletions test/unit/controls.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import VolumeControl from '../../src/js/control-bar/volume-control/volume-contro
import MuteToggle from '../../src/js/control-bar/mute-toggle.js';
import PlaybackRateMenuButton from '../../src/js/control-bar/playback-rate-menu/playback-rate-menu-button.js';
import Slider from '../../src/js/slider/slider.js';
import FullscreenToggle from '../../src/js/control-bar/fullscreen-toggle.js';
import TestHelpers from './test-helpers.js';
import document from 'global/document';

Expand Down Expand Up @@ -110,3 +111,14 @@ QUnit.test('should hide playback rate control if it\'s not supported', function(

QUnit.ok(playbackRate.el().className.indexOf('vjs-hidden') >= 0, 'playbackRate is not hidden');
});

QUnit.test('Fullscreen control text should be correct when fullscreenchange is triggered', function() {
const player = TestHelpers.makePlayer();
const fullscreentoggle = new FullscreenToggle(player);
player.isFullscreen(true);
player.trigger('fullscreenchange');
QUnit.equal(fullscreentoggle.controlText(), 'Non-Fullscreen', 'Control Text is correct while switching to fullscreen mode');
player.isFullscreen(false);
player.trigger('fullscreenchange');
QUnit.equal(fullscreentoggle.controlText(), 'Fullscreen', 'Control Text is correct while switching back to normal mode');
});