Skip to content

Commit

Permalink
HFP-1779 Clean up code
Browse files Browse the repository at this point in the history
Use identity operator instead of equality operator
Use constants for video state
  • Loading branch information
otacke committed Apr 1, 2018
1 parent 1f18bdb commit f977a64
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 7 deletions.
3 changes: 2 additions & 1 deletion scripts/html5.js
@@ -1,5 +1,6 @@
/** @namespace H5P */
H5P.VideoHtml5 = (function ($) {
'use strict';

/**
* HTML5 video player for H5P.
Expand Down Expand Up @@ -283,7 +284,7 @@ H5P.VideoHtml5 = (function ($) {
skipRateChange = false;
return; // Avoid firing event when changing back
}
if (H5P.Video.IE11_PLAYBACK_RATE_FIX && playbackRate != video.playbackRate) { // Intentional
if (H5P.Video.IE11_PLAYBACK_RATE_FIX && playbackRate !== video.playbackRate) { // Intentional
// Prevent change in playback rate not triggered by the user
video.playbackRate = playbackRate;
skipRateChange = true;
Expand Down
1 change: 1 addition & 0 deletions scripts/video.js
@@ -1,5 +1,6 @@
/** @namespace H5P */
H5P.Video = (function ($, ContentCopyrights, MediaCopyright, handlers) {
'use strict';

/**
* The ultimate H5P video player!
Expand Down
14 changes: 8 additions & 6 deletions scripts/youtube.js
@@ -1,5 +1,7 @@
/** @namespace H5P */

H5P.VideoYouTube = (function ($) {
'use strict'

/**
* YouTube video player for H5P.
Expand Down Expand Up @@ -105,7 +107,7 @@ H5P.VideoYouTube = (function ($) {
}
},
onStateChange: function (state) {
if (state.data > -1 && state.data < 4) {
if (state.data >= H5P.Video.ENDED && state.data <= H5P.Video.BUFFERING) {

// Fix for keeping playback rate in IE11
if (H5P.Video.IE11_PLAYBACK_RATE_FIX && state.data === H5P.Video.PLAYING && playbackRate !== 1) {
Expand All @@ -118,19 +120,19 @@ H5P.VideoYouTube = (function ($) {
self.trigger('stateChange', state.data);

// Calls for xAPI events.
if (state.data === 1) {
if (state.data === H5P.Video.PLAYING) {
// Get and send play call when not seeking.
if (self.seeking === false) {
self.trigger('play', self.videoXAPI.getArgsXAPIPlayed(player.getCurrentTime()));
}
}
else if (state.data === 2) {
else if (state.data === H5P.Video.PAUSED) {
// This is a paused event.
if (self.seeking === false && self.previousState !== 3) {
if (self.seeking === false && self.previousState !== H5P.Video.BUFFERING) {
self.trigger('paused', self.videoXAPI.getArgsXAPIPaused(player.getCurrentTime(), self.duration));
}
}
else if (state.data === 0) {
else if (state.data === H5P.Video.ENDED) {
// Send xapi trigger if video progress indicates finished.
var length = self.duration;
if (length > 0) {
Expand Down Expand Up @@ -214,7 +216,7 @@ H5P.VideoYouTube = (function ($) {
break;
}

return (returnType.toLowerCase().trim()=='width') ? width : height;
return (returnType.toLowerCase().trim() === 'width') ? width : height;
};

/**
Expand Down

0 comments on commit f977a64

Please sign in to comment.