Merge branch 'develop' of https://github.com/Selz/plyr into develop

# Conflicts:
#	dist/plyr.js
This commit is contained in:
Sam Potts 2017-03-25 10:37:21 +11:00
commit 4a2866d05f
3 changed files with 62 additions and 6 deletions

4
dist/plyr.js vendored

File diff suppressed because one or more lines are too long

View File

@ -672,7 +672,12 @@ player.source({
srclang:'en',
src: '/path/to/captions.vtt',
default: true
}]
}],
loopKeyEvents: {
toggleLoop: 76,
loopin: 73,
loopout: 79
}
});
```
@ -988,6 +993,21 @@ By default, a player will bind the following keyboard shortcuts when it has focu
<td></td>
<td>Toggle captions</td>
</tr>
<tr>
<td><code>l</code></td>
<td></td>
<td>Toggle Loop All/No Loop</td>
</tr>
<tr>
<td><code>i</code></td>
<td></td>
<td>Set the start marker of the loop</td>
</tr>
<tr>
<td><code>o</code></td>
<td></td>
<td>Set the end marker of the loop</td>
</tr>
</tbody>
</table>

View File

@ -2471,7 +2471,7 @@
// Toggle loop
function toggleLoop(type) {
if (!inArray(['start', 'end', 'all'], type)) {
if (!inArray(['start', 'end', 'all', 'toggle'], type)) {
type = 'none';
}
@ -2496,11 +2496,21 @@
case 'all':
config.loop.start = 0;
config.loop.end = plyr.media.duration;
config.loop.end = plyr.media.duration - 2;
config.loop.indicator.start = 0;
config.loop.indicator.end = 100;
break;
case 'toggle':
if (config.loop) {
config.loop.start = 0;
config.loop.end = null;
} else {
config.loop.start = 0;
config.loop.end = plyr.media.duration - 2;
}
break;
default:
config.loop.start = 0;
config.loop.end = null;
@ -3520,6 +3530,9 @@
var allowed = [48, 49, 50, 51, 52, 53, 54, 56, 57, 75, 77, 70, 67];
var count = get().length;
//add also to allowed the keys of looping events
allowed = allowed.concat(Object.values(config.loopKeyEvents));
// Only handle global key press if there's only one player
// and the key is in the allowed keys
// and if the focused element is not editable (e.g. text input)
@ -3565,8 +3578,9 @@
// Which keycodes should we prevent default
var preventDefault = [48, 49, 50, 51, 52, 53, 54, 56, 57, 32, 75, 38, 40, 77, 39, 37, 70, 67];
var checkFocus = [38, 40];
var loopKeyEventsValues = Object.values(config.loopKeyEvents);
if (inArray(checkFocus, code)) {
if (inArray(checkFocus, code) || inArray(loopKeyEventsValues, code)) {
var focused = getFocusElement();
if (is.htmlElement(focused) && getFocusElement().type === "radio") {
@ -3645,6 +3659,28 @@
break;
}
//Loop events
var loopKeyBindings = config.loopKeyEvents;
var hasBindedKey = loopKeyEventsValues.filter(function(el) {
return preventDefault.indexOf(el) > -1;
}).length >= 1;
if (hasBindedKey) {
loopKeyBindings = defaults.loopKeyEvents;
}
switch (code) {
case loopKeyBindings.toggleLoop:
toggleLoop('toggle');
break;
case loopKeyBindings.loopin:
toggleLoop('loopin');
break;
case loopKeyBindings.loopout:
toggleLoop('loopout');
break;
}
// Escape is handle natively when in full screen
// So we only need to worry about non native
if (!support.fullscreen && plyr.isFullscreen && code === 27) {