This repository has been archived on 2024-07-22. You can view files and clone it, but cannot push or open issues or pull requests.
Zaimki/components/Flag.vue

105 lines
3.5 KiB
Vue
Raw Normal View History

<template>
2021-04-01 09:35:39 -07:00
<span class="flag-wrapper">
<a v-if="link" :href="`/${config.nouns.route}/${config.terminology.route}#${link.toLowerCase()}`" :title="alt">
2021-04-21 11:06:17 -07:00
<img :src="img" :alt="name" class="flag-mini rounded"/>
2022-05-07 13:52:18 -07:00
<Twemoji><Spelling escape :text="name"/><sup v-if="custom" class="text-muted"><small><Icon v="user"/></small></sup><sup v-if="asterisk" class="text-muted"><small>*</small></sup></Twemoji>
2021-04-01 09:35:39 -07:00
</a>
<span v-else :title="alt">
2021-04-21 11:06:17 -07:00
<img :src="img" :alt="name" class="flag-mini rounded"/>
2022-05-07 13:52:18 -07:00
<Twemoji><Spelling escape :text="name"/><sup v-if="custom" class="text-muted"><small><Icon v="user"/></small></sup><sup v-if="asterisk" class="text-muted"><small>*</small></sup></Twemoji>
2021-04-01 09:35:39 -07:00
</span>
<span class="flag-preview bg-white rouded p-2 border">
2021-04-21 11:06:17 -07:00
<img :src="img" :alt="name" class="rounded"/>
2022-05-07 13:52:18 -07:00
<span v-if="asterisk" class="alert alert-warning small d-block mt-2 mb-0 p-2">
*
<T>profile.flagsAsterisk</T>
</span>
<span v-if="custom" class="alert alert-warning small d-block mt-2 mb-0 p-2">
2021-04-05 08:03:13 -07:00
<Icon v="user"/>
<T>profile.flagsCustomWarning</T>
</span>
2021-04-01 09:35:39 -07:00
</span>
</span>
</template>
<script>
export default {
props: {
name: { required: true },
alt: { required: true },
img: { required: true },
2020-12-21 08:35:58 -08:00
terms: { },
2021-04-05 08:03:13 -07:00
custom: { type: Boolean },
2022-05-07 13:52:18 -07:00
asterisk: { type: Boolean },
2020-12-18 09:22:35 -08:00
},
computed: {
link() {
if (!this.config.terminology.enabled || !(this.config.terminology.published || this.$isGranted('terms'))) {
2020-12-18 09:22:35 -08:00
return null;
}
let fallback = null;
2020-12-21 08:35:58 -08:00
for (let term of this.terms || []) {
// exact match
if (term.key && term.key.toLowerCase() === this.alt.toLowerCase()) {
return term.key;
}
if (term.term.toLowerCase() === this.name.toLowerCase()) {
2020-12-18 09:22:35 -08:00
return this.name;
}
if (term.original.toLowerCase() === this.alt.toLowerCase()) {
2020-12-18 09:22:35 -08:00
return this.alt;
}
// fallback
if (term.key && term.key.toLowerCase().includes(this.alt.toLowerCase())) {
fallback = term.key;
}
if (term.term.toLowerCase().includes(this.name.toLowerCase())) {
fallback = this.name;
}
if (term.original.toLowerCase().includes(this.alt.toLowerCase())) {
fallback = this.alt;
}
2020-12-18 09:22:35 -08:00
}
return fallback;
2020-12-18 09:22:35 -08:00
},
2020-12-08 14:14:40 -08:00
},
}
</script>
<style lang="scss" scoped>
2021-04-01 09:35:39 -07:00
.flag-mini {
height: 1rem;
}
2021-04-01 09:35:39 -07:00
.flag-wrapper {
position: relative;
.flag-preview {
position: absolute;
top: 1.5em;
left: 0;
z-index: 999;
display: none;
2021-04-05 08:03:13 -07:00
img {
max-height: 128px;
}
2021-04-01 09:35:39 -07:00
}
2022-05-07 13:52:18 -07:00
text-align: left;
font-weight: normal;
2021-04-01 09:35:39 -07:00
&:hover {
.flag-preview {
display: block;
2022-05-07 13:52:18 -07:00
span {
white-space: normal;
}
2021-04-01 09:35:39 -07:00
}
}
}
</style>