@everymatrix/casino-search 0.0.367 → 0.0.368
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 +30 -30
- package/dist/casino-search.js +418 -418
- package/dist/casino-search.js.map +1 -1
- package/index.html +100 -100
- package/index.js +1 -1
- package/package.json +2 -2
- package/public/reset.css +47 -47
- package/rollup.config.js +59 -59
- package/src/CasinoSearch.svelte +415 -415
- package/src/i18n.js +27 -27
- package/src/index.ts +4 -4
- package/src/translations.js +193 -193
- package/stories/CasinoSearch.stories.js +13 -13
- package/tsconfig.json +6 -6
package/src/CasinoSearch.svelte
CHANGED
|
@@ -1,415 +1,415 @@
|
|
|
1
|
-
<svelte:options tag={null} />
|
|
2
|
-
|
|
3
|
-
<script lang="ts">
|
|
4
|
-
import { _, addNewMessages, setLocale } from './i18n';
|
|
5
|
-
import { Translations } from './translations.js';
|
|
6
|
-
import { getDevice } from 'rvhelper';
|
|
7
|
-
import { onMount } from 'svelte';
|
|
8
|
-
|
|
9
|
-
import '@everymatrix/casino-game-thumbnail';
|
|
10
|
-
|
|
11
|
-
export let endpoint:string = '';
|
|
12
|
-
export let datasource:string = '';
|
|
13
|
-
export let lang:string = 'en';
|
|
14
|
-
export let clientstyling:string = '';
|
|
15
|
-
export let clientstylingurl:string = '';
|
|
16
|
-
|
|
17
|
-
let userAgent:any = window.navigator.userAgent;
|
|
18
|
-
let searchArray:Array<any> = [];
|
|
19
|
-
let searchedValues:any = [];
|
|
20
|
-
let gamesCache:Object = {};
|
|
21
|
-
|
|
22
|
-
let searchValue:string = '';
|
|
23
|
-
let searchElement:HTMLElement;
|
|
24
|
-
let searchCancelled:boolean = true;
|
|
25
|
-
let searchActive:boolean = false;
|
|
26
|
-
|
|
27
|
-
let isLoading:boolean = false;
|
|
28
|
-
let customStylingContainer:HTMLElement;
|
|
29
|
-
|
|
30
|
-
Object.keys(Translations).forEach((item:any):void => {
|
|
31
|
-
addNewMessages(item, Translations[item]);
|
|
32
|
-
});
|
|
33
|
-
|
|
34
|
-
const messageHandler = (e:any):void => {
|
|
35
|
-
if (e.data && e.data.type == 'OpenGameFrame') {
|
|
36
|
-
addSearchedItem(e.data.gameId);
|
|
37
|
-
}
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
const onFocus = ():void => {
|
|
41
|
-
searchCancelled = false;
|
|
42
|
-
searchActive = true;
|
|
43
|
-
|
|
44
|
-
if (endpoint && datasource && lang) {
|
|
45
|
-
if (searchValue.length < 2) {
|
|
46
|
-
let recentSearchedGames = getCookieValue(`searchedGamesWds_casino`);
|
|
47
|
-
let recentSearchedGamesArray:Array<any> = [];
|
|
48
|
-
|
|
49
|
-
if (recentSearchedGames) {
|
|
50
|
-
recentSearchedGamesArray = recentSearchedGames.split(',');
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
let promises:Array<Promise<any>> = [];
|
|
54
|
-
let index = 0;
|
|
55
|
-
let length = recentSearchedGamesArray.length;
|
|
56
|
-
|
|
57
|
-
if (length > 0) {
|
|
58
|
-
for (index = 0; index < length; index++) {
|
|
59
|
-
let url:any = new URL(`${endpoint}/casino/games/${recentSearchedGamesArray[index]}`);
|
|
60
|
-
|
|
61
|
-
url.searchParams.append('language', lang);
|
|
62
|
-
url.searchParams.append('datasource', datasource);
|
|
63
|
-
url.searchParams.append('platform', getDevice(userAgent));
|
|
64
|
-
|
|
65
|
-
promises.push(getGame(url, recentSearchedGamesArray[index]));
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
Promise.all(promises).then((res:any):void => {
|
|
69
|
-
searchArray = res;
|
|
70
|
-
});
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
}
|
|
74
|
-
sendSearchStatus(searchActive);
|
|
75
|
-
}
|
|
76
|
-
|
|
77
|
-
const getGames = (url:URL):Promise<any> => {
|
|
78
|
-
return new Promise((resolve, reject):void => {
|
|
79
|
-
isLoading = true;
|
|
80
|
-
|
|
81
|
-
fetch(url.href)
|
|
82
|
-
.then((res:any) => res.json())
|
|
83
|
-
.then((games:any) => {
|
|
84
|
-
isLoading = false;
|
|
85
|
-
|
|
86
|
-
resolve(games);
|
|
87
|
-
}).catch((err:any) => {
|
|
88
|
-
isLoading = false;
|
|
89
|
-
|
|
90
|
-
console.error(err);
|
|
91
|
-
|
|
92
|
-
reject(err);
|
|
93
|
-
});
|
|
94
|
-
});
|
|
95
|
-
}
|
|
96
|
-
|
|
97
|
-
const getGame = (url:any, gameId?:string):Promise<any> => {
|
|
98
|
-
return new Promise((resolve, reject) => {
|
|
99
|
-
isLoading = true;
|
|
100
|
-
|
|
101
|
-
if (gameId && Object.keys(gamesCache).indexOf(gameId) >= 0) {
|
|
102
|
-
isLoading = false;
|
|
103
|
-
|
|
104
|
-
resolve(gamesCache[gameId]);
|
|
105
|
-
} else {
|
|
106
|
-
fetch(url)
|
|
107
|
-
.then(fetchRes => fetchRes.json())
|
|
108
|
-
.then(gameData => {
|
|
109
|
-
isLoading = false;
|
|
110
|
-
|
|
111
|
-
gamesCache[gameData[0].gameId] = gameData[0];
|
|
112
|
-
|
|
113
|
-
resolve(gameData[0]);
|
|
114
|
-
}).catch((err:any) => {
|
|
115
|
-
isLoading = false;
|
|
116
|
-
|
|
117
|
-
console.error(err);
|
|
118
|
-
|
|
119
|
-
reject(err);
|
|
120
|
-
});
|
|
121
|
-
}
|
|
122
|
-
});
|
|
123
|
-
}
|
|
124
|
-
|
|
125
|
-
const addSearchedItem = (gameID:any):void => {
|
|
126
|
-
searchedValues = getCookieValue(`searchedGamesWds_casino`);
|
|
127
|
-
|
|
128
|
-
if (searchedValues) {
|
|
129
|
-
searchedValues = searchedValues.split(',');
|
|
130
|
-
} else {
|
|
131
|
-
searchedValues = [];
|
|
132
|
-
}
|
|
133
|
-
|
|
134
|
-
if (searchedValues.indexOf(gameID) === -1) {
|
|
135
|
-
let value;
|
|
136
|
-
|
|
137
|
-
searchedValues.push(gameID);
|
|
138
|
-
value = searchedValues.join(',');
|
|
139
|
-
document.cookie = `searchedGamesWds_casino=` + value;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
const getCookieValue = (name:string):string => {
|
|
144
|
-
let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
|
|
145
|
-
|
|
146
|
-
if (match) {
|
|
147
|
-
return match[2];
|
|
148
|
-
}
|
|
149
|
-
}
|
|
150
|
-
|
|
151
|
-
const cancelSearch = ():void => {
|
|
152
|
-
searchValue = '';
|
|
153
|
-
searchCancelled = true;
|
|
154
|
-
isLoading = false;
|
|
155
|
-
searchArray = [];
|
|
156
|
-
searchActive = false;
|
|
157
|
-
|
|
158
|
-
sendSearchStatus(searchActive);
|
|
159
|
-
}
|
|
160
|
-
|
|
161
|
-
const clearSearch = ():void => {
|
|
162
|
-
searchValue = '';
|
|
163
|
-
searchElement.focus();
|
|
164
|
-
}
|
|
165
|
-
|
|
166
|
-
// --- Communication with other widgets
|
|
167
|
-
|
|
168
|
-
const sendSearchStatus = (searchStatus):void => {
|
|
169
|
-
window.postMessage({ type: searchStatus === true ? 'searchActive' : 'searchCancelled', searchStatus});
|
|
170
|
-
};
|
|
171
|
-
|
|
172
|
-
const setActiveLanguage = ():void => {
|
|
173
|
-
setLocale(lang);
|
|
174
|
-
}
|
|
175
|
-
|
|
176
|
-
const setClientStyling = ():void => {
|
|
177
|
-
let sheet = document.createElement('style');
|
|
178
|
-
sheet.innerHTML = clientstyling;
|
|
179
|
-
customStylingContainer.appendChild(sheet);
|
|
180
|
-
}
|
|
181
|
-
|
|
182
|
-
const setClientStylingURL = ():void => {
|
|
183
|
-
let url:URL = new URL(clientstylingurl);
|
|
184
|
-
let cssFile:HTMLElement = document.createElement('style');
|
|
185
|
-
|
|
186
|
-
fetch(url.href)
|
|
187
|
-
.then((res:any) => res.text())
|
|
188
|
-
.then((data:any) => {
|
|
189
|
-
cssFile.innerHTML = data
|
|
190
|
-
|
|
191
|
-
if (customStylingContainer) {
|
|
192
|
-
setTimeout(() => { customStylingContainer.appendChild(cssFile) }, 1);
|
|
193
|
-
}
|
|
194
|
-
});
|
|
195
|
-
}
|
|
196
|
-
|
|
197
|
-
$: if (searchValue.length >= 2) {
|
|
198
|
-
const searchUrl:URL = new URL(`${endpoint}/casino/games`);
|
|
199
|
-
|
|
200
|
-
searchUrl.searchParams.append("datasource", datasource);
|
|
201
|
-
searchUrl.searchParams.append("expand", "vendor");
|
|
202
|
-
searchUrl.searchParams.append("platform", getDevice(userAgent));
|
|
203
|
-
searchUrl.searchParams.append("language", lang);
|
|
204
|
-
searchUrl.searchParams.append("pagination", "offset=0,limit=30");
|
|
205
|
-
searchUrl.searchParams.append("filter", `name=${searchValue}`);
|
|
206
|
-
|
|
207
|
-
getGames(searchUrl).then((searchData:any) => {
|
|
208
|
-
searchArray = searchData.items.map((item) => item);
|
|
209
|
-
});
|
|
210
|
-
} else {
|
|
211
|
-
if (!searchCancelled) {
|
|
212
|
-
onFocus();
|
|
213
|
-
}
|
|
214
|
-
}
|
|
215
|
-
|
|
216
|
-
onMount(()=> {
|
|
217
|
-
window.addEventListener('message', messageHandler, false);
|
|
218
|
-
|
|
219
|
-
return () => {
|
|
220
|
-
window.removeEventListener('message', messageHandler);
|
|
221
|
-
}
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
$: lang && setActiveLanguage();
|
|
225
|
-
$: clientstyling && setClientStyling();
|
|
226
|
-
$: clientstylingurl && setClientStylingURL();
|
|
227
|
-
|
|
228
|
-
</script>
|
|
229
|
-
|
|
230
|
-
<div bind:this={customStylingContainer}>
|
|
231
|
-
<div class="CasinoSearch">
|
|
232
|
-
<div class="Search">
|
|
233
|
-
<div class="SearchIcon">
|
|
234
|
-
<svg width="14" height="15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
235
|
-
<path stroke="#212121" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="m10.48 10.985 2.21 2.373"/>
|
|
236
|
-
<circle cx="6.5" cy="6.5" r="5.75" stroke="#212121" stroke-width="1.5"/>
|
|
237
|
-
</svg>
|
|
238
|
-
</div>
|
|
239
|
-
<div class="SearchContainer">
|
|
240
|
-
<input class="SearchInput" type="search" placeholder="Search for Games" bind:value={searchValue} on:focus={onFocus} bind:this={searchElement}>
|
|
241
|
-
<span on:click={() => clearSearch()} class="SearchClearButton { searchValue.length != 0 ? '' : 'NotVisible'}">
|
|
242
|
-
<svg width="11" height="11" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
243
|
-
<path d="m1.45 1.5 8.1 8M1.45 9.5l8.1-8" stroke="#717171" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
244
|
-
</svg>
|
|
245
|
-
</span>
|
|
246
|
-
</div>
|
|
247
|
-
<small on:click={() => cancelSearch()} class="SearchCancelButton {searchCancelled ? 'NotVisible' : ''}">
|
|
248
|
-
{$_('Translations.cancel')}
|
|
249
|
-
</small>
|
|
250
|
-
</div>
|
|
251
|
-
{#if isLoading}
|
|
252
|
-
<p>{$_('Translations.loading')}</p>
|
|
253
|
-
{:else}
|
|
254
|
-
{#if searchActive == true && searchValue.length < 2}
|
|
255
|
-
<p class="SearchMessage">{$_('Translations.recentSearch')}</p>
|
|
256
|
-
{#if searchArray.length == 0}
|
|
257
|
-
<div class="ResultsContainerError">
|
|
258
|
-
<p class="SearchMessage">{$_('Translations.noRecentSearches')}</p>
|
|
259
|
-
</div>
|
|
260
|
-
{/if}
|
|
261
|
-
{:else if searchArray.length != 0}
|
|
262
|
-
<p class="SearchMessage">{$_('Translations.searchResult')}</p>
|
|
263
|
-
{/if}
|
|
264
|
-
<div class="SearchResultsContainer {searchActive == true ? '': 'NotVisible'}">
|
|
265
|
-
{#if searchCancelled === false}
|
|
266
|
-
{#each searchArray as game}
|
|
267
|
-
<casino-game-thumbnail
|
|
268
|
-
lang={lang}
|
|
269
|
-
gamethumbnail={game.thumbnail}
|
|
270
|
-
gamename={game.name}
|
|
271
|
-
gamevendor={game.vendor.name}
|
|
272
|
-
gameisnew={game.isNew}
|
|
273
|
-
gamepopularity={game.popularity}
|
|
274
|
-
gamecellsize={game.cellSize}
|
|
275
|
-
gameid={game.id}
|
|
276
|
-
gamefunmode={game.hasFunMode}
|
|
277
|
-
gamefavorite={game.isFavorite}
|
|
278
|
-
livelobbyendpoint={game.details ? game.launchUrl : ''}
|
|
279
|
-
endpoint={endpoint}
|
|
280
|
-
></casino-game-thumbnail>
|
|
281
|
-
{/each}
|
|
282
|
-
{/if}
|
|
283
|
-
{#if searchValue.length >= 2 && searchArray.length == 0}
|
|
284
|
-
<div class="ResultsContainerError">
|
|
285
|
-
<p class="SearchMessage">{$_('Translations.notFound')}</p>
|
|
286
|
-
<p>{$_('Translations.notFoundText')}</p>
|
|
287
|
-
</div>
|
|
288
|
-
{/if}
|
|
289
|
-
</div>
|
|
290
|
-
{/if}
|
|
291
|
-
</div>
|
|
292
|
-
</div>
|
|
293
|
-
|
|
294
|
-
<style lang="scss">
|
|
295
|
-
:host {
|
|
296
|
-
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
|
|
297
|
-
}
|
|
298
|
-
|
|
299
|
-
$color-grey: #717171;
|
|
300
|
-
$color-light-grey: #cacaca;
|
|
301
|
-
$color-black: #212121;
|
|
302
|
-
|
|
303
|
-
$grid-gap: 8px;
|
|
304
|
-
$grid-cell-size: 167px;
|
|
305
|
-
$grid-cell-size-small: 110px;
|
|
306
|
-
$grid-cell-size-medium: 122px;
|
|
307
|
-
|
|
308
|
-
*,
|
|
309
|
-
*::before,
|
|
310
|
-
*::after {
|
|
311
|
-
margin: 0;
|
|
312
|
-
padding: 0;
|
|
313
|
-
box-sizing: border-box;
|
|
314
|
-
}
|
|
315
|
-
|
|
316
|
-
.CasinoSearch {
|
|
317
|
-
margin: 16px;
|
|
318
|
-
}
|
|
319
|
-
|
|
320
|
-
.Search {
|
|
321
|
-
display: flex;
|
|
322
|
-
align-items: center;
|
|
323
|
-
position: relative;
|
|
324
|
-
justify-content: space-between;
|
|
325
|
-
margin-bottom: 20px;
|
|
326
|
-
|
|
327
|
-
&Icon{
|
|
328
|
-
position: absolute;
|
|
329
|
-
left: 5%;
|
|
330
|
-
z-index: 1;
|
|
331
|
-
|
|
332
|
-
svg {
|
|
333
|
-
height: 14px;
|
|
334
|
-
width: 13px;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
&Container {
|
|
338
|
-
width: 100%;
|
|
339
|
-
position: relative;
|
|
340
|
-
}
|
|
341
|
-
|
|
342
|
-
&Input {
|
|
343
|
-
border-radius: 4px;
|
|
344
|
-
border: 1px solid $color-light-grey;
|
|
345
|
-
color: $color-grey;
|
|
346
|
-
display: block;
|
|
347
|
-
font-size: 16px;
|
|
348
|
-
font-weight: 300;
|
|
349
|
-
padding: 14px 5px 14px 46px;
|
|
350
|
-
width:100%;
|
|
351
|
-
|
|
352
|
-
&::placeholder {
|
|
353
|
-
color: $color-grey;
|
|
354
|
-
font-size: 16px;
|
|
355
|
-
font-weight: 300;
|
|
356
|
-
}
|
|
357
|
-
|
|
358
|
-
&:focus {
|
|
359
|
-
outline: 1px solid #d9d7d7;
|
|
360
|
-
}
|
|
361
|
-
|
|
362
|
-
&::-webkit-search-decoration,
|
|
363
|
-
&::-webkit-search-cancel-button,
|
|
364
|
-
&::-webkit-search-results-button,
|
|
365
|
-
&::-webkit-search-results-decoration {
|
|
366
|
-
-webkit-appearance:none;
|
|
367
|
-
}
|
|
368
|
-
}
|
|
369
|
-
|
|
370
|
-
&ClearButton{
|
|
371
|
-
position: absolute;
|
|
372
|
-
top: 30%;
|
|
373
|
-
right: 15px;
|
|
374
|
-
}
|
|
375
|
-
|
|
376
|
-
&CancelButton {
|
|
377
|
-
color: $color-grey;
|
|
378
|
-
font-weight: 300;
|
|
379
|
-
margin-left: 8px;
|
|
380
|
-
}
|
|
381
|
-
|
|
382
|
-
&Message {
|
|
383
|
-
font-size: 18px;
|
|
384
|
-
font-weight: 600;
|
|
385
|
-
margin: 24px 0;
|
|
386
|
-
color: $color-black;
|
|
387
|
-
}
|
|
388
|
-
|
|
389
|
-
&ResultsContainer {
|
|
390
|
-
display: grid;
|
|
391
|
-
gap: $grid-gap;
|
|
392
|
-
grid-template-columns: repeat(auto-fill, minmax(Min($grid-cell-size, 46%), 1fr));
|
|
393
|
-
grid-template-rows: repeat(auto-fill, $grid-cell-size);
|
|
394
|
-
grid-auto-rows: $grid-cell-size;
|
|
395
|
-
grid-auto-columns: $grid-cell-size;
|
|
396
|
-
grid-auto-flow: row dense;
|
|
397
|
-
}
|
|
398
|
-
}
|
|
399
|
-
|
|
400
|
-
.ResultsContainerError {
|
|
401
|
-
text-align: center;
|
|
402
|
-
width: 300px;
|
|
403
|
-
color: $color-grey;
|
|
404
|
-
font-weight: 300;
|
|
405
|
-
position: absolute;
|
|
406
|
-
top: 50%;
|
|
407
|
-
left: 50%;
|
|
408
|
-
transform: translate(-50%, -50%);
|
|
409
|
-
}
|
|
410
|
-
|
|
411
|
-
.NotVisible {
|
|
412
|
-
display: none;
|
|
413
|
-
}
|
|
414
|
-
|
|
415
|
-
</style>
|
|
1
|
+
<svelte:options tag={null} />
|
|
2
|
+
|
|
3
|
+
<script lang="ts">
|
|
4
|
+
import { _, addNewMessages, setLocale } from './i18n';
|
|
5
|
+
import { Translations } from './translations.js';
|
|
6
|
+
import { getDevice } from 'rvhelper';
|
|
7
|
+
import { onMount } from 'svelte';
|
|
8
|
+
|
|
9
|
+
import '@everymatrix/casino-game-thumbnail';
|
|
10
|
+
|
|
11
|
+
export let endpoint:string = '';
|
|
12
|
+
export let datasource:string = '';
|
|
13
|
+
export let lang:string = 'en';
|
|
14
|
+
export let clientstyling:string = '';
|
|
15
|
+
export let clientstylingurl:string = '';
|
|
16
|
+
|
|
17
|
+
let userAgent:any = window.navigator.userAgent;
|
|
18
|
+
let searchArray:Array<any> = [];
|
|
19
|
+
let searchedValues:any = [];
|
|
20
|
+
let gamesCache:Object = {};
|
|
21
|
+
|
|
22
|
+
let searchValue:string = '';
|
|
23
|
+
let searchElement:HTMLElement;
|
|
24
|
+
let searchCancelled:boolean = true;
|
|
25
|
+
let searchActive:boolean = false;
|
|
26
|
+
|
|
27
|
+
let isLoading:boolean = false;
|
|
28
|
+
let customStylingContainer:HTMLElement;
|
|
29
|
+
|
|
30
|
+
Object.keys(Translations).forEach((item:any):void => {
|
|
31
|
+
addNewMessages(item, Translations[item]);
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
const messageHandler = (e:any):void => {
|
|
35
|
+
if (e.data && e.data.type == 'OpenGameFrame') {
|
|
36
|
+
addSearchedItem(e.data.gameId);
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
const onFocus = ():void => {
|
|
41
|
+
searchCancelled = false;
|
|
42
|
+
searchActive = true;
|
|
43
|
+
|
|
44
|
+
if (endpoint && datasource && lang) {
|
|
45
|
+
if (searchValue.length < 2) {
|
|
46
|
+
let recentSearchedGames = getCookieValue(`searchedGamesWds_casino`);
|
|
47
|
+
let recentSearchedGamesArray:Array<any> = [];
|
|
48
|
+
|
|
49
|
+
if (recentSearchedGames) {
|
|
50
|
+
recentSearchedGamesArray = recentSearchedGames.split(',');
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
let promises:Array<Promise<any>> = [];
|
|
54
|
+
let index = 0;
|
|
55
|
+
let length = recentSearchedGamesArray.length;
|
|
56
|
+
|
|
57
|
+
if (length > 0) {
|
|
58
|
+
for (index = 0; index < length; index++) {
|
|
59
|
+
let url:any = new URL(`${endpoint}/casino/games/${recentSearchedGamesArray[index]}`);
|
|
60
|
+
|
|
61
|
+
url.searchParams.append('language', lang);
|
|
62
|
+
url.searchParams.append('datasource', datasource);
|
|
63
|
+
url.searchParams.append('platform', getDevice(userAgent));
|
|
64
|
+
|
|
65
|
+
promises.push(getGame(url, recentSearchedGamesArray[index]));
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
Promise.all(promises).then((res:any):void => {
|
|
69
|
+
searchArray = res;
|
|
70
|
+
});
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
sendSearchStatus(searchActive);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
const getGames = (url:URL):Promise<any> => {
|
|
78
|
+
return new Promise((resolve, reject):void => {
|
|
79
|
+
isLoading = true;
|
|
80
|
+
|
|
81
|
+
fetch(url.href)
|
|
82
|
+
.then((res:any) => res.json())
|
|
83
|
+
.then((games:any) => {
|
|
84
|
+
isLoading = false;
|
|
85
|
+
|
|
86
|
+
resolve(games);
|
|
87
|
+
}).catch((err:any) => {
|
|
88
|
+
isLoading = false;
|
|
89
|
+
|
|
90
|
+
console.error(err);
|
|
91
|
+
|
|
92
|
+
reject(err);
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
const getGame = (url:any, gameId?:string):Promise<any> => {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
|
+
isLoading = true;
|
|
100
|
+
|
|
101
|
+
if (gameId && Object.keys(gamesCache).indexOf(gameId) >= 0) {
|
|
102
|
+
isLoading = false;
|
|
103
|
+
|
|
104
|
+
resolve(gamesCache[gameId]);
|
|
105
|
+
} else {
|
|
106
|
+
fetch(url)
|
|
107
|
+
.then(fetchRes => fetchRes.json())
|
|
108
|
+
.then(gameData => {
|
|
109
|
+
isLoading = false;
|
|
110
|
+
|
|
111
|
+
gamesCache[gameData[0].gameId] = gameData[0];
|
|
112
|
+
|
|
113
|
+
resolve(gameData[0]);
|
|
114
|
+
}).catch((err:any) => {
|
|
115
|
+
isLoading = false;
|
|
116
|
+
|
|
117
|
+
console.error(err);
|
|
118
|
+
|
|
119
|
+
reject(err);
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
});
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
const addSearchedItem = (gameID:any):void => {
|
|
126
|
+
searchedValues = getCookieValue(`searchedGamesWds_casino`);
|
|
127
|
+
|
|
128
|
+
if (searchedValues) {
|
|
129
|
+
searchedValues = searchedValues.split(',');
|
|
130
|
+
} else {
|
|
131
|
+
searchedValues = [];
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
if (searchedValues.indexOf(gameID) === -1) {
|
|
135
|
+
let value;
|
|
136
|
+
|
|
137
|
+
searchedValues.push(gameID);
|
|
138
|
+
value = searchedValues.join(',');
|
|
139
|
+
document.cookie = `searchedGamesWds_casino=` + value;
|
|
140
|
+
}
|
|
141
|
+
}
|
|
142
|
+
|
|
143
|
+
const getCookieValue = (name:string):string => {
|
|
144
|
+
let match = document.cookie.match(new RegExp('(^| )' + name + '=([^;]+)'));
|
|
145
|
+
|
|
146
|
+
if (match) {
|
|
147
|
+
return match[2];
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
const cancelSearch = ():void => {
|
|
152
|
+
searchValue = '';
|
|
153
|
+
searchCancelled = true;
|
|
154
|
+
isLoading = false;
|
|
155
|
+
searchArray = [];
|
|
156
|
+
searchActive = false;
|
|
157
|
+
|
|
158
|
+
sendSearchStatus(searchActive);
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const clearSearch = ():void => {
|
|
162
|
+
searchValue = '';
|
|
163
|
+
searchElement.focus();
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
// --- Communication with other widgets
|
|
167
|
+
|
|
168
|
+
const sendSearchStatus = (searchStatus):void => {
|
|
169
|
+
window.postMessage({ type: searchStatus === true ? 'searchActive' : 'searchCancelled', searchStatus});
|
|
170
|
+
};
|
|
171
|
+
|
|
172
|
+
const setActiveLanguage = ():void => {
|
|
173
|
+
setLocale(lang);
|
|
174
|
+
}
|
|
175
|
+
|
|
176
|
+
const setClientStyling = ():void => {
|
|
177
|
+
let sheet = document.createElement('style');
|
|
178
|
+
sheet.innerHTML = clientstyling;
|
|
179
|
+
customStylingContainer.appendChild(sheet);
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
const setClientStylingURL = ():void => {
|
|
183
|
+
let url:URL = new URL(clientstylingurl);
|
|
184
|
+
let cssFile:HTMLElement = document.createElement('style');
|
|
185
|
+
|
|
186
|
+
fetch(url.href)
|
|
187
|
+
.then((res:any) => res.text())
|
|
188
|
+
.then((data:any) => {
|
|
189
|
+
cssFile.innerHTML = data
|
|
190
|
+
|
|
191
|
+
if (customStylingContainer) {
|
|
192
|
+
setTimeout(() => { customStylingContainer.appendChild(cssFile) }, 1);
|
|
193
|
+
}
|
|
194
|
+
});
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
$: if (searchValue.length >= 2) {
|
|
198
|
+
const searchUrl:URL = new URL(`${endpoint}/casino/games`);
|
|
199
|
+
|
|
200
|
+
searchUrl.searchParams.append("datasource", datasource);
|
|
201
|
+
searchUrl.searchParams.append("expand", "vendor");
|
|
202
|
+
searchUrl.searchParams.append("platform", getDevice(userAgent));
|
|
203
|
+
searchUrl.searchParams.append("language", lang);
|
|
204
|
+
searchUrl.searchParams.append("pagination", "offset=0,limit=30");
|
|
205
|
+
searchUrl.searchParams.append("filter", `name=${searchValue}`);
|
|
206
|
+
|
|
207
|
+
getGames(searchUrl).then((searchData:any) => {
|
|
208
|
+
searchArray = searchData.items.map((item) => item);
|
|
209
|
+
});
|
|
210
|
+
} else {
|
|
211
|
+
if (!searchCancelled) {
|
|
212
|
+
onFocus();
|
|
213
|
+
}
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
onMount(()=> {
|
|
217
|
+
window.addEventListener('message', messageHandler, false);
|
|
218
|
+
|
|
219
|
+
return () => {
|
|
220
|
+
window.removeEventListener('message', messageHandler);
|
|
221
|
+
}
|
|
222
|
+
});
|
|
223
|
+
|
|
224
|
+
$: lang && setActiveLanguage();
|
|
225
|
+
$: clientstyling && setClientStyling();
|
|
226
|
+
$: clientstylingurl && setClientStylingURL();
|
|
227
|
+
|
|
228
|
+
</script>
|
|
229
|
+
|
|
230
|
+
<div bind:this={customStylingContainer}>
|
|
231
|
+
<div class="CasinoSearch">
|
|
232
|
+
<div class="Search">
|
|
233
|
+
<div class="SearchIcon">
|
|
234
|
+
<svg width="14" height="15" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
235
|
+
<path stroke="#212121" stroke-width="2" stroke-linecap="round" stroke-linejoin="round" d="m10.48 10.985 2.21 2.373"/>
|
|
236
|
+
<circle cx="6.5" cy="6.5" r="5.75" stroke="#212121" stroke-width="1.5"/>
|
|
237
|
+
</svg>
|
|
238
|
+
</div>
|
|
239
|
+
<div class="SearchContainer">
|
|
240
|
+
<input class="SearchInput" type="search" placeholder="Search for Games" bind:value={searchValue} on:focus={onFocus} bind:this={searchElement}>
|
|
241
|
+
<span on:click={() => clearSearch()} class="SearchClearButton { searchValue.length != 0 ? '' : 'NotVisible'}">
|
|
242
|
+
<svg width="11" height="11" fill="none" xmlns="http://www.w3.org/2000/svg">
|
|
243
|
+
<path d="m1.45 1.5 8.1 8M1.45 9.5l8.1-8" stroke="#717171" stroke-width="2" stroke-linecap="round" stroke-linejoin="round"/>
|
|
244
|
+
</svg>
|
|
245
|
+
</span>
|
|
246
|
+
</div>
|
|
247
|
+
<small on:click={() => cancelSearch()} class="SearchCancelButton {searchCancelled ? 'NotVisible' : ''}">
|
|
248
|
+
{$_('Translations.cancel')}
|
|
249
|
+
</small>
|
|
250
|
+
</div>
|
|
251
|
+
{#if isLoading}
|
|
252
|
+
<p>{$_('Translations.loading')}</p>
|
|
253
|
+
{:else}
|
|
254
|
+
{#if searchActive == true && searchValue.length < 2}
|
|
255
|
+
<p class="SearchMessage">{$_('Translations.recentSearch')}</p>
|
|
256
|
+
{#if searchArray.length == 0}
|
|
257
|
+
<div class="ResultsContainerError">
|
|
258
|
+
<p class="SearchMessage">{$_('Translations.noRecentSearches')}</p>
|
|
259
|
+
</div>
|
|
260
|
+
{/if}
|
|
261
|
+
{:else if searchArray.length != 0}
|
|
262
|
+
<p class="SearchMessage">{$_('Translations.searchResult')}</p>
|
|
263
|
+
{/if}
|
|
264
|
+
<div class="SearchResultsContainer {searchActive == true ? '': 'NotVisible'}">
|
|
265
|
+
{#if searchCancelled === false}
|
|
266
|
+
{#each searchArray as game}
|
|
267
|
+
<casino-game-thumbnail
|
|
268
|
+
lang={lang}
|
|
269
|
+
gamethumbnail={game.thumbnail}
|
|
270
|
+
gamename={game.name}
|
|
271
|
+
gamevendor={game.vendor.name}
|
|
272
|
+
gameisnew={game.isNew}
|
|
273
|
+
gamepopularity={game.popularity}
|
|
274
|
+
gamecellsize={game.cellSize}
|
|
275
|
+
gameid={game.id}
|
|
276
|
+
gamefunmode={game.hasFunMode}
|
|
277
|
+
gamefavorite={game.isFavorite}
|
|
278
|
+
livelobbyendpoint={game.details ? game.launchUrl : ''}
|
|
279
|
+
endpoint={endpoint}
|
|
280
|
+
></casino-game-thumbnail>
|
|
281
|
+
{/each}
|
|
282
|
+
{/if}
|
|
283
|
+
{#if searchValue.length >= 2 && searchArray.length == 0}
|
|
284
|
+
<div class="ResultsContainerError">
|
|
285
|
+
<p class="SearchMessage">{$_('Translations.notFound')}</p>
|
|
286
|
+
<p>{$_('Translations.notFoundText')}</p>
|
|
287
|
+
</div>
|
|
288
|
+
{/if}
|
|
289
|
+
</div>
|
|
290
|
+
{/if}
|
|
291
|
+
</div>
|
|
292
|
+
</div>
|
|
293
|
+
|
|
294
|
+
<style lang="scss">
|
|
295
|
+
:host {
|
|
296
|
+
font-family: system-ui, -apple-system, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif, 'Apple Color Emoji', 'Segoe UI Emoji';
|
|
297
|
+
}
|
|
298
|
+
|
|
299
|
+
$color-grey: #717171;
|
|
300
|
+
$color-light-grey: #cacaca;
|
|
301
|
+
$color-black: #212121;
|
|
302
|
+
|
|
303
|
+
$grid-gap: 8px;
|
|
304
|
+
$grid-cell-size: 167px;
|
|
305
|
+
$grid-cell-size-small: 110px;
|
|
306
|
+
$grid-cell-size-medium: 122px;
|
|
307
|
+
|
|
308
|
+
*,
|
|
309
|
+
*::before,
|
|
310
|
+
*::after {
|
|
311
|
+
margin: 0;
|
|
312
|
+
padding: 0;
|
|
313
|
+
box-sizing: border-box;
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
.CasinoSearch {
|
|
317
|
+
margin: 16px;
|
|
318
|
+
}
|
|
319
|
+
|
|
320
|
+
.Search {
|
|
321
|
+
display: flex;
|
|
322
|
+
align-items: center;
|
|
323
|
+
position: relative;
|
|
324
|
+
justify-content: space-between;
|
|
325
|
+
margin-bottom: 20px;
|
|
326
|
+
|
|
327
|
+
&Icon{
|
|
328
|
+
position: absolute;
|
|
329
|
+
left: 5%;
|
|
330
|
+
z-index: 1;
|
|
331
|
+
|
|
332
|
+
svg {
|
|
333
|
+
height: 14px;
|
|
334
|
+
width: 13px;
|
|
335
|
+
}
|
|
336
|
+
}
|
|
337
|
+
&Container {
|
|
338
|
+
width: 100%;
|
|
339
|
+
position: relative;
|
|
340
|
+
}
|
|
341
|
+
|
|
342
|
+
&Input {
|
|
343
|
+
border-radius: 4px;
|
|
344
|
+
border: 1px solid $color-light-grey;
|
|
345
|
+
color: $color-grey;
|
|
346
|
+
display: block;
|
|
347
|
+
font-size: 16px;
|
|
348
|
+
font-weight: 300;
|
|
349
|
+
padding: 14px 5px 14px 46px;
|
|
350
|
+
width:100%;
|
|
351
|
+
|
|
352
|
+
&::placeholder {
|
|
353
|
+
color: $color-grey;
|
|
354
|
+
font-size: 16px;
|
|
355
|
+
font-weight: 300;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
&:focus {
|
|
359
|
+
outline: 1px solid #d9d7d7;
|
|
360
|
+
}
|
|
361
|
+
|
|
362
|
+
&::-webkit-search-decoration,
|
|
363
|
+
&::-webkit-search-cancel-button,
|
|
364
|
+
&::-webkit-search-results-button,
|
|
365
|
+
&::-webkit-search-results-decoration {
|
|
366
|
+
-webkit-appearance:none;
|
|
367
|
+
}
|
|
368
|
+
}
|
|
369
|
+
|
|
370
|
+
&ClearButton{
|
|
371
|
+
position: absolute;
|
|
372
|
+
top: 30%;
|
|
373
|
+
right: 15px;
|
|
374
|
+
}
|
|
375
|
+
|
|
376
|
+
&CancelButton {
|
|
377
|
+
color: $color-grey;
|
|
378
|
+
font-weight: 300;
|
|
379
|
+
margin-left: 8px;
|
|
380
|
+
}
|
|
381
|
+
|
|
382
|
+
&Message {
|
|
383
|
+
font-size: 18px;
|
|
384
|
+
font-weight: 600;
|
|
385
|
+
margin: 24px 0;
|
|
386
|
+
color: $color-black;
|
|
387
|
+
}
|
|
388
|
+
|
|
389
|
+
&ResultsContainer {
|
|
390
|
+
display: grid;
|
|
391
|
+
gap: $grid-gap;
|
|
392
|
+
grid-template-columns: repeat(auto-fill, minmax(Min($grid-cell-size, 46%), 1fr));
|
|
393
|
+
grid-template-rows: repeat(auto-fill, $grid-cell-size);
|
|
394
|
+
grid-auto-rows: $grid-cell-size;
|
|
395
|
+
grid-auto-columns: $grid-cell-size;
|
|
396
|
+
grid-auto-flow: row dense;
|
|
397
|
+
}
|
|
398
|
+
}
|
|
399
|
+
|
|
400
|
+
.ResultsContainerError {
|
|
401
|
+
text-align: center;
|
|
402
|
+
width: 300px;
|
|
403
|
+
color: $color-grey;
|
|
404
|
+
font-weight: 300;
|
|
405
|
+
position: absolute;
|
|
406
|
+
top: 50%;
|
|
407
|
+
left: 50%;
|
|
408
|
+
transform: translate(-50%, -50%);
|
|
409
|
+
}
|
|
410
|
+
|
|
411
|
+
.NotVisible {
|
|
412
|
+
display: none;
|
|
413
|
+
}
|
|
414
|
+
|
|
415
|
+
</style>
|