basklee-nuxt 0.9.11 → 0.9.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +12 -2
- package/package.json +1 -1
- package/templates/app/components/basklee/blog/BlogArticle.README.md +1 -1
- package/templates/app/middleware/00.basklee.global.ts +40 -1
- package/templates/app/stores/basklee.ts +4 -0
- package/templates/app/stores/baskleeSelections.ts +61 -4
- package/templates/app/utils/basklee/blogArticleHtml.ts +13 -2
- package/templates/app/utils/basklee/blogMediaFallback.ts +18 -1
- package/templates/app/utils/basklee/blogYoutubeCover.ts +285 -0
- package/templates/app/utils/basklee/presentation.ts +105 -0
- package/templates/app/utils/basklee/privacyLabels.ts +8 -7
- package/templates/basklee/COMPONENTS.md +10 -4
package/README.md
CHANGED
|
@@ -516,7 +516,7 @@ route data. The homepage retains additional backend Open Graph and Twitter tags
|
|
|
516
516
|
through `useHead()`. Profile and logout pages remain excluded from indexing;
|
|
517
517
|
search results retain their `noindex, follow` policy.
|
|
518
518
|
A product page takes the product's SEO tab: its heading is the page title (the product name without one), its meta description and keywords fill their tags, and its own Open Graph and Twitter Cards tags are added in the page's language only, replacing a default tag of the same name.
|
|
519
|
-
Pages with a canonical address also link the same page in the other storefront languages (`hreflang`) and set `og:type` and `og:locale`; a journal article adds its publication date (`article:published_time`) and schema.org `BlogPosting` data. The store icon (`logos.ico`) is the page's `<link rel="icon">`. An unknown `?locale` opens the
|
|
519
|
+
Pages with a canonical address also link the same page in the other storefront languages (`hreflang`) and set `og:type` and `og:locale`; a journal article adds its publication date (`article:published_time`) and schema.org `BlogPosting` data. The store icon (`logos.ico`) is the page's `<link rel="icon">`. An unknown `?locale` opens the language closest to the browser's, else the first one.
|
|
520
520
|
|
|
521
521
|
List pages (journal, categories, stores) link their previous and next pages as real links (`?page=2`). Each later page has its own canonical address and a title with its page number; a journal page past the last one answers 404.
|
|
522
522
|
|
|
@@ -657,7 +657,17 @@ from `store.locales` directly. Import it without a data prop. It accepts a
|
|
|
657
657
|
`label` (default `Language`), `disabled` (default `false`) and `codeOnly`
|
|
658
658
|
(default `false`). Missing names
|
|
659
659
|
fall back to another translation, then the human name or code. Empty data
|
|
660
|
-
disables the selector.
|
|
660
|
+
disables the selector. A visit without `?locale` opens in the language and
|
|
661
|
+
currency the customer picked in the selectors on an earlier visit (the
|
|
662
|
+
`basklee_locale` and `basklee_currency` cookies, kept for a year; the privacy
|
|
663
|
+
page and the cookie notice name them). Without a pick it opens in the storefront
|
|
664
|
+
language closest to the browser's languages (`Accept-Language` during the server
|
|
665
|
+
render, `navigator.languages` in the browser): the same code first, then the same
|
|
666
|
+
language (`ru-RU` finds `ru`, `en` finds `en-GB`); the first available language when
|
|
667
|
+
none of them is offered. A language picked in the selector goes into the address.
|
|
668
|
+
A link with another `?locale` shows that language without replacing the pick:
|
|
669
|
+
`setLocale(code, false)` and `setCurrency(id, false)` change the selection
|
|
670
|
+
without keeping it.
|
|
661
671
|
|
|
662
672
|
Flags from `flag_img` appear beside the selected language and in every dropdown
|
|
663
673
|
option that has an available image. Missing or failed images leave the language
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "basklee-nuxt",
|
|
3
|
-
"version": "0.9.
|
|
3
|
+
"version": "0.9.13",
|
|
4
4
|
"description": "Nuxt 4 storefront for your Basklee marketplace: setup CLI, server API gateway, typed store and ready-made catalog, cart, checkout and account components in English, Russian and Spanish, plus an Android app build. Powered by Basklee: https://basklee.com",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"license": "MIT",
|
|
@@ -22,7 +22,7 @@ When `has_full_access` is false, the article shows its preview and an access pan
|
|
|
22
22
|
|
|
23
23
|
The first preview image is shown above the text, in an area that keeps its proportions. A post without a preview image, or with an image that fails to load, shows no cover. The cover and the images of the text open larger: a click, `Enter` or `Space` on one opens `ProductReviewImageViewer` at that image, with the article's other images a step away and each image's caption (its `figcaption`, else its `title`, else its `alt`) under it. The images get `role="button"`, a keyboard stop and an «Open image» name; a zoom-in cursor marks them. Images inside a link, a button or a product placement keep their own action. The helper is `app/utils/basklee/blogImageViewer.ts`. Article videos are shown with their poster image; their addresses may be backend paths (`/ps3/...`). In an Android app build the backend's own media paths (`/ps3/...`: cover, article videos, images and videos inside the text) load from the storefront address.
|
|
24
24
|
|
|
25
|
-
A picture, video or YouTube player of the text that does not load is replaced by a placeholder in the text's own colours: «The image could not be loaded» with the picture's `alt`, or «The video could not be loaded» with a link to the video file or to the video on YouTube. A blocked YouTube gives no error, so the article checks once per page whether YouTube's image server answers within 8 seconds; the players stay when it does. Pictures of product cards keep the card's own placeholder. The helper is `app/utils/basklee/blogMediaFallback.ts`.
|
|
25
|
+
A picture, video or YouTube player of the text that does not load is replaced by a placeholder in the text's own colours: «The image could not be loaded» with the picture's `alt`, or «The video could not be loaded» with a link to the video file or to the video on YouTube. A blocked YouTube gives no error, so the article checks once per page whether YouTube's image server answers within 8 seconds; the players stay when it does. A player that plays gets a cover over YouTube's suggestions of other videos: while it is paused («Continue watching») or has ended («Watch again»), the page lays its own layer over the frame, because YouTube has no setting that turns the suggestions off. Player addresses carry `rel=0` (suggestions from the video's own channel only) and `enablejsapi=1`, so the page hears the player through postMessage; no YouTube script is loaded into the page. In full screen the cover cannot reach the player. The helper is `app/utils/basklee/blogYoutubeCover.ts`, called by `guardBlogMedia`. Pictures of product cards keep the card's own placeholder. The helper is `app/utils/basklee/blogMediaFallback.ts`.
|
|
26
26
|
|
|
27
27
|
When the first successful `blog_posts_get` response has no article with this ID, the server render of the supplied page answers HTTP 404; after client-side navigation the component emits `missing`. The backend returns an empty list for an unknown ID, an unpublished article and a subscription-only article that the current visitor cannot open. An article returned with `has_full_access = false` keeps its preview and the access panel with the Plans link. An article that disappears after sign-out keeps the “This article is unavailable” state on the page. A failed request is not a missing article: the error notice keeps its Refresh button. The supplied `app/pages/journal/[id].vue` opens the storefront 404 page on `missing` through `useBaskleeMissingPage()`.
|
|
28
28
|
|
|
@@ -1,6 +1,15 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import {
|
|
2
|
+
abortNavigation,
|
|
3
|
+
defineNuxtRouteMiddleware,
|
|
4
|
+
useRequestHeaders,
|
|
5
|
+
} from '#imports';
|
|
2
6
|
import { useBaskleeAppLoad } from '@/composables/useBaskleeAppLoad';
|
|
3
7
|
import { storefrontPageError } from '@/composables/useBaskleeMissingPage';
|
|
8
|
+
import {
|
|
9
|
+
localesMatch,
|
|
10
|
+
savedChoices,
|
|
11
|
+
wantedLanguages,
|
|
12
|
+
} from '@/utils/basklee/presentation';
|
|
4
13
|
|
|
5
14
|
/**
|
|
6
15
|
* Bootstrap precedes page setup. A failed Application Load opens the
|
|
@@ -13,8 +22,38 @@ export default defineNuxtRouteMiddleware(async (to) => {
|
|
|
13
22
|
? to.query.locale
|
|
14
23
|
: '';
|
|
15
24
|
|
|
25
|
+
// A visit without ?locale= opens in the language and currency the customer
|
|
26
|
+
// picked before (the basklee_locale and basklee_currency cookies). Without
|
|
27
|
+
// a pick, the storefront language closest to the browser's languages (the
|
|
28
|
+
// request's Accept-Language while the server renders, navigator.languages
|
|
29
|
+
// in the browser); the storefront's first language when none is offered.
|
|
30
|
+
if (store.status === 'idle') {
|
|
31
|
+
const headers = import.meta.server
|
|
32
|
+
? useRequestHeaders(['accept-language', 'cookie'])
|
|
33
|
+
: undefined;
|
|
34
|
+
const saved = savedChoices(headers ? headers.cookie : document.cookie);
|
|
35
|
+
store.wantLocales([
|
|
36
|
+
locale,
|
|
37
|
+
saved.locale,
|
|
38
|
+
...wantedLanguages(
|
|
39
|
+
headers ? headers['accept-language'] : navigator.languages,
|
|
40
|
+
),
|
|
41
|
+
]);
|
|
42
|
+
store.wantCurrency(saved.currency);
|
|
43
|
+
}
|
|
44
|
+
|
|
16
45
|
await initialize(locale);
|
|
17
46
|
|
|
47
|
+
// A link with another ?locale= shows that language; it is not the
|
|
48
|
+
// customer's pick, so the next visit still opens in the saved one.
|
|
49
|
+
if (
|
|
50
|
+
locale &&
|
|
51
|
+
store.status === 'success' &&
|
|
52
|
+
!localesMatch(store.localeCode, locale)
|
|
53
|
+
) {
|
|
54
|
+
store.setLocale(locale, false);
|
|
55
|
+
}
|
|
56
|
+
|
|
18
57
|
if (!to.matched.length) {
|
|
19
58
|
return;
|
|
20
59
|
}
|
|
@@ -74,6 +74,8 @@ function createStoreState(scope: string, pinia: Pinia) {
|
|
|
74
74
|
const lengthId = forwardedState(selectionRefs.lengthId);
|
|
75
75
|
const {
|
|
76
76
|
setLocale,
|
|
77
|
+
wantLocales,
|
|
78
|
+
wantCurrency,
|
|
77
79
|
setCurrency,
|
|
78
80
|
setUnit,
|
|
79
81
|
} = selections;
|
|
@@ -409,6 +411,8 @@ function createStoreState(scope: string, pinia: Pinia) {
|
|
|
409
411
|
currentLocale,
|
|
410
412
|
currentCurrency,
|
|
411
413
|
setLocale,
|
|
414
|
+
wantLocales,
|
|
415
|
+
wantCurrency,
|
|
412
416
|
setCurrency,
|
|
413
417
|
setUnit,
|
|
414
418
|
getProducts,
|
|
@@ -3,6 +3,12 @@ import type { ComputedRef } from 'vue';
|
|
|
3
3
|
import { defineStore } from 'pinia';
|
|
4
4
|
import type { Pinia } from 'pinia';
|
|
5
5
|
import { resolveBaskleeDomain } from '@/stores/baskleeDomainAccess';
|
|
6
|
+
import {
|
|
7
|
+
closestLocale,
|
|
8
|
+
rememberChoice,
|
|
9
|
+
SAVED_CURRENCY_COOKIE,
|
|
10
|
+
SAVED_LOCALE_COOKIE,
|
|
11
|
+
} from '@/utils/basklee/presentation';
|
|
6
12
|
import '@/stores/basklee';
|
|
7
13
|
import type { IAppLoadCommon } from '@/interfaces/basklee/appBase/IAppLoadCommon';
|
|
8
14
|
|
|
@@ -17,6 +23,12 @@ export function useBaskleeSelections(
|
|
|
17
23
|
const currencyId = ref('');
|
|
18
24
|
const weightId = ref('');
|
|
19
25
|
const lengthId = ref('');
|
|
26
|
+
// What the customer asked for before the storefront knew its languages:
|
|
27
|
+
// the address's ?locale=, the language picked on an earlier visit, then
|
|
28
|
+
// the browser's languages.
|
|
29
|
+
const wantedLocales = ref<string[]>([]);
|
|
30
|
+
// The currency picked on an earlier visit.
|
|
31
|
+
const wantedCurrency = ref('');
|
|
20
32
|
const locales = computed(() => init.value?.locale ?? {});
|
|
21
33
|
const currencies = computed(() => init.value?.currencies ?? {});
|
|
22
34
|
const weights = computed(() => init.value?.weights ?? {});
|
|
@@ -46,7 +58,10 @@ export function useBaskleeSelections(
|
|
|
46
58
|
) ?? '';
|
|
47
59
|
}
|
|
48
60
|
|
|
49
|
-
|
|
61
|
+
// The customer's pick (remember = true, the language and currency
|
|
62
|
+
// switchers) is kept for later visits; a language that comes from the
|
|
63
|
+
// address is shown without being kept.
|
|
64
|
+
function setLocale(code: string, remember = true) {
|
|
50
65
|
const entry = findLocale(code);
|
|
51
66
|
if (!entry) {
|
|
52
67
|
return;
|
|
@@ -55,11 +70,18 @@ export function useBaskleeSelections(
|
|
|
55
70
|
currencyId.value = availableCurrency(entry[1].currency);
|
|
56
71
|
weightId.value = unitId(weights.value, entry[1].weight);
|
|
57
72
|
lengthId.value = unitId(lengths.value, entry[1].length);
|
|
73
|
+
if (remember) {
|
|
74
|
+
rememberChoice(SAVED_LOCALE_COOKIE, localeCode.value);
|
|
75
|
+
rememberChoice(SAVED_CURRENCY_COOKIE, currencyId.value);
|
|
76
|
+
}
|
|
58
77
|
}
|
|
59
78
|
|
|
60
|
-
function setCurrency(id: string) {
|
|
79
|
+
function setCurrency(id: string, remember = true) {
|
|
61
80
|
if (currencies.value[id]?.allowed_select) {
|
|
62
81
|
currencyId.value = id;
|
|
82
|
+
if (remember) {
|
|
83
|
+
rememberChoice(SAVED_CURRENCY_COOKIE, id);
|
|
84
|
+
}
|
|
63
85
|
}
|
|
64
86
|
}
|
|
65
87
|
|
|
@@ -75,13 +97,44 @@ export function useBaskleeSelections(
|
|
|
75
97
|
}
|
|
76
98
|
}
|
|
77
99
|
|
|
100
|
+
/** Languages the customer wants, most wanted first (see reconcile). */
|
|
101
|
+
function wantLocales(tags: readonly (string | null | undefined)[]) {
|
|
102
|
+
wantedLocales.value = tags
|
|
103
|
+
.map((tag) => tag?.trim() ?? '')
|
|
104
|
+
.filter(Boolean);
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/** The currency picked on an earlier visit (see reconcile). */
|
|
108
|
+
function wantCurrency(id: string | null | undefined) {
|
|
109
|
+
wantedCurrency.value = id?.trim() ?? '';
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
function wantedLocale() {
|
|
113
|
+
const code = closestLocale(
|
|
114
|
+
Object.entries(locales.value).map(
|
|
115
|
+
([key, value]) => value.code?.trim() || key,
|
|
116
|
+
),
|
|
117
|
+
wantedLocales.value,
|
|
118
|
+
);
|
|
119
|
+
return code ? findLocale(code) : undefined;
|
|
120
|
+
}
|
|
121
|
+
|
|
122
|
+
// A language still offered stays; otherwise the one closest to what the
|
|
123
|
+
// customer wants; otherwise the storefront's first language. A currency
|
|
124
|
+
// still offered stays; otherwise the one picked on an earlier visit;
|
|
125
|
+
// otherwise the language's own.
|
|
78
126
|
function reconcile() {
|
|
79
|
-
const selected =
|
|
127
|
+
const selected =
|
|
128
|
+
findLocale(localeCode.value) ??
|
|
129
|
+
wantedLocale() ??
|
|
130
|
+
Object.entries(locales.value)[0];
|
|
80
131
|
localeCode.value = selected?.[1].code?.trim() || selected?.[0] || '';
|
|
81
132
|
currencyId.value = availableCurrency(
|
|
82
133
|
currencies.value[currencyId.value]?.allowed_select
|
|
83
134
|
? currencyId.value
|
|
84
|
-
:
|
|
135
|
+
: currencies.value[wantedCurrency.value]?.allowed_select
|
|
136
|
+
? wantedCurrency.value
|
|
137
|
+
: selected?.[1].currency,
|
|
85
138
|
);
|
|
86
139
|
weightId.value = unitId(
|
|
87
140
|
weights.value,
|
|
@@ -109,6 +162,8 @@ export function useBaskleeSelections(
|
|
|
109
162
|
currencyId,
|
|
110
163
|
weightId,
|
|
111
164
|
lengthId,
|
|
165
|
+
wantedLocales,
|
|
166
|
+
wantedCurrency,
|
|
112
167
|
locales,
|
|
113
168
|
currencies,
|
|
114
169
|
weights,
|
|
@@ -116,6 +171,8 @@ export function useBaskleeSelections(
|
|
|
116
171
|
currentLocale,
|
|
117
172
|
currentCurrency,
|
|
118
173
|
setLocale,
|
|
174
|
+
wantLocales,
|
|
175
|
+
wantCurrency,
|
|
119
176
|
setCurrency,
|
|
120
177
|
setUnit,
|
|
121
178
|
reconcile,
|
|
@@ -113,12 +113,18 @@ const authorRelTokens = new Set(['nofollow', 'sponsored', 'ugc']);
|
|
|
113
113
|
const youtubeEmbed =
|
|
114
114
|
/^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/([\w-]{11})(?:\?([^#]*))?$/i;
|
|
115
115
|
|
|
116
|
+
// Options of every player address: suggestions from the same channel only, events for the page.
|
|
117
|
+
const youtubeEmbedOptions = ['rel=0', 'enablejsapi=1'];
|
|
118
|
+
|
|
116
119
|
export const blogYoutubeAllow =
|
|
117
120
|
'accelerometer; autoplay; clipboard-write; encrypted-media; gyroscope; picture-in-picture';
|
|
118
121
|
|
|
119
122
|
/**
|
|
120
123
|
* The privacy-enhanced player address for a YouTube embed address, or an
|
|
121
|
-
* empty string for anything else (other sites, other YouTube pages).
|
|
124
|
+
* empty string for anything else (other sites, other YouTube pages). The
|
|
125
|
+
* address keeps YouTube's suggestions to the video's own channel (`rel=0`)
|
|
126
|
+
* and lets the page hear the player (`enablejsapi=1`), so blogYoutubeCover.ts
|
|
127
|
+
* can cover the suggestions while the player is paused or ended.
|
|
122
128
|
*/
|
|
123
129
|
export function blogYoutubeEmbedSource(value: string) {
|
|
124
130
|
const match = youtubeEmbed.exec(value.trim());
|
|
@@ -129,7 +135,12 @@ export function blogYoutubeEmbedSource(value: string) {
|
|
|
129
135
|
|
|
130
136
|
const start = /(?:^|&)start=(\d{1,6})(?:&|$)/.exec(match[2] ?? '')?.[1];
|
|
131
137
|
|
|
132
|
-
|
|
138
|
+
const query = [
|
|
139
|
+
...(start && Number(start) > 0 ? [`start=${Number(start)}`] : []),
|
|
140
|
+
...youtubeEmbedOptions,
|
|
141
|
+
].join('&');
|
|
142
|
+
|
|
143
|
+
return `https://www.youtube-nocookie.com/embed/${match[1]}?${query}`;
|
|
133
144
|
}
|
|
134
145
|
|
|
135
146
|
function prepareYoutubeFrame(node: Element) {
|
|
@@ -5,16 +5,23 @@
|
|
|
5
5
|
* takes its place: the reader sees what was meant to be there instead of a
|
|
6
6
|
* broken-image icon or an empty frame; a video placeholder links to the video.
|
|
7
7
|
*
|
|
8
|
+
* The YouTube players that do play get a cover over YouTube's suggestions of
|
|
9
|
+
* other videos while paused or ended (blogYoutubeCover.ts, next to this file).
|
|
10
|
+
*
|
|
8
11
|
* Framework-free: call it on the element holding the article HTML after each
|
|
9
12
|
* render and call the returned function when the element goes away. The same
|
|
10
13
|
* file is used by every storefront (keep the copies identical).
|
|
11
14
|
*/
|
|
12
15
|
|
|
16
|
+
import { coverYoutubeSuggestions } from './blogYoutubeCover';
|
|
17
|
+
|
|
13
18
|
export interface IBlogMediaFallbackLabels {
|
|
14
19
|
image: string;
|
|
15
20
|
video: string;
|
|
16
21
|
openVideo: string;
|
|
17
22
|
watchYoutube: string;
|
|
23
|
+
videoResume: string;
|
|
24
|
+
videoReplay: string;
|
|
18
25
|
}
|
|
19
26
|
|
|
20
27
|
const LABELS: Record<string, IBlogMediaFallbackLabels> = {
|
|
@@ -23,18 +30,24 @@ const LABELS: Record<string, IBlogMediaFallbackLabels> = {
|
|
|
23
30
|
video: 'The video could not be loaded',
|
|
24
31
|
openVideo: 'Open the video',
|
|
25
32
|
watchYoutube: 'Watch on YouTube',
|
|
33
|
+
videoResume: 'Continue watching',
|
|
34
|
+
videoReplay: 'Watch again',
|
|
26
35
|
},
|
|
27
36
|
ru: {
|
|
28
37
|
image: 'Не удалось загрузить изображение',
|
|
29
38
|
video: 'Не удалось загрузить видео',
|
|
30
39
|
openVideo: 'Открыть видео',
|
|
31
40
|
watchYoutube: 'Смотреть на YouTube',
|
|
41
|
+
videoResume: 'Продолжить просмотр',
|
|
42
|
+
videoReplay: 'Смотреть снова',
|
|
32
43
|
},
|
|
33
44
|
es: {
|
|
34
45
|
image: 'No se pudo cargar la imagen',
|
|
35
46
|
video: 'No se pudo cargar el vídeo',
|
|
36
47
|
openVideo: 'Abrir el vídeo',
|
|
37
48
|
watchYoutube: 'Ver en YouTube',
|
|
49
|
+
videoResume: 'Seguir viendo',
|
|
50
|
+
videoReplay: 'Ver de nuevo',
|
|
38
51
|
},
|
|
39
52
|
};
|
|
40
53
|
|
|
@@ -247,7 +260,8 @@ function youtubeReachable(view: Window & typeof globalThis, videoId: string, lat
|
|
|
247
260
|
|
|
248
261
|
/**
|
|
249
262
|
* Watches the images, videos and YouTube players under `root` and replaces the
|
|
250
|
-
* ones that fail with a placeholder
|
|
263
|
+
* ones that fail with a placeholder; the players get the suggestions cover.
|
|
264
|
+
* Returns the function that stops watching.
|
|
251
265
|
*/
|
|
252
266
|
export function guardBlogMedia(
|
|
253
267
|
root: HTMLElement | null | undefined,
|
|
@@ -315,8 +329,11 @@ export function guardBlogMedia(
|
|
|
315
329
|
});
|
|
316
330
|
}
|
|
317
331
|
|
|
332
|
+
const stopCovers = coverYoutubeSuggestions(root, { resume: labels.videoResume, replay: labels.videoReplay });
|
|
333
|
+
|
|
318
334
|
return () => {
|
|
319
335
|
active = false;
|
|
320
336
|
root.removeEventListener('error', onError, true);
|
|
337
|
+
stopCovers();
|
|
321
338
|
};
|
|
322
339
|
}
|
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Keeps YouTube's suggestions of other videos off a player of the page: the
|
|
3
|
+
* «More videos» shelf a paused player shows and the grid of videos at the end.
|
|
4
|
+
* YouTube has no setting that turns them off (`rel=0` only keeps them to the
|
|
5
|
+
* video's own channel), so the page listens to the player and lays its own
|
|
6
|
+
* cover over the frame while the player is paused («Continue watching») or has
|
|
7
|
+
* ended («Watch again»). The cover takes the whole frame: a paused player also
|
|
8
|
+
* shows a «More videos» button in its control bar.
|
|
9
|
+
*
|
|
10
|
+
* The player talks to the page with postMessage when its address has
|
|
11
|
+
* `enablejsapi=1`; no YouTube script is loaded into the page. A player that
|
|
12
|
+
* sends nothing (an address without `enablejsapi=1`, YouTube blocked) stays as
|
|
13
|
+
* it is. In full screen the cover cannot reach the player and is not shown.
|
|
14
|
+
*
|
|
15
|
+
* Framework-free and without imports: call it on the element holding the
|
|
16
|
+
* players after each render and call the returned function when the element
|
|
17
|
+
* goes away. The same file is used by every storefront (keep the copies
|
|
18
|
+
* identical).
|
|
19
|
+
*/
|
|
20
|
+
|
|
21
|
+
export interface IYoutubeCoverLabels {
|
|
22
|
+
resume: string;
|
|
23
|
+
replay: string;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const LABELS: Record<string, IYoutubeCoverLabels> = {
|
|
27
|
+
en: { resume: 'Continue watching', replay: 'Watch again' },
|
|
28
|
+
ru: { resume: 'Продолжить просмотр', replay: 'Смотреть снова' },
|
|
29
|
+
es: { resume: 'Seguir viendo', replay: 'Ver de nuevo' },
|
|
30
|
+
};
|
|
31
|
+
|
|
32
|
+
/** The cover texts in the page language («ru», «en-US», …); English when the language is unknown. */
|
|
33
|
+
export function youtubeCoverLabels(locale?: string | null): IYoutubeCoverLabels {
|
|
34
|
+
const code = String(locale ?? '').toLowerCase().split(/[-_]/)[0] ?? '';
|
|
35
|
+
|
|
36
|
+
return LABELS[code] ?? LABELS.en!;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
const COVER = 'data-youtube-cover';
|
|
40
|
+
const STYLE_ID = 'basklee-youtube-cover-style';
|
|
41
|
+
// A player that answers: youtube.com or youtube-nocookie.com, /embed/<id>, with enablejsapi=1.
|
|
42
|
+
const PLAYER = /^https:\/\/(?:www\.)?youtube(?:-nocookie)?\.com\/embed\/[\w-]{11}\?(?:[^#]*&)?enablejsapi=1(?:[&#]|$)/i;
|
|
43
|
+
const ORIGINS = new Set([
|
|
44
|
+
'https://www.youtube-nocookie.com',
|
|
45
|
+
'https://youtube-nocookie.com',
|
|
46
|
+
'https://www.youtube.com',
|
|
47
|
+
'https://youtube.com',
|
|
48
|
+
]);
|
|
49
|
+
const ENDED = 0;
|
|
50
|
+
const PAUSED = 2;
|
|
51
|
+
const PING_MS = 250;
|
|
52
|
+
const PING_MAX = 40;
|
|
53
|
+
|
|
54
|
+
// The cover sits in <body>, so the page's own styles of the article do not reach it.
|
|
55
|
+
const STYLE = `
|
|
56
|
+
[${COVER}]{all:initial;position:absolute;z-index:2;box-sizing:border-box;display:flex;align-items:center;justify-content:center;padding:1rem;cursor:pointer;color:#fff;font:600 1rem/1.2 system-ui,-apple-system,"Segoe UI",Roboto,sans-serif;background:rgb(15 23 42 / 45%);-webkit-backdrop-filter:blur(16px);backdrop-filter:blur(16px)}
|
|
57
|
+
[${COVER}][hidden]{display:none!important}
|
|
58
|
+
[${COVER}="ended"]{background:rgb(15 23 42 / 92%)}
|
|
59
|
+
[${COVER}]>span{display:inline-flex;align-items:center;gap:.6rem;padding:.75rem 1.25rem;border-radius:999px;background:rgb(255 255 255 / 14%);box-shadow:inset 0 0 0 1px rgb(255 255 255 / 40%);transition:background .15s ease}
|
|
60
|
+
[${COVER}]:hover>span,[${COVER}]:focus-visible>span{background:rgb(255 255 255 / 26%)}
|
|
61
|
+
[${COVER}]:focus-visible{outline:3px solid #fff;outline-offset:-3px}
|
|
62
|
+
[${COVER}] svg{width:1.4em;height:1.4em;flex:none}
|
|
63
|
+
`;
|
|
64
|
+
|
|
65
|
+
const SVG_NS = 'http://www.w3.org/2000/svg';
|
|
66
|
+
const ICONS = {
|
|
67
|
+
resume: 'M8 5.5v13l10.5-6.5z',
|
|
68
|
+
replay: 'M4 12a8 8 0 1 0 2.35-5.65M4 4v4h4',
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
function ensureStyle(document: Document) {
|
|
72
|
+
if (document.getElementById(STYLE_ID)) {
|
|
73
|
+
return;
|
|
74
|
+
}
|
|
75
|
+
const style = document.createElement('style');
|
|
76
|
+
style.id = STYLE_ID;
|
|
77
|
+
style.textContent = STYLE;
|
|
78
|
+
document.head?.appendChild(style);
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
function icon(document: Document, kind: keyof typeof ICONS) {
|
|
82
|
+
const svg = document.createElementNS(SVG_NS, 'svg');
|
|
83
|
+
const path = document.createElementNS(SVG_NS, 'path');
|
|
84
|
+
svg.setAttribute('viewBox', '0 0 24 24');
|
|
85
|
+
svg.setAttribute('aria-hidden', 'true');
|
|
86
|
+
path.setAttribute('d', ICONS[kind]);
|
|
87
|
+
if (kind === 'resume') {
|
|
88
|
+
path.setAttribute('fill', 'currentColor');
|
|
89
|
+
} else {
|
|
90
|
+
path.setAttribute('fill', 'none');
|
|
91
|
+
path.setAttribute('stroke', 'currentColor');
|
|
92
|
+
path.setAttribute('stroke-width', '2');
|
|
93
|
+
path.setAttribute('stroke-linecap', 'round');
|
|
94
|
+
path.setAttribute('stroke-linejoin', 'round');
|
|
95
|
+
}
|
|
96
|
+
svg.appendChild(path);
|
|
97
|
+
return svg;
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
function playerState(data: unknown): number | undefined {
|
|
101
|
+
let message = data;
|
|
102
|
+
if (typeof message === 'string') {
|
|
103
|
+
try {
|
|
104
|
+
message = JSON.parse(message);
|
|
105
|
+
} catch {
|
|
106
|
+
return undefined;
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
if (!message || typeof message !== 'object') {
|
|
110
|
+
return undefined;
|
|
111
|
+
}
|
|
112
|
+
const { event, info } = message as { event?: unknown; info?: unknown };
|
|
113
|
+
if (event === 'onStateChange' && typeof info === 'number') {
|
|
114
|
+
return info;
|
|
115
|
+
}
|
|
116
|
+
if (event === 'infoDelivery' && info && typeof info === 'object') {
|
|
117
|
+
const state = (info as { playerState?: unknown }).playerState;
|
|
118
|
+
return typeof state === 'number' ? state : undefined;
|
|
119
|
+
}
|
|
120
|
+
return undefined;
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
function cover(frame: HTMLIFrameElement, labels: IYoutubeCoverLabels): () => void {
|
|
124
|
+
const document = frame.ownerDocument;
|
|
125
|
+
const view = document.defaultView!;
|
|
126
|
+
const target = new URL(frame.src).origin;
|
|
127
|
+
const element = document.createElement('button');
|
|
128
|
+
const face = document.createElement('span');
|
|
129
|
+
const caption = document.createElement('span');
|
|
130
|
+
let mode: 'paused' | 'ended' | '' = '';
|
|
131
|
+
let heard = false;
|
|
132
|
+
let pings = 0;
|
|
133
|
+
let pinger: ReturnType<typeof setInterval> | undefined;
|
|
134
|
+
|
|
135
|
+
element.type = 'button';
|
|
136
|
+
element.hidden = true;
|
|
137
|
+
element.setAttribute(COVER, '');
|
|
138
|
+
face.append(caption);
|
|
139
|
+
element.append(face);
|
|
140
|
+
document.body.appendChild(element);
|
|
141
|
+
|
|
142
|
+
const post = (message: Record<string, unknown>) => {
|
|
143
|
+
frame.contentWindow?.postMessage(JSON.stringify({ ...message, id: 1, channel: 'widget' }), target);
|
|
144
|
+
};
|
|
145
|
+
|
|
146
|
+
// Over the frame wherever the page puts it: the cover's own containing block is <body> or <html>.
|
|
147
|
+
const place = () => {
|
|
148
|
+
if (!mode) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
const box = frame.getBoundingClientRect();
|
|
152
|
+
const host = element.offsetParent as HTMLElement | null;
|
|
153
|
+
let top = box.top + view.scrollY;
|
|
154
|
+
let left = box.left + view.scrollX;
|
|
155
|
+
if (host && view.getComputedStyle(host).position !== 'static') {
|
|
156
|
+
const hostBox = host.getBoundingClientRect();
|
|
157
|
+
top = box.top - hostBox.top - host.clientTop + host.scrollTop;
|
|
158
|
+
left = box.left - hostBox.left - host.clientLeft + host.scrollLeft;
|
|
159
|
+
}
|
|
160
|
+
element.style.top = `${top}px`;
|
|
161
|
+
element.style.left = `${left}px`;
|
|
162
|
+
element.style.width = `${box.width}px`;
|
|
163
|
+
element.style.height = `${box.height}px`;
|
|
164
|
+
};
|
|
165
|
+
|
|
166
|
+
const show = (next: typeof mode) => {
|
|
167
|
+
if (next && (document.fullscreenElement === frame || !frame.isConnected || frame.getClientRects().length === 0)) {
|
|
168
|
+
next = '';
|
|
169
|
+
}
|
|
170
|
+
mode = next;
|
|
171
|
+
if (!next) {
|
|
172
|
+
element.hidden = true;
|
|
173
|
+
element.removeAttribute('aria-label');
|
|
174
|
+
return;
|
|
175
|
+
}
|
|
176
|
+
const text = next === 'paused' ? labels.resume : labels.replay;
|
|
177
|
+
element.setAttribute(COVER, next);
|
|
178
|
+
element.setAttribute('aria-label', text);
|
|
179
|
+
caption.textContent = text;
|
|
180
|
+
face.querySelector('svg')?.remove();
|
|
181
|
+
face.prepend(icon(document, next === 'paused' ? 'resume' : 'replay'));
|
|
182
|
+
element.hidden = false;
|
|
183
|
+
place();
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
const onMessage = (event: MessageEvent) => {
|
|
187
|
+
if (event.source !== frame.contentWindow || !ORIGINS.has(event.origin)) {
|
|
188
|
+
return;
|
|
189
|
+
}
|
|
190
|
+
heard = true;
|
|
191
|
+
const state = playerState(event.data);
|
|
192
|
+
if (state === undefined) {
|
|
193
|
+
return;
|
|
194
|
+
}
|
|
195
|
+
show(state === PAUSED ? 'paused' : state === ENDED ? 'ended' : '');
|
|
196
|
+
};
|
|
197
|
+
|
|
198
|
+
const onClick = () => {
|
|
199
|
+
if (mode === 'ended') {
|
|
200
|
+
post({ event: 'command', func: 'seekTo', args: [0, true] });
|
|
201
|
+
}
|
|
202
|
+
post({ event: 'command', func: 'playVideo', args: [] });
|
|
203
|
+
show('');
|
|
204
|
+
};
|
|
205
|
+
|
|
206
|
+
// The player starts sending once the page says it listens; it may still be loading, so ask a few times.
|
|
207
|
+
const ping = () => {
|
|
208
|
+
if (heard || pings >= PING_MAX) {
|
|
209
|
+
clearInterval(pinger);
|
|
210
|
+
pinger = undefined;
|
|
211
|
+
return;
|
|
212
|
+
}
|
|
213
|
+
pings += 1;
|
|
214
|
+
post({ event: 'listening' });
|
|
215
|
+
};
|
|
216
|
+
const startPinging = () => {
|
|
217
|
+
pings = 0;
|
|
218
|
+
clearInterval(pinger);
|
|
219
|
+
ping();
|
|
220
|
+
pinger = setInterval(ping, PING_MS);
|
|
221
|
+
};
|
|
222
|
+
|
|
223
|
+
const onLayout = () => place();
|
|
224
|
+
const onFullscreen = () => {
|
|
225
|
+
if (document.fullscreenElement === frame) {
|
|
226
|
+
show('');
|
|
227
|
+
}
|
|
228
|
+
};
|
|
229
|
+
|
|
230
|
+
view.addEventListener('message', onMessage);
|
|
231
|
+
view.addEventListener('resize', onLayout);
|
|
232
|
+
document.addEventListener('scroll', onLayout, true);
|
|
233
|
+
document.addEventListener('fullscreenchange', onFullscreen);
|
|
234
|
+
frame.addEventListener('load', startPinging);
|
|
235
|
+
element.addEventListener('click', onClick);
|
|
236
|
+
startPinging();
|
|
237
|
+
|
|
238
|
+
return () => {
|
|
239
|
+
clearInterval(pinger);
|
|
240
|
+
view.removeEventListener('message', onMessage);
|
|
241
|
+
view.removeEventListener('resize', onLayout);
|
|
242
|
+
document.removeEventListener('scroll', onLayout, true);
|
|
243
|
+
document.removeEventListener('fullscreenchange', onFullscreen);
|
|
244
|
+
frame.removeEventListener('load', startPinging);
|
|
245
|
+
element.remove();
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
const covered = new WeakSet<HTMLIFrameElement>();
|
|
250
|
+
|
|
251
|
+
/**
|
|
252
|
+
* Covers YouTube's suggestions in every player under `root` (an iframe or an
|
|
253
|
+
* element holding them). Returns the function that removes the covers.
|
|
254
|
+
*/
|
|
255
|
+
export function coverYoutubeSuggestions(
|
|
256
|
+
root: Element | null | undefined,
|
|
257
|
+
labels: IYoutubeCoverLabels = youtubeCoverLabels(),
|
|
258
|
+
): () => void {
|
|
259
|
+
const document = root?.ownerDocument;
|
|
260
|
+
if (!root || !document?.defaultView || !document.body) {
|
|
261
|
+
return () => {};
|
|
262
|
+
}
|
|
263
|
+
const frames = [
|
|
264
|
+
...(root.tagName === 'IFRAME' ? [root as HTMLIFrameElement] : []),
|
|
265
|
+
...root.querySelectorAll('iframe'),
|
|
266
|
+
].filter((frame) => PLAYER.test(frame.getAttribute('src') ?? '') && !covered.has(frame));
|
|
267
|
+
if (!frames.length) {
|
|
268
|
+
return () => {};
|
|
269
|
+
}
|
|
270
|
+
ensureStyle(document);
|
|
271
|
+
const stops = frames.map((frame) => {
|
|
272
|
+
covered.add(frame);
|
|
273
|
+
const stop = cover(frame, labels);
|
|
274
|
+
return () => {
|
|
275
|
+
covered.delete(frame);
|
|
276
|
+
stop();
|
|
277
|
+
};
|
|
278
|
+
});
|
|
279
|
+
|
|
280
|
+
return () => {
|
|
281
|
+
for (const stop of stops) {
|
|
282
|
+
stop();
|
|
283
|
+
}
|
|
284
|
+
};
|
|
285
|
+
}
|
|
@@ -70,3 +70,108 @@ export function localesMatch(left: string, right: string) {
|
|
|
70
70
|
value.trim().toLowerCase().replaceAll('_', '-');
|
|
71
71
|
return normalize(left) === normalize(right);
|
|
72
72
|
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The languages a customer's browser asks for, most wanted first: an
|
|
76
|
+
* Accept-Language header («ru-RU,ru;q=0.9,en;q=0.8») or navigator.languages.
|
|
77
|
+
*/
|
|
78
|
+
export function wantedLanguages(
|
|
79
|
+
source: string | readonly string[] | null | undefined,
|
|
80
|
+
): string[] {
|
|
81
|
+
if (!source) {
|
|
82
|
+
return [];
|
|
83
|
+
}
|
|
84
|
+
if (typeof source !== 'string') {
|
|
85
|
+
return source.map((tag) => tag.trim()).filter(Boolean);
|
|
86
|
+
}
|
|
87
|
+
return source
|
|
88
|
+
.split(',')
|
|
89
|
+
.map((part, index) => {
|
|
90
|
+
const [tag = '', ...parameters] = part.split(';');
|
|
91
|
+
const weight = parameters
|
|
92
|
+
.map((parameter) => /^q=([0-9.]+)$/i.exec(parameter.trim()))
|
|
93
|
+
.find(Boolean);
|
|
94
|
+
return { tag: tag.trim(), weight: weight ? Number(weight[1]) : 1, index };
|
|
95
|
+
})
|
|
96
|
+
.filter((item) => item.tag && item.tag !== '*' && item.weight > 0)
|
|
97
|
+
.sort((left, right) => right.weight - left.weight || left.index - right.index)
|
|
98
|
+
.map((item) => item.tag);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
/**
|
|
102
|
+
* The shop's language closest to what the customer wants, in the customer's
|
|
103
|
+
* order: the same tag first (pt_BR = pt-BR), then the same language (ru-RU
|
|
104
|
+
* finds ru, en finds en-GB). Nothing when no wanted language is offered.
|
|
105
|
+
*/
|
|
106
|
+
export function closestLocale(
|
|
107
|
+
available: readonly string[],
|
|
108
|
+
wanted: readonly string[],
|
|
109
|
+
): string | undefined {
|
|
110
|
+
const language = (tag: string) =>
|
|
111
|
+
tag.trim().toLowerCase().split(/[-_]/)[0] ?? '';
|
|
112
|
+
for (const tag of wanted) {
|
|
113
|
+
const same = available.find((code) => localesMatch(code, tag));
|
|
114
|
+
if (same) {
|
|
115
|
+
return same;
|
|
116
|
+
}
|
|
117
|
+
const kin = language(tag)
|
|
118
|
+
? available.find((code) => language(code) === language(tag))
|
|
119
|
+
: undefined;
|
|
120
|
+
if (kin) {
|
|
121
|
+
return kin;
|
|
122
|
+
}
|
|
123
|
+
}
|
|
124
|
+
return undefined;
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
/** Cookies that keep the language and currency the customer picked. */
|
|
128
|
+
export const SAVED_LOCALE_COOKIE = 'basklee_locale';
|
|
129
|
+
export const SAVED_CURRENCY_COOKIE = 'basklee_currency';
|
|
130
|
+
const SAVED_CHOICE_SECONDS = 60 * 60 * 24 * 365;
|
|
131
|
+
|
|
132
|
+
/**
|
|
133
|
+
* The language and currency the customer picked on an earlier visit, read
|
|
134
|
+
* from a `Cookie` header or document.cookie; empty when nothing was picked.
|
|
135
|
+
*/
|
|
136
|
+
export function savedChoices(cookies: string | null | undefined): {
|
|
137
|
+
locale: string;
|
|
138
|
+
currency: string;
|
|
139
|
+
} {
|
|
140
|
+
const values = new Map<string, string>();
|
|
141
|
+
for (const pair of (cookies ?? '').split(';')) {
|
|
142
|
+
const separator = pair.indexOf('=');
|
|
143
|
+
if (separator <= 0) {
|
|
144
|
+
continue;
|
|
145
|
+
}
|
|
146
|
+
try {
|
|
147
|
+
values.set(
|
|
148
|
+
pair.slice(0, separator).trim(),
|
|
149
|
+
decodeURIComponent(pair.slice(separator + 1).trim()),
|
|
150
|
+
);
|
|
151
|
+
} catch {
|
|
152
|
+
// A value that is not URI-encoded is not ours.
|
|
153
|
+
}
|
|
154
|
+
}
|
|
155
|
+
return {
|
|
156
|
+
locale: values.get(SAVED_LOCALE_COOKIE) ?? '',
|
|
157
|
+
currency: values.get(SAVED_CURRENCY_COOKIE) ?? '',
|
|
158
|
+
};
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Keeps a pick of the customer for a year (in the browser only): the next
|
|
163
|
+
* visit without `?locale=` opens in it instead of the browser's language.
|
|
164
|
+
*/
|
|
165
|
+
export function rememberChoice(name: string, value: string) {
|
|
166
|
+
if (typeof document === 'undefined' || !value) {
|
|
167
|
+
return;
|
|
168
|
+
}
|
|
169
|
+
const secure = globalThis.location?.protocol === 'https:' ? '; Secure' : '';
|
|
170
|
+
try {
|
|
171
|
+
document.cookie =
|
|
172
|
+
`${name}=${encodeURIComponent(value)}; Path=/; ` +
|
|
173
|
+
`Max-Age=${SAVED_CHOICE_SECONDS}; SameSite=Lax${secure}`;
|
|
174
|
+
} catch {
|
|
175
|
+
// Without cookies the pick lasts until the page is closed.
|
|
176
|
+
}
|
|
177
|
+
}
|
|
@@ -2,7 +2,8 @@
|
|
|
2
2
|
* Texts of the privacy page (/privacy) and the cookie notice.
|
|
3
3
|
*
|
|
4
4
|
* The page describes what the storefront itself does: the account, orders,
|
|
5
|
-
* the
|
|
5
|
+
* the platform cookies (the session, the CSRF token, the language and
|
|
6
|
+
* currency the customer picked) and the notice's own storage mark. A store that
|
|
6
7
|
* adds analytics, chat widgets or other cookies lists them in the cookies
|
|
7
8
|
* section here. The operator is the store's company from the platform's
|
|
8
9
|
* contact details; `{company}` in a text is replaced with its name.
|
|
@@ -89,7 +90,7 @@ const ru: PrivacyLabels = {
|
|
|
89
90
|
id: 'cookies',
|
|
90
91
|
title: '7. Cookie и локальное хранилище',
|
|
91
92
|
text: [
|
|
92
|
-
'Сайт использует только необходимые для работы cookie: sessionid сохраняет вход в аккаунт, csrftoken защищает формы от подделки запросов.',
|
|
93
|
+
'Сайт использует только необходимые для работы cookie: sessionid сохраняет вход в аккаунт, csrftoken защищает формы от подделки запросов. Если вы сами выберете язык или валюту, cookie basklee_locale и basklee_currency запомнят выбор на год, чтобы сайт открывался с ним.',
|
|
93
94
|
'В локальном хранилище браузера сохраняется отметка о том, что вы видели уведомление о cookie. Рекламных и аналитических cookie нет. Если запретить cookie, вход и оформление заказа не будут работать.',
|
|
94
95
|
],
|
|
95
96
|
},
|
|
@@ -103,7 +104,7 @@ const ru: PrivacyLabels = {
|
|
|
103
104
|
],
|
|
104
105
|
cookie: {
|
|
105
106
|
label: 'Уведомление о cookie',
|
|
106
|
-
text: 'Сайт использует только необходимые cookie: для входа в
|
|
107
|
+
text: 'Сайт использует только необходимые cookie: для входа в аккаунт, защиты форм и чтобы запомнить выбранные вами язык и валюту.',
|
|
107
108
|
link: 'Подробнее',
|
|
108
109
|
ok: 'Понятно',
|
|
109
110
|
},
|
|
@@ -166,7 +167,7 @@ const es: PrivacyLabels = {
|
|
|
166
167
|
id: 'cookies',
|
|
167
168
|
title: '7. Cookies y almacenamiento local',
|
|
168
169
|
text: [
|
|
169
|
-
'El sitio solo usa las cookies que necesita para funcionar: sessionid mantiene tu sesión iniciada y csrftoken protege los formularios contra la falsificación de solicitudes.',
|
|
170
|
+
'El sitio solo usa las cookies que necesita para funcionar: sessionid mantiene tu sesión iniciada y csrftoken protege los formularios contra la falsificación de solicitudes. Si eliges tú el idioma o la moneda, las cookies basklee_locale y basklee_currency guardan tu elección durante un año para que el sitio se abra con ella.',
|
|
170
171
|
'El almacenamiento local del navegador guarda el hecho de que ya has visto el aviso de cookies. No hay cookies publicitarias ni de analítica. Si bloqueas las cookies, no funcionan el inicio de sesión ni la compra.',
|
|
171
172
|
],
|
|
172
173
|
},
|
|
@@ -178,7 +179,7 @@ const es: PrivacyLabels = {
|
|
|
178
179
|
],
|
|
179
180
|
cookie: {
|
|
180
181
|
label: 'Aviso de cookies',
|
|
181
|
-
text: 'El sitio solo usa las cookies que necesita: para iniciar tu sesión
|
|
182
|
+
text: 'El sitio solo usa las cookies que necesita: para iniciar tu sesión, proteger los formularios y recordar el idioma y la moneda que elijas.',
|
|
182
183
|
link: 'Más información',
|
|
183
184
|
ok: 'Aceptar',
|
|
184
185
|
},
|
|
@@ -241,7 +242,7 @@ const en: PrivacyLabels = {
|
|
|
241
242
|
id: 'cookies',
|
|
242
243
|
title: '7. Cookies and local storage',
|
|
243
244
|
text: [
|
|
244
|
-
'The site uses only the cookies it needs to work: sessionid keeps you signed in, csrftoken protects forms from request forgery.',
|
|
245
|
+
'The site uses only the cookies it needs to work: sessionid keeps you signed in, csrftoken protects forms from request forgery. When you pick a language or currency yourself, basklee_locale and basklee_currency keep the choice for a year, so the site opens with it.',
|
|
245
246
|
'The browser’s local storage keeps the fact that you have seen the cookie notice. There are no advertising or analytics cookies. If you block cookies, signing in and checking out do not work.',
|
|
246
247
|
],
|
|
247
248
|
},
|
|
@@ -253,7 +254,7 @@ const en: PrivacyLabels = {
|
|
|
253
254
|
],
|
|
254
255
|
cookie: {
|
|
255
256
|
label: 'Cookie notice',
|
|
256
|
-
text: 'The site uses only the cookies it needs: to sign you in and to
|
|
257
|
+
text: 'The site uses only the cookies it needs: to sign you in, to protect forms and to remember the language and currency you pick.',
|
|
257
258
|
link: 'Learn more',
|
|
258
259
|
ok: 'OK',
|
|
259
260
|
},
|
|
@@ -9,18 +9,24 @@ Field pages describe their data and usage with a physical interface reference.
|
|
|
9
9
|
Fields used by supplied components also link to their previews and source files.
|
|
10
10
|
Configuration and shared counters have dedicated data references.
|
|
11
11
|
|
|
12
|
-
The store chooses the
|
|
13
|
-
|
|
12
|
+
The store chooses the language and currency the customer picked on an earlier
|
|
13
|
+
visit (the `basklee_locale` and `basklee_currency` cookies), else the available
|
|
14
|
+
language closest to the browser's languages (the first available one when none
|
|
15
|
+
is close) and its default currency and units. A pick in `MainLanguageSwitcher`
|
|
16
|
+
or `MainCurrencySwitcher` is kept for a year; a language from the address
|
|
17
|
+
(`?locale`) is shown but not kept. `MainLanguageSwitcher` updates `store.localeCode` and replaces the current
|
|
14
18
|
currency and unit selections with that language's defaults;
|
|
15
19
|
`MainCurrencySwitcher` updates `store.currencyId`. `UnitSwitcher` uses
|
|
16
20
|
`kind="weights"` or `kind="lengths"` and updates `store.weightId` or
|
|
17
21
|
`store.lengthId`. Components react to the shared choice. `MainSearch` keeps its
|
|
18
22
|
query in `store.searchQuery`. These preferences persist across route changes in
|
|
19
23
|
the current session; `reset()` clears them. Refresh preserves choices that are
|
|
20
|
-
still available. Browser reload initializes them again
|
|
24
|
+
still available. Browser reload initializes them again, from the kept language
|
|
25
|
+
and currency first.
|
|
21
26
|
|
|
22
27
|
For explicit application controls, call `store.setLocale(code)`,
|
|
23
|
-
`store.setCurrency(id)` or `store.setUnit(kind, id)
|
|
28
|
+
`store.setCurrency(id)` or `store.setUnit(kind, id)`; pass `false` as the second
|
|
29
|
+
argument of `setLocale` or `setCurrency` to change the choice without keeping it. Navigation and translation
|
|
24
30
|
plugin integration remain your application's responsibility. Prices use the
|
|
25
31
|
backend's converted amounts for the selected currency.
|
|
26
32
|
|