aboutsummaryrefslogtreecommitdiffstats
path: root/src/js/listeners.js
diff options
context:
space:
mode:
authorSam Potts <sam@potts.es>2018-03-27 23:43:38 +1100
committerSam Potts <sam@potts.es>2018-03-27 23:43:38 +1100
commit7b1e4abda7058c602c6d542ea2e12f0cba4fa332 (patch)
treeecc9c4c5b5a3468fe29d6ea054085ac4440d7b46 /src/js/listeners.js
parent0cf75eed3f8ec982300b2abdfd0347f638f83205 (diff)
downloadplyr-7b1e4abda7058c602c6d542ea2e12f0cba4fa332.tar.lz
plyr-7b1e4abda7058c602c6d542ea2e12f0cba4fa332.tar.xz
plyr-7b1e4abda7058c602c6d542ea2e12f0cba4fa332.zip
Controls fixes
Diffstat (limited to 'src/js/listeners.js')
-rw-r--r--src/js/listeners.js19
1 files changed, 17 insertions, 2 deletions
diff --git a/src/js/listeners.js b/src/js/listeners.js
index 888202c2..a0edc7c6 100644
--- a/src/js/listeners.js
+++ b/src/js/listeners.js
@@ -17,6 +17,7 @@ class Listeners {
this.handleKey = this.handleKey.bind(this);
this.toggleMenu = this.toggleMenu.bind(this);
+ this.firstTouch = this.firstTouch.bind(this);
}
// Handle key presses
@@ -187,6 +188,17 @@ class Listeners {
controls.toggleMenu.call(this.player, event);
}
+ // Device is touch enabled
+ firstTouch() {
+ this.player.touch = true;
+
+ // Add touch class
+ utils.toggleClass(this.player.elements.container, this.player.config.classNames.isTouch, true);
+
+ // Clean up
+ utils.off(document.body, 'touchstart', this.firstTouch);
+ }
+
// Global window & document listeners
global(toggle = true) {
// Keyboard shortcuts
@@ -196,6 +208,9 @@ class Listeners {
// Click anywhere closes menu
utils.toggleListener(document.body, 'click', this.toggleMenu, toggle);
+
+ // Detect touch by events
+ utils.on(document.body, 'touchstart', this.firstTouch);
}
// Container listeners
@@ -288,7 +303,7 @@ class Listeners {
// On click play, pause ore restart
utils.on(wrapper, 'click', () => {
// Touch devices will just show controls (if we're hiding controls)
- if (this.player.config.hideControls && support.touch && !this.player.paused) {
+ if (this.player.config.hideControls && this.player.touch && !this.player.paused) {
return;
}
@@ -538,7 +553,7 @@ class Listeners {
if (this.player.config.hideControls) {
// Watch for cursor over controls so they don't hide when trying to interact
on(this.player.elements.controls, 'mouseenter mouseleave', event => {
- this.player.elements.controls.hover = event.type === 'mouseenter';
+ this.player.elements.controls.hover = !this.player.touch && event.type === 'mouseenter';
});
// Watch for cursor over controls so they don't hide when trying to interact