@everymatrix/casino-slider 0.0.221 → 0.0.225
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/dist/casino-slider.js +1 -1
- package/dist/casino-slider.js.map +1 -1
- package/package.json +2 -2
- package/src/CasinoSlider.svelte +31 -28
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@everymatrix/casino-slider",
|
3
|
-
"version": "0.0.
|
3
|
+
"version": "0.0.225",
|
4
4
|
"main": "dist/casino-slider.js",
|
5
5
|
"svelte": "src/index.ts",
|
6
6
|
"scripts": {
|
@@ -36,5 +36,5 @@
|
|
36
36
|
"publishConfig": {
|
37
37
|
"access": "public"
|
38
38
|
},
|
39
|
-
"gitHead": "
|
39
|
+
"gitHead": "f58cef61f569c3d9b496becafc3ab9e93cb5eca7"
|
40
40
|
}
|
package/src/CasinoSlider.svelte
CHANGED
@@ -4,65 +4,61 @@
|
|
4
4
|
import { onMount } from 'svelte';
|
5
5
|
import { getDevice } from 'rvhelper';
|
6
6
|
|
7
|
-
export let
|
8
|
-
export let onclickeventname:string = 'defaultEvent';
|
7
|
+
export let actionevent:string = 'defaultEvent';
|
9
8
|
export let favoritesnumber:string = '0';
|
10
9
|
export let location:string = '';
|
11
10
|
export let clientstyling:string = '';
|
12
11
|
export let clientstylingurl:string = '';
|
13
12
|
export let identity:string = '';
|
14
13
|
export let containermaxwidth:string = '';
|
14
|
+
export let activeindex:string = '';
|
15
15
|
|
16
|
-
let userAgent:
|
17
|
-
let isMobile = (getDevice(userAgent) === 'PC') ? false : true;
|
16
|
+
let userAgent:string = window.navigator.userAgent;
|
17
|
+
let isMobile:boolean = (getDevice(userAgent) === 'PC') ? false : true;
|
18
|
+
let sliderdata:string = '';
|
18
19
|
|
19
20
|
let carousel:any;
|
20
|
-
let
|
21
|
+
let activeIndex:number;
|
21
22
|
let customStylingContainer:HTMLElement;
|
22
23
|
|
23
24
|
// Clicking on the slider item will trigger this method and send a postmessage on window
|
24
25
|
// @TODO itemId type fix
|
25
|
-
let handleClick = (
|
26
|
-
|
26
|
+
let handleClick = (item:any, index:number):void => {
|
27
|
+
activeIndex = index;
|
27
28
|
|
28
|
-
window.postMessage({ type:
|
29
|
+
window.postMessage({ type: actionevent, itemId: item.id, index, item }, window.location.href);
|
29
30
|
};
|
30
31
|
|
31
|
-
|
32
|
-
if (e.data && e.data.type == "SetSliderIndex") {
|
33
|
-
active = e.data.categoryData ? sliderdata.map((e) => { return e.id; }).indexOf(e.data.categoryData.id) : 0;
|
34
|
-
}
|
35
|
-
|
36
|
-
if (e.data && e.data.type == `SetSliderIndex_${identity}`) {
|
37
|
-
active = e.data.index;
|
38
|
-
}
|
39
|
-
}
|
40
|
-
|
41
|
-
let scrollLeft = () => {
|
32
|
+
let scrollLeft = ():void => {
|
42
33
|
carousel.scrollBy({
|
43
|
-
left: -
|
34
|
+
left: -250,
|
44
35
|
behavior: 'smooth'
|
45
36
|
});
|
46
37
|
}
|
47
38
|
|
48
|
-
let scrollRight = () => {
|
39
|
+
let scrollRight = ():void => {
|
49
40
|
carousel.scrollBy({
|
50
|
-
left: +
|
41
|
+
left: +250,
|
51
42
|
behavior: 'smooth'
|
52
43
|
});
|
53
44
|
}
|
54
45
|
|
55
|
-
const
|
46
|
+
const setActiveIndex = ():void => {
|
47
|
+
activeIndex = parseInt(activeindex, 10);
|
48
|
+
}
|
49
|
+
|
50
|
+
const setClientStyling = ():void => {
|
56
51
|
let sheet = document.createElement('style');
|
57
52
|
sheet.innerHTML = clientstyling;
|
58
53
|
setTimeout(() => { customStylingContainer.appendChild(sheet); });
|
59
54
|
}
|
60
55
|
|
61
|
-
const setClientStylingURL = () => {
|
56
|
+
const setClientStylingURL = ():void => {
|
62
57
|
let cssFile = document.createElement('style');
|
58
|
+
let url:URL = new URL(clientstylingurl);
|
63
59
|
|
64
60
|
if (clientstylingurl) {
|
65
|
-
fetch(
|
61
|
+
fetch(url.href)
|
66
62
|
.then((res:any) => res.text())
|
67
63
|
.then((data:any) => {
|
68
64
|
cssFile.innerHTML = data
|
@@ -72,14 +68,21 @@
|
|
72
68
|
}
|
73
69
|
}
|
74
70
|
|
71
|
+
const messageHandler = (e:any) => {
|
72
|
+
if (e.data.type == 'SliderData' && e.data.identity == identity) {
|
73
|
+
sliderdata = e.data.data;
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
75
77
|
onMount(() => {
|
76
78
|
window.addEventListener('message', messageHandler, false);
|
77
79
|
|
78
80
|
return () => {
|
79
81
|
window.removeEventListener('message', messageHandler);
|
80
82
|
}
|
81
|
-
})
|
83
|
+
})
|
82
84
|
|
85
|
+
$: (activeindex || activeindex == 0) && setActiveIndex();
|
83
86
|
$: clientstyling && setClientStyling();
|
84
87
|
$: clientstylingurl && setClientStylingURL();
|
85
88
|
</script>
|
@@ -95,9 +98,9 @@
|
|
95
98
|
<ul class="CarouselItems" bind:this={carousel}>
|
96
99
|
{#if sliderdata.length > 0}
|
97
100
|
{#each sliderdata as item, index (item.id)}
|
98
|
-
<li class="CarouselItem" class:active={
|
101
|
+
<li class="CarouselItem" class:active={activeIndex == index} on:click={e => handleClick(item, index)}>
|
99
102
|
{#if location === 'headerMain'}
|
100
|
-
<a
|
103
|
+
<a>{item.label}</a>
|
101
104
|
{:else}
|
102
105
|
{item.name} {item.id === "FAVORITES" ? "(" + favoritesnumber + ")" : ''}
|
103
106
|
{/if}
|