Skip to content

Commit

Permalink
handle out-of-bound markers more gracefully (hide them)
Browse files Browse the repository at this point in the history
  • Loading branch information
spchuang committed Dec 13, 2017
1 parent 490308b commit f401c74
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 14 deletions.
2 changes: 1 addition & 1 deletion demo/example.html
Original file line number Diff line number Diff line change
Expand Up @@ -105,7 +105,7 @@
text: ":)"
},
{
time: 999,
time: 300,
text: "too far"
}
]
Expand Down
12 changes: 7 additions & 5 deletions dist/videojs-markers.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion dist/videojs-markers.js.map

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion dist/videojs-markers.min.js

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

14 changes: 8 additions & 6 deletions src/videojs.markers.js
Original file line number Diff line number Diff line change
Expand Up @@ -184,6 +184,12 @@ function registerVideoJsMarkersPlugin(options) {
markerDiv.style[key] = setting.markerStyle[key];
});

// hide out-of-bound markers
const ratio = marker.time / player.duration();
if (ratio < 0 || ratio > 1) {
markerDiv.style.display = 'none';
}

// set position
markerDiv.style.left = getPosition(marker) + '%';
if (marker.duration) {
Expand All @@ -195,11 +201,7 @@ function registerVideoJsMarkersPlugin(options) {
}
}

function createMarkerDiv(marker: Marker): ?Object {
var ratio = marker.time / player.duration();
if (ratio < 0 || ratio > 1) {
return null;
}
function createMarkerDiv(marker: Marker): Object {

var markerDiv = videojs.createEl('div', {}, {
'data-marker-key': marker.key,
Expand Down Expand Up @@ -433,7 +435,7 @@ function registerVideoJsMarkersPlugin(options) {

// remove existing markers if already initialized
player.markers.removeAll();
addMarkers(options.markers);
addMarkers(setting.markers);

if (setting.breakOverlay.display) {
initializeOverlay();
Expand Down

0 comments on commit f401c74

Please sign in to comment.