2016-03-27 06:13:17 +00:00
|
|
|
<template>
|
2016-06-25 16:05:24 +00:00
|
|
|
<span class="view-modes">
|
2016-11-17 09:25:58 +00:00
|
|
|
<a class="thumbnails" :class="{ active: mutatedMode === 'thumbnails' }"
|
2016-06-25 16:05:24 +00:00
|
|
|
title="View as thumbnails"
|
|
|
|
@click.prevent="setMode('thumbnails')"><i class="fa fa-th-large"></i></a>
|
2016-11-17 09:25:58 +00:00
|
|
|
<a class="list" :class="{ active: mutatedMode === 'list' }"
|
2016-06-25 16:05:24 +00:00
|
|
|
title="View as list"
|
|
|
|
@click.prevent="setMode('list')"><i class="fa fa-list"></i></a>
|
|
|
|
</span>
|
2016-03-27 06:13:17 +00:00
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2016-06-25 16:05:24 +00:00
|
|
|
import isMobile from 'ismobilejs';
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
import { event } from '../../utils';
|
|
|
|
import { preferenceStore as preferences } from '../../stores';
|
2016-06-25 05:24:55 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
export default {
|
|
|
|
props: ['mode', 'for'],
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
mutatedMode: this.mode,
|
|
|
|
};
|
|
|
|
},
|
2016-06-25 05:24:55 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
computed: {
|
|
|
|
/**
|
|
|
|
* The preference key for local storage for persistent mode.
|
|
|
|
*
|
|
|
|
* @return {string}
|
|
|
|
*/
|
|
|
|
preferenceKey() {
|
|
|
|
return `${this.for}ViewMode`;
|
|
|
|
},
|
|
|
|
},
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
methods: {
|
|
|
|
setMode(mode) {
|
|
|
|
preferences[this.preferenceKey] = this.mutatedMode = mode;
|
|
|
|
this.$parent.changeViewMode(mode);
|
|
|
|
},
|
|
|
|
},
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
created() {
|
|
|
|
event.on('koel:ready', () => {
|
|
|
|
this.mutatedMode = preferences[this.preferenceKey];
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
// If the value is empty, we set a default mode.
|
|
|
|
// On mobile, the mode should be 'listing'.
|
|
|
|
// For desktop, 'thumbnails'.
|
|
|
|
if (!this.mutatedMode) {
|
|
|
|
this.mutatedMode = isMobile.phone ? 'list' : 'thumbnails';
|
|
|
|
}
|
2016-06-25 10:20:30 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
this.setMode(this.mutatedMode);
|
|
|
|
});
|
|
|
|
},
|
|
|
|
};
|
2016-03-27 06:13:17 +00:00
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="sass" scoped>
|
2016-06-25 16:05:24 +00:00
|
|
|
@import "../../../sass/partials/_vars.scss";
|
|
|
|
@import "../../../sass/partials/_mixins.scss";
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
.view-modes {
|
|
|
|
display: flex;
|
|
|
|
flex: 0 0 64px;
|
|
|
|
border: 1px solid rgba(255, 255, 255, .2);
|
|
|
|
height: 2rem;
|
|
|
|
border-radius: 5px;
|
|
|
|
overflow: hidden;
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
a {
|
|
|
|
width: 50%;
|
|
|
|
text-align: center;
|
|
|
|
line-height: 2rem;
|
|
|
|
font-size: 1rem;
|
2016-03-27 06:13:17 +00:00
|
|
|
|
2016-06-25 16:05:24 +00:00
|
|
|
&.active {
|
|
|
|
background: #fff;
|
|
|
|
color: #111;
|
2016-03-27 06:13:17 +00:00
|
|
|
}
|
2016-06-25 16:05:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
@media only screen and(max-width: 768px) {
|
|
|
|
flex: auto;
|
|
|
|
width: 64px;
|
|
|
|
margin-top: 8px;
|
|
|
|
}
|
|
|
|
}
|
2016-03-27 06:13:17 +00:00
|
|
|
</style>
|