Skip to content

Commit

Permalink
Prevent default action for handled media events. Fixes #573 and fixes #…
Browse files Browse the repository at this point in the history
…620 (dup)
  • Loading branch information
Cameron Tangney committed Jul 10, 2013
1 parent fdf7f4f commit 0bdbe02
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions src/js/media/html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ vjs.Html5.prototype.setupTriggers = function(){
// Triggers removed using this.off when disposed

vjs.Html5.prototype.eventHandler = function(e){
// Prevent default action from being called on the target (the video element),
// as all events handled here originated from it. Fixes #620.
e.preventDefault();

this.trigger(e);

// No need for media events to bubble up.
Expand Down
19 changes: 19 additions & 0 deletions test/unit/media.html5.js
Original file line number Diff line number Diff line change
Expand Up @@ -32,4 +32,23 @@ test('should re-link the player if the tech is moved', function(){
tech.createEl();

strictEqual(player, tech.el()['player']);
});

test('should not call default action on media event', function() {
expect(2);
var player = {
id: function() { return 'id'; },
el: function() { return document.createElement('div'); },
options_: {},
trigger: function(event) {
ok(event.type === 'play', 'non-play media event fired');
ok(event.isDefaultPrevented(), 'default action not prevented');
},
ready: function() {}
};
var tech = new vjs.Html5(player, { el: vjs.TEST_VID });
// Mediafaker doesn't support play/pause, so dispatch an event manually.
var event = document.createEvent('CustomEvent');
event.initCustomEvent('play', false /*bubbles*/, true /*cancelable*/, null);
tech.el_.dispatchEvent(event);
});

0 comments on commit 0bdbe02

Please sign in to comment.