materio-d9/web/themes/custom/materiotheme/vuejs/components/Content/Card.vue

157 lines
4.4 KiB
Vue
Raw Normal View History

<template>
<article class="card">
<header>
<h1>{{ item.title }}</h1>
2019-07-25 21:23:23 +02:00
<h4>{{ item.field_short_description }}</h4>
<span class="ref">{{ item.field_reference }}</span>
</header>
2020-11-24 14:07:10 +01:00
<nav class="tools">
<section class="tool flags">
<span class="btn mdi mdi-folder-outline"/>
<div class="tool-content">
<ul>
<li v-if="flagcolls" v-for="coll in flagcolls" :key="coll.id">
<span
class="flag mdi"
:class="[
flagIsLoading(coll.id) ? 'mdi-loading mdi-spin' : flagIsActive(coll.id) ? 'mdi-close isActive' : 'mdi-plus'
]"
:collid="coll.id"
@click.prevent="onFlagActionCard"
>
{{ coll.name }}
</span>
</li>
</ul>
</div>
</section>
</nav>
2019-06-11 18:04:46 +02:00
<section class="images" v-switcher>
<figure
v-for="(img, index) in item.images"
:key="img.url"
>
<img
class="lazy"
v-lazy="index"
:data-src="img.url"
:title="img.title"
/>
<img class="blank" :src="blanksrc">
</figure>
</section>
</article>
</template>
<script>
2020-11-24 14:07:10 +01:00
import { mapState, mapActions } from 'vuex'
export default {
name: "Card",
props: ['item'],
2019-06-11 18:04:46 +02:00
data() {
return {
2020-11-24 14:07:10 +01:00
blanksrc:`${drupalSettings.path.themePath}/assets/img/blank.gif`,
loadingFlag: false
2019-06-11 18:04:46 +02:00
}
},
2020-11-24 14:07:10 +01:00
computed: {
...mapState({
flagcolls: state => state.User.flagcolls
})
},
2019-06-11 18:04:46 +02:00
directives: {
lazy: {
bind(img,binding){
// console.log('lazy bind', img, binding);
if(binding.value === 0){
img.setAttribute('src', img.getAttribute('data-src'))
img.removeAttribute('data-src')
img.classList.remove('lazy')
}
}
},
switcher: {
inserted(el,binding){
// switch images on mousemove
el.addEventListener('mousemove', function(event) {
let figs = this.querySelectorAll('figure')
// console.log('mousemove', this, event, figs.length);
// let len = figs.length
// let w = this.clientWidth;
// let g = w / len;
// let delta = Math.floor(event.layerX / g)
let delta = Math.floor(event.layerX / (this.clientWidth / figs.length))
// console.log('delta', delta);
figs.forEach((fig, index) => {
// console.log(index);
if(index == delta){
fig.style.display = "block"
}else{
fig.style.display = "none"
}
})
})
}
}
},
mounted() {
// lazy load images on mouseover
this.$el.addEventListener('mouseover', function(event) {
let imgs = this.querySelectorAll('.images figure img.lazy')
// console.log('mouseover', this, imgs);
2019-06-11 18:04:46 +02:00
imgs.forEach((img) => {
// console.log('forEach img',img);
img.setAttribute('src', img.getAttribute('data-src'))
img.removeAttribute('data-src')
img.classList.remove('lazy')
})
}, {once : true})
2020-11-24 14:07:10 +01:00
},
methods: {
...mapActions({
flag: 'User/flag',
unFlag: 'User/unFlag'
}),
flagIsActive(collid) {
// console.log(this.item.uuid);
// console.log(this.flagcolls[collid].items_uuids);
return this.flagcolls[collid].items_uuids.indexOf(this.item.uuid) !== -1;
},
flagIsLoading(collid) {
// console.log(this.item.uuid);
// console.log(this.flagcolls[collid].items_uuids);
return collid === this.loadingFlag;
},
onFlagActionCard (e) {
console.log("Card onFlagActionCard", isActive, e);
if (!this.loadingFlag) {
let collid = e.target.getAttribute('collid');
let isActive = this.flagIsActive(collid);
// console.log('collid', collid);
// console.log("this.item", this.item);
this.loadingFlag = collid;
if (isActive) {
this.unFlag({uuid: this.item.uuid, collid: collid})
.then(data => {
console.log("onFlagActionCard then", data);
this.loadingFlag = false;
})
}else{
this.flag({uuid: this.item.uuid, collid: collid})
.then(data => {
console.log("onFlagActionCard then", data);
this.loadingFlag = false;
})
}
}
}
2019-06-11 18:04:46 +02:00
}
}
</script>
<style lang="scss" scoped>
</style>