Remove jquery from the ft-player component (#2647)

This commit is contained in:
absidue 2022-10-05 10:25:50 +02:00 committed by GitHub
parent ccb980aa0d
commit 5677c3182d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 31 additions and 41 deletions

View File

@ -2,7 +2,6 @@ import Vue from 'vue'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import FtCard from '../ft-card/ft-card.vue' import FtCard from '../ft-card/ft-card.vue'
import $ from 'jquery'
import videojs from 'video.js' import videojs from 'video.js'
import qualitySelector from '@silvermine/videojs-quality-selector' import qualitySelector from '@silvermine/videojs-quality-selector'
import fs from 'fs' import fs from 'fs'
@ -302,8 +301,6 @@ export default Vue.extend({
} }
}, },
mounted: function () { mounted: function () {
this.id = this._uid
const volume = sessionStorage.getItem('volume') const volume = sessionStorage.getItem('volume')
if (volume !== null) { if (volume !== null) {
@ -348,14 +345,13 @@ export default Vue.extend({
}, },
methods: { methods: {
initializePlayer: async function () { initializePlayer: async function () {
const videoPlayer = document.getElementById(this.id) if (typeof this.$refs.video !== 'undefined') {
if (videoPlayer !== null) {
if (!this.useDash) { if (!this.useDash) {
qualitySelector(videojs, { showQualitySelectionLabelInControlBar: true }) qualitySelector(videojs, { showQualitySelectionLabelInControlBar: true })
await this.determineDefaultQualityLegacy() await this.determineDefaultQualityLegacy()
} }
this.player = videojs(videoPlayer, { this.player = videojs(this.$refs.video, {
html5: { html5: {
preloadTextTracks: false, preloadTextTracks: false,
vhs: { vhs: {
@ -957,14 +953,13 @@ export default Vue.extend({
this.selectedMimeType = 'auto' this.selectedMimeType = 'auto'
} }
const qualityItems = $('.quality-item').get() const qualityItems = document.querySelectorAll('.quality-item')
$('.quality-item').removeClass('quality-selected')
qualityItems.forEach((item) => { qualityItems.forEach((item) => {
const qualityText = $(item).find('.vjs-menu-item-text').get(0) item.classList.remove('quality-selected')
const qualityText = item.querySelector('.vjs-menu-item-text')
if (qualityText.innerText === selectedQuality.toLowerCase()) { if (qualityText.innerText === selectedQuality.toLowerCase()) {
$(item).addClass('quality-selected') item.classList.add('quality-selected')
} }
}) })
@ -1182,6 +1177,8 @@ export default Vue.extend({
}, },
toggleVideoLoop: async function () { toggleVideoLoop: async function () {
const loopButton = document.getElementById('loopButton')
if (!this.player.loop()) { if (!this.player.loop()) {
const currentTheme = this.$store.state.settings.mainColor const currentTheme = this.$store.state.settings.mainColor
const colorNames = this.$store.state.utils.colorNames const colorNames = this.$store.state.utils.colorNames
@ -1193,18 +1190,18 @@ export default Vue.extend({
const themeTextColor = await this.calculateColorLuminance(colorValues[nameIndex]) const themeTextColor = await this.calculateColorLuminance(colorValues[nameIndex])
$('#loopButton').addClass('vjs-icon-loop-active') loopButton.classList.add('vjs-icon-loop-active')
if (themeTextColor === '#000000') { if (themeTextColor === '#000000') {
$('#loopButton').addClass('loop-black') loopButton.classList.add('loop-black')
$('#loopButton').removeClass('loop-white') loopButton.classList.remove('loop-white')
} }
this.player.loop(true) this.player.loop(true)
} else { } else {
$('#loopButton').removeClass('vjs-icon-loop-active') loopButton.classList.remove('vjs-icon-loop-active')
$('#loopButton').removeClass('loop-black') loopButton.classList.remove('loop-black')
$('#loopButton').addClass('loop-white') loopButton.classList.add('loop-white')
this.player.loop(false) this.player.loop(false)
} }
}, },
@ -1269,11 +1266,11 @@ export default Vue.extend({
toggleTheatreMode: function() { toggleTheatreMode: function() {
if (!this.player.isFullscreen_) { if (!this.player.isFullscreen_) {
const toggleTheatreModeButton = $('#toggleTheatreModeButton') const toggleTheatreModeButton = document.getElementById('toggleTheatreModeButton')
if (!this.$parent.useTheatreMode) { if (!this.$parent.useTheatreMode) {
toggleTheatreModeButton.addClass('vjs-icon-theatre-active') toggleTheatreModeButton.classList.add('vjs-icon-theatre-active')
} else { } else {
toggleTheatreModeButton.removeClass('vjs-icon-theatre-active') toggleTheatreModeButton.classList.remove('vjs-icon-theatre-active')
} }
} }
@ -1608,8 +1605,8 @@ export default Vue.extend({
this.player.removeClass('vjs-full-screen') this.player.removeClass('vjs-full-screen')
this.player.isFullWindow = false this.player.isFullWindow = false
document.documentElement.style.overflow = this.player.docOrigOverflow document.documentElement.style.overflow = this.player.docOrigOverflow
$('body').removeClass('vjs-full-window') document.body.classList.remove('vjs-full-window')
$('#fullwindow').removeClass('vjs-icon-fullwindow-exit') document.getElementById('fullwindow').classList.remove('vjs-icon-fullwindow-exit')
this.player.trigger('exitFullWindow') this.player.trigger('exitFullWindow')
} else { } else {
this.player.addClass('vjs-full-screen') this.player.addClass('vjs-full-screen')
@ -1617,8 +1614,8 @@ export default Vue.extend({
this.player.isFullWindow = true this.player.isFullWindow = true
this.player.docOrigOverflow = document.documentElement.style.overflow this.player.docOrigOverflow = document.documentElement.style.overflow
document.documentElement.style.overflow = 'hidden' document.documentElement.style.overflow = 'hidden'
$('body').addClass('vjs-full-window') document.body.classList.add('vjs-full-window')
$('#fullwindow').addClass('vjs-icon-fullwindow-exit') document.getElementById('fullwindow').classList.add('vjs-icon-fullwindow-exit')
this.player.trigger('enterFullWindow') this.player.trigger('enterFullWindow')
} }
} }
@ -1629,8 +1626,8 @@ export default Vue.extend({
this.player.isFullWindow = false this.player.isFullWindow = false
document.documentElement.style.overflow = this.player.docOrigOverflow document.documentElement.style.overflow = this.player.docOrigOverflow
this.player.removeClass('vjs-full-screen') this.player.removeClass('vjs-full-screen')
$('body').removeClass('vjs-full-window') document.body.classList.remove('vjs-full-window')
$('#fullwindow').removeClass('vjs-icon-fullwindow-exit') document.getElementById('fullwindow').classList.remove('vjs-icon-fullwindow-exit')
this.player.trigger('exitFullWindow') this.player.trigger('exitFullWindow')
} }
}, },
@ -1644,16 +1641,11 @@ export default Vue.extend({
}, },
hideMouseTimeout: function () { hideMouseTimeout: function () {
if (this.id === '') { if (typeof this.$refs.video !== 'undefined') {
return this.$refs.video.style.cursor = 'default'
}
const videoPlayer = $(`#${this.id} video`).get(0)
if (typeof (videoPlayer) !== 'undefined') {
videoPlayer.style.cursor = 'default'
clearTimeout(this.mouseTimeout) clearTimeout(this.mouseTimeout)
this.mouseTimeout = window.setTimeout(function () { this.mouseTimeout = setTimeout(() => {
videoPlayer.style.cursor = 'none' this.$refs.video.style.cursor = 'none'
}, 2650) }, 2650)
} }
}, },
@ -1694,9 +1686,9 @@ export default Vue.extend({
toggleFullscreenClass: function () { toggleFullscreenClass: function () {
if (this.player.isFullscreen()) { if (this.player.isFullscreen()) {
$('body').addClass('vjs--full-screen-enabled') document.body.classList.add('vjs--full-screen-enabled')
} else { } else {
$('body').removeClass('vjs--full-screen-enabled') document.body.classList.remove('vjs--full-screen-enabled')
} }
}, },

View File

@ -1,7 +1,7 @@
<template> <template>
<div class="relative"> <div class="relative">
<video <video
:id="id" ref="video"
class="ftVideoPlayer video-js vjs-default-skin dark" class="ftVideoPlayer video-js vjs-default-skin dark"
:poster="thumbnail" :poster="thumbnail"
controls controls

View File

@ -1,6 +1,5 @@
import Vue from 'vue' import Vue from 'vue'
import { mapActions } from 'vuex' import { mapActions } from 'vuex'
import $ from 'jquery'
import fs from 'fs' import fs from 'fs'
import ytDashGen from 'yt-dash-manifest-generator' import ytDashGen from 'yt-dash-manifest-generator'
import FtLoader from '../../components/ft-loader/ft-loader.vue' import FtLoader from '../../components/ft-loader/ft-loader.vue'
@ -1214,8 +1213,7 @@ export default Vue.extend({
if (this.$route.fullPath.includes('/watch')) { if (this.$route.fullPath.includes('/watch')) {
const routeId = this.$route.params.id const routeId = this.$route.params.id
if (routeId === videoId) { if (routeId === videoId) {
const activePlayer = $('.ftVideoPlayer video').get(0) this.$refs.videoPlayer.$refs.video.currentTime = watchTime
activePlayer.currentTime = watchTime
} }
} }