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

prevent default action for simple html5 media events. fixes #573, fixes #620 (duplicate bug) #630

Closed
wants to merge 5 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions src/js/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,8 +277,9 @@ vjs.trigger = function(elem, event) {
elemData.dispatcher.call(elem, event);
}

// Unless explicitly stopped, recursively calls this function to bubble the event up the DOM.
if (parent && !event.isPropagationStopped()) {
// Unless explicitly stopped or the event does not bubble (e.g. media events)
// recursively calls this function to bubble the event up the DOM.
if (parent && !event.isPropagationStopped() && event.bubbles !== false) {
vjs.trigger(parent, event);

// If at the top of the DOM, triggers the default action unless disabled.
Expand Down
25 changes: 25 additions & 0 deletions test/unit/events.js
Original file line number Diff line number Diff line change
Expand Up @@ -89,3 +89,28 @@ test('should stop immediate propagtion', function(){

vjs.trigger(el, 'test');
});

test('should bubble up DOM unless bubbles == false', function(){
expect(3);

var outer = document.createElement('div');
var inner = outer.appendChild(document.createElement('div'));

// Verify that if bubbles === true, event bubbles up dom.
vjs.on(inner, 'bubbles', function(e){
ok(true, 'Inner listener fired');
});
vjs.on(outer, 'bubbles', function(e){
ok(true, 'Outer listener fired');
});
vjs.trigger(inner, { type:'bubbles', target:inner, bubbles:true });

// Only change 'bubbles' to false, and verify only inner handler is called.
vjs.on(inner, 'nobub', function(e){
ok(true, 'Inner listener fired');
});
vjs.on(outer, 'nobub', function(e){
ok(false, 'Outer listener fired');
});
vjs.trigger(inner, { type:'nobub', target:inner, bubbles:false });
});