2020-05-07 20:10:13 +00:00
|
|
|
import $ from 'jquery'
|
|
|
|
|
2020-04-25 09:01:30 +00:00
|
|
|
/* ===== Globals ====== */
|
2020-05-24 11:20:04 +00:00
|
|
|
// Object is needed for vue proxy
|
|
|
|
window.vol = {
|
|
|
|
preview_max_volume: 100
|
|
|
|
}
|
2020-04-25 09:01:30 +00:00
|
|
|
|
|
|
|
/* ===== Locals ===== */
|
|
|
|
let preview_track = document.getElementById('preview-track')
|
|
|
|
let preview_stopped = true
|
|
|
|
|
|
|
|
// init stuff
|
2020-04-28 18:42:22 +00:00
|
|
|
function init() {
|
2020-04-26 17:33:09 +00:00
|
|
|
preview_track.volume = 1
|
2020-04-25 09:01:30 +00:00
|
|
|
|
2020-04-26 17:33:09 +00:00
|
|
|
// start playing when track loaded
|
|
|
|
preview_track.addEventListener('canplay', function () {
|
|
|
|
preview_track.play()
|
|
|
|
preview_stopped = false
|
2020-06-02 13:25:15 +00:00
|
|
|
$(preview_track).animate({ volume: vol.preview_max_volume / 100 }, 500)
|
2020-04-26 17:33:09 +00:00
|
|
|
})
|
2020-04-25 09:01:30 +00:00
|
|
|
|
2020-04-26 17:33:09 +00:00
|
|
|
// auto fadeout when at the end of the song
|
|
|
|
preview_track.addEventListener('timeupdate', function () {
|
|
|
|
if (preview_track.currentTime > preview_track.duration - 1) {
|
|
|
|
$(preview_track).animate({ volume: 0 }, 800)
|
|
|
|
preview_stopped = true
|
|
|
|
$('a[playing] > .preview_controls').css({ opacity: 0 })
|
|
|
|
$('*').removeAttr('playing')
|
|
|
|
$('.preview_controls').text('play_arrow')
|
|
|
|
$('.preview_playlist_controls').text('play_arrow')
|
|
|
|
}
|
|
|
|
})
|
2020-04-25 09:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// on modal closing
|
2020-04-28 18:42:22 +00:00
|
|
|
function stopStackedTabsPreview() {
|
2020-04-26 17:33:09 +00:00
|
|
|
if (
|
|
|
|
$('.preview_playlist_controls').filter(function () {
|
|
|
|
return $(this).attr('playing')
|
|
|
|
}).length > 0
|
|
|
|
) {
|
|
|
|
$(preview_track).animate({ volume: 0 }, 800)
|
|
|
|
preview_stopped = true
|
|
|
|
$('.preview_playlist_controls').removeAttr('playing')
|
|
|
|
$('.preview_playlist_controls').text('play_arrow')
|
|
|
|
}
|
2020-04-25 09:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// on hover event
|
2020-04-28 18:42:22 +00:00
|
|
|
function previewMouseEnter(e) {
|
2020-06-02 13:25:15 +00:00
|
|
|
console.log('mouse Enter')
|
2020-04-26 17:33:09 +00:00
|
|
|
$(e.currentTarget).css({ opacity: 1 })
|
2020-04-25 09:01:30 +00:00
|
|
|
}
|
2020-04-28 18:42:22 +00:00
|
|
|
|
2020-05-22 22:15:29 +00:00
|
|
|
function previewMouseLeave(event) {
|
|
|
|
const { currentTarget: obj } = event
|
|
|
|
|
2020-04-26 17:33:09 +00:00
|
|
|
if (($(obj).parent().attr('playing') && preview_stopped) || !$(obj).parent().attr('playing')) {
|
|
|
|
$(obj).css({ opacity: 0 }, 200)
|
|
|
|
}
|
2020-04-25 09:01:30 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
// on click event
|
2020-04-28 18:42:22 +00:00
|
|
|
function playPausePreview(e) {
|
2020-04-26 17:33:09 +00:00
|
|
|
e.preventDefault()
|
2020-05-22 22:15:29 +00:00
|
|
|
|
|
|
|
const { currentTarget: obj } = event
|
|
|
|
|
2020-04-26 17:33:09 +00:00
|
|
|
var icon = obj.tagName == 'I' ? $(obj) : $(obj).children('i')
|
2020-06-02 13:25:15 +00:00
|
|
|
|
2020-04-26 17:33:09 +00:00
|
|
|
if ($(obj).attr('playing')) {
|
|
|
|
if (preview_track.paused) {
|
|
|
|
preview_track.play()
|
|
|
|
preview_stopped = false
|
|
|
|
icon.text('pause')
|
2020-06-02 13:25:15 +00:00
|
|
|
$(preview_track).animate({ volume: vol.preview_max_volume / 100 }, 500)
|
2020-04-26 17:33:09 +00:00
|
|
|
} else {
|
|
|
|
preview_stopped = true
|
|
|
|
icon.text('play_arrow')
|
|
|
|
$(preview_track).animate({ volume: 0 }, 250, 'swing', () => {
|
|
|
|
preview_track.pause()
|
|
|
|
})
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
$('*').removeAttr('playing')
|
|
|
|
$(obj).attr('playing', true)
|
|
|
|
$('.preview_controls').text('play_arrow')
|
|
|
|
$('.preview_playlist_controls').text('play_arrow')
|
|
|
|
$('.preview_controls').css({ opacity: 0 })
|
|
|
|
icon.text('pause')
|
|
|
|
icon.css({ opacity: 1 })
|
|
|
|
preview_stopped = false
|
|
|
|
$(preview_track).animate({ volume: 0 }, 250, 'swing', () => {
|
|
|
|
preview_track.pause()
|
|
|
|
$('#preview-track_source').prop('src', $(obj).data('preview'))
|
|
|
|
preview_track.load()
|
|
|
|
})
|
|
|
|
}
|
2020-04-25 09:01:30 +00:00
|
|
|
}
|
2020-04-28 18:42:22 +00:00
|
|
|
|
|
|
|
export default {
|
|
|
|
init,
|
|
|
|
stopStackedTabsPreview,
|
|
|
|
previewMouseEnter,
|
|
|
|
previewMouseLeave,
|
|
|
|
playPausePreview
|
|
|
|
}
|