card references, change to query, refactor code

This commit is contained in:
André Weller
2019-05-16 11:26:29 +02:00
parent b327d205dd
commit 5c4d466d43

View File

@@ -1,5 +1,5 @@
<template lang="pug"> <template lang="pug">
.card(:class="{'card--active': isReferenced}") .card(:class="checkReference")
//- a.card--link(:href="url" :target='title' rel='noreferrer') //- a.card--link(:href="url" :target='title' rel='noreferrer')
p.card--title {{title}} p.card--title {{title}}
p.card--description {{desc}} p.card--description {{desc}}
@@ -12,44 +12,34 @@
<script> <script>
export default { export default {
props: ['title', 'desc', 'url'], props: ['title', 'desc', 'url'],
data(){
return {
isReferenced: false,
}
},
methods: { methods: {
async createCopyUrl() { async createCopyUrl() {
try { try {
let currentPath = this.$router.history.current.path let currentPath = this.$router.history.current.path
let reference = this.$props.title.replace(/ /g, '').toLowerCase() let reference = this.createReferenceTag(this.$props.title)
await this.$copyText(`https://webgems.io${currentPath}?card=${reference}`) await this.$copyText(`https://webgems.io${currentPath}?card=${reference}`)
this.$router.push(`${currentPath}?card=${reference}`) this.$router.push(`${currentPath}?card=${reference}`)
this.$forceUpdate()
} catch (e) { } catch (e) {
console.error(e); console.error(e);
} }
}, },
screateCopyUrl() { createReferenceTag(tag){
this.$router.push(`${this.$router.history.current.path}#${this.$props.title.replace(/ /g, '').toLowerCase()}`) return tag.replace(/ /g, '').toLowerCase()
}, }
},
computed: {
checkReference(){ checkReference(){
if(typeof this.$route.query.card != undefined) { if(typeof this.$route.query.card != undefined) {
console.log(this.$route.query.card) const query = this.$route.query.card
const title = this.createReferenceTag(this.$props.title)
const query = this.$route.query.card; return title === query
const title = this.$props.title.replace(/ /g, ''); ? 'card--active'
: ''
title.toLowerCase() === query
? this.isReferenced = true
: this.isReferenced = false
} }
}, },
}, },
mounted() {
this.checkReference()
},
} }
</script> </script>
@@ -117,4 +107,38 @@ export default {
align-self: flex-end; align-self: flex-end;
} }
} }
.tooltip .tooltiptext {
visibility: hidden;
width: 120px;
background-color: #555;
color: #fff;
text-align: center;
border-radius: 6px;
padding: 5px 0;
position: absolute;
z-index: 1;
bottom: 125%;
left: 50%;
margin-left: -60px;
opacity: 0;
transition: opacity 0.3s;
}
.tooltip .tooltiptext::after {
content: "";
position: absolute;
top: 100%;
left: 50%;
margin-left: -5px;
border-width: 5px;
border-style: solid;
border-color: #555 transparent transparent transparent;
}
.tooltip:hover .tooltiptext {
visibility: visible;
opacity: 1;
}
</style> </style>