Skip to content

Commit 42096b7

Browse files
committed
docs: ad fallback
1 parent 2ce568a commit 42096b7

File tree

1 file changed

+59
-2
lines changed

1 file changed

+59
-2
lines changed

docs/src/components/Ad.vue

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,62 @@
11
<template>
2-
<div id="ad" :class="{ 'placement-home': placement === 'home-page' }"></div>
2+
<div v-if="!hasError" id="ad" :class="{ 'placement-home': placement === 'home-page' }"></div>
3+
<div v-else id="ad" class="error">
4+
<div class="p-4 flex flex-col">
5+
<span class="font-bold font-display">🙏 Enable Ads</span>
6+
<span class="mt-2"> Please enable ads on your browser for this website. </span>
7+
<span class="mt-1"> Ads are a funding source to this project. </span>
8+
9+
<div class="mt-2 or-fund-it">
10+
<span class="mx-1 whitespace-nowrap">or consider</span>
11+
</div>
12+
13+
<a
14+
target="_blank"
15+
rel="noopener"
16+
href="https://github.com/sponsors/logaretm"
17+
class="mt-2 bg-pink-600 py-1 px-2 text-white font-medium flex items-center justify-center font-display rounded group hover:bg-pink-700"
18+
>
19+
<svg
20+
class="stroke-current transform transition duration-200 group-hover:scale-110 w-5 h-5 mr-1"
21+
fill="none"
22+
viewBox="0 0 24 24"
23+
xmlns="http://www.w3.org/2000/svg"
24+
>
25+
<path
26+
stroke-linecap="round"
27+
stroke-linejoin="round"
28+
stroke-width="2"
29+
d="M4.318 6.318a4.5 4.5 0 000 6.364L12 20.364l7.682-7.682a4.5 4.5 0 00-6.364-6.364L12 7.636l-1.318-1.318a4.5 4.5 0 00-6.364 0z"
30+
></path>
31+
</svg>
32+
33+
Sponsor
34+
</a>
35+
</div>
36+
</div>
337
</template>
438

539
<script setup lang="ts">
6-
import { onMounted } from 'vue';
40+
import { onMounted, ref } from 'vue';
741
842
defineProps<{
943
placement?: 'content' | 'home-page';
1044
}>();
1145
46+
const hasError = ref(false);
47+
1248
function loadScript() {
1349
const script = document.createElement('script');
1450
script.src = '//cdn.carbonads.com/carbon.js?serve=CE7DKKQ7&placement=vee-validatelogaretmcom';
1551
script.id = '_carbonads_js';
1652
1753
const el = document.querySelector('#ad');
1854
el?.appendChild(script);
55+
script.onerror = error => {
56+
if (navigator.onLine) {
57+
hasError.value = true;
58+
}
59+
};
1960
}
2061
2162
onMounted(loadScript);
@@ -122,6 +163,22 @@ onMounted(loadScript);
122163
#carbonads {
123164
@apply bg-zinc-800;
124165
}
166+
167+
&.error {
168+
@apply bg-zinc-800;
169+
}
170+
}
171+
}
172+
173+
.or-fund-it {
174+
@apply text-zinc-500 flex items-center space-x-2;
175+
176+
&::before,
177+
&::after {
178+
height: 1px;
179+
width: 100%;
180+
content: '';
181+
@apply flex-shrink bg-zinc-500;
125182
}
126183
}
127184
</style>

0 commit comments

Comments
 (0)