@playpilot/tpi 6.4.0-beta.6 → 6.4.0-beta.8
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/package.json
CHANGED
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
const targetThreshold = 0.7
|
|
7
7
|
const posterSelector = '[data-playpilot-poster]'
|
|
8
8
|
|
|
9
|
+
let postersShownForLink: Record<string, HTMLElement> = {}
|
|
9
10
|
let scrollTimeout: ReturnType<typeof setTimeout> | null = null
|
|
10
11
|
|
|
11
12
|
onMount(() => {
|
|
@@ -33,18 +34,21 @@
|
|
|
33
34
|
for (const link of linksWithinTargetViewport) {
|
|
34
35
|
if (linksWithCurrentlyVisiblePosters.has(link)) continue
|
|
35
36
|
|
|
36
|
-
|
|
37
|
+
const posterUrl = link.dataset.playpilotPosterUrl!
|
|
38
|
+
|
|
39
|
+
if (posterUrl in postersShownForLink && postersShownForLink[posterUrl] !== link) continue
|
|
40
|
+
|
|
41
|
+
createPosterForLink(link, posterUrl)
|
|
37
42
|
linksWithCurrentlyVisiblePosters.add(link)
|
|
43
|
+
postersShownForLink[posterUrl] = link
|
|
38
44
|
}
|
|
39
45
|
}
|
|
40
46
|
|
|
41
|
-
function createPosterForLink(link: HTMLElement): void {
|
|
42
|
-
const posterUrl = link.dataset.playpilotPosterUrl!
|
|
43
|
-
|
|
47
|
+
function createPosterForLink(link: HTMLElement, src: string): void {
|
|
44
48
|
const element = document.createElement('img')
|
|
45
49
|
element.classList.add('playpilot-floating-poster')
|
|
46
50
|
element.dataset.playpilotPoster = ''
|
|
47
|
-
element.src =
|
|
51
|
+
element.src = src
|
|
48
52
|
element.alt = ''
|
|
49
53
|
element.onload = () => element.classList.add('loaded')
|
|
50
54
|
|
|
@@ -74,8 +78,9 @@
|
|
|
74
78
|
for (const link of linksWithCurrentlyVisiblePosters) {
|
|
75
79
|
destroyPosterForLink(link)
|
|
76
80
|
linksWithCurrentlyVisiblePosters.delete(link)
|
|
81
|
+
postersShownForLink = {}
|
|
77
82
|
}
|
|
78
|
-
},
|
|
83
|
+
}, 1000)
|
|
79
84
|
}
|
|
80
85
|
</script>
|
|
81
86
|
|
|
@@ -70,12 +70,12 @@ describe('FloatingPoster', () => {
|
|
|
70
70
|
})
|
|
71
71
|
|
|
72
72
|
it('Should create poster for each link in viewport', async () => {
|
|
73
|
-
createPosterLink(10)
|
|
74
|
-
createPosterLink(500)
|
|
75
|
-
createPosterLink(500)
|
|
76
|
-
createPosterLink(510)
|
|
77
|
-
createPosterLink(520)
|
|
78
|
-
createPosterLink(2000)
|
|
73
|
+
createPosterLink(10, '0.jpg')
|
|
74
|
+
createPosterLink(500, '1.jpg')
|
|
75
|
+
createPosterLink(500, '2.jpg')
|
|
76
|
+
createPosterLink(510, '3.jpg')
|
|
77
|
+
createPosterLink(520, '4.jpg')
|
|
78
|
+
createPosterLink(2000, '5.jpg')
|
|
79
79
|
|
|
80
80
|
render(PostersScrollReveal)
|
|
81
81
|
|
|
@@ -84,6 +84,19 @@ describe('FloatingPoster', () => {
|
|
|
84
84
|
expect(document.querySelectorAll('[data-playpilot-poster]')).toHaveLength(4)
|
|
85
85
|
})
|
|
86
86
|
|
|
87
|
+
it('Should create poster only for unique poster urls', async () => {
|
|
88
|
+
createPosterLink(500, '1.jpg')
|
|
89
|
+
createPosterLink(500, '1.jpg')
|
|
90
|
+
createPosterLink(510, '2.jpg')
|
|
91
|
+
createPosterLink(520, '2.jpg')
|
|
92
|
+
|
|
93
|
+
render(PostersScrollReveal)
|
|
94
|
+
|
|
95
|
+
window.dispatchEvent(new Event('scroll'))
|
|
96
|
+
|
|
97
|
+
expect(document.querySelectorAll('[data-playpilot-poster]')).toHaveLength(2)
|
|
98
|
+
})
|
|
99
|
+
|
|
87
100
|
it('Should hide poster after not scrolling for given timeout', async () => {
|
|
88
101
|
createPosterLink(500)
|
|
89
102
|
|