perf: removed jQuery; chore: updated COMPILE-UI
This commit is contained in:
parent
b00d6e70a6
commit
717a1a87b8
@ -34,6 +34,8 @@ By simply running
|
|||||||
$ npm run dev
|
$ npm run dev
|
||||||
```
|
```
|
||||||
|
|
||||||
|
P.S.: You need to be inside the [deemix-pyweb](https://codeberg.org/RemixDev/deemix-pyweb) repo to have the server working correctly.
|
||||||
|
|
||||||
you will have 3 tasks running at the same time:
|
you will have 3 tasks running at the same time:
|
||||||
- the server
|
- the server
|
||||||
- the [rollup](https://rollupjs.org/guide/en/) watcher pointing to the configured `.js` file and ready to re-bundle
|
- the [rollup](https://rollupjs.org/guide/en/) watcher pointing to the configured `.js` file and ready to re-bundle
|
||||||
|
File diff suppressed because one or more lines are too long
@ -5,9 +5,11 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script>
|
<script>
|
||||||
import $ from 'jquery'
|
// import $ from 'jquery'
|
||||||
import EventBus from '@/utils/EventBus'
|
import EventBus from '@/utils/EventBus'
|
||||||
|
|
||||||
|
import { adjustVolume } from '@/utils/adjust-volume'
|
||||||
|
|
||||||
export default {
|
export default {
|
||||||
data: () => ({
|
data: () => ({
|
||||||
previewStopped: false
|
previewStopped: false
|
||||||
@ -25,90 +27,158 @@ export default {
|
|||||||
await this.$refs.preview.play()
|
await this.$refs.preview.play()
|
||||||
|
|
||||||
this.previewStopped = false
|
this.previewStopped = false
|
||||||
$(this.$refs.preview).animate({ volume: window.vol.preview_max_volume / 100 }, 500)
|
|
||||||
|
await adjustVolume(this.$refs.preview, window.vol.preview_max_volume / 100, { duration: 500 })
|
||||||
|
// $(this.$refs.preview).animate({ volume: window.vol.preview_max_volume / 100 }, 500)
|
||||||
|
// this.$refs.preview.volume = window.vol.preview_max_volume / 100
|
||||||
},
|
},
|
||||||
onTimeUpdate() {
|
async onTimeUpdate() {
|
||||||
// Prevents first time entering in this function
|
// Prevents first time entering in this function
|
||||||
if (isNaN(this.$refs.preview.duration)) return
|
if (isNaN(this.$refs.preview.duration)) return
|
||||||
|
|
||||||
let duration = this.$refs.preview.duration
|
let duration = this.$refs.preview.duration
|
||||||
if (!isFinite(duration)) duration = 30
|
|
||||||
|
if (!isFinite(duration)) {
|
||||||
|
duration = 30
|
||||||
|
}
|
||||||
|
|
||||||
if (duration - this.$refs.preview.currentTime >= 1) return
|
if (duration - this.$refs.preview.currentTime >= 1) return
|
||||||
if (this.previewStopped) return
|
if (this.previewStopped) return
|
||||||
|
|
||||||
$(this.$refs.preview).animate({ volume: 0 }, 800)
|
await adjustVolume(this.$refs.preview, 0, { duration: 800 })
|
||||||
|
// this.$refs.preview.volume = 0
|
||||||
|
// $(this.$refs.preview).animate({ volume: 0 }, 800)
|
||||||
|
|
||||||
this.previewStopped = true
|
this.previewStopped = true
|
||||||
|
|
||||||
$('a[playing] > .preview_controls').css({ opacity: 0 })
|
// $('a[playing] > .preview_controls').css({ opacity: 0 })
|
||||||
$('*').removeAttr('playing')
|
|
||||||
$('.preview_controls').text('play_arrow')
|
document.querySelectorAll('a[playing] > .preview_controls').forEach(control => {
|
||||||
$('.preview_playlist_controls').text('play_arrow')
|
control.style.opacity = 0
|
||||||
|
})
|
||||||
|
|
||||||
|
// $('*').removeAttr('playing')
|
||||||
|
document.querySelectorAll('*').forEach(el => {
|
||||||
|
el.removeAttribute('playing')
|
||||||
|
})
|
||||||
|
|
||||||
|
// $('.preview_controls').text('play_arrow')
|
||||||
|
// $('.preview_playlist_controls').text('play_arrow')
|
||||||
|
document.querySelectorAll('.preview_controls, .preview_playlist_controls').forEach(el => {
|
||||||
|
el.textContent = 'play_arrow'
|
||||||
|
})
|
||||||
},
|
},
|
||||||
playPausePreview(e) {
|
async playPausePreview(e) {
|
||||||
e.preventDefault()
|
e.preventDefault()
|
||||||
e.stopPropagation()
|
e.stopPropagation()
|
||||||
|
|
||||||
const { currentTarget: obj } = event
|
const { currentTarget: obj } = event
|
||||||
|
|
||||||
var $icon = obj.tagName == 'I' ? $(obj) : $(obj).children('i')
|
// var $icon = obj.tagName == 'I' ? $(obj) : $(obj).children('i')
|
||||||
|
var icon = obj.tagName == 'I' ? obj : obj.querySelector('i')
|
||||||
|
|
||||||
if ($(obj).attr('playing')) {
|
// if ($(obj).attr('playing')) {
|
||||||
|
if (obj.hasAttribute('playing')) {
|
||||||
if (this.$refs.preview.paused) {
|
if (this.$refs.preview.paused) {
|
||||||
this.$refs.preview.play()
|
this.$refs.preview.play()
|
||||||
this.previewStopped = false
|
this.previewStopped = false
|
||||||
|
|
||||||
$icon.text('pause')
|
// $icon.text('pause')
|
||||||
|
icon.innerText = 'pause'
|
||||||
|
|
||||||
$(this.$refs.preview).animate({ volume: window.vol.preview_max_volume / 100 }, 500)
|
// this.$refs.preview.volume = window.vol.preview_max_volume / 100
|
||||||
|
await adjustVolume(this.$refs.preview, window.vol.preview_max_volume / 100, { duration: 500 })
|
||||||
|
// $(this.$refs.preview).animate({ volume: window.vol.preview_max_volume / 100 }, 500)
|
||||||
} else {
|
} else {
|
||||||
this.previewStopped = true
|
this.previewStopped = true
|
||||||
|
|
||||||
$icon.text('play_arrow')
|
// $icon.text('play_arrow')
|
||||||
|
icon.innerText = 'play_arrow'
|
||||||
|
|
||||||
$(this.$refs.preview).animate({ volume: 0 }, 250, 'swing', () => {
|
// this.$refs.preview.volume = 0
|
||||||
|
|
||||||
|
await adjustVolume(this.$refs.preview, 0, { duration: 250 })
|
||||||
|
// $(this.$refs.preview).animate({ volume: 0 }, 250, 'swing', () => {
|
||||||
this.$refs.preview.pause()
|
this.$refs.preview.pause()
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
$('*').removeAttr('playing')
|
// $('*').removeAttr('playing')
|
||||||
$(obj).attr('playing', true)
|
document.querySelectorAll('*').forEach(el => {
|
||||||
|
el.removeAttribute('playing')
|
||||||
|
})
|
||||||
|
// $(obj).attr('playing', true)
|
||||||
|
obj.setAttribute('playing', true)
|
||||||
|
|
||||||
$('.preview_controls').text('play_arrow')
|
// $('.preview_controls').text('play_arrow')
|
||||||
$('.preview_playlist_controls').text('play_arrow')
|
// $('.preview_playlist_controls').text('play_arrow')
|
||||||
$('.preview_controls').css({ opacity: 0 })
|
|
||||||
|
|
||||||
$icon.text('pause')
|
document.querySelectorAll('.preview_controls, .preview_playlist_controls').forEach(el => {
|
||||||
$icon.css({ opacity: 1 })
|
el.textContent = 'play_arrow'
|
||||||
|
})
|
||||||
|
|
||||||
|
// $('.preview_controls').css({ opacity: 0 })
|
||||||
|
document.querySelectorAll('.preview_controls').forEach(el => {
|
||||||
|
el.style.opacity = 0
|
||||||
|
})
|
||||||
|
|
||||||
|
// $icon.text('pause')
|
||||||
|
// $icon.css({ opacity: 1 })
|
||||||
|
icon.innerText = 'pause'
|
||||||
|
icon.style.opacity = 1
|
||||||
|
|
||||||
this.previewStopped = false
|
this.previewStopped = false
|
||||||
|
|
||||||
$(this.$refs.preview).animate({ volume: 0 }, 250, 'swing', () => {
|
// this.$refs.preview.volume = 0
|
||||||
|
// $(this.$refs.preview).animate({ volume: 0 }, 250, 'swing', () => {
|
||||||
|
await adjustVolume(this.$refs.preview, 0, { duration: 250 })
|
||||||
this.$refs.preview.pause()
|
this.$refs.preview.pause()
|
||||||
$('#preview-track_source').prop('src', $(obj).data('preview'))
|
|
||||||
|
// $('#preview-track_source').prop('src', $(obj).data('preview'))
|
||||||
|
document.getElementById('preview-track_source').src = obj.getAttribute('data-preview')
|
||||||
|
|
||||||
this.$refs.preview.load()
|
this.$refs.preview.load()
|
||||||
})
|
// })
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
stopStackedTabsPreview() {
|
async stopStackedTabsPreview() {
|
||||||
if (
|
let controls = Array.prototype.slice.call(document.querySelectorAll('.preview_playlist_controls[playing]'))
|
||||||
$('.preview_playlist_controls').filter(function () {
|
|
||||||
return $(this).attr('playing')
|
// $('.preview_playlist_controls').filter(function () {
|
||||||
}).length > 0
|
// return $(this).attr('playing')
|
||||||
) {
|
// }).length
|
||||||
$(this.$refs.preview).animate({ volume: 0 }, 800)
|
|
||||||
|
if (controls.length === 0) return
|
||||||
|
|
||||||
|
// $(this.$refs.preview).animate({ volume: 0 }, 800)
|
||||||
|
await adjustVolume(this.$refs.preview, 0, { duration: 800 })
|
||||||
|
// this.$refs.preview.volume = 0
|
||||||
this.previewStopped = true
|
this.previewStopped = true
|
||||||
$('.preview_playlist_controls').removeAttr('playing')
|
|
||||||
$('.preview_playlist_controls').text('play_arrow')
|
controls.forEach(control => {
|
||||||
}
|
control.removeAttribute('playing')
|
||||||
|
control.innerText = 'play_arrow'
|
||||||
|
})
|
||||||
|
|
||||||
|
// $('.preview_playlist_controls').removeAttr('playing')
|
||||||
|
// $('.preview_playlist_controls').text('play_arrow')
|
||||||
},
|
},
|
||||||
previewMouseEnter(e) {
|
previewMouseEnter(e) {
|
||||||
$(e.currentTarget).css({ opacity: 1 })
|
e.currentTarget.style.opacity = 1
|
||||||
|
// $(e.currentTarget).css({ opacity: 1 })
|
||||||
},
|
},
|
||||||
previewMouseLeave(event) {
|
previewMouseLeave(event) {
|
||||||
const { currentTarget: obj } = event
|
const { currentTarget: obj } = event
|
||||||
|
|
||||||
if (($(obj).parent().attr('playing') && this.previewStopped) || !$(obj).parent().attr('playing')) {
|
const parentIsPlaying = obj.parentElement.hasAttribute('playing')
|
||||||
$(obj).css({ opacity: 0 }, 200)
|
|
||||||
|
// if (($(obj).parent().attr('playing') && this.previewStopped) || !$(obj).parent().attr('playing')) {
|
||||||
|
// $(obj).css({ opacity: 0 }, 200)
|
||||||
|
// }
|
||||||
|
|
||||||
|
if ((parentIsPlaying && this.previewStopped) || !parentIsPlaying) {
|
||||||
|
// $(obj).css({ opacity: 0 }, 200)
|
||||||
|
obj.style.opacity = 0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
28
src/utils/adjust-volume.js
Normal file
28
src/utils/adjust-volume.js
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
// https://stackoverflow.com/questions/7451508/html5-audio-playback-with-fade-in-and-fade-out#answer-13149848
|
||||||
|
export async function adjustVolume(element, newVolume, { duration = 1000, easing = swing, interval = 13 } = {}) {
|
||||||
|
const originalVolume = element.volume
|
||||||
|
const delta = newVolume - originalVolume
|
||||||
|
|
||||||
|
if (!delta || !duration || !easing || !interval) {
|
||||||
|
element.volume = newVolume
|
||||||
|
return Promise.resolve()
|
||||||
|
}
|
||||||
|
|
||||||
|
const ticks = Math.floor(duration / interval)
|
||||||
|
let tick = 1
|
||||||
|
|
||||||
|
return new Promise(resolve => {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
element.volume = originalVolume + easing(tick / ticks) * delta
|
||||||
|
// console.log(element.volume)
|
||||||
|
if (++tick === ticks) {
|
||||||
|
clearInterval(timer)
|
||||||
|
resolve()
|
||||||
|
}
|
||||||
|
}, interval)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
|
export function swing(p) {
|
||||||
|
return 0.5 - Math.cos(p * Math.PI) / 2
|
||||||
|
}
|
@ -1,5 +1,4 @@
|
|||||||
import Toastify from 'toastify-js'
|
import Toastify from 'toastify-js'
|
||||||
import $ from 'jquery'
|
|
||||||
|
|
||||||
import { socket } from '@/utils/socket'
|
import { socket } from '@/utils/socket'
|
||||||
|
|
||||||
@ -8,49 +7,83 @@ let toastsWithId = {}
|
|||||||
export const toast = function(msg, icon = null, dismiss = true, id = null) {
|
export const toast = function(msg, icon = null, dismiss = true, id = null) {
|
||||||
if (toastsWithId[id]) {
|
if (toastsWithId[id]) {
|
||||||
let toastObj = toastsWithId[id]
|
let toastObj = toastsWithId[id]
|
||||||
let toastDOM = $(`div.toastify[toast_id=${id}]`)
|
|
||||||
|
let toastElement = document.querySelectorAll(`div.toastify[toast_id=${id}]`)
|
||||||
|
|
||||||
if (msg) {
|
if (msg) {
|
||||||
toastDOM.find('.toast-message').html(msg)
|
toastElement.forEach(toast => {
|
||||||
|
const messages = toast.querySelectorAll('.toast-message')
|
||||||
|
|
||||||
|
messages.forEach(message => {
|
||||||
|
message.innerHTML = msg
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
if (icon) {
|
if (icon) {
|
||||||
if (icon == 'loading') icon = `<div class="circle-loader"></div>`
|
if (icon == 'loading') {
|
||||||
else icon = `<i class="material-icons">${icon}</i>`
|
icon = `<div class="circle-loader"></div>`
|
||||||
toastDOM.find('.toast-icon').html(icon)
|
} else {
|
||||||
|
icon = `<i class="material-icons">${icon}</i>`
|
||||||
|
}
|
||||||
|
|
||||||
|
toastElement.forEach(toast => {
|
||||||
|
const icons = toast.querySelectorAll('.toast-icon')
|
||||||
|
|
||||||
|
icons.forEach(toastIcon => {
|
||||||
|
toastIcon.innerHTML = icon
|
||||||
|
})
|
||||||
|
})
|
||||||
}
|
}
|
||||||
if (dismiss !== null && dismiss) {
|
if (dismiss !== null && dismiss) {
|
||||||
toastDOM.addClass('dismissable')
|
toastElement.forEach(toast => {
|
||||||
setTimeout(function() {
|
toast.classList.add('dismissable')
|
||||||
|
})
|
||||||
|
|
||||||
|
setTimeout(() => {
|
||||||
toastObj.hideToast()
|
toastObj.hideToast()
|
||||||
|
|
||||||
delete toastsWithId[id]
|
delete toastsWithId[id]
|
||||||
}, 3000)
|
}, 3000)
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
if (icon == null) icon = ''
|
if (icon == null) {
|
||||||
else if (icon == 'loading') icon = `<div class="circle-loader"></div>`
|
icon = ''
|
||||||
else icon = `<i class="material-icons">${icon}</i>`
|
} else if (icon == 'loading') {
|
||||||
|
icon = `<div class="circle-loader"></div>`
|
||||||
|
} else {
|
||||||
|
icon = `<i class="material-icons">${icon}</i>`
|
||||||
|
}
|
||||||
|
|
||||||
let toastObj = Toastify({
|
let toastObj = Toastify({
|
||||||
text: `<span class="toast-icon">${icon}</span><span class="toast-message">${msg}</toast>`,
|
text: `<span class="toast-icon">${icon}</span><span class="toast-message">${msg}</toast>`,
|
||||||
duration: dismiss ? 3000 : 0,
|
duration: dismiss ? 3000 : 0,
|
||||||
gravity: 'bottom',
|
gravity: 'bottom',
|
||||||
position: 'left',
|
position: 'left',
|
||||||
className: dismiss ? 'dismissable' : '',
|
className: dismiss ? 'dismissable' : '',
|
||||||
onClick: function(){
|
onClick: function() {
|
||||||
let dismissable = true
|
let dismissable = true
|
||||||
if (id){
|
|
||||||
|
if (id) {
|
||||||
let toastClasses = document.querySelector(`div.toastify[toast_id=${id}]`).classList
|
let toastClasses = document.querySelector(`div.toastify[toast_id=${id}]`).classList
|
||||||
if (toastClasses){
|
|
||||||
dismissable = Array.from(toastClasses).indexOf('dismissable') != -1
|
if (toastClasses) {
|
||||||
|
dismissable = Array.prototype.slice.call(toastClasses).indexOf('dismissable') != -1
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (toastObj && dismissable) {
|
if (toastObj && dismissable) {
|
||||||
toastObj.hideToast()
|
toastObj.hideToast()
|
||||||
if (id) delete toastsWithId[id]
|
|
||||||
|
if (id) {
|
||||||
|
delete toastsWithId[id]
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}).showToast()
|
}).showToast()
|
||||||
if (id) {
|
if (id) {
|
||||||
toastsWithId[id] = toastObj
|
toastsWithId[id] = toastObj
|
||||||
$(toastObj.toastElement).attr('toast_id', id)
|
|
||||||
|
toastObj.toastElement.setAttribute('toast_id', id)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user