koel/resources/assets/js/components/shared/song-item.vue

99 lines
2.3 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
<tr
@dblclick.prevent="play"
class="song-item"
:class="{ 'selected': selected, 'playing': playing }"
>
<td class="title">{{ song.title }}</td>
<td class="artist">{{ song.album.artist.name }}</td>
<td class="album">{{ song.album.name }}</td>
<td class="time">{{ song.fmtLength }}</td>
2016-01-06 16:41:59 +00:00
<td class="check"><input type="checkbox" @click.stop="select($event)"></td>
2015-12-13 04:42:28 +00:00
</tr>
</template>
<script>
2016-01-06 16:41:59 +00:00
import $ from 'jquery';
2015-12-13 04:42:28 +00:00
import playback from '../../services/playback';
export default {
props: ['song'],
data() {
return {
playing: false,
};
},
methods: {
/**
* Play the song.
*/
play() {
playback.play(this.song);
},
2016-01-06 16:41:59 +00:00
/**
* Select a row.
*/
select(e) {
if ($(e.target).prop('checked')) {
$(e.target).parents('tr').addClass('selected');
} else {
$(e.target).parents('tr').removeClass('selected');
}
// Let the parent listing know to collect the selected songs.
this.$dispatch('song:selection-changed');
},
2015-12-13 04:42:28 +00:00
},
events: {
/**
* Listen to 'song:play' event and set the "playing" status.
*
2016-01-06 16:41:59 +00:00
* @param {Object} song The current playing song.
2015-12-13 04:42:28 +00:00
*/
'song:play': function (song) {
this.playing = this.song.id === song.id;
return true;
},
},
};
</script>
<style lang="sass">
@import "resources/assets/sass/partials/_vars.scss";
@import "resources/assets/sass/partials/_mixins.scss";
.song-item {
border-bottom: 1px solid $color2ndBgr;
&:hover {
background: rgba(255, 255, 255, .05);
}
.time {
color: $color2ndText;
}
.title {
min-width: 192px;
}
2016-01-06 16:41:59 +00:00
.check {
max-width: 32px;
}
2015-12-13 04:42:28 +00:00
&.selected {
background-color: rgba(255, 255, 255, .08);
}
&.playing {
color: $colorHighlight;
}
}
</style>