From 9555b80cc08eb930a548e071ff44630f6212a336 Mon Sep 17 00:00:00 2001 From: Gary Katsevman Date: Tue, 12 Mar 2013 11:46:45 -0400 Subject: [PATCH] Make buttons accept tap events as well as click. Prevent mouseevents when touch is available --- src/js/controls.js | 20 +++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/src/js/controls.js b/src/js/controls.js index b543dbbc0..10258ed11 100644 --- a/src/js/controls.js +++ b/src/js/controls.js @@ -42,7 +42,7 @@ vjs.ControlBar = function(player, options){ this.player_.on('touchmove', function() { touchstart = false; }); - this.player_.on('touchend', vjs.bind(this, function() { + this.player_.on('touchend', vjs.bind(this, function(event) { var idx; if (touchstart) { idx = this.el().className.search('fade-in'); @@ -53,6 +53,8 @@ vjs.ControlBar = function(player, options){ } } touchstart = false; + + event.preventDefault(); })); })); }; @@ -104,6 +106,22 @@ vjs.ControlBar.prototype.lockShowing = function(){ vjs.Button = function(player, options){ goog.base(this, player, options); + var touchstart = false; + this.on('touchstart', function() { + touchstart = true; + }); + this.on('touchmove', function() { + touchstart = false; + }); + var self = this; + this.on('touchend', function(event) { + if (touchstart) { + self.onClick(event); + } + event.preventDefault(); + event.stopPropagation(); + }); + this.on('click', this.onClick); this.on('focus', this.onFocus); this.on('blur', this.onBlur);