2021-06-28 00:50:06 +00:00
|
|
|
<template>
|
|
|
|
<a
|
|
|
|
v-if="campaign"
|
2021-07-05 22:01:44 +00:00
|
|
|
:href="campaign.url || campaign.affiliate?.url"
|
2021-06-28 00:50:06 +00:00
|
|
|
target="_blank"
|
|
|
|
class="campaign"
|
|
|
|
>
|
|
|
|
<img
|
2021-07-05 22:01:44 +00:00
|
|
|
v-if="campaign.banner.entity.type === 'network' || !campaign.banner.entity.parent"
|
2021-07-04 22:06:18 +00:00
|
|
|
:src="`/img/banners/${campaign.banner.entity.slug}/${campaign.banner.id}.${campaign.banner.type || 'jpg'}`"
|
2021-06-28 03:13:41 +00:00
|
|
|
:width="campaign.banner.width"
|
|
|
|
:height="campaign.banner.height"
|
2021-06-28 00:50:06 +00:00
|
|
|
class="campaign-banner"
|
|
|
|
>
|
|
|
|
|
|
|
|
<img
|
|
|
|
v-if="campaign.banner.entity.type === 'channel' && campaign.banner.entity.parent?.type === 'network'"
|
2021-07-04 22:06:18 +00:00
|
|
|
:src="`/img/banners/${campaign.banner.entity.parent.slug}/${campaign.banner.entity.slug}/${campaign.banner.id}.${campaign.banner.type || 'jpg'}`"
|
2021-06-28 03:13:41 +00:00
|
|
|
:width="campaign.banner.width"
|
|
|
|
:height="campaign.banner.height"
|
2021-06-28 00:50:06 +00:00
|
|
|
class="campaign-banner"
|
|
|
|
>
|
|
|
|
</a>
|
|
|
|
</template>
|
|
|
|
|
|
|
|
<script>
|
2021-06-28 03:13:41 +00:00
|
|
|
function ratioFilter(banner) {
|
|
|
|
if (!banner) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minHeight && banner.height < this.minHeight) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maxHeight && banner.height > this.minHeight) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.minRatio && banner.ratio < this.minRatio) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (this.maxRatio && banner.ratio > this.maxRatio) {
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2021-06-28 00:50:06 +00:00
|
|
|
function entityCampaign() {
|
|
|
|
const bannerCampaigns = this.entity.campaigns
|
2022-07-18 00:42:30 +00:00
|
|
|
.concat(this.entity.children?.flatMap((child) => child.campaigns))
|
2021-06-28 00:50:06 +00:00
|
|
|
.concat(this.entity.parent?.campaigns)
|
2022-07-18 00:42:30 +00:00
|
|
|
.filter((campaignX) => campaignX && this.ratioFilter(campaignX.banner));
|
2021-06-28 00:50:06 +00:00
|
|
|
|
|
|
|
if (bannerCampaigns.length > 0) {
|
2021-06-28 03:13:41 +00:00
|
|
|
const randomCampaign = bannerCampaigns[Math.floor(Math.random() * bannerCampaigns.length)];
|
|
|
|
|
|
|
|
this.$emit('campaign', randomCampaign);
|
|
|
|
return randomCampaign;
|
2021-06-28 00:50:06 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 03:13:41 +00:00
|
|
|
this.$emit('campaign', null);
|
2021-06-28 00:50:06 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
function tagCampaign() {
|
2022-07-18 00:42:30 +00:00
|
|
|
const campaignBanners = this.tag.banners.filter((banner) => banner.campaigns.length > 0 && this.ratioFilter(banner));
|
2021-06-28 00:50:06 +00:00
|
|
|
const banner = campaignBanners[Math.floor(Math.random() * campaignBanners.length)];
|
|
|
|
|
|
|
|
if (banner?.campaigns.length > 0) {
|
2021-06-28 03:13:41 +00:00
|
|
|
const randomCampaign = {
|
2021-06-28 00:50:06 +00:00
|
|
|
...banner.campaigns[Math.floor(Math.random() * banner.campaigns.length)],
|
|
|
|
banner,
|
|
|
|
};
|
2021-06-28 03:13:41 +00:00
|
|
|
|
|
|
|
this.$emit('campaign', randomCampaign);
|
|
|
|
return randomCampaign;
|
2021-06-28 00:50:06 +00:00
|
|
|
}
|
|
|
|
|
2021-06-28 03:13:41 +00:00
|
|
|
this.$emit('campaign', null);
|
2021-06-28 00:50:06 +00:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
2022-07-18 00:42:30 +00:00
|
|
|
async function genericCampaign() {
|
|
|
|
const randomCampaign = await this.$store.dispatch('fetchRandomCampaign', { minRatio: this.minRatio, maxRatio: this.maxRatio });
|
|
|
|
|
|
|
|
this.campaign = randomCampaign;
|
|
|
|
this.$emit('campaign', randomCampaign);
|
|
|
|
|
|
|
|
return randomCampaign;
|
|
|
|
}
|
|
|
|
|
|
|
|
async function mounted() {
|
2021-06-28 00:50:06 +00:00
|
|
|
if (this.entity) {
|
2022-07-18 00:42:30 +00:00
|
|
|
await this.entityCampaign();
|
2021-06-28 00:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (this.tag) {
|
2022-07-18 00:42:30 +00:00
|
|
|
await this.tagCampaign();
|
2021-06-28 00:50:06 +00:00
|
|
|
}
|
|
|
|
|
2022-07-18 00:42:30 +00:00
|
|
|
await this.genericCampaign();
|
2021-06-28 00:50:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export default {
|
|
|
|
props: {
|
|
|
|
entity: {
|
|
|
|
type: Object,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
tag: {
|
|
|
|
type: Object,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-07-05 22:01:44 +00:00
|
|
|
minHeight: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
maxHeight: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-06-28 03:13:41 +00:00
|
|
|
minRatio: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
|
|
|
maxRatio: {
|
|
|
|
type: Number,
|
|
|
|
default: null,
|
|
|
|
},
|
2021-06-28 00:50:06 +00:00
|
|
|
},
|
2021-06-28 03:13:41 +00:00
|
|
|
emits: ['campaign'],
|
2022-07-18 00:42:30 +00:00
|
|
|
data() {
|
|
|
|
return {
|
|
|
|
campaign: null,
|
|
|
|
};
|
2021-06-28 00:50:06 +00:00
|
|
|
},
|
2022-07-18 00:42:30 +00:00
|
|
|
mounted,
|
2021-06-28 00:50:06 +00:00
|
|
|
methods: {
|
|
|
|
entityCampaign,
|
2022-07-18 00:42:30 +00:00
|
|
|
genericCampaign,
|
2021-06-28 03:13:41 +00:00
|
|
|
ratioFilter,
|
2021-06-28 00:50:06 +00:00
|
|
|
tagCampaign,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
</script>
|
|
|
|
|
|
|
|
<style lang="scss" scoped>
|
|
|
|
.campaign {
|
|
|
|
height: 100%;
|
|
|
|
display: inline-flex;
|
|
|
|
align-items: center;
|
|
|
|
justify-content: center;
|
|
|
|
}
|
|
|
|
|
|
|
|
.campaign-banner {
|
2021-06-28 03:13:41 +00:00
|
|
|
height: auto;
|
2021-06-28 00:50:06 +00:00
|
|
|
max-height: 100%;
|
|
|
|
max-width: 100%;
|
|
|
|
}
|
|
|
|
</style>
|