Spaces:
Build error
Build error
Open in new tab if cookies are disabled (#580)
Browse files* Open in new tab if cookies are disabled
* lint
src/lib/components/DisclaimerModal.svelte
CHANGED
@@ -4,6 +4,7 @@
|
|
4 |
import { PUBLIC_APP_DESCRIPTION, PUBLIC_APP_NAME } from "$env/static/public";
|
5 |
import LogoHuggingFaceBorderless from "$lib/components/icons/LogoHuggingFaceBorderless.svelte";
|
6 |
import Modal from "$lib/components/Modal.svelte";
|
|
|
7 |
import type { LayoutData } from "../../routes/$types";
|
8 |
import Logo from "./icons/Logo.svelte";
|
9 |
|
@@ -46,6 +47,12 @@
|
|
46 |
class:bg-white={$page.data.loginEnabled}
|
47 |
class:text-gray-800={$page.data.loginEnabled}
|
48 |
class:hover:bg-slate-100={$page.data.loginEnabled}
|
|
|
|
|
|
|
|
|
|
|
|
|
49 |
>
|
50 |
{#if $page.data.loginEnabled}
|
51 |
Try as guest
|
|
|
4 |
import { PUBLIC_APP_DESCRIPTION, PUBLIC_APP_NAME } from "$env/static/public";
|
5 |
import LogoHuggingFaceBorderless from "$lib/components/icons/LogoHuggingFaceBorderless.svelte";
|
6 |
import Modal from "$lib/components/Modal.svelte";
|
7 |
+
import { cookiesAreEnabled } from "$lib/utils/cookiesAreEnabled";
|
8 |
import type { LayoutData } from "../../routes/$types";
|
9 |
import Logo from "./icons/Logo.svelte";
|
10 |
|
|
|
47 |
class:bg-white={$page.data.loginEnabled}
|
48 |
class:text-gray-800={$page.data.loginEnabled}
|
49 |
class:hover:bg-slate-100={$page.data.loginEnabled}
|
50 |
+
on:click={(e) => {
|
51 |
+
if (!cookiesAreEnabled()) {
|
52 |
+
e.preventDefault();
|
53 |
+
window.open(window.location.href, "_blank");
|
54 |
+
}
|
55 |
+
}}
|
56 |
>
|
57 |
{#if $page.data.loginEnabled}
|
58 |
Try as guest
|
src/lib/utils/cookiesAreEnabled.ts
ADDED
@@ -0,0 +1,13 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import { browser } from "$app/environment";
|
2 |
+
|
3 |
+
export function cookiesAreEnabled(): boolean {
|
4 |
+
if (!browser) return false;
|
5 |
+
if (navigator.cookieEnabled) return navigator.cookieEnabled;
|
6 |
+
|
7 |
+
// Create cookie
|
8 |
+
document.cookie = "cookietest=1";
|
9 |
+
const ret = document.cookie.indexOf("cookietest=") != -1;
|
10 |
+
// Delete cookie
|
11 |
+
document.cookie = "cookietest=1; expires=Thu, 01-Jan-1970 00:00:01 GMT";
|
12 |
+
return ret;
|
13 |
+
}
|