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

Implement vjs-ended class #1857

Closed
wants to merge 2 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
4 changes: 4 additions & 0 deletions src/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -389,6 +389,8 @@ vjs.Player.prototype.unloadTech = function(){
vjs.Player.prototype.onLoadStart = function() {
// TODO: Update to use `emptied` event instead. See #1277.

this.removeClass('vjs-ended');

// reset the error state
this.error(null);

Expand Down Expand Up @@ -446,6 +448,7 @@ vjs.Player.prototype.onLoadedAllData;
* @event play
*/
vjs.Player.prototype.onPlay = function(){
this.removeClass('vjs-ended');
this.removeClass('vjs-paused');
this.addClass('vjs-playing');

Expand Down Expand Up @@ -540,6 +543,7 @@ vjs.Player.prototype.onProgress = function(){
* @event ended
*/
vjs.Player.prototype.onEnded = function(){
this.addClass('vjs-ended');
if (this.options_['loop']) {
this.currentTime(0);
this.play();
Expand Down
20 changes: 20 additions & 0 deletions test/unit/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -483,6 +483,26 @@ test('should remove vjs-has-started class', function(){
ok(player.el().className.indexOf('vjs-has-started') !== -1, 'vjs-has-started class added again');
});

test('should add and remove vjs-ended class', function() {
expect(4);

var player = PlayerTest.makePlayer({});

player.trigger('loadstart');
player.trigger('play');
player.trigger('ended');
ok(player.el().className.indexOf('vjs-ended') !== -1, 'vjs-ended class added');

player.trigger('play');
ok(player.el().className.indexOf('vjs-ended') === -1, 'vjs-ended class removed');

player.trigger('ended');
ok(player.el().className.indexOf('vjs-ended') !== -1, 'vjs-ended class re-added');

player.trigger('loadstart');
ok(player.el().className.indexOf('vjs-ended') === -1, 'vjs-ended class removed');
});

test('player should handle different error types', function(){
expect(8);
var player = PlayerTest.makePlayer({});
Expand Down