koel/resources/assets/js/components/main-wrapper/extra/index.vue

164 lines
5.2 KiB
Vue
Raw Normal View History

2015-12-13 04:42:28 +00:00
<template>
2016-04-05 09:19:20 +00:00
<section id="extra" :class="{ showing: state.showExtraPanel }">
<div class="tabs">
<div class="header clear">
2016-02-08 13:14:51 +00:00
<a @click.prevent="currentView = 'lyrics'"
2016-01-16 18:11:24 +00:00
:class="{ active: currentView === 'lyrics' }">Lyrics</a>
2016-02-08 13:14:51 +00:00
<a @click.prevent="currentView = 'artistInfo'"
2016-01-16 18:11:24 +00:00
:class="{ active: currentView === 'artistInfo' }">Artist</a>
2016-02-08 13:14:51 +00:00
<a @click.prevent="currentView = 'albumInfo'"
2016-01-16 18:11:24 +00:00
:class="{ active: currentView === 'albumInfo' }">Album</a>
</div>
2015-12-13 04:42:28 +00:00
<div class="panes">
2016-06-25 05:24:55 +00:00
<lyrics :song="song" ref="lyrics" v-show="currentView === 'lyrics'"></lyrics>
<artist-info v-if="song.artist.id"
:artist="song.artist"
:mode="'sidebar'"
ref="artist-info"
v-show="currentView === 'artistInfo'">
</artist-info>
2016-06-25 05:24:55 +00:00
<album-info v-if="song.album.id"
:album="song.album"
:mode="'sidebar'"
ref="album-info"
v-show="currentView === 'albumInfo'">
</album-info>
</div>
2015-12-13 04:42:28 +00:00
</div>
</section>
</template>
<script>
import isMobile from 'ismobilejs';
2016-03-31 08:58:46 +00:00
import { invokeMap } from 'lodash';
import $ from 'jquery';
2016-02-08 13:14:51 +00:00
2016-06-25 05:24:55 +00:00
import { event } from '../../../utils';
2015-12-13 04:42:28 +00:00
import lyrics from './lyrics.vue';
2016-03-13 17:00:32 +00:00
import artistInfo from './artist-info.vue';
import albumInfo from './album-info.vue';
2016-04-05 09:19:20 +00:00
import preferences from '../../../stores/preference';
import songStore from '../../../stores/song';
2016-06-05 11:29:49 +00:00
import songInfoService from '../../../services/info/song';
2016-02-08 13:14:51 +00:00
2015-12-13 04:42:28 +00:00
export default {
2016-06-25 05:24:55 +00:00
name: 'main-wrapper--extra--index',
components: { lyrics, artistInfo, albumInfo },
2015-12-13 04:42:28 +00:00
data() {
return {
2016-02-08 13:14:51 +00:00
song: songStore.stub,
2016-04-05 09:19:20 +00:00
state: preferences.state,
currentView: 'lyrics',
2015-12-13 04:42:28 +00:00
};
},
watch: {
/**
* Watch the "showExtraPanel" property to add/remove the corresponding class
* to/from the html tag.
* Some element's CSS can then be controlled based on this class.
*/
2016-04-05 09:19:20 +00:00
'state.showExtraPanel': function (newVal) {
2016-03-20 13:42:33 +00:00
if (newVal && !isMobile.any) {
$('html').addClass('with-extra-panel');
} else {
$('html').removeClass('with-extra-panel');
}
},
},
2016-06-25 05:24:55 +00:00
mounted() {
// On ready, add 'with-extra-panel' class.
2016-03-20 13:42:33 +00:00
if (!isMobile.any) {
$('html').addClass('with-extra-panel');
}
2015-12-13 04:42:28 +00:00
if (isMobile.phone) {
2016-02-08 13:14:51 +00:00
// On a mobile device, we always hide the panel initially regardless of
2015-12-13 04:42:28 +00:00
// the saved preference.
2016-04-05 09:19:20 +00:00
preferences.showExtraPanel = false;
2015-12-13 04:42:28 +00:00
}
},
2015-12-30 04:14:47 +00:00
methods: {
/**
2016-02-08 13:14:51 +00:00
* Reset all self and applicable child components' states.
2015-12-30 04:14:47 +00:00
*/
2016-02-08 13:14:51 +00:00
resetState() {
this.currentView = 'lyrics';
this.song = songStore.stub;
2016-03-31 08:58:46 +00:00
invokeMap(this.$refs, 'resetState');
2015-12-30 04:14:47 +00:00
},
},
2016-06-25 05:24:55 +00:00
created() {
event.on({
'main-content-view:load': view => {
// Hide the panel away if a main view is triggered on mobile.
if (isMobile.phone) {
preferences.showExtraPanel = false;
}
},
2016-06-25 05:24:55 +00:00
'song:played': song => songInfoService.fetch(this.song = song),
2016-06-25 05:24:55 +00:00
'koel:teardown': () => this.resetState(),
});
2015-12-13 04:42:28 +00:00
},
};
</script>
<style lang="sass">
2016-03-13 17:00:32 +00:00
@import "../../../../sass/partials/_vars.scss";
@import "../../../../sass/partials/_mixins.scss";
2016-02-08 13:14:51 +00:00
2015-12-13 04:42:28 +00:00
#extra {
2016-01-12 14:53:15 +00:00
flex: 0 0 $extraPanelWidth;
padding: 24px 16px $footerHeight;
2015-12-13 04:42:28 +00:00
background: $colorExtraBgr;
max-height: calc(100vh - #{$headerHeight + $footerHeight});
display: none;
color: $color2ndText;
2016-02-24 13:29:23 +00:00
overflow: auto;
2016-03-13 03:28:43 +00:00
-ms-overflow-style: -ms-autohiding-scrollbar;
2016-02-24 13:29:23 +00:00
2016-03-13 03:28:43 +00:00
html.touchevents & {
2016-02-24 13:29:23 +00:00
// Enable scroll with momentum on touch devices
overflow-y: scroll;
-webkit-overflow-scrolling: touch;
}
2015-12-13 04:42:28 +00:00
&.showing {
display: block;
}
h1 {
font-weight: $fontWeight_UltraThin;
2016-06-02 09:46:01 +00:00
font-size: 2.2rem;
2015-12-13 04:42:28 +00:00
margin-bottom: 16px;
2016-06-02 09:46:01 +00:00
line-height: 2.8rem;
2015-12-13 04:42:28 +00:00
}
@media only screen and (max-width : 1024px) {
2015-12-13 04:42:28 +00:00
position: fixed;
height: calc(100vh - #{$headerHeight + $footerHeight});
padding-bottom: $footerHeight; // make sure the footer can never overlap the content
width: $extraPanelWidth;
2015-12-13 04:42:28 +00:00
z-index: 5;
top: $headerHeight;
right: -100%;
transition: right .3s ease-in;
2015-12-13 04:42:28 +00:00
&.showing {
right: 0;
2015-12-13 04:42:28 +00:00
}
}
@media only screen and (max-width : 667px) {
2015-12-13 04:42:28 +00:00
width: 100%;
}
}
</style>