Skip to content

Commit b02181b

Browse files
tiagofragosogkatsev
authored andcommitted
feat: Add vjs-touch-enabled class for touch supporting devices (videojs#5663)
Fixes videojs#2999
1 parent 874cc21 commit b02181b

File tree

2 files changed

+22
-4
lines changed

2 files changed

+22
-4
lines changed

src/js/player.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -501,9 +501,11 @@ class Player extends Component {
501501

502502
// TODO: Make this smarter. Toggle user state between touching/mousing
503503
// using events, since devices can have both touch and mouse events.
504-
// if (browser.TOUCH_ENABLED) {
505-
// this.addClass('vjs-touch-enabled');
506-
// }
504+
// TODO: Make this check be performed again when the window switches between monitors
505+
// (See https://github.com/videojs/video.js/issues/5683)
506+
if (browser.TOUCH_ENABLED) {
507+
this.addClass('vjs-touch-enabled');
508+
}
507509

508510
// iOS Safari has broken hover handling
509511
if (!browser.IS_IOS) {

test/unit/player.test.js

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -633,7 +633,23 @@ QUnit.test('should add a touch-enabled classname when touch is supported', funct
633633

634634
const player = TestHelpers.makePlayer({});
635635

636-
assert.ok(player.el().className.indexOf('vjs-touch-enabled'), 'touch-enabled classname added');
636+
assert.notEqual(player.el().className.indexOf('vjs-touch-enabled'), -1, 'touch-enabled classname added');
637+
638+
browser.TOUCH_ENABLED = origTouch;
639+
player.dispose();
640+
});
641+
642+
QUnit.test('should not add a touch-enabled classname when touch is not supported', function(assert) {
643+
assert.expect(1);
644+
645+
// Fake not having touch support in case that the browser running the test supports it
646+
const origTouch = browser.TOUCH_ENABLED;
647+
648+
browser.TOUCH_ENABLED = false;
649+
650+
const player = TestHelpers.makePlayer({});
651+
652+
assert.equal(player.el().className.indexOf('vjs-touch-enabled'), -1, 'touch-enabled classname not added');
637653

638654
browser.TOUCH_ENABLED = origTouch;
639655
player.dispose();

0 commit comments

Comments
 (0)