Skip to content

Commit

Permalink
js: remove unused dependency 'videojs.hotkeys.min.js'
Browse files Browse the repository at this point in the history
Support for controlling the player volume by scrolling over it is
still retained by copying over the relevant code part from the
aforementioned library.
  • Loading branch information
leonklingele committed Aug 14, 2019
1 parent a7cd2e5 commit 7b5136c
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 17 deletions.
45 changes: 45 additions & 0 deletions assets/js/player.js
Original file line number Diff line number Diff line change
Expand Up @@ -415,5 +415,50 @@ window.addEventListener('keydown', e => {
}
}, false);

// Add support for controlling the player volume by scrolling over it. Adapted from
// https://github.com/ctd1500/videojs-hotkeys/blob/bb4a158b2e214ccab87c2e7b95f42bc45c6bfd87/videojs.hotkeys.js#L292-L328
(function() {
const volumeStep = 0.05;
const enableVolumeScroll = true;
const enableHoverScroll = true;
const doc = document;
const pEl = document.getElementById('player');

var volumeHover = false;
var volumeSelector = pEl.querySelector('.vjs-volume-menu-button') || pEl.querySelector('.vjs-volume-panel');
if (volumeSelector != null) {
volumeSelector.onmouseover = function() { volumeHover = true; };
volumeSelector.onmouseout = function() { volumeHover = false; };
}

var mouseScroll = function mouseScroll(event) {
var activeEl = doc.activeElement;
if (enableHoverScroll) {
// If we leave this undefined then it can match non-existent elements below
activeEl = 0;
}

// When controls are disabled, hotkeys will be disabled as well
if (player.controls()) {
if (volumeHover) {
if (enableVolumeScroll) {
event = window.event || event;
var delta = Math.max(-1, Math.min(1, (event.wheelDelta || -event.detail)));
event.preventDefault();

if (delta == 1) {
increase_volume(volumeStep);
} else if (delta == -1) {
increase_volume(-volumeStep);
}
}
}
}
};

player.on('mousewheel', mouseScroll);
player.on("DOMMouseScroll", mouseScroll);
}());

// Since videojs-share can sometimes be blocked, we defer it until last
player.share(shareOptions);
2 changes: 0 additions & 2 deletions assets/js/videojs.hotkeys.min.js

This file was deleted.

1 change: 0 additions & 1 deletion src/invidious/views/components/player_sources.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
<script src="/js/video.min.js?v=<%= ASSET_COMMIT %>"></script>
<script src="/js/videojs-contrib-quality-levels.min.js?v=<%= ASSET_COMMIT %>"></script>
<script src="/js/videojs-http-source-selector.min.js?v=<%= ASSET_COMMIT %>"></script>
<script src="/js/videojs.hotkeys.min.js?v=<%= ASSET_COMMIT %>"></script>
<script src="/js/videojs-markers.min.js?v=<%= ASSET_COMMIT %>"></script>
<script src="/js/videojs-share.min.js?v=<%= ASSET_COMMIT %>"></script>
<script src="/js/videojs-vtt-thumbnails.min.js?v=<%= ASSET_COMMIT %>"></script>
Expand Down
14 changes: 0 additions & 14 deletions src/invidious/views/licenses.ecr
Original file line number Diff line number Diff line change
Expand Up @@ -135,20 +135,6 @@
</td>
</tr>

<tr>
<td>
<a href="/js/videojs.hotkeys.min.js?v=<%= ASSET_COMMIT %>">videojs.hotkeys.min.js</a>
</td>

<td>
<a href="http://www.apache.org/licenses/LICENSE-2.0">Apache-2.0-only</a>
</td>

<td>
<a href="https://github.com/ctd1500/videojs-hotkeys"><%= translate(locale, "source") %></a>
</td>
</tr>

<tr>
<td>
<a href="/js/videojs-http-source-selector.min.js?v=<%= ASSET_COMMIT %>">videojs-http-source-selector.min.js</a>
Expand Down

0 comments on commit 7b5136c

Please sign in to comment.